-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrosswalk.go
714 lines (682 loc) · 23.6 KB
/
crosswalk.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
// Package eprinttools is a collection of structures, functions and programs// for working with the EPrints XML and EPrints REST API
//
// @author R. S. Doiel, <rsdoiel@caltech.edu>
//
// 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
/**
* simple.go implements an Invenio 3 like JSON representation
* of an EPrint record. This is intended to make the development of
* V2 of feeds easier for both our audience and in for our internal
* programming needs.
*
* See documentation and example on Invenio's structured data:
*
* - https://inveniordm.docs.cern.ch/reference/metadata/
* - https://github.com/caltechlibrary/caltechdata_api/blob/ce16c6856eb7f6424db65c1b06de741bbcaee2c8/tests/conftest.py#L147
*
*/
import (
"fmt"
"strings"
"time"
// Caltech Library Packages
"github.com/caltechlibrary/simplified"
)
func CrosswalkEPrintToRecord(eprint *EPrint, rec *simplified.Record) error {
rec.Schema = `local://records/record-v2.0.0.json`
rec.ID = fmt.Sprintf("%s:%d", eprint.Collection, eprint.EPrintID)
if err := parentFromEPrint(eprint, rec); err != nil {
return err
}
if err := externalPIDFromEPrint(eprint, rec); err != nil {
return err
}
if err := recordAccessFromEPrint(eprint, rec); err != nil {
return err
}
if err := metadataFromEPrint(eprint, rec); err != nil {
return err
}
if err := filesFromEPrint(eprint, rec); err != nil {
return err
}
if eprint.EPrintStatus == "deletion" {
if err := tombstoneFromEPrint(eprint, rec); err != nil {
return err
}
}
if err := createdUpdatedFromEPrint(eprint, rec); err != nil {
return err
}
/*
if err := pidFromEPrint(eprint, rec); err != nil {
return err
}
*/
// Now finish simple record normalization ...
if err := mapResourceType(rec); err != nil {
return err
}
if err := simplifyCreators(rec); err != nil {
return err
}
if err := simplifyContributors(rec); err != nil {
return err
}
// FIXME: Map eprint record types to invenio RDM record types we've
// decided on.
// FIXME: Funders must have a title, could just copy in the funder
// name for now.
if err := simplifyFunding(rec); err != nil {
return err
}
return nil
}
// simplifyCreators make sure the identifiers are mapped to Invenio-RDM
// identifiers.
func simplifyCreators(rec *simplified.Record) error {
if rec.Metadata.Creators != nil && len(rec.Metadata.Creators) > 0 {
creators := []*simplified.Creator{}
for _, creator := range rec.Metadata.Creators {
//FIXME: do I need to handle assigning a role here?
appendCreator := false
if creator.PersonOrOrg != nil && creator.PersonOrOrg.FamilyName != "" {
if creator.PersonOrOrg.Identifiers != nil && len(creator.PersonOrOrg.Identifiers) > 0 {
for _, identifier := range creator.PersonOrOrg.Identifiers {
if identifier.Scheme == "creator_id" {
identifier.Scheme = "clpid"
}
}
appendCreator = true
}
}
if appendCreator {
creators = append(creators, creator)
}
}
if len(creators) > 0 {
rec.Metadata.Creators = creators
}
}
return nil
}
// simplifyContributors make sure the identifiers are mapped to Invenio-RDM
// identifiers.
func simplifyContributors(rec *simplified.Record) error {
if rec.Metadata.Contributors != nil && len(rec.Metadata.Contributors) > 0 {
contributors := []*simplified.Creator{}
for _, contributor := range rec.Metadata.Contributors {
appendContributor := false
if contributor.PersonOrOrg != nil && contributor.PersonOrOrg.FamilyName != "" {
appendContributor = true
if contributor.PersonOrOrg.Identifiers != nil && len(contributor.PersonOrOrg.Identifiers) > 0 {
for _, identifier := range contributor.PersonOrOrg.Identifiers {
switch identifier.Scheme {
// conf_creators_id
// corp_creators_id
// creators_id
// exhibitors_id
// lyricists_id
// producers_id
case "thesis_advisor_id":
identifier.Scheme = "clpid"
case "thesis_committee_id":
identifier.Scheme = "clpid"
case "author_id":
identifier.Scheme = "clpid"
case "editor_id":
identifier.Scheme = "clpid"
case "contributor_id":
identifier.Scheme = "clpid"
}
}
}
}
if appendContributor {
if contributor.Role == nil {
return fmt.Errorf("contributor is missing role -> %+v", contributor)
}
contributors = append(contributors, contributor)
}
}
if len(contributors) > 0 {
rec.Metadata.Contributors = contributors
}
}
return nil
}
func simplifyFunding(rec *simplified.Record) error {
if rec.Metadata.Funding != nil && len(rec.Metadata.Funding) > 0 {
for _, funder := range rec.Metadata.Funding {
if funder.Funder != nil {
funder.Funder.Scheme = ""
}
if funder.Award != nil {
if funder.Award.Number == "" {
funder.Award = nil
} else {
//NOTE: funder.Award.Title is a struct in
// Invenio-RDM like
// ```
// title : { "lang": "en", "unavailable" }
// ```
// This needs to be normalized in the final
// Python processing for importing into Invenio-RDM.
funder.Award.Scheme = ""
}
}
}
}
return nil
}
// mapResourceType maps the EPrints record types to a predetermined
// Invenio-RDM record type.
func mapResourceType(rec *simplified.Record) error {
// FIXME: need to load this from a configuration file
crosswalkResourceTypes := map[string]string{
"article": "publication-article",
}
if rec.Metadata.ResourceType != nil {
// Should always have an id for a reource_type
if id, ok := rec.Metadata.ResourceType["id"].(string); ok {
if val, hasID := crosswalkResourceTypes[id]; hasID {
rec.Metadata.ResourceType["id"] = val
//} else { // FIXME: I don't want to implement a full mapping yet.
// return fmt.Errorf("failed to find id %q in record type crosswalk", id)
}
}
}
return nil
}
/*
// PIDFromEPrint crosswalks the PID from an EPrint record.
func pidFromEPrint(eprint *EPrint, rec *simplified.Record) error {
data := map[string]interface{}{}
src := fmt.Sprintf(`{
"id": %d,
"pid": { "eprint": "eprintid"}
}`, eprint.EPrintID)
err := jsonDecode([]byte(src), &data)
if err != nil {
return fmt.Errorf("Cannot generate PID from EPrint %d", eprint.EPrintID)
}
rec.PID = data
return nil
}
*/
// parentFromEPrint crosswalks the Perent unique ID from EPrint record.
func parentFromEPrint(eprint *EPrint, rec *simplified.Record) error {
if eprint.Reviewer != "" {
parent := new(simplified.RecordIdentifier)
parent.ID = fmt.Sprintf("%s:%d", eprint.Collection, eprint.EPrintID)
parent.Access = new(simplified.Access)
ownedBy := new(simplified.User)
ownedBy.User = eprint.UserID
ownedBy.DisplayName = eprint.Reviewer
parent.Access.OwnedBy = append(parent.Access.OwnedBy, ownedBy)
rec.Parent = parent
} else {
rec.Parent = nil
}
return nil
}
// externalPIDFromEPrint aggregates all the external identifiers
// from the EPrint record into Record
func externalPIDFromEPrint(eprint *EPrint, rec *simplified.Record) error {
rec.ExternalPIDs = map[string]*simplified.PersistentIdentifier{}
// Pickup DOI
if eprint.DOI != "" {
pid := new(simplified.PersistentIdentifier)
pid.Identifier = eprint.DOI
pid.Provider = "datacite"
pid.Client = ""
rec.ExternalPIDs["doi"] = pid
}
// Pickup ISSN
if eprint.ISBN != "" {
pid := new(simplified.PersistentIdentifier)
pid.Identifier = eprint.ISSN
pid.Provider = ""
pid.Client = ""
rec.ExternalPIDs["issn"] = pid
}
// Pickup ISBN
if eprint.ISBN != "" {
pid := new(simplified.PersistentIdentifier)
pid.Identifier = eprint.ISBN
pid.Provider = ""
pid.Client = ""
rec.ExternalPIDs["isbn"] = pid
}
//FIXME: figure out if we have other persistent identifiers
//scattered in the EPrints XML and map them.
return nil
}
// recordAccessFromEPrint extracts access permissions from the EPrint
func recordAccessFromEPrint(eprint *EPrint, rec *simplified.Record) error {
isPublic := true
if (eprint.ReviewStatus == "review") ||
(eprint.ReviewStatus == "withheld") ||
(eprint.ReviewStatus == "gradoffice") ||
(eprint.ReviewStatus == "notapproved") {
isPublic = false
}
if eprint.EPrintStatus != "archive" || eprint.MetadataVisibility != "show" {
isPublic = false
}
rec.RecordAccess = new(simplified.RecordAccess)
// By default lets assume the files are restricted.
rec.RecordAccess.Files = "resticted"
if isPublic {
rec.RecordAccess.Record = "public"
} else {
rec.RecordAccess.Record = "restricted"
}
// Need to make sure record is not embargoed
if eprint.Documents != nil {
for i := 0; i < eprint.Documents.Length(); i++ {
doc := eprint.Documents.IndexOf(i)
if doc.DateEmbargo != "" {
embargo := new(simplified.Embargo)
embargo.Until = doc.DateEmbargo
if eprint.Suggestions != "" {
embargo.Reason = eprint.Suggestions
}
if doc.Security == "internal" {
embargo.Active = true
} else {
embargo.Active = false
}
rec.RecordAccess.Embargo = embargo
break
}
}
}
return nil
}
func uriToContributorType(role_uri string) string {
roles := map[string]string{
// Article Author
"http://coda.library.caltech.edu/ARA": "author_section",
// Astronaut
"http://coda.library.caltech.edu/AST": "astronaut",
// Author of afterword, colophon, etc.
"http://www.loc.gov/loc.terms/relators/AFT": "aft",
// Bibliographic antecedent
"http://www.loc.gov/loc.terms/relators/ANT": "ant",
// Author in quotations or text abstracts
"http://www.loc.gov/loc.terms/relators/AQT": "aqt",
// Screenwriter
"http://www.loc.gov/loc.terms/relators/AUS": "screenwriter",
// Author, joint author
"http://www.loc.gov/loc.terms/relators/AUT": "author",
// Collaborator
"http://www.loc.gov/loc.terms/relators/CLB": "collaborator",
// Compiler
"http://www.loc.gov/loc.terms/relators/COM": "compiler",
// Contributor
"http://www.loc.gov/loc.terms/relators/CTB": "contributor",
// Directory
"http://www.loc.gov/loc.terms/relators/DRT": "director",
// Editor
"http://www.loc.gov/loc.terms/relators/EDT": "editor",
// Narrator
"http://www.loc.gov/loc.terms/relators/NRT": "narrator",
// Other
"http://www.loc.gov/loc.terms/relators/OTH": "other",
// Publishing director
"http://www.loc.gov/loc.terms/relators/PBD": "publishing_director",
// Programmer
"http://www.loc.gov/loc.terms/relators/PRG": "programmer",
// Reviewer
"http://www.loc.gov/loc.terms/relators/REV": "reviewer",
// Research team member
"http://www.loc.gov/loc.terms/relators/RTM": "research_team",
// Speaker
"http://www.loc.gov/loc.terms/relators/SPK": "speaker",
// Teacher
"http://www.loc.gov/loc.terms/relators/TCH": "teacher",
// Translator
"http://www.loc.gov/loc.terms/relators/TRL": "translator",
}
if val, ok := roles[role_uri]; ok {
return val
}
return "contributor"
}
func creatorFromItem(item *Item, objType string, objRoleSrc string, objIdType string) *simplified.Creator {
person := new(simplified.PersonOrOrg)
person.Type = objType
if item.Name != nil {
person.FamilyName = item.Name.Family
person.GivenName = item.Name.Given
}
if item.ORCID != "" {
identifier := new(simplified.Identifier)
identifier.Scheme = "orcid"
identifier.Identifier = item.ORCID
person.Identifiers = append(person.Identifiers, identifier)
}
if item.ID != "" {
identifier := new(simplified.Identifier)
identifier.Scheme = objIdType
identifier.Identifier = item.ID
person.Identifiers = append(person.Identifiers, identifier)
}
creator := new(simplified.Creator)
creator.PersonOrOrg = person
switch objRoleSrc{
case "contributor":
//NOTE: for contributors we need to map the type as LOC URI
// to a person's role.
contributorType := "contributor"
if item != nil {
contributorType = uriToContributorType(item.Type)
}
creator.Role = &simplified.Role{ ID: contributorType }
case "editor":
creator.Role = &simplified.Role{ ID: "editor" }
}
// FIXME: For Creators we skip adding the role and affiliation for now,
// it break RDM.
//creator.PersonOrOrg.Role = &simplified.Role{ ID: objRoleSrc }
//FIXME: Need to map affiliation here when we're ready.
return creator
}
func dateTypeFromTimestamp(dtType string, timestamp string, description string) *simplified.DateType {
dt := new(simplified.DateType)
dt.Type = new(simplified.Type)
dt.Type.ID = dtType
dt.Type.Title = map[string]string{
"en": dtType,
}
dt.Description = description
if len(timestamp) > 9 {
dt.Date = timestamp[0:10]
} else {
dt.Date = timestamp
}
return dt
}
func mkSimpleIdentifier(scheme, value string) *simplified.Identifier {
identifier := new(simplified.Identifier)
identifier.Scheme = strings.ToLower(scheme)
identifier.Identifier = value
return identifier
}
func funderFromItem(item *Item) *simplified.Funder {
funder := new(simplified.Funder)
if item.GrantNumber != "" {
funder.Award = new(simplified.AwardIdentifier)
funder.Award.Number = item.GrantNumber
funder.Award.Scheme = "eprints_grant_number"
}
if item.Agency != "" {
org := new(simplified.FunderIdentifier)
org.Name = item.Agency
org.Scheme = "eprints_agency"
funder.Funder = org
}
return funder
}
// metadataFromEPrint extracts metadata from the EPrint record
func metadataFromEPrint(eprint *EPrint, rec *simplified.Record) error {
metadata := new(simplified.Metadata)
metadata.ResourceType = make(map[string]interface{})
metadata.ResourceType["id"] = eprint.Type
// NOTE: Creators get listed in the citation, Contributors do not.
if (eprint.Creators != nil) && (eprint.Creators.Items != nil) {
for _, item := range eprint.Creators.Items {
creator := creatorFromItem(item, "personal", "creator", "creator_id")
metadata.Creators = append(metadata.Creators, creator)
}
}
if (eprint.CorpCreators != nil) && (eprint.CorpCreators.Items != nil) {
for _, item := range eprint.CorpCreators.Items {
creator := creatorFromItem(item, "organizational", "corporate_creator", "organization_id")
metadata.Creators = append(metadata.Creators, creator)
}
}
if (eprint.Contributors != nil) && (eprint.Contributors.Items != nil) {
for _, item := range eprint.Contributors.Items {
contributor := creatorFromItem(item, "personal", "contributor", "contributor_id")
metadata.Contributors = append(metadata.Contributors, contributor)
}
}
if (eprint.CorpContributors != nil) && (eprint.CorpContributors.Items != nil) {
for _, item := range eprint.CorpContributors.Items {
contributor := creatorFromItem(item, "organizational", "corporate_contributor", "organization_id")
metadata.Contributors = append(metadata.Contributors, contributor)
}
}
if (eprint.Editors != nil) && (eprint.Editors.Items != nil) {
for _, item := range eprint.Editors.Items {
editor := creatorFromItem(item, "personal", "editor", "editor_id")
metadata.Contributors = append(metadata.Contributors, editor)
}
}
if (eprint.ThesisAdvisor != nil) && (eprint.ThesisAdvisor.Items != nil) {
for _, item := range eprint.ThesisAdvisor.Items {
advisor := creatorFromItem(item, "personal", "thesis_advisor", "thesis_advisor_id")
metadata.Contributors = append(metadata.Contributors, advisor)
}
}
if (eprint.ThesisCommittee != nil) && (eprint.ThesisCommittee.Items != nil) {
for _, item := range eprint.ThesisCommittee.Items {
committee := creatorFromItem(item, "personal", "thesis_committee", "thesis_committee_id")
metadata.Contributors = append(metadata.Contributors, committee)
}
}
metadata.Title = eprint.Title
if (eprint.AltTitle != nil) && (eprint.AltTitle.Items != nil) {
for _, item := range eprint.AltTitle.Items {
if strings.TrimSpace(item.Value) != "" {
title := new(simplified.TitleDetail)
title.Title = item.Value
metadata.AdditionalTitles = append(metadata.AdditionalTitles, title)
}
}
}
if eprint.Abstract != "" {
metadata.Description = eprint.Abstract
}
metadata.PublicationDate = eprint.PubDate()
// Rights are scattered in several EPrints fields, they need to
// be evaluated to create a "Rights" object used in DataCite/Invenio
addRights := false
rights := new(simplified.Right)
rights.Title = map[string]string{}
rights.Description = map[string]string{}
if eprint.Rights != "" {
addRights = true
/*
rights.Description = map["en"] &simplified.Description{
Description: eprint.Rights,
}
*/
rights.Description["en"] = eprint.Rights
}
// Figure out if our copyright information is in the Note field.
if (eprint.Note != "") && (strings.Contains(eprint.Note, "©") || strings.Contains(eprint.Note, "copyright") || strings.Contains(eprint.Note, "(c)")) {
addRights = true
/*
rights.Description = &simplified.Description{
Description: fmt.Sprintf("%s", eprint.Note),
}
*/
rights.Description["en"] = fmt.Sprintf("%s", eprint.Note)
}
if addRights {
metadata.Rights = append(metadata.Rights, rights)
}
if eprint.CopyrightStatement != "" {
rights := new(simplified.Right)
rights.Description = map[string]string{}
/*
rights.Description = &simplified.Description{
Description: eprint.CopyrightStatement,
}
*/
rights.Description["en"] = eprint.CopyrightStatement
metadata.Rights = append(metadata.Rights, rights)
}
// FIXME: work with Tom to sort out how "Rights" and document level
// copyright info should work.
if (eprint.Subjects != nil) && (eprint.Subjects.Items != nil) {
for _, item := range eprint.Subjects.Items {
subject := new(simplified.Subject)
subject.Subject = item.Value
metadata.Subjects = append(metadata.Subjects, subject)
}
}
// Dates are scattered through the primary eprint table.
if (eprint.DateType != "published") && (eprint.Date != "") {
metadata.Dates = append(metadata.Dates, dateTypeFromTimestamp("pub_date", eprint.Date, "Publication Date"))
}
if eprint.Datestamp != "" {
metadata.Dates = append(metadata.Dates, dateTypeFromTimestamp("created", eprint.Datestamp, "Created from EPrint's datestamp field"))
}
if eprint.LastModified != "" {
metadata.Dates = append(metadata.Dates, dateTypeFromTimestamp("updated", eprint.LastModified, "Created from EPrint's last_modified field"))
}
/*
// status_changed is not a date type in Invenio-RDM, might be mapped
// into available object.
// FIXME: is this date reflect when it changes status or when it was made available?
if eprint.StatusChanged != "" {
metadata.Dates = append(metadata.Dates, dateTypeFromTimestamp("status_changed", eprint.StatusChanged, "Created from EPrint's status_changed field"))
}
*/
if eprint.RevNumber != 0 {
metadata.Version = fmt.Sprintf("v%d", eprint.RevNumber)
}
if eprint.Publisher != "" {
metadata.Publisher = eprint.Publisher
} else if eprint.Publication != "" {
metadata.Publisher = eprint.Publication
} else if eprint.DOI == "" {
metadata.Publisher = "Caltech Library"
}
// Pickup EPrint ID as "external identifier" in .metadata.identifier
if eprint.EPrintID > 0 {
metadata.Identifiers = append(metadata.Identifiers, mkSimpleIdentifier("eprintid", fmt.Sprintf("%d", eprint.EPrintID)))
}
if eprint.DOI != "" {
metadata.Identifiers = append(metadata.Identifiers, mkSimpleIdentifier("doi", eprint.DOI))
}
if eprint.ISBN != "" {
metadata.Identifiers = append(metadata.Identifiers, mkSimpleIdentifier("isbn", eprint.ISBN))
}
if eprint.ISSN != "" {
metadata.Identifiers = append(metadata.Identifiers, mkSimpleIdentifier("issn", eprint.ISSN))
}
if eprint.PMCID != "" {
metadata.Identifiers = append(metadata.Identifiers, mkSimpleIdentifier("pmcid", eprint.PMCID))
}
if (eprint.Funders != nil) && (eprint.Funders.Items != nil) {
for _, item := range eprint.Funders.Items {
if item.Agency != "" {
metadata.Funding = append(metadata.Funding, funderFromItem(item))
}
}
}
rec.Metadata = metadata
return nil
}
// filesFromEPrint extracts all the file specific metadata from the
// EPrint record
func filesFromEPrint(eprint *EPrint, rec *simplified.Record) error {
// crosswalk Files from EPrints DocumentList
if (eprint != nil) && (eprint.Documents != nil) && (eprint.Documents.Length() > 0) {
addFiles := false
files := new(simplified.Files)
files.Order = []string{}
files.Enabled = true
files.Entries = map[string]*simplified.Entry{}
for i := 0; i < eprint.Documents.Length(); i++ {
doc := eprint.Documents.IndexOf(i)
if len(doc.Files) > 0 {
for _, docFile := range doc.Files {
addFiles = true
entry := new(simplified.Entry)
entry.FileID = docFile.URL
entry.Size = docFile.FileSize
entry.MimeType = docFile.MimeType
if docFile.Hash != "" {
entry.CheckSum = fmt.Sprintf("%s:%s", strings.ToLower(docFile.HashType), docFile.Hash)
}
files.Entries[docFile.Filename] = entry
if strings.HasPrefix(docFile.Filename, "preview") {
files.DefaultPreview = docFile.Filename
}
}
}
}
if addFiles {
rec.Files = files
} else {
rec.Files = nil
}
}
return nil
}
// tombstoneFromEPrint builds a tombstone is the EPrint record
// eprint_status is deletion.
func tombstoneFromEPrint(eprint *EPrint, rec *simplified.Record) error {
// FIXME: crosswalk Tombstone
if eprint.EPrintStatus == "deletion" {
tombstone := new(simplified.Tombstone)
tombstone.RemovedBy = new(simplified.User)
tombstone.RemovedBy.DisplayName = eprint.Reviewer
tombstone.RemovedBy.User = eprint.UserID
if eprint.Suggestions != "" {
tombstone.Reason = eprint.Suggestions
}
rec.Tombstone = tombstone
}
return nil
}
// createdUpdatedFromEPrint extracts
func createdUpdatedFromEPrint(eprint *EPrint, rec *simplified.Record) error {
var (
created, updated time.Time
err error
tmFmt string
)
// crosswalk Created date
if len(eprint.Datestamp) > 0 {
tmFmt = timestamp
if len(eprint.Datestamp) < 11 {
tmFmt = datestamp
}
created, err = time.Parse(tmFmt, eprint.Datestamp)
if err != nil {
return fmt.Errorf("Error parsing datestamp, %s", err)
}
rec.Created = created
}
if len(eprint.LastModified) > 0 {
tmFmt = timestamp
if len(eprint.LastModified) == 10 {
tmFmt = datestamp
}
updated, err = time.Parse(tmFmt, eprint.LastModified)
if err != nil {
return fmt.Errorf("Error parsing last modified date, %s", err)
}
rec.Updated = updated
}
return nil
}