Skip to content

Commit

Permalink
Handle embargo correctly in NIHMS XML. Also make some minor cleanups …
Browse files Browse the repository at this point in the history
…to the serializer.
  • Loading branch information
markpatton authored and rpoet-jh committed Nov 6, 2023
1 parent b4a05b7 commit c7dd7fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,41 @@ private void write_metadata(Document doc) {
LocalDate now = LocalDate.now();

if (lift.isAfter(now)) {
Period period = Period.between(LocalDate.now(), lift);
root.setAttribute("embargo-months", "" + period.getMonths());
long months = Period.between(LocalDate.now(), lift).toTotalMonths();

// The max embargo time is 12 months
if (months > 12) {
months = 12;
}

root.setAttribute("embargo-months", "" + months);
}
}

if (article != null && article.getDoi() != null) {
// DOI may not include UTI's scheme or host, only path
String path = article.getDoi().getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}

root.setAttribute("doi", path);
}

// There is an optional agency attribute.
// Should only be used for non-NIH funders when grant information is also given

if (journal != null) {
Element journal_meta = doc.createElement("journal-meta");
root.appendChild(journal_meta);

add_text_element(doc, journal_meta, "nlm-ta", journal.getJournalId());

// If the IssnPubType is incomplete (either the pubType or issn is null or
// empty), we should omit it from the metadata, per NIH's requirements.
// See https://github.com/OA-PASS/metadata-schemas/pull/28 and
// https://github.com/OA-PASS/jhu-package-providers/issues/16
journal.getIssnPubTypes().values().forEach(issnPubType -> {
// if the IssnPubType is incomplete (either the pubType or issn is null or
// empty), we should
// omit it from the metadata, per NIH's requirements
// See https://github.com/OA-PASS/metadata-schemas/pull/28 and
// https://github.com/OA-PASS/jhu-package-providers/issues/16
if (issnPubType.pubType == null || issnPubType.issn == null || issnPubType.issn.trim().isEmpty()) {
LOG.debug("Discarding incomplete ISSN: {}", issnPubType);
return;
Expand All @@ -139,27 +157,13 @@ private void write_metadata(Document doc) {
});

add_text_element(doc, journal_meta, "journal-title", journal.getJournalTitle());

// TODO No place for journal.getJournalType
}

if (manuscript != null) {
if (manuscript != null && manuscript.title != null) {
add_text_element(doc, root, "manuscript-title", manuscript.title);
}

// TODO No place to put manuscript.getManuscriptUrl()
// TODO Add citation element?

if (article != null && article.getDoi() != null) {
// DOI may not include UTI's scheme or host, only path
// TODO Cannot find any documentation about this
String path = article.getDoi().getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}

root.setAttribute("doi", path);
}
// Could add a citation element if we had all the information

List<DepositMetadata.Person> persons = metadata.getPersons();

Expand Down Expand Up @@ -205,5 +209,8 @@ private void write_metadata(Document doc) {
}
}
}

// Could add grant information here if it was useful.
// Can only be used for a set list of funders
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setUp() throws Exception {
mdBuilder = mock(MetadataBuilder.class);

String expectedSubmissionUuid = UUID.randomUUID().toString();
when(submission.getId()).thenReturn("http://example.org/" + expectedSubmissionUuid);
when(submission.getId()).thenReturn(expectedSubmissionUuid);

when(mdBuilder.build()).thenReturn(metadata);

Expand Down

0 comments on commit c7dd7fb

Please sign in to comment.