Skip to content

Commit

Permalink
Merge branch 'main' into russ-856-email-intgr
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Jan 16, 2024
2 parents 3e53ca3 + 0c6a2e7 commit 3b65699
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,11 @@ enum OPTS {

}

/**
* Funder Mapping for Nihms Packages
*/
interface FunderMapping {
String KEY = "FUNDER-MAPPING";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public DepositSubmission createDepositSubmission(Submission submissionEntity, Li
metadata.setJournalMetadata(journal);
ArrayList<DepositMetadata.Person> persons = new ArrayList<>();
metadata.setPersons(persons);
ArrayList<DepositMetadata.Grant> grants = new ArrayList<>();
metadata.setGrantsMetadata(grants);

// Data from the Submission resource
submission.setId(submissionEntity.getId());
Expand Down Expand Up @@ -129,6 +131,7 @@ public DepositSubmission createDepositSubmission(Submission submissionEntity, Li
// Data from the User resources for the PI and CoPIs
User piEntity = grantEntity.getPi();
persons.add(createPerson(piEntity, DepositMetadata.PERSON_TYPE.pi));
grants.add(createGrant(piEntity, grantEntity));

for (User copiEntity : grantEntity.getCoPis()) {
persons.add(createPerson(copiEntity, DepositMetadata.PERSON_TYPE.copi));
Expand Down Expand Up @@ -188,6 +191,15 @@ private DepositMetadata.Person createAuthor(String fullName) {
return person;
}

private DepositMetadata.Grant createGrant(User userEntity, Grant grantEntity) {
DepositMetadata.Grant grant = new DepositMetadata.Grant();
grant.setGrantId(grantEntity.getAwardNumber());
grant.setGrantPi(createPerson(userEntity, DepositMetadata.PERSON_TYPE.pi));
grant.setFunder(grantEntity.getPrimaryFunder().getName());
grant.setFunderLocalKey(grantEntity.getPrimaryFunder().getLocalKey());
return grant;
}

/**
* Convenience method for retrieving a string property.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public int hashCode() {
@Override
public String toString() {
return "RepositoryDepositConfig{" + "depositProcessing=" + depositProcessing +
", statusMapping=" + statusMapping + '}';
", statusMapping=" + statusMapping + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.time.Period;
import java.util.Arrays;
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;
Expand All @@ -30,6 +32,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;
Expand All @@ -48,9 +52,19 @@ public class NihmsMetadataSerializer implements StreamingSerializer {
private static final Logger LOG = LoggerFactory.getLogger(NihmsMetadataSerializer.class);

private DepositMetadata metadata;
private Map<String, String> funderMapping;

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
Expand Down Expand Up @@ -92,16 +106,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();
Expand All @@ -128,6 +153,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
Expand All @@ -143,7 +172,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;
}
Expand All @@ -159,15 +188,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);

Expand All @@ -177,20 +212,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
Expand All @@ -201,16 +236,62 @@ 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();

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 (funderKeys.stream().anyMatch(funderMapping::containsKey)) {

Element grantsElement = doc.createElement("grants");
root.appendChild(grantsElement);

for (DepositMetadata.Grant grant : grantsList) {
if (funderMapping.containsKey(grant.getFunderLocalKey())) {
if (StringUtils.isNotBlank(grant.getFunder())) {
Element grantElement = doc.createElement("grant");
grantsElement.appendChild(grantElement);

// Could add grant information here if it was useful.
// Can only be used for a set list of funders
if (StringUtils.isNotBlank(grant.getGrantId())) {
grantElement.setAttribute("id", grant.getGrantId());
}

//use the nihms abbreviations for funders, the accepted list is in the nihms DTD
grantElement.setAttribute("funder", funderMapping.get(grant.getFunderLocalKey()));

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());
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static String getNonCollidingFilename(String fileName, DepositFileType fi
public void start(DepositSubmission submission, List<DepositFileResource> custodialResources,
Map<String, Object> packageOptions) {
manifestSerializer = new NihmsManifestSerializer(submission.getManifest());
metadataSerializer = new NihmsMetadataSerializer(submission.getMetadata());
metadataSerializer = new NihmsMetadataSerializer(submission.getMetadata(), packageOptions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ static Function<Deposit, TransportResponse> performDeposit(DepositWorkerContext

try {
packager = dc.packager();

packageStream = packager.getAssembler().assemble(
dc.depositSubmission(), packager.getAssemblerOptions());
packagerConfig = packager.getConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public class DepositSubmissionModelBuilderIT extends AbstractDepositSubmissionIT
private static final String EXPECTED_DOI = "10.1039/c7fo01251a";
private static final String EXPECTED_EMBARGO_END_DATE = "2018-06-30";
private static final int EXPECTED_SUBMITER_COUNT = 1;
private static final int EXPECTED_PI_COUNT = 1;
private static final int EXPECTED_CO_PI_COUNT = 2;
private static final int EXPECTED_PI_COUNT = 2;
private static final int EXPECTED_CO_PI_COUNT = 4;
private static final int EXPECTED_AUTHOR_COUNT = 6;
private static final String EXPECTED_NLMTA = "Food Funct";
private static final String EXPECTED_GRANT1 = "R01EY026617";
private static final String EXPECTED_GRANT2 = "R01EY026618";
private static final Map<String, DepositMetadata.IssnPubType> EXPECTED_ISSNS =
new HashMap<>() {
{
Expand Down Expand Up @@ -159,10 +161,15 @@ public void testBuildDepositSubmission() throws IOException {
.anyMatch(author ->
author.getName().equals("Raymond J. Playford")));

//test the grants associated with the submission
List<DepositMetadata.Grant> grants = submission.getMetadata().getGrantsMetadata();

assertNotNull(grants.stream().filter(matchGrant -> matchGrant.getGrantId() == EXPECTED_GRANT1));
assertNotNull(grants.stream().filter(matchGrant -> matchGrant.getGrantId() == EXPECTED_GRANT2));

// Read something out of the submission metadata
assertTrue(submission.getSubmissionMeta().has("agreements"));
JsonObject agreement = submission.getSubmissionMeta().getAsJsonObject("agreements");
assertTrue(agreement.has("JScholarship"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void commonContributorsAndFewAuthors() throws Exception {
assertEquals("Elsevier", qdc.getElementsByTagNameNS(DC_NS, DC_PUBLISHER).item(0).getTextContent());

// Contributor list does not include submitting user, only PIs (from Grant) and authors (from metadata)
assertEquals(5, qdc.getElementsByTagNameNS(DC_NS, DC_CONTRIBUTOR).getLength());
assertEquals(8, qdc.getElementsByTagNameNS(DC_NS, DC_CONTRIBUTOR).getLength());
for (int i = 0; i < 5; i++) {
// Contributors must have names, whether they come from
// first/middle/last or only display name (in Submission), or from metadata.
Expand Down
Loading

0 comments on commit 3b65699

Please sign in to comment.