-
Notifications
You must be signed in to change notification settings - Fork 0
/
eprint3x.go
2577 lines (2295 loc) · 84 KB
/
eprint3x.go
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
// Package eprinttools is a collection of structures, functions and programs// for working with the EPrints XML and EPrints REST API
//
// @author R. S. Doiel, <[email protected]>
//
// Copyright (c) 2021, Caltech
// All rights not granted herein are expressly reserved by Caltech.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package eprinttools
import (
"bytes"
"encoding/json"
"encoding/xml"
"fmt"
"strconv"
"strings"
"time"
)
// These default values are used when apply clsrules set
var (
// DefaultCollection holds the default collection to use on deposit
DefaultCollection string
// DefaultRights sets the eprint.Rights to a default value on deposit
DefaultRights string
// DefaultOfficialURL holds a URL prefix for the persistent URL,
// an ID Number will get added when generating per record
// official_url values.
DefaultOfficialURL string
// DefaultRefereed
DefaultRefereed string
// DefaultStatus
DefaultStatus string
// counter is just an internal incremented number, used in generator ID to increase
// uniqueness in the id/url scheme used by the resolver. See DR-441 bug report for Windows 10.
counter int
)
//
// NOTE: This file contains the general structure in Caltech Libraries EPrints 3.x based repositories.
//
// EPrints is the high level XML you get from the REST API.
// E.g. curl -L -O https://eprints3.example.org/rest/eprint/1234.xml
// Then parse the 1234.xml document stucture.
type EPrints struct {
XMLName xml.Name `xml:"eprints" json:"-"`
XMLNS string `xml:"xmlns,attr,omitempty" json:"xmlns,omitempty"`
EPrint []*EPrint `xml:"eprint" json:"eprint"`
}
// EPrint is the record contated in a EPrints XML document such as they used
// to store revisions.
type EPrint struct {
XMLName xml.Name `json:"-"`
ID string `xml:"id,attr,omitempty" json:"id,omitempty"`
EPrintID int `xml:"eprintid,omitempty" json:"eprint_id,omitempty"`
RevNumber int `xml:"rev_number,omitempty" json:"rev_number,omitempty"`
Documents *DocumentList `xml:"documents>document,omitempty" json:"documents,omitempty"`
EPrintStatus string `xml:"eprint_status,omitempty" json:"eprint_status,omitempty"`
UserID int `xml:"userid,omitempty" json:"userid,omitempty"`
Dir string `xml:"dir,omitempty" json:"dir,omitempty"`
Datestamp string `xml:"datestamp,omitempty" json:"datestamp,omitempty"`
DatestampYear int `xml:"-" json:"-"`
DatestampMonth int `xml:"-" json:"-"`
DatestampDay int `xml:"-" json:"-"`
DatestampHour int `xml:"-" json:"-"`
DatestampMinute int `xml:"-" json:"-"`
DatestampSecond int `xml:"-" json:"-"`
LastModified string `xml:"lastmod,omitempty" json:"lastmod,omitempty"`
LastModifiedYear int `xml:"-" json:"-"`
LastModifiedMonth int `xml:"-" json:"-"`
LastModifiedDay int `xml:"-" json:"-"`
LastModifiedHour int `xml:"-" json:"-"`
LastModifiedMinute int `xml:"-" json:"-"`
LastModifiedSecond int `xml:"-" json:"-"`
StatusChanged string `xml:"status_changed,omitempty" json:"status_changed,omitempty"`
StatusChangedYear int `xml:"-" json:"-"`
StatusChangedMonth int `xml:"-" json:"-"`
StatusChangedDay int `xml:"-" json:"-"`
StatusChangedHour int `xml:"-" json:"-"`
StatusChangedMinute int `xml:"-" json:"-"`
StatusChangedSecond int `xml:"-" json:"-"`
Type string `xml:"type,omitempty" json:"type,omitempty"`
MetadataVisibility string `xml:"metadata_visibility,omitempty" json:"metadata_visibility,omitempty"`
Creators *CreatorItemList `xml:"creators,omitempty" json:"creators,omitempty"`
Title string `xml:"title,omitempty" json:"title,omitempty"`
IsPublished string `xml:"ispublished,omitempty" json:"ispublished,omitempty"`
FullTextStatus string `xml:"full_text_status,omitempty" json:"full_text_status,omitempty"`
Keywords string `xml:"keywords,omitempty" json:"keywords,omitempty"`
//Keyword *KeywordItemList `xml:"-" json:""`
Note string `xml:"note,omitempty" json:"note,omitempty"`
Abstract string `xml:"abstract,omitempty" json:"abstract,omitempty"`
Date string `xml:"date,omitempty" json:"date,omitempty"`
DateYear int `xml:"-" json:"-"`
DateMonth int `xml:"-" json:"-"`
DateDay int `xml:"-" json:"-"`
DateType string `xml:"date_type,omitempty" json:"date_type,omitempty"`
Series string `xml:"series,omitempty" json:"series,omitempty"`
Publication string `xml:"publication,omitempty" json:"publication,omitempty"`
Volume string `xml:"volume,omitempty" json:"volume,omitempty"`
Number string `xml:"number,omitempty" json:"number,omitempty"`
Publisher string `xml:"publisher,omitempty" json:"publisher,omitempty"`
PlaceOfPub string `xml:"place_of_pub,omitempty" json:"place_of_pub,omitempty"`
Edition string `xml:"edition,omitempty" json:"edition,omitempty"`
PageRange string `xml:"pagerange,omitempty" json:"pagerange,omitempty"`
Pages int `xml:"pages,omitempty" json:"pages,omitempty"`
EventType string `xml:"event_type,omitempty" json:"event_type,omitempty"`
EventTitle string `xml:"event_title,omitempty" json:"event_title,omitempty"`
EventLocation string `xml:"event_location,omitempty" json:"event_location,omitempty"`
EventDates string `xml:"event_dates,omitempty" json:"event_dates,omitempty"`
IDNumber string `xml:"id_number,omitempty" json:"id_number,omitempty"`
Refereed string `xml:"refereed,omitempty" json:"refereed,omitempty"`
ISBN string `xml:"isbn,omitempty" json:"isbn,omitempty"`
ISSN string `xml:"issn,omitempty" json:"issn,omitempty"`
BookTitle string `xml:"book_title,omitempty" json:"book_title,omitempty"`
Editors *EditorItemList `xml:"editors,omitempty" json:"editors,omitempty"`
OfficialURL string `xml:"official_url,omitempty" json:"official_url,omitempty"`
AltURL string `xml:"alt_url,omitempty" json:"alt_url,omitempty"`
RelatedURL *RelatedURLItemList `xml:"related_url,omitempty" json:"related_url,omitempty"`
ReferenceText *ReferenceTextItemList `xml:"referencetext,omitempty" json:"referencetext,omitempty"`
Projects *ProjectItemList `xml:"projects,omitempty" json:"projects,omitempty"`
Rights string `xml:"rights,omitempty" json:"rights,omitempty"`
Funders *FunderItemList `xml:"funders,omitempty" json:"funders,omitempty"`
Collection string `xml:"collection,omitempty" json:"collection,omitempty"`
Reviewer string `xml:"reviewer,omitempty" json:"reviewer,omitempty"`
OfficialCitation string `xml:"official_cit,omitempty" json:"official_cit,omitempty"`
OtherNumberingSystem *OtherNumberingSystemItemList `xml:"other_numbering_system,omitempty" json:"other_numbering_system,omitempty"`
LocalGroup *LocalGroupItemList `xml:"local_group,omitempty" json:"local_group,omitempty"`
ErrataText string `xml:"errata,omitempty" json:"errata,omitempty"`
Contributors *ContributorItemList `xml:"contributors,omitempty" json:"contributors,omitempty"`
MonographType string `xml:"monograph_type,omitempty" json:"monograph_type,omitempty"`
// Caltech Library uses suggestions as an internal note field (RSD, 2018-02-15)
Suggestions string `xml:"suggestions,omitempty" json:"suggestions,omitempty"`
// Deposited By from user table, assemble a name string (E.g. Ruth Sustaita)
DepositedBy string `xml:"-" json:"deposited_by,omitempty"`
// Deposited On is from the datestamp_* fields brining together as a sngle timetstamp string that includes hour, minute as well as date.
DepositedOn string `xml:"-" json:"deposited_on,omitempty"`
// CaletchLN has a "coverage_dates" field in the eprint table.
CoverageDates string `xml:"coverage_dates,omitempty" json:"coverage_dates,omitempty"`
// NOTE: Misc fields discoverd exploring REST API records, not currently used at Caltech Library (RSD, 2018-01-02)
Subjects *SubjectItemList `xml:"subjects,omitempty" json:"subjects,omitempty"`
PresType string `xml:"pres_type,omitempty" json:"presentation_type,omitempty"`
Succeeds int `xml:"succeeds,omitempty" json:"succeeds,omitempty"`
Commentary int `xml:"commentary,omitempty" json:"commentary,omitempty"`
ContactEMail string `xml:"contact_email,omitempty" json:"contect_email,omitempty"`
// NOTE: EPrints XML doesn't include fileinfo
FileInfo string `xml:"-" json:"-"`
Latitude float64 `xml:"latitude,omitempty" json:"latitude,omitempty"`
Longitude float64 `xml:"longitude,omitempty" json:"longitude,omitempty"`
ItemIssues *ItemIssueItemList `xml:"item_issues,omitempty" json:"item_issues,omitempty"`
ItemIssuesCount int `xml:"item_issues_count,omitempty" json:"item_issues_count,omitempty"`
CorpCreators *CorpCreatorItemList `xml:"corp_creators,omitempty" json:"corp_creators,omitempty"`
CorpContributors *CorpContributorItemList `xml:"corp_contributors,omitempty" json:"corp_contributors,omitempty"`
Department string `xml:"department,omitempty" json:"department,omitempty"`
OutputMedia string `xml:"output_media,omitempty" json:"output_media,omitempty"`
Exhibitors *ExhibitorItemList `xml:"exhibitors,omitempty" json:"exhibitors,omitempty"`
NumPieces int `xml:"num_pieces,omitempty" json:"num_pieces,omitempty"`
CompositionType string `xml:"composition_type,omitempty" json:"composition_type,omitempty"`
Producers *ProducerItemList `xml:"producers,omitempty" json:"producers,omitempty"`
Conductors *ConductorItemList `xml:"conductors,omitempty" json:"conductors,omitempty"`
Lyricists *LyricistItemList `xml:"lyricists,omitempty" json:"lyricists,omitempty"`
Accompaniment *AccompanimentItemList `xml:"accompaniment,omitempty" json:"accompaniment,omitempty"`
DataType string `xml:"data_type,omitempty" json:"data_type,omitempty"`
PedagogicType string `xml:"pedagogic_type,omitempty" json:"pedagogic_type,omitempty"`
CompletionTime string `xml:"completion_time,omitempty" json:"completion_time,omitempty"`
TaskPurpose string `xml:"task_purpose,omitempty" json:"task_purpose,omitempty"`
SkillAreas *SkillAreaItemList `xml:"skill_areas,omitempty" json:"skill_areas,omitempty"`
CopyrightHolders *CopyrightHolderItemList `xml:"copyright_holders,omitempty" json:"copyright_holders,omitempty"`
LearningLevelText string `xml:"learning_level,omitempty" json:"learning_level,omitempty"`
//LearningLevel *LearningLevelItemList `xml:"-" json:"-"`
DOI string `xml:"doi,omitempty" json:"doi,omitempty"`
PMCID string `xml:"pmc_id,omitempty" json:"pmcid,omitempty"`
PMID string `xml:"pmid,omitempty" json:"pmid,omitempty"`
ParentURL string `xml:"parent_url,omitempty" json:"parent_url,omitempty"`
Reference *ReferenceItemList `xml:"reference,omitempty" json:"reference,omitempty"`
ConfCreators *ConfCreatorItemList `xml:"conf_creators,omitempty" json:"conf_creators,omitempty"`
AltTitle *AltTitleItemList `xml:"alt_title,omitempty" json:"alt_title,omitempty"`
TOC string `xml:"toc,omitempty" json:"toc,omitempty"`
Interviewer string `xml:"interviewer,omitempty" json:"interviewer,omitempty"`
InterviewDate string `xml:"interviewdate,omitempty" json:"interviewdate,omitempty"`
//GScholar *GScholarItemList `xml:"gscholar,omitempty" json:"gscholar,omitempty"`
NonSubjKeywords string `xml:"nonsubj_keywords,omitempty" json:"nonsubj_keywords,omitempty"`
Season string `xml:"season,omitempty" json:"season,omitempty"`
ClassificationCode string `xml:"classification_code,omitempty" json:"classification_code,omitempty"`
Shelves *ShelfItemList `xml:"shelves,omitempty" json:"shelves,omitempty"`
Relation *RelationItemList `xml:"relation,omitempty" json:"relation,omitempty"`
// NOTE: Sword deposit fields
SwordDepository string `xml:"sword_depository,omitempty" json:"sword_depository,omitempty"`
SwordDepositor int `xml:"sword_depositor,omitempty" json:"sword_depositor,omitempty"`
SwordSlug string `xml:"sword_slug,omitempty" json:"sword_slug,omitempty"`
ImportID int `xml:"importid,omitempty" json:"import_id,omitempty"`
// Patent related fields
PatentApplicant string `xml:"patent_applicant,omitempty" json:"patent_applicant,omitempty"`
PatentNumber string `xml:"patent_number,omitempty" json:"patent_number,omitempty"`
PatentAssignee *PatentAssigneeItemList `xml:"patent_assignee,omitempty" json:"patent_assignee,omitempty"`
PatentClassificationText string `xml:"-" json:"-"`
//PatentClassification *PatentClassificationItemList `xml:"patent_classification,omitempty" json:"patent_classification,omitempty"`
RelatedPatents *RelatedPatentItemList `xml:"related_patents,omitempty" json:"related_patents,omitempty"`
// Thesis oriented fields
Divisions *DivisionItemList `xml:"divisions,omitemmpty" json:"divisions,omitempty"`
Institution string `xml:"institution,omitempty" json:"institution,omitempty"`
ThesisType string `xml:"thesis_type,omitempty" json:"thesis_type,omitempty"`
ThesisAdvisor *ThesisAdvisorItemList `xml:"thesis_advisor,omitempty" json:"thesis_advisor,omitempty"`
ThesisCommittee *ThesisCommitteeItemList `xml:"thesis_committee,omitempty" json:"thesis_committee,omitempty"`
ThesisDegree string `xml:"thesis_degree,omitempty" json:"thesis_degree,omitempty"`
ThesisDegreeGrantor string `xml:"thesis_degree_grantor,omitempty" json:"thesis_degree_grantor,omitempty"`
ThesisDegreeDate string `xml:"thesis_degree_date,omitempty" json:"thesis_degree_date,omitempty"`
ThesisDegreeDateYear int `xml:"-" json:"-"`
ThesisDegreeDateMonth int `xml:"-" json:"-"`
ThesisDegreeDateDay int `xml:"-" json:"-"`
ThesisSubmittedDate string `xml:"thesis_submitted_date,omitempty" json:"thesis_submitted_date,omitempty"`
ThesisSubmittedDateYear int `xml:"-" json:"-"`
ThesisSubmittedDateMonth int `xml:"-" json:"-"`
ThesisSubmittedDateDay int `xml:"-" json:"-"`
ThesisDefenseDate string `xml:"thesis_defense_date,omitempty" json:"thesis_defense_date,omitempty"`
ThesisDefenseDateYear int `xml:"-" json:"-"`
ThesisDefenseDateMonth int `xml:"-" json:"-"`
ThesisDefenseDateDay int `xml:"-" json:"-"`
ThesisApprovedDate string `xml:"thesis_approved_date,omitempty" json:"thesis_approved_date,omitempty"`
ThesisApprovedDateYear int `xml:"-" json:"-"`
ThesisApprovedDateMonth int `xml:"-" json:"-"`
ThesisApprovedDateDay int `xml:"-" json:"-"`
ThesisPublicDate string `xml:"thesis_public_date,omitempty" json:"thesis_public_date,omitempty"`
ThesisPublicDateYear int `xml:"-" json:"-"`
ThesisPublicDateMonth int `xml:"-" json:"-"`
ThesisPublicDateDay int `xml:"-" json:"-"`
ThesisAuthorEMail string `xml:"thesis_author_email,omitempty" json:"thesis_author_email,omitempty"`
HideThesisAuthorEMail string `xml:"hide_thesis_author_email,omitempty" json:"hide_thesis_author_email,omitempty"`
// NOTE: GradOfficeApproval isn't output by CaltechTHESIS.
GradOfficeApprovalDate string `xml:"gradofc_approval_date,omitempty" json:"gradofc_approval_date,omitempty"`
GradOfficeApprovalDateYear int `xml:"-" json:"-"`
GradOfficeApprovalDateMonth int `xml:"-" json:"-"`
GradOfficeApprovalDateDay int `xml:"-" json:"-"`
ThesisAwards string `xml:"thesis_awards,omitempty" json:"thesis_awards,omitempty"`
ReviewStatus string `xml:"review_status,omitempty" json:"review_status,omitempty"`
OptionMajor *OptionMajorItemList `xml:"option_major,omitempty" json:"option_major,omitempty"`
OptionMinor *OptionMinorItemList `xml:"option_minor,omitempty" json:"option_minor,omitempty"`
CopyrightStatement string `xml:"copyright_statement,omitempty" json:"copyright_statement,omitempty"`
// Custom fields from some EPrints repositories
Source string `xml:"source,omitempty" json:"source,omitempty"`
ReplacedBy int `xml:"replacedby,omitempty" json:"replacedby,omitempty"`
// Edit Control Fields
EditLockUser int `xml:"-" json:"-"`
EditLockSince int `xml:"-" json:"-"`
EditLockUntil int `xml:"-" json:"-"`
// Fields identified through harvesting.
//ReferenceTextString string `xml:"referencetext,omitempty" json:"referencetext,omitempty"`
Language string `xml:"language,omitempty" json:"language,omitempty"`
// Synthetic fields are created to help in eventual migration of
// EPrints field data to other JSON formats.
PrimaryObject map[string]interface{} `xml:"-" json:"primary_object,omitempty"`
RelatedObjects []map[string]interface{} `xml:"-" json:"related_objects,omitempty"`
}
// PubDate returns the publication date or empty string
func (eprint *EPrint) PubDate() string {
if eprint.DateType == "published" {
return eprint.Date
}
return ""
}
// Item is a generic type used by various fields (e.g. Creator, Division, OptionMajor)
type Item struct {
XMLName xml.Name `xml:"item" json:"-"`
Name *Name `xml:"name,omitempty" json:"name,omitempty"`
Pos int `xml:"-" json:"-"`
ID string `xml:"id,omitempty" json:"id,omitempty"`
EMail string `xml:"email,omitempty" json:"email,omitempty"`
ShowEMail string `xml:"show_email,omitempty" json:"show_email,omitempty"`
Role string `xml:"role,omitempty" json:"role,omitempty"`
URL string `xml:"url,omitempty" json:"url,omitempty"`
Type string `xml:"type,omitempty" json:"type,omitempty"`
Description string `xml:"description,omitempty" json:"description,omitempty"`
Agency string `xml:"agency,omitempty" json:"agency,omitempty"`
GrantNumber string `xml:"grant_number,omitempty" json:"grant_number,omitempty"`
URI string `xml:"uri,omitempty" json:"uri,omitempty"`
ORCID string `xml:"orcid,omitempty" json:"orcid,omitempty"`
ROR string `xml:"ror,omitempty" json:"ror,omitempty"`
Timestamp string `xml:"timestamp,omitempty" json:"timestamp,omitempty"`
Status string `xml:"status,omitempty" json:"status,omitempty"`
ReportedBy string `xml:"reported_by,omitempty" json:"reported_by,omitempty"`
ResolvedBy string `xml:"resolved_by,omitempty" json:"resolved_by,omitempty"`
Comment string `xml:"comment,omitempty" json:"comment,omitempty"`
Value string `xml:",chardata" json:"value,omitempty"`
}
// SetAttribute takes a lower case string and value and sets
// the attribute of the related item.
func (item *Item) SetAttribute(key string, value interface{}) bool {
switch value.(type) {
case string:
value = strings.TrimSpace(value.(string))
}
switch strings.ToLower(key) {
case "name":
item.Name = value.(*Name)
return true
case "pos":
item.Pos = value.(int)
return true
case "id":
item.ID = value.(string)
return true
case "email":
item.EMail = value.(string)
return true
case "showemail":
item.ShowEMail = value.(string)
return true
case "show_email":
item.ShowEMail = value.(string)
return true
case "role":
item.Role = value.(string)
return true
case "url":
item.URL = value.(string)
return true
case "type":
item.Type = value.(string)
return true
case "description":
item.Description = value.(string)
return true
case "agency":
item.Agency = value.(string)
return true
case "grantnumber":
item.GrantNumber = value.(string)
return true
case "grant_number":
item.GrantNumber = value.(string)
return true
case "uri":
item.URI = value.(string)
return true
case "orcid":
item.ORCID = value.(string)
return true
case "ror":
item.ROR = value.(string)
return true
case "timestamp":
item.Timestamp = value.(string)
return true
case "status":
item.Status = value.(string)
return true
case "reportedby":
item.ReportedBy = value.(string)
return true
case "reported_by":
item.ReportedBy = value.(string)
return true
case "resolvedby":
item.ResolvedBy = value.(string)
return true
case "resolved_by":
item.ResolvedBy = value.(string)
return true
case "comment":
item.Comment = value.(string)
return true
case "value":
item.Value = value.(string)
return true
case "":
item.Value = value.(string)
return true
}
return false
}
// MarshalJSON() is a custom JSON marshaler for Item
func (item *Item) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{}
flatten := true
if item.Name != nil {
m["name"] = item.Name
flatten = false
}
if strings.TrimSpace(item.ID) != "" {
m["id"] = item.ID
flatten = false
}
if strings.TrimSpace(item.EMail) != "" {
m["email"] = item.EMail
flatten = false
}
if strings.TrimSpace(item.ShowEMail) != "" {
m["show_email"] = item.ShowEMail
flatten = false
}
if strings.TrimSpace(item.Role) != "" {
m["role"] = item.Role
flatten = false
}
if strings.TrimSpace(item.URL) != "" {
m["url"] = item.URL
flatten = false
}
if strings.TrimSpace(item.Type) != "" {
m["type"] = item.Type
flatten = false
}
if strings.TrimSpace(item.Description) != "" {
m["description"] = item.Description
flatten = false
}
if strings.TrimSpace(item.Agency) != "" {
m["agency"] = item.Agency
flatten = false
}
if strings.TrimSpace(item.GrantNumber) != "" {
m["grant_number"] = item.GrantNumber
flatten = false
}
if strings.TrimSpace(item.URI) != "" {
m["uri"] = item.URI
flatten = false
}
if s := strings.TrimSpace(item.ORCID); s != "" {
//FIXME: should validate the orcid to avoid legacy data issues
m["orcid"] = s
flatten = false
}
if s := strings.TrimSpace(item.Value); s != "" {
if flatten == true {
return json.Marshal(s)
}
m["value"] = s
}
return json.Marshal(m)
}
func (item *Item) UnmarshalJSON(src []byte) error {
if bytes.HasPrefix(src, []byte(`"`)) && bytes.HasSuffix(src, []byte(`"`)) {
item.Value = fmt.Sprintf("%s", bytes.Trim(src, `"`))
return nil
}
m := make(map[string]interface{})
err := jsonDecode(src, &m)
if err != nil {
return err
}
for key, value := range m {
switch key {
case "name":
name := new(Name)
switch value.(type) {
case string:
name.Value = value.(string)
case map[string]interface{}:
m := value.(map[string]interface{})
if family, ok := m["family"]; ok == true {
name.Family = family.(string)
}
if given, ok := m["given"]; ok == true {
name.Given = given.(string)
}
if id, ok := m["id"]; ok == true {
name.ID = id.(string)
}
if orcid, ok := m["orcid"]; ok == true {
name.ID = orcid.(string)
}
}
item.Name = name
case "id":
item.ID = value.(string)
case "email":
item.EMail = value.(string)
case "show_email":
item.ShowEMail = value.(string)
case "role":
item.Role = value.(string)
case "url":
item.URL = value.(string)
case "type":
item.Type = value.(string)
case "description":
item.Description = value.(string)
case "agency":
item.Agency = value.(string)
case "grant_number":
item.GrantNumber = value.(string)
case "uri":
item.URI = value.(string)
case "orcid":
item.ORCID = value.(string)
case "value":
item.Value = value.(string)
}
}
return err
}
// ItemsInterface describes a common set of operations on an item list.
type ItemsInterface interface {
// Init will initialize the item interface element (e.g. initialize .Items array)
Init()
// Append an item to an ItemList
Append(*Item) int
// Length returns the item count
Length() int
// IndexOf returns Item or nil
IndexOf(int) *Item
// SetAttributOf at index position sets an item's attribute
SetAttributeOf(int, string, interface{}) bool
}
// CreatorItemList holds a list of authors
type CreatorItemList struct {
XMLName xml.Name `xml:"creators" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *CreatorItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the Creator list and returns the new count of items
func (itemList *CreatorItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length() returns item count
func (itemList *CreatorItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf() returns item or nil
func (itemList *CreatorItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *CreatorItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 {
if i >= itemList.Length() {
for j := itemList.Length(); j <= i; j++ {
item := new(Item)
itemList.Append(item)
}
}
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// GetIDs for each item in the list return a slice of strings holding the ids.
func (itemList *CreatorItemList) GetIDs() []string {
ids := []string{}
if itemList != nil && itemList.Items != nil {
for _, item := range itemList.Items {
if item.ID != "" {
ids = append(ids, item.ID)
}
}
}
return ids
}
// EditorItemList holds a list of editors
type EditorItemList struct {
XMLName xml.Name `xml:"editors" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *EditorItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the Editor item list and returns the new count of items
func (itemList *EditorItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length() returns the number of items in the list
func (itemList *EditorItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf() returns an item in the list or nil
func (itemList *EditorItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *EditorItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// GetIDs for each item in the list return a slice of strings holding the ids.
func (itemList *EditorItemList) GetIDs() []string {
ids := []string{}
if itemList != nil && itemList.Items != nil {
for _, item := range itemList.Items {
if item.ID != "" {
ids = append(ids, item.ID)
}
}
}
return ids
}
// RelatedURLItemList holds the related URLs (e.g. doi, aux material doi)
type RelatedURLItemList struct {
XMLName xml.Name `xml:"related_url" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *RelatedURLItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append an item to the related url item list
func (itemList *RelatedURLItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length() returns item count
func (itemList *RelatedURLItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf() returns item or nil
func (itemList *RelatedURLItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *RelatedURLItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// ReferenceTextItemList
type ReferenceTextItemList struct {
XMLName xml.Name `xml:"referencetext" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *ReferenceTextItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the reference text url item list and returns the new count of items
func (itemList *ReferenceTextItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length returns the length of an ReferenceTextItemList
func (itemList *ReferenceTextItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf returns an Item or nil
func (itemList *ReferenceTextItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *ReferenceTextItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// UnmarshJSON takes a reference text list of item and returns
// an appropriately values to assigned struct.
func (itemList *ReferenceTextItemList) UnmarshalJSON(src []byte) error {
var values []string
m := make(map[string][]interface{})
err := jsonDecode(src, &m)
if err != nil {
return err
}
if itemList, ok := m["items"]; ok == true {
for _, item := range itemList {
switch item.(type) {
case string:
values = append(values, item.(string))
}
}
}
for _, value := range values {
item := new(Item)
item.SetAttribute("value", value)
itemList.Append(item)
}
return err
}
// ProjectItemList
type ProjectItemList struct {
XMLName xml.Name `xml:"projects" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *ProjectItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the project item list and returns the new count of items
func (itemList *ProjectItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length() returns the length of the item list
func (itemList *ProjectItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf returns an item or nil
func (itemList *ProjectItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *ProjectItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// FunderItemList
type FunderItemList struct {
XMLName xml.Name `xml:"funders" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *FunderItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the funder item list and returns the new count of items
func (itemList *FunderItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length of item list
func (itemList *FunderItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf returns an item or nil
func (itemList *FunderItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *FunderItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// LocalGroupItemList holds the related URLs (e.g. doi, aux material doi)
type LocalGroupItemList struct {
XMLName xml.Name `xml:"local_group" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *LocalGroupItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the local group item list and returns the new count of items
func (itemList *LocalGroupItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length returns length of item list
func (itemList *LocalGroupItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf returns an item or nil
func (itemList *LocalGroupItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *LocalGroupItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// GetGroups returns a slice of string with local_group values
func (itemList *LocalGroupItemList) GetGroups() []string {
groups := []string{}
if itemList != nil && itemList.Items != nil {
for _, group := range itemList.Items {
if group.Value != "" {
groups = append(groups, group.Value)
}
}
}
return groups
}
// OtherNumberingSystemItemList
type OtherNumberingSystemItemList struct {
XMLName xml.Name `xml:"other_numbering_system" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *OtherNumberingSystemItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the other numbering system item list and returns the new count of items
func (itemList *OtherNumberingSystemItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length returns the length of the item
func (itemList *OtherNumberingSystemItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf return an item or nil
func (itemList *OtherNumberingSystemItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *OtherNumberingSystemItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// ContributorItemList
type ContributorItemList struct {
XMLName xml.Name `xml:"contributors" json:"-"`
Items []*Item `xml:"item,omitempty" json:"items,omitempty"`
}
// Init will initilize the Items array attribute of List
func (itemList *ContributorItemList) Init() {
if itemList.Items == nil {
itemList.Items = []*Item{}
}
}
// Append adds an item to the contributor item list and returns the new count of items
func (itemList *ContributorItemList) Append(item *Item) int {
itemList.Items = append(itemList.Items, item)
return len(itemList.Items)
}
// Length returns the number of items in list
func (itemList *ContributorItemList) Length() int {
if itemList != nil {
return len(itemList.Items)
}
return 0
}
// IndexOf returns an item or nil
func (itemList *ContributorItemList) IndexOf(i int) *Item {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i]
}
return nil
}
// SetAttributeOf at pos set item attribute return success
func (itemList *ContributorItemList) SetAttributeOf(i int, key string, value interface{}) bool {
if i >= 0 && i < itemList.Length() {
return itemList.Items[i].SetAttribute(key, value)
}
return false
}
// GetIDs for each item in the list return a slice of strings holding the ids.
func (itemList *ContributorItemList) GetIDs() []string {
ids := []string{}
if itemList != nil && itemList.Items != nil {
for _, item := range itemList.Items {
if item.ID != "" {
ids = append(ids, item.ID)
}