Skip to content

Commit

Permalink
Checkstyle fixes and add test for DSpace metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
markpatton committed Dec 19, 2024
1 parent d0481d1 commit 5bf461e
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,32 @@
import org.springframework.stereotype.Component;

/**
* dc.title for the Manuscript
* dc.publisher for the publisher name
* dc.identifier.citation for the Manuscript
* dc.identifier.doi for the DOI
* dc.contributor for each non-submitter associated with the Manuscript
* dc.description.abstract for the Manuscript
* dc.date.issued for the publication date
* DSPACE_FIELD_EMBARGO_LIFT Date that the embargo is lifted
* DSPACE_FIELD_EMBARGO_TERMS Date that the embargo is lifted
* DSpace metadata fields set:
* <ul>
* <li>dc.title for the Manuscript
* <li>dc.publisher for the publisher name
* <li>dc.identifier.citation for the Manuscript
* <li>dc.identifier.doi for the DOI
* <li>dc.contributor for each non-submitter associated with the Manuscript
* <li>dc.description.abstract for the Manuscript
* <li>dc.date.issued for the publication date
* <li>DSPACE_FIELD_EMBARGO_LIFT Date that the embargo is lifted
* <li>DSPACE_FIELD_EMBARGO_TERMS Date that the embargo is lifted
* </ul>
*/
@Component
public class DSpaceMetadataMapper {
// Section of workspace item form to add metadata
private static final String SECTION = "traditionalpageone";

@Value("${dspace.field.embargo.lift}")
private String dspaceFieldEmbargoLift;
private final String dspaceFieldEmbargoLift;
private final String dspaceFieldEmbargoTerms;

@Value("${dspace.field.embargo.terms}")
private String dspaceFieldEmbargoTerms;
public DSpaceMetadataMapper(@Value("${dspace.field.embargo.lift}") String dspaceFieldEmbargoLift,
@Value("${dspace.field.embargo.terms}") String dspaceFieldEmbargoTerms) {
this.dspaceFieldEmbargoLift = dspaceFieldEmbargoLift;
this.dspaceFieldEmbargoTerms = dspaceFieldEmbargoTerms;
}

public String patchWorkspaceItem(DepositSubmission submission) {
DepositMetadata depositMd = submission.getMetadata();
Expand All @@ -59,10 +65,8 @@ public String patchWorkspaceItem(DepositSubmission submission) {

JSONArray metadata = new JSONArray();

String title = manuscriptMd.getTitle();

// Required by DSpace
metadata.add(add_array(SECTION, "dc.title", title));
metadata.add(add_array(SECTION, "dc.title", manuscriptMd.getTitle()));

if (journalMd != null && journalMd.getPublisherName() != null) {
metadata.add(add_array(SECTION, "dc.publisher", journalMd.getPublisherName()));
Expand Down Expand Up @@ -140,7 +144,7 @@ private JSONObject array_value(String value) {
return obj;
}

// TODO Could we use citation in CrossRef metadata?
// TODO Could we use citation from CrossRef metadata?
private String createCitation(DepositSubmission submission) {
DepositMetadata submissionMd = submission.getMetadata();
DepositMetadata.Article articleMd = submissionMd.getArticleMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public TransportResponse send(PackageStream packageStream, Map<String, String> m
workspaceItemId = Integer.parseInt(ref.substring(DEPOSIT_STATUS_REF_PREFIX.length()));
}
} catch (NumberFormatException e) {
// nop
}

if (workspaceItemId == -1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package org.eclipse.pass.deposit.provider.dspace;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.net.URI;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;

import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.eclipse.pass.deposit.model.DepositManifest;
import org.eclipse.pass.deposit.model.DepositMetadata;
import org.eclipse.pass.deposit.model.DepositMetadata.Article;
import org.eclipse.pass.deposit.model.DepositMetadata.Journal;
import org.eclipse.pass.deposit.model.DepositMetadata.Manuscript;
import org.eclipse.pass.deposit.model.DepositMetadata.PERSON_TYPE;
import org.eclipse.pass.deposit.model.DepositMetadata.Person;
import org.eclipse.pass.deposit.model.DepositSubmission;
import org.junit.jupiter.api.Test;

public class DSpaceMetadataMapperTest {
@Test
public void testPatchWorkspaceItem() {
DSpaceMetadataMapper mapper = new DSpaceMetadataMapper("test.embargo.lift", "test.embargo.terms");

DepositSubmission ds = new DepositSubmission();
DepositManifest manifest = new DepositManifest();
DepositMetadata md = new DepositMetadata();

ds.setManifest(manifest);
ds.setMetadata(md);

Article article = md.getArticleMetadata();
Journal journal = md.getJournalMetadata();
Manuscript manuscript = md.getManuscriptMetadata();

manuscript.setTitle("this is a title");
manuscript.setMsAbstract("This is a compelling abstract.");
journal.setJournalTitle("journal title");
journal.setPublisherName("publisher name");
article.setDoi(URI.create("10.1016/j.iheduc.2015.08.004"));
article.setIssue("1");
article.setVolume("2");

Person author1 = new Person();
author1.setEmail("p1@example.com");
author1.setFirstName("P1");
author1.setFullName("P1 Person");
author1.setLastName("Person");
author1.setMiddleName("One");
author1.setType(PERSON_TYPE.author);

Person author2 = new Person();
author2.setEmail("p2@example.com");
author2.setFirstName("P2");
author2.setFullName("P2 Person");
author2.setLastName("Person");
author2.setMiddleName("Two");
author2.setType(PERSON_TYPE.author);

md.getPersons().add(author1);
md.getPersons().add(author2);

ZonedDateTime pubDate = ZonedDateTime.now();
ZonedDateTime embargoDate = pubDate.plusYears(1);

journal.setPublicationDate(pubDate);
article.setEmbargoLiftDate(embargoDate);

ds.setSubmissionDate(pubDate);

String json = mapper.patchWorkspaceItem(ds);

DocumentContext jsonContext = JsonPath.parse(json);

checkValue(jsonContext, "dc.title", manuscript.getTitle());
checkValue(jsonContext, "dc.identifier.doi", article.getDoi().toString());
checkValue(jsonContext, "dc.description.abstract", manuscript.getMsAbstract());
checkValue(jsonContext, "dc.publisher", journal.getPublisherName());
checkValue(jsonContext, "dc.identifier.citation",
"Person, P1 One, Person, P2 Two. (2024-12-19). journal title. 2 (1). 10.1016/j.iheduc.2015.08.004.");
checkValue(jsonContext, "dc.contributor.author", "P1 Person", "P2 Person");
checkValue(jsonContext, "dc.date.issued",
journal.getPublicationDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
checkValue(jsonContext, "test.embargo.lift",
article.getEmbargoLiftDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
checkValue(jsonContext, "test.embargo.terms",
article.getEmbargoLiftDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
}

private void checkValue(DocumentContext context, String key, String... expected) {
String path = "$[?(@.path == '/sections/traditionalpageone/" + key + "')].value[*].value";

List<String> values = context.read(path);

assertEquals(Arrays.asList(expected), values);
}

@Test
public void testPatchWorkspaceItemMinimalMetadata() {
DSpaceMetadataMapper mapper = new DSpaceMetadataMapper("test.embargo.lift", "test.embargo.terms");

DepositSubmission ds = new DepositSubmission();
DepositManifest manifest = new DepositManifest();
DepositMetadata md = new DepositMetadata();
Journal journal = md.getJournalMetadata();

ds.setManifest(manifest);
ds.setMetadata(md);

Manuscript manuscript = md.getManuscriptMetadata();
ZonedDateTime pubDate = ZonedDateTime.now();

manuscript.setTitle("this is a title");
journal.setPublicationDate(pubDate);

String json = mapper.patchWorkspaceItem(ds);

DocumentContext jsonContext = JsonPath.parse(json);

checkValue(jsonContext, "dc.title", manuscript.getTitle());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,10 @@ private void initDSpaceApiStubs() throws IOException {
private void verifyDSpaceApiStubs(int expectedCount) throws IOException {
WireMock.verify(expectedCount, getRequestedFor(urlEqualTo("/dspace/api/security/csrf")));
WireMock.verify(expectedCount, postRequestedFor(urlEqualTo("/dspace/api/authn/#")));
WireMock.verify(expectedCount, getRequestedFor(urlEqualTo("/dspace/api/discover/search/objects?query=handle:collectionhandle")));
WireMock.verify(expectedCount, postRequestedFor(urlEqualTo("/dspace/api/submission/workspaceitems?owningCollection=collectionuuid")));
WireMock.verify(expectedCount, getRequestedFor(
urlEqualTo("/dspace/api/discover/search/objects?query=handle:collectionhandle")));
WireMock.verify(expectedCount, postRequestedFor(
urlEqualTo("/dspace/api/submission/workspaceitems?owningCollection=collectionuuid")));
WireMock.verify(expectedCount, patchRequestedFor(urlEqualTo("/dspace/api/submission/workspaceitems/1")));
WireMock.verify(expectedCount, postRequestedFor(urlEqualTo("/dspace/api/workflow/workflowitems")));
}
Expand Down

0 comments on commit 5bf461e

Please # to comment.