From 6cb893d08fc82bc3bd82aa40970c79f378197d33 Mon Sep 17 00:00:00 2001 From: Timothy Sanders Date: Tue, 9 Jan 2024 16:45:42 -0500 Subject: [PATCH] Cleanup --- .../nihms/NihmsMetadataSerializer.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/provider/nihms/NihmsMetadataSerializer.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/provider/nihms/NihmsMetadataSerializer.java index 80465eed..7fb72271 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/provider/nihms/NihmsMetadataSerializer.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/provider/nihms/NihmsMetadataSerializer.java @@ -198,7 +198,7 @@ private void addManuscriptTitle(Document doc, Element root) { private void addContacts(Document doc, Element root) { List persons = metadata.getPersons(); - if (persons != null && persons.size() > 0) { + if (persons != null && !persons.isEmpty()) { Element contacts = doc.createElement("contacts"); root.appendChild(contacts); @@ -247,37 +247,40 @@ private void addGrants(Document doc, Element root) { if (grantsList != null && !grantsList.isEmpty()) { List funderKeys = grantsList.stream() - .map(DepositMetadata.Grant::getFunderLocalKey) // Map each Grant to its funderKey - .collect(Collectors.toList()); + .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); for (DepositMetadata.Grant grant : grantsList) { - if (StringUtils.isNotBlank(grant.getFunder())) { - Element grantElement = doc.createElement("grant"); - grantsElement.appendChild(grantElement); - grantElement.setAttribute("funder", grant.getFunder()); - - 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(funderMapping.containsKey(grant.getFunderLocalKey())) { + if (StringUtils.isNotBlank(grant.getFunder())) { + Element grantElement = doc.createElement("grant"); + grantsElement.appendChild(grantElement); + grantElement.setAttribute("funder", funderMapping.get(grant.getFunderLocalKey())); + + if (StringUtils.isNotBlank(grant.getGrantId())) { + grantElement.setAttribute("id", grant.getGrantId()); } - if (StringUtils.isNotBlank(pi.getEmail())) { - piElement.setAttribute("email", pi.getEmail()); + + 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()); + } } } }