-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmodel.rs
More file actions
3132 lines (2768 loc) · 105 KB
/
model.rs
File metadata and controls
3132 lines (2768 loc) · 105 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use std::sync::Arc;
use chrono::naive::NaiveDate;
use juniper::{FieldError, FieldResult};
use uuid::Uuid;
use zitadel::actix::introspection::IntrospectedUser;
use super::types::inputs::{
ContributionOrderBy, Convert, Direction, FundingOrderBy, IssueOrderBy, LanguageOrderBy,
LengthUnit, PriceOrderBy, SubjectOrderBy, TimeExpression, WeightUnit,
};
use crate::db::PgPool;
use crate::markup::{convert_from_jats, ConversionLimit, MarkupFormat};
use crate::model::{
additional_resource::{AdditionalResource, AdditionalResourceOrderBy},
affiliation::{Affiliation, AffiliationOrderBy},
award::{Award, AwardOrderBy, AwardRole},
biography::{Biography, BiographyOrderBy},
book_review::{BookReview, BookReviewOrderBy},
contact::{Contact, ContactOrderBy, ContactType},
contribution::{Contribution, ContributionType},
contributor::Contributor,
endorsement::{Endorsement, EndorsementOrderBy},
file::{ChecksumAlgorithm, File, FileType},
funding::Funding,
imprint::{Imprint, ImprintField, ImprintOrderBy},
institution::Institution,
issue::Issue,
language::{Language, LanguageCode, LanguageRelation},
locale::LocaleCode,
location::{Location, LocationOrderBy, LocationPlatform},
price::{CurrencyCode, Price},
publication::{
AccessibilityException, AccessibilityStandard, Publication, PublicationOrderBy,
PublicationType,
},
publisher::Publisher,
r#abstract::{Abstract, AbstractOrderBy, AbstractType},
reference::{Reference, ReferenceOrderBy},
series::{Series, SeriesType},
subject::{Subject, SubjectType},
title::{Title, TitleOrderBy},
work::{Work, WorkOrderBy, WorkStatus, WorkType},
work_featured_video::WorkFeaturedVideo,
work_relation::{RelationType, WorkRelation, WorkRelationOrderBy},
CountryCode, Crud, Doi, Isbn, Orcid, Ror, Timestamp,
};
use crate::policy::PolicyContext;
use crate::storage::{CloudFrontClient, S3Client};
use thoth_errors::ThothError;
impl juniper::Context for Context {}
pub struct Context {
pub db: Arc<PgPool>,
pub user: Option<IntrospectedUser>,
pub s3_client: Arc<S3Client>,
pub cloudfront_client: Arc<CloudFrontClient>,
}
impl Context {
pub fn new(
pool: Arc<PgPool>,
user: Option<IntrospectedUser>,
s3_client: Arc<S3Client>,
cloudfront_client: Arc<CloudFrontClient>,
) -> Self {
Self {
db: pool,
user,
s3_client,
cloudfront_client,
}
}
pub fn s3_client(&self) -> &S3Client {
self.s3_client.as_ref()
}
pub fn cloudfront_client(&self) -> &CloudFrontClient {
self.cloudfront_client.as_ref()
}
}
impl PolicyContext for Context {
fn db(&self) -> &PgPool {
&self.db
}
fn user(&self) -> Option<&IntrospectedUser> {
self.user.as_ref()
}
}
#[juniper::graphql_object(Context = Context, description = "A written text that can be published")]
impl Work {
#[graphql(description = "Thoth ID of the work")]
pub fn work_id(&self) -> &Uuid {
&self.work_id
}
#[graphql(description = "Type of the work")]
pub fn work_type(&self) -> &WorkType {
&self.work_type
}
#[graphql(description = "Publication status of the work")]
pub fn work_status(&self) -> &WorkStatus {
&self.work_status
}
#[graphql(description = "Concatenation of title and subtitle with punctuation mark")]
#[graphql(
deprecated = "Please use Work `titles` field instead to get the correct full title in a multilingual manner"
)]
pub fn full_title(&self, ctx: &Context) -> FieldResult<String> {
Ok(Title::canonical_from_work_id(&ctx.db, &self.work_id)?.full_title)
}
#[graphql(description = "Main title of the work (excluding subtitle)")]
#[graphql(
deprecated = "Please use Work `titles` field instead to get the correct title in a multilingual manner"
)]
pub fn title(&self, ctx: &Context) -> FieldResult<String> {
Ok(Title::canonical_from_work_id(&ctx.db, &self.work_id)?.title)
}
#[graphql(description = "Secondary title of the work (excluding main title)")]
#[graphql(
deprecated = "Please use Work `titles` field instead to get the correct sub_title in a multilingual manner"
)]
pub fn subtitle(&self, ctx: &Context) -> FieldResult<Option<String>> {
Ok(Title::canonical_from_work_id(&ctx.db, &self.work_id)?.subtitle)
}
#[graphql(
description = "Short abstract of the work. Where a work has two different versions of the abstract, the truncated version should be entered here. Otherwise, it can be left blank. This field is not output in metadata formats; where relevant, Long Abstract is used instead."
)]
#[graphql(
deprecated = "Please use Work `abstracts` field instead to get the correct short abstract in a multilingual manner"
)]
pub fn short_abstract(&self, ctx: &Context) -> FieldResult<Option<String>> {
Ok(
Abstract::short_canonical_from_work_id(&ctx.db, &self.work_id)
.map(|a| a.content)
.ok(),
)
}
#[graphql(
description = "Abstract of the work. Where a work has only one abstract, it should be entered here, and Short Abstract can be left blank. Long Abstract is output in metadata formats, and Short Abstract is not."
)]
#[graphql(
deprecated = "Please use Work `abstracts` field instead to get the correct long abstract in a multilingual manner"
)]
pub fn long_abstract(&self, ctx: &Context) -> FieldResult<Option<String>> {
Ok(
Abstract::long_canonical_from_work_id(&ctx.db, &self.work_id)
.map(|a| a.content)
.ok(),
)
}
#[allow(clippy::too_many_arguments)]
#[graphql(description = "Query titles by work ID")]
fn titles(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = "".to_string(),
description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on title_, subtitle, full_title fields"
)]
filter: Option<String>,
#[graphql(
default = TitleOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<TitleOrderBy>,
#[graphql(
default = vec![],
description = "If set, only shows results with these locale codes"
)]
locale_codes: Option<Vec<LocaleCode>>,
#[graphql(
default = MarkupFormat::JatsXml,
description = "If set, only shows results with this markup format"
)]
markup_format: Option<MarkupFormat>,
) -> FieldResult<Vec<Title>> {
let mut titles = Title::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
filter,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
locale_codes.unwrap_or_default(),
vec![],
None,
None,
)
.map_err(FieldError::from)?;
let markup = markup_format.ok_or(ThothError::MissingMarkupFormat)?;
for title in titles.iter_mut() {
title.title = convert_from_jats(&title.title, markup, ConversionLimit::Title)?;
title.subtitle = title
.subtitle
.as_ref()
.map(|subtitle| convert_from_jats(subtitle, markup, ConversionLimit::Title))
.transpose()?;
title.full_title =
convert_from_jats(&title.full_title, markup, ConversionLimit::Title)?;
}
Ok(titles)
}
#[allow(clippy::too_many_arguments)]
#[graphql(description = "Query abstracts by work ID")]
fn abstracts(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = "".to_string(),
description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on title_, subtitle, full_title fields"
)]
filter: Option<String>,
#[graphql(
default = AbstractOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<AbstractOrderBy>,
#[graphql(
default = vec![],
description = "If set, only shows results with these locale codes"
)]
locale_codes: Option<Vec<LocaleCode>>,
#[graphql(
default = MarkupFormat::JatsXml,
description = "If set, only shows results with this markup format"
)]
markup_format: Option<MarkupFormat>,
) -> FieldResult<Vec<Abstract>> {
let mut abstracts = Abstract::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
filter,
order.unwrap_or_default(),
vec![],
Some(*self.work_id()),
None,
locale_codes.unwrap_or_default(),
vec![],
None,
None,
)
.map_err(FieldError::from)?;
let markup = markup_format.ok_or(ThothError::MissingMarkupFormat)?;
for r#abstract in &mut abstracts {
r#abstract.content =
convert_from_jats(&r#abstract.content, markup, ConversionLimit::Abstract)?;
}
Ok(abstracts)
}
#[graphql(description = "Internal reference code")]
pub fn reference(&self) -> Option<&String> {
self.reference.as_ref()
}
#[graphql(description = "Edition number of the work (not applicable to chapters)")]
pub fn edition(&self) -> Option<&i32> {
self.edition.as_ref()
}
#[graphql(description = "Thoth ID of the work's imprint")]
pub fn imprint_id(&self) -> Uuid {
self.imprint_id
}
#[graphql(
description = "Digital Object Identifier of the work as full URL, using the HTTPS scheme and the doi.org domain (e.g. https://doi.org/10.11647/obp.0001)"
)]
pub fn doi(&self) -> Option<&Doi> {
self.doi.as_ref()
}
#[graphql(description = "Date the work was published")]
pub fn publication_date(&self) -> Option<NaiveDate> {
self.publication_date
}
#[graphql(
description = "Date the work was withdrawn from publication. Only applies to out of print and withdrawn works."
)]
pub fn withdrawn_date(&self) -> Option<NaiveDate> {
self.withdrawn_date
}
#[graphql(description = "Place of publication of the work")]
pub fn place(&self) -> Option<&String> {
self.place.as_ref()
}
#[graphql(
description = "Total number of pages in the work. In most cases, unnumbered pages (e.g. endpapers) should be omitted from this count."
)]
pub fn page_count(&self) -> Option<&i32> {
self.page_count.as_ref()
}
#[graphql(
description = "Breakdown of work's page count into front matter, main content, and/or back matter (e.g. 'xi + 140')"
)]
pub fn page_breakdown(&self) -> Option<&String> {
self.page_breakdown.as_ref()
}
#[graphql(description = "Total number of images in the work")]
pub fn image_count(&self) -> Option<&i32> {
self.image_count.as_ref()
}
#[graphql(description = "Total number of tables in the work")]
pub fn table_count(&self) -> Option<&i32> {
self.table_count.as_ref()
}
#[graphql(description = "Total number of audio fragments in the work")]
pub fn audio_count(&self) -> Option<&i32> {
self.audio_count.as_ref()
}
#[graphql(description = "Total number of video fragments in the work")]
pub fn video_count(&self) -> Option<&i32> {
self.video_count.as_ref()
}
#[graphql(
description = "URL of the license which applies to this work (frequently a Creative Commons license for open-access works)"
)]
pub fn license(&self) -> Option<&String> {
self.license.as_ref()
}
#[graphql(description = "Copyright holder of the work")]
pub fn copyright_holder(&self) -> Option<&String> {
self.copyright_holder.as_ref()
}
#[graphql(description = "URL of the web page of the work")]
pub fn landing_page(&self) -> Option<&String> {
self.landing_page.as_ref()
}
#[graphql(
description = "Library of Congress Control Number of the work (not applicable to chapters)"
)]
pub fn lccn(&self) -> Option<&String> {
self.lccn.as_ref()
}
#[graphql(
description = "OCLC (WorldCat) Control Number of the work (not applicable to chapters)"
)]
pub fn oclc(&self) -> Option<&String> {
self.oclc.as_ref()
}
#[graphql(
description = "A general-purpose field used to include information that does not have a specific designated field"
)]
pub fn general_note(&self) -> Option<&String> {
self.general_note.as_ref()
}
#[graphql(
description = "Indicates that the work contains a bibliography or other similar information"
)]
pub fn bibliography_note(&self) -> Option<&String> {
self.bibliography_note.as_ref()
}
#[graphql(description = "Table of contents of the work (not applicable to chapters)")]
pub fn toc(&self) -> Option<&String> {
self.toc.as_ref()
}
#[graphql(description = "Description of additional resources linked to this work")]
pub fn resources_description(
&self,
#[graphql(
default = MarkupFormat::JatsXml,
description = "Markup format used for rendering resources description",
)]
markup_format: Option<MarkupFormat>,
) -> FieldResult<Option<String>> {
self.resources_description
.as_ref()
.map(|value| {
convert_from_jats(
value,
markup_format.ok_or(ThothError::MissingMarkupFormat)?,
ConversionLimit::Abstract,
)
})
.transpose()
.map_err(Into::into)
}
#[graphql(description = "URL of the work's cover image")]
pub fn cover_url(&self) -> Option<&String> {
self.cover_url.as_ref()
}
#[graphql(description = "Caption describing the work's cover image")]
pub fn cover_caption(&self) -> Option<&String> {
self.cover_caption.as_ref()
}
#[graphql(description = "Date and time at which the work record was created")]
pub fn created_at(&self) -> Timestamp {
self.created_at
}
#[graphql(description = "Date and time at which the work record was last updated")]
pub fn updated_at(&self) -> Timestamp {
self.updated_at
}
#[graphql(description = "Page number on which the work begins (only applicable to chapters)")]
pub fn first_page(&self) -> Option<&String> {
self.first_page.as_ref()
}
#[graphql(description = "Page number on which the work ends (only applicable to chapters)")]
pub fn last_page(&self) -> Option<&String> {
self.last_page.as_ref()
}
#[graphql(
description = "Concatenation of first page and last page with dash (only applicable to chapters)"
)]
pub fn page_interval(&self) -> Option<&String> {
self.page_interval.as_ref()
}
#[graphql(
description = "Date and time at which the work record or any of its linked records was last updated"
)]
pub fn updated_at_with_relations(&self) -> Timestamp {
self.updated_at_with_relations
}
#[graphql(description = "Get this work's imprint")]
pub fn imprint(&self, context: &Context) -> FieldResult<Imprint> {
Imprint::from_id(&context.db, &self.imprint_id).map_err(Into::into)
}
#[graphql(description = "Get contributions linked to this work")]
pub fn contributions(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = ContributionOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<ContributionOrderBy>,
#[graphql(
default = vec![],
description = "Specific types to filter by",
)]
contribution_types: Option<Vec<ContributionType>>,
) -> FieldResult<Vec<Contribution>> {
Contribution::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
None,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
contribution_types.unwrap_or_default(),
vec![],
None,
None,
)
.map_err(Into::into)
}
#[allow(clippy::too_many_arguments)]
#[graphql(description = "Get languages linked to this work")]
pub fn languages(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = LanguageOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<LanguageOrderBy>,
#[graphql(
default = vec![],
description = "Specific languages to filter by"
)]
language_codes: Option<Vec<LanguageCode>>,
#[graphql(
description = "(deprecated) A specific relation to filter by"
)]
language_relation: Option<LanguageRelation>,
#[graphql(
default = vec![],
description = "Specific relations to filter by"
)]
language_relations: Option<Vec<LanguageRelation>>,
) -> FieldResult<Vec<Language>> {
let mut relations = language_relations.unwrap_or_default();
if let Some(relation) = language_relation {
relations.push(relation);
}
Language::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
None,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
language_codes.unwrap_or_default(),
relations,
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get publications linked to this work")]
pub fn publications(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = "".to_string(),
description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on isbn"
)]
filter: Option<String>,
#[graphql(
default = PublicationOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<PublicationOrderBy>,
#[graphql(
default = vec![],
description = "Specific types to filter by",
)]
publication_types: Option<Vec<PublicationType>>,
) -> FieldResult<Vec<Publication>> {
Publication::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
filter,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
publication_types.unwrap_or_default(),
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get subjects linked to this work")]
pub fn subjects(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = "".to_string(),
description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on subject_code"
)]
filter: Option<String>,
#[graphql(
default = SubjectOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<SubjectOrderBy>,
#[graphql(
default = vec![],
description = "Specific types to filter by",
)]
subject_types: Option<Vec<SubjectType>>,
) -> FieldResult<Vec<Subject>> {
Subject::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
filter,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
subject_types.unwrap_or_default(),
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get fundings linked to this work")]
pub fn fundings(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = FundingOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<FundingOrderBy>,
) -> FieldResult<Vec<Funding>> {
Funding::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
None,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
vec![],
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get issues linked to this work")]
pub fn issues(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = IssueOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<IssueOrderBy>,
) -> FieldResult<Vec<Issue>> {
Issue::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
None,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
vec![],
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get other works related to this work")]
pub fn relations(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = WorkRelationOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<WorkRelationOrderBy>,
#[graphql(
default = vec![],
description = "Specific types to filter by",
)]
relation_types: Option<Vec<RelationType>>,
) -> FieldResult<Vec<WorkRelation>> {
WorkRelation::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
None,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
relation_types.unwrap_or_default(),
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get the front cover file for this work")]
pub fn frontcover(&self, context: &Context) -> FieldResult<Option<File>> {
File::from_work_id(&context.db, &self.work_id).map_err(Into::into)
}
#[graphql(description = "Get references cited by this work")]
pub fn references(
&self,
context: &Context,
#[graphql(default = 100, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = "".to_string(),
description = "A query string to search. This argument is a test, do not rely on it. At present it simply searches for case insensitive literals on doi, unstructured_citation, issn, isbn, journal_title, article_title, series_title, volume_title, author, standard_designator, standards_body_name, and standards_body_acronym"
)]
filter: Option<String>,
#[graphql(
default = ReferenceOrderBy::default(),
description = "The order in which to sort the results"
)]
order: Option<ReferenceOrderBy>,
) -> FieldResult<Vec<Reference>> {
Reference::all(
&context.db,
limit.unwrap_or_default(),
offset.unwrap_or_default(),
filter,
order.unwrap_or_default(),
vec![],
Some(self.work_id),
None,
vec![],
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get additional resources linked to this work")]
pub fn additional_resources(
&self,
context: &Context,
#[graphql(default = 50, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
#[graphql(
default = MarkupFormat::JatsXml,
description = "Markup format used for rendering textual fields"
)]
markup_format: Option<MarkupFormat>,
) -> FieldResult<Vec<AdditionalResource>> {
let mut additional_resources = AdditionalResource::all(
&context.db,
limit.unwrap_or(50),
offset.unwrap_or_default(),
None,
AdditionalResourceOrderBy::default(),
vec![],
Some(self.work_id),
None,
vec![],
vec![],
None,
None,
)?;
let markup = markup_format.ok_or(ThothError::MissingMarkupFormat)?;
for additional_resource in &mut additional_resources {
additional_resource.title =
convert_from_jats(&additional_resource.title, markup, ConversionLimit::Title)?;
additional_resource.description = additional_resource
.description
.as_ref()
.map(|description| {
convert_from_jats(description, markup, ConversionLimit::Abstract)
})
.transpose()?;
}
Ok(additional_resources)
}
#[graphql(description = "Get awards linked to this work")]
pub fn awards(
&self,
context: &Context,
#[graphql(default = 50, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
) -> FieldResult<Vec<Award>> {
Award::all(
&context.db,
limit.unwrap_or(50),
offset.unwrap_or_default(),
None,
AwardOrderBy::default(),
vec![],
Some(self.work_id),
None,
vec![],
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get endorsements linked to this work")]
pub fn endorsements(
&self,
context: &Context,
#[graphql(default = 50, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
) -> FieldResult<Vec<Endorsement>> {
Endorsement::all(
&context.db,
limit.unwrap_or(50),
offset.unwrap_or_default(),
None,
EndorsementOrderBy::default(),
vec![],
Some(self.work_id),
None,
vec![],
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get book reviews linked to this work")]
pub fn book_reviews(
&self,
context: &Context,
#[graphql(default = 50, description = "The number of items to return")] limit: Option<i32>,
#[graphql(default = 0, description = "The number of items to skip")] offset: Option<i32>,
) -> FieldResult<Vec<BookReview>> {
BookReview::all(
&context.db,
limit.unwrap_or(50),
offset.unwrap_or_default(),
None,
BookReviewOrderBy::default(),
vec![],
Some(self.work_id),
None,
vec![],
vec![],
None,
None,
)
.map_err(Into::into)
}
#[graphql(description = "Get the featured video linked to this work")]
pub fn featured_video(&self, context: &Context) -> FieldResult<Option<WorkFeaturedVideo>> {
WorkFeaturedVideo::from_work_id(&context.db, &self.work_id).map_err(Into::into)
}
}
#[juniper::graphql_object(Context = Context, description = "A manifestation of a written text")]
impl Publication {
#[graphql(description = "Thoth ID of the publication")]
pub fn publication_id(&self) -> Uuid {
self.publication_id
}
#[graphql(description = "Format of this publication")]
pub fn publication_type(&self) -> &PublicationType {
&self.publication_type
}
#[graphql(description = "Thoth ID of the work to which this publication belongs")]
pub fn work_id(&self) -> Uuid {
self.work_id
}
#[graphql(
description = "International Standard Book Number of the publication, in ISBN-13 format"
)]
pub fn isbn(&self) -> Option<&Isbn> {
self.isbn.as_ref()
}
#[graphql(description = "Date and time at which the publication record was created")]
pub fn created_at(&self) -> Timestamp {
self.created_at
}
#[graphql(description = "Date and time at which the publication record was last updated")]
pub fn updated_at(&self) -> Timestamp {
self.updated_at
}
#[graphql(
description = "Width of the physical Publication (in mm, cm or in) (only applicable to non-Chapter Paperbacks and Hardbacks)"
)]
pub fn width(
&self,
#[graphql(
default = LengthUnit::default(),
description = "Unit of measurement in which to represent the width (mm, cm or in)",
)]
units: LengthUnit,
) -> Option<f64> {
match units {
LengthUnit::Mm => self.width_mm,
LengthUnit::Cm => self
.width_mm
.map(|w| w.convert_length_from_to(&LengthUnit::Mm, &LengthUnit::Cm)),
LengthUnit::In => self.width_in,
}
}
#[graphql(
description = "Height of the physical Publication (in mm, cm or in) (only applicable to non-Chapter Paperbacks and Hardbacks)"
)]
pub fn height(
&self,
#[graphql(
default = LengthUnit::default(),
description = "Unit of measurement in which to represent the height (mm, cm or in)",
)]
units: LengthUnit,
) -> Option<f64> {
match units {
LengthUnit::Mm => self.height_mm,
LengthUnit::Cm => self
.height_mm
.map(|w| w.convert_length_from_to(&LengthUnit::Mm, &LengthUnit::Cm)),
LengthUnit::In => self.height_in,
}
}
#[graphql(
description = "Depth of the physical Publication (in mm, cm or in) (only applicable to non-Chapter Paperbacks and Hardbacks)"
)]
pub fn depth(
&self,
#[graphql(
default = LengthUnit::default(),
description = "Unit of measurement in which to represent the depth (mm, cm or in)",
)]
units: LengthUnit,
) -> Option<f64> {
match units {
LengthUnit::Mm => self.depth_mm,
LengthUnit::Cm => self
.depth_mm
.map(|w| w.convert_length_from_to(&LengthUnit::Mm, &LengthUnit::Cm)),
LengthUnit::In => self.depth_in,
}
}
#[graphql(
description = "Weight of the physical Publication (in g or oz) (only applicable to non-Chapter Paperbacks and Hardbacks)"
)]
pub fn weight(
&self,
#[graphql(
default = WeightUnit::default(),
description = "Unit of measurement in which to represent the weight (grams or ounces)",
)]
units: WeightUnit,
) -> Option<f64> {
match units {
WeightUnit::G => self.weight_g,
WeightUnit::Oz => self.weight_oz,
}
}
#[graphql(description = "WCAG standard accessibility level met by this publication (if any)")]
pub fn accessibility_standard(&self) -> Option<&AccessibilityStandard> {
self.accessibility_standard.as_ref()
}
#[graphql(
description = "EPUB- or PDF-specific standard accessibility level met by this publication, if applicable"
)]
pub fn accessibility_additional_standard(&self) -> Option<&AccessibilityStandard> {
self.accessibility_additional_standard.as_ref()
}