-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update NIHMS metadata, Adding Grant and Funder to bulk_meta.xml #79
Changes from 33 commits
b3c6343
72d15a9
21b7584
d67069c
6b6573f
a90e231
a3e4080
ab148a3
c02a9a0
7771af8
23ffc13
d571614
f0d6471
9123db4
b1e2591
40dbdee
cbcc853
85fcb7d
1ad3b52
39874de
a70b638
3a0c45f
bc1b17d
6cb893d
5be99d0
6d18160
9b63b14
8000aa2
68a08ba
1d05b45
adc236c
6d28894
1d79d1d
9152306
c5da2e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,10 @@ | |
import java.time.LocalDate; | ||
import java.time.Period; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.transform.OutputKeys; | ||
|
@@ -30,6 +33,8 @@ | |
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.eclipse.pass.deposit.assembler.PackageOptions; | ||
import org.eclipse.pass.deposit.assembler.SizedStream; | ||
import org.eclipse.pass.deposit.model.DepositMetadata; | ||
import org.eclipse.pass.deposit.model.JournalPublicationType; | ||
|
@@ -48,9 +53,19 @@ public class NihmsMetadataSerializer implements StreamingSerializer { | |
private static final Logger LOG = LoggerFactory.getLogger(NihmsMetadataSerializer.class); | ||
|
||
private DepositMetadata metadata; | ||
private Map<String, String> funderMapping = new HashMap<>(); | ||
|
||
public NihmsMetadataSerializer(DepositMetadata metadata) { | ||
public NihmsMetadataSerializer(DepositMetadata metadata, Map<String, Object> packageOptions) { | ||
this.metadata = metadata; | ||
Object funderMappingObj = packageOptions.get(PackageOptions.FunderMapping.KEY); | ||
if (funderMappingObj instanceof Map<?, ?>) { | ||
this.funderMapping = ((Map<?, ?>) funderMappingObj).entrySet().stream() | ||
.collect(Collectors.toMap( | ||
e -> (String) e.getKey(), | ||
e -> (String) e.getValue())); | ||
} else { | ||
throw new ClassCastException("FunderMapping is not a Map<String, String>"); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -92,16 +107,27 @@ private void add_text_element(Document doc, Element parent, String name, String | |
} | ||
|
||
private void write_metadata(Document doc) { | ||
DepositMetadata.Manuscript manuscript = metadata.getManuscriptMetadata(); | ||
DepositMetadata.Article article = metadata.getArticleMetadata(); | ||
DepositMetadata.Journal journal = metadata.getJournalMetadata(); | ||
|
||
Element root = doc.createElement("manuscript-submit"); | ||
doc.appendChild(root); | ||
|
||
if (manuscript.getNihmsId() != null) { | ||
addManuscriptMetadata(root); | ||
addArticleMetadata(root); | ||
addJournalMetadata(doc, root); | ||
addManuscriptTitle(doc, root); | ||
addContacts(doc, root); | ||
addGrants(doc, root); | ||
} | ||
|
||
private void addManuscriptMetadata(Element root) { | ||
DepositMetadata.Manuscript manuscript = metadata.getManuscriptMetadata(); | ||
|
||
if (StringUtils.isNotBlank(manuscript.getNihmsId())) { | ||
root.setAttribute("manuscript-id", manuscript.getNihmsId()); | ||
} | ||
} | ||
|
||
private void addArticleMetadata(Element root) { | ||
DepositMetadata.Article article = metadata.getArticleMetadata(); | ||
|
||
if (article != null && metadata.getArticleMetadata().getEmbargoLiftDate() != null) { | ||
LocalDate lift = article.getEmbargoLiftDate().toLocalDate(); | ||
|
@@ -128,6 +154,10 @@ private void write_metadata(Document doc) { | |
|
||
root.setAttribute("doi", path); | ||
} | ||
} | ||
|
||
private void addJournalMetadata(Document doc, Element root) { | ||
DepositMetadata.Journal journal = metadata.getJournalMetadata(); | ||
|
||
// There is an optional agency attribute. | ||
// Should only be used for non-NIH funders when grant information is also given | ||
|
@@ -143,7 +173,7 @@ private void write_metadata(Document doc) { | |
// 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 (issnPubType.pubType == null || issnPubType.issn == null || issnPubType.issn.trim().isEmpty()) { | ||
if (issnPubType.pubType == null || StringUtils.isBlank(issnPubType.issn)) { | ||
LOG.debug("Discarding incomplete ISSN: {}", issnPubType); | ||
return; | ||
} | ||
|
@@ -159,15 +189,21 @@ private void write_metadata(Document doc) { | |
add_text_element(doc, journal_meta, "journal-title", journal.getJournalTitle()); | ||
} | ||
|
||
if (manuscript != null && manuscript.title != null) { | ||
} | ||
|
||
private void addManuscriptTitle(Document doc, Element root) { | ||
DepositMetadata.Manuscript manuscript = metadata.getManuscriptMetadata(); | ||
|
||
if (manuscript != null && StringUtils.isNotBlank(manuscript.title)) { | ||
add_text_element(doc, root, "manuscript-title", manuscript.title); | ||
} | ||
|
||
// Could add a citation element if we had all the information | ||
} | ||
|
||
private void addContacts(Document doc, Element root) { | ||
List<DepositMetadata.Person> persons = metadata.getPersons(); | ||
|
||
if (persons != null && persons.size() > 0) { | ||
if (persons != null && !persons.isEmpty()) { | ||
Element contacts = doc.createElement("contacts"); | ||
root.appendChild(contacts); | ||
|
||
|
@@ -177,20 +213,20 @@ private void write_metadata(Document doc) { | |
Element p = doc.createElement("person"); | ||
contacts.appendChild(p); | ||
|
||
if (person.getFirstName() != null) { | ||
if (StringUtils.isNotBlank(person.getFirstName())) { | ||
p.setAttribute("fname", person.getFirstName()); | ||
} else { | ||
if (person.getFullName() != null) { | ||
if (StringUtils.isNotBlank(person.getFullName())) { | ||
p.setAttribute("fname", person.getFullName().split("\\s")[0]); | ||
} | ||
} | ||
if (person.getMiddleName() != null) { | ||
if (StringUtils.isNotBlank(person.getMiddleName())) { | ||
p.setAttribute("mname", person.getMiddleName()); | ||
} | ||
if (person.getLastName() != null) { | ||
if (StringUtils.isNotBlank(person.getLastName())) { | ||
p.setAttribute("lname", person.getLastName()); | ||
} else { | ||
if (person.getFullName() != null) { | ||
if (StringUtils.isNotBlank(person.getFullName())) { | ||
String[] split = person.getFullName().split("\\s"); | ||
if (split.length > 2) { | ||
// middle name is present | ||
|
@@ -201,16 +237,76 @@ private void write_metadata(Document doc) { | |
} | ||
} | ||
} | ||
if (person.getEmail() != null) { | ||
if (StringUtils.isNotBlank(person.getEmail())) { | ||
p.setAttribute("email", person.getEmail()); | ||
} | ||
|
||
p.setAttribute("person-type", "author"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void addGrants(Document doc, Element root) { | ||
List<DepositMetadata.Grant> grantsList = metadata.getGrantsMetadata(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is already very long. It would be good to pull this new code out into a new method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about creating a method just for the grants, but it would seem awkward for only that component to have it's own method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, your suggestion would be good clean up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
if (grantsList != null && !grantsList.isEmpty()) { | ||
List<String> funderKeys = grantsList.stream() | ||
.map(DepositMetadata.Grant::getFunderLocalKey) | ||
.toList(); | ||
|
||
//Only create the top level grant element if at least one of the keys is associated with nihms | ||
if (funderLocalKeyExists(funderKeys)) { | ||
|
||
Element grantsElement = doc.createElement("grants"); | ||
root.appendChild(grantsElement); | ||
|
||
// Could add grant information here if it was useful. | ||
// Can only be used for a set list of funders | ||
for (DepositMetadata.Grant grant : grantsList) { | ||
if (funderMapping.containsKey(grant.getFunderLocalKey())) { | ||
if (StringUtils.isNotBlank(grant.getFunder())) { | ||
Element grantElement = doc.createElement("grant"); | ||
grantsElement.appendChild(grantElement); | ||
|
||
//use the nihms abbreviations for funders, the accepted list is in the nihms DTD | ||
grantElement.setAttribute("funder", funderMapping.get(grant.getFunderLocalKey())); | ||
|
||
if (StringUtils.isNotBlank(grant.getGrantId())) { | ||
grantElement.setAttribute("id", grant.getGrantId()); | ||
} | ||
|
||
DepositMetadata.Person pi = grant.getGrantPi(); | ||
if (pi != null) { | ||
Element piElement = doc.createElement("PI"); | ||
grantElement.appendChild(piElement); | ||
|
||
if (StringUtils.isNotBlank(pi.getFirstName())) { | ||
piElement.setAttribute("fname", pi.getFirstName()); | ||
} | ||
if (StringUtils.isNotBlank(pi.getLastName())) { | ||
piElement.setAttribute("lname", pi.getLastName()); | ||
} | ||
if (StringUtils.isNotBlank(pi.getEmail())) { | ||
piElement.setAttribute("email", pi.getEmail()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Used to determine if one of the grants localKeys exists in the list of accepted nihms funders | ||
* | ||
* @return True if at least one nihms funderKey exists in the metadata grant list | ||
*/ | ||
private boolean funderLocalKeyExists(List<String> metaDataGrantFunderKeys) { | ||
for (String key : metaDataGrantFunderKeys) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's right. Much cleaner using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if (funderMapping.containsKey(key)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,44 @@ | |
"algorithms": [ | ||
"sha512", | ||
"md5" | ||
] | ||
], | ||
"funder-mapping": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking we don't want this map here in the src repositories.json since it is specific to JHU. I think it should be removed, which means you will need to create a new test-repositories.json most likely to test your code, but I think it is cleaner to this for the community. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
"johnshopkins.edu:funder:300032": "ahqr", | ||
"johnshopkins.edu:funder:300293": "cdc", | ||
"johnshopkins.edu:funder:300859": "cdc", | ||
"johnshopkins.edu:funder:301459": "va", | ||
"johnshopkins.edu:funder:300453": "epa", | ||
"johnshopkins.edu:funder:303444": "hhmi", | ||
"johnshopkins.edu:funder:300484": "nih", | ||
"johnshopkins.edu:funder:300865": "nih", | ||
"johnshopkins.edu:funder:300869": "nih", | ||
"johnshopkins.edu:funder:300866": "nih", | ||
"johnshopkins.edu:funder:308302": "nih", | ||
"johnshopkins.edu:funder:305950": "nih", | ||
"johnshopkins.edu:funder:302727": "nih", | ||
"johnshopkins.edu:funder:300863": "nih", | ||
"johnshopkins.edu:funder:300874": "nih", | ||
"johnshopkins.edu:funder:300861": "nih", | ||
"johnshopkins.edu:funder:300842": "nih", | ||
"johnshopkins.edu:funder:303587": "nih", | ||
"johnshopkins.edu:funder:303586": "nih", | ||
"johnshopkins.edu:funder:306099": "nih", | ||
"johnshopkins.edu:funder:300858": "nih", | ||
"johnshopkins.edu:funder:301479": "nih", | ||
"johnshopkins.edu:funder:300870": "nih", | ||
"johnshopkins.edu:funder:303589": "nih", | ||
"johnshopkins.edu:funder:300860": "nih", | ||
"johnshopkins.edu:funder:300852": "nih", | ||
"johnshopkins.edu:funder:302822": "nih", | ||
"johnshopkins.edu:funder:302592": "nih", | ||
"johnshopkins.edu:funder:303585": "nih", | ||
"johnshopkins.edu:funder:303574": "nih", | ||
"johnshopkins.edu:funder:300867": "nih", | ||
"johnshopkins.edu:funder:303580": "nih", | ||
"johnshopkins.edu:funder:301978": "nih", | ||
"johnshopkins.edu:funder:305204": "aspr", | ||
"johnshopkins.edu:funder:303395": "fda" | ||
} | ||
} | ||
}, | ||
"transport-config": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that's not longer used. Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.