Skip to content
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 XML metadata to match latest version #66

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

import static org.eclipse.pass.deposit.assembler.AssemblerSupport.buildMetadata;

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

import org.eclipse.pass.deposit.assembler.AbstractAssembler;
import org.eclipse.pass.deposit.assembler.ArchivingPackageStream;
Expand All @@ -45,7 +43,7 @@ public class NihmsAssembler extends AbstractAssembler {
* Package specification URI identifying the NIHMS native packaging spec, as specified by their 07/2017
* bulk publishing pdf.
*/
public static final String SPEC_NIHMS_NATIVE_2017_07 = "nihms-native-2017-07";
public static final String SPEC_NIHMS_NATIVE_2022_05 = "nihms-native-2022-05";

/**
* Mime type of zip files.
Expand Down Expand Up @@ -81,20 +79,11 @@ protected PackageStream createPackageStream(DepositSubmission submission,
}

static void namePackage(DepositSubmission submission, MetadataBuilder mb) {
String submissionUuid = null;

try {
URI submissionUri = URI.create(submission.getId());
submissionUuid = submissionUri.getPath().substring(submissionUri.getPath().lastIndexOf("/") + 1);
} catch (Exception e) {
submissionUuid = UUID.randomUUID().toString();
}

String packageFileName = String.format(PACKAGE_FILE_NAME,
SPEC_NIHMS_NATIVE_2017_07,
SPEC_NIHMS_NATIVE_2022_05,
ZonedDateTime.now()
.format(DateTimeFormatter.ofPattern("uuuu-MM-dd_HH-MM-ss")),
submissionUuid);
submission.getId());

StringBuilder ext = new StringBuilder(packageFileName);
PackageStream.Metadata md = mb.build();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.eclipse.pass.deposit.provider.nihms;

import static org.eclipse.pass.deposit.provider.nihms.NihmsAssembler.APPLICATION_GZIP;
import static org.eclipse.pass.deposit.provider.nihms.NihmsAssembler.SPEC_NIHMS_NATIVE_2017_07;
import static org.eclipse.pass.deposit.provider.nihms.NihmsAssembler.SPEC_NIHMS_NATIVE_2022_05;
import static org.eclipse.pass.deposit.util.DepositTestUtil.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -78,7 +78,7 @@ public void setUp() throws Exception {
protected Map<String, Object> getOptions() {
return new HashMap<>() {
{
put(Spec.KEY, SPEC_NIHMS_NATIVE_2017_07);
put(Spec.KEY, SPEC_NIHMS_NATIVE_2022_05);
put(Archive.KEY, Archive.OPTS.TAR);
put(Compression.KEY, Compression.OPTS.GZIP);
}
Expand All @@ -101,7 +101,7 @@ protected void verifyStreamMetadata(PackageStream.Metadata metadata) {
assertEquals(Compression.OPTS.GZIP, metadata.compression());
assertEquals(Archive.OPTS.TAR, metadata.archive());
assertTrue(metadata.archived());
assertEquals(SPEC_NIHMS_NATIVE_2017_07, metadata.spec());
assertEquals(SPEC_NIHMS_NATIVE_2022_05, metadata.spec());
assertEquals(APPLICATION_GZIP, metadata.mimeType());
}

Expand Down Expand Up @@ -205,10 +205,10 @@ public void testPackageMetadata() throws Exception {

// root element is <nihms-submit>
Element root = metaDom.getDocumentElement();
assertEquals("nihms-submit", root.getTagName());
assertEquals("manuscript-submit", root.getTagName());

// required <title> element is present with the manuscript title as the value
Element title = asList(root.getElementsByTagName("title")).get(0);
// required <manuscript-title> element is present with the manuscript title as the value
Element title = asList(root.getElementsByTagName("manuscript-title")).get(0);
assertEquals(submission.getMetadata().getManuscriptMetadata().getTitle(), title.getTextContent());

// Insure that only one <person> element is present in the submission metadata
Expand Down Expand Up @@ -242,8 +242,7 @@ public void testPackageMetadata() throws Exception {
});

// Assert that the DOI is present in the metadata
Element ms = asList(root.getElementsByTagName("manuscript")).get(0);
assertEquals(submission.getMetadata().getArticleMetadata().getDoi().toString(), ms.getAttribute("doi"));
assertEquals(submission.getMetadata().getArticleMetadata().getDoi().toString(), root.getAttribute("doi"));

// Assert that the ISSNs are present in the metadata as the <issn> element
List<Element> issns = asList(root.getElementsByTagName("issn"));
Expand All @@ -255,10 +254,10 @@ public void testPackageMetadata() throws Exception {
issns.forEach(issn -> assertTrue(issnPubTypes.containsKey(issn.getTextContent())));
issns.forEach(issn -> {
DepositMetadata.IssnPubType pubType = issnPubTypes.get(issn.getTextContent());
if (pubType.pubType == JournalPublicationType.OPUB) {
assertEquals(issn.getAttribute("pub-type"), JournalPublicationType.EPUB.name().toLowerCase());
if (pubType.pubType == JournalPublicationType.OPUB || pubType.pubType == JournalPublicationType.EPUB) {
assertEquals(issn.getAttribute("issn-type"), "electronic");
} else {
assertEquals(issn.getAttribute("pub-type"), pubType.pubType.name().toLowerCase());
assertEquals(issn.getAttribute("issn-type"), "print");
}
});

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -42,6 +43,7 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.stream.StreamSource;

import com.github.jknack.handlebars.internal.Files;
import org.apache.commons.io.IOUtils;
import org.eclipse.pass.deposit.assembler.SizedStream;
import org.eclipse.pass.deposit.model.DepositMetadata;
Expand Down Expand Up @@ -101,6 +103,7 @@ public void setup() throws Exception {

// populate article metadata
article.setDoi(URI.create("10.1234/smh0000001"));
article.setEmbargoLiftDate(ZonedDateTime.now().plusYears(100));

//populate persons
DepositMetadata.Person person1 = new DepositMetadata.Person();
Expand All @@ -113,8 +116,8 @@ public void setup() throws Exception {

// Enter the first person twice, as both an author and a PI
DepositMetadata.Person person1a = new DepositMetadata.Person(person1);
person1.setType(DepositMetadata.PERSON_TYPE.pi);
personList.add(person1);
person1a.setType(DepositMetadata.PERSON_TYPE.pi);
personList.add(person1a);

DepositMetadata.Person person2 = new DepositMetadata.Person();
person2.setType(DepositMetadata.PERSON_TYPE.submitter);
Expand Down Expand Up @@ -160,7 +163,7 @@ public void testSerializedMetadataValidity() throws Exception {
OutputStream os = new FileOutputStream(targetFile);

os.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".getBytes());
os.write("<!DOCTYPE nihms-submit SYSTEM \"bulksubmission.dtd\">\n".getBytes());
os.write("<!DOCTYPE manuscript-submit SYSTEM \"bulksubmission.dtd\">\n".getBytes());
os.write(buffer);
os.close();

Expand All @@ -170,6 +173,15 @@ public void testSerializedMetadataValidity() throws Exception {
v.setSchemaSource(dtd);
StreamSource s = new StreamSource(targetFile);
ValidationResult r = v.validateInstance(s);

if (!r.isValid()) {
System.err.println(Files.read(targetFile, UTF_8));

r.getProblems().forEach(p -> {
System.err.println(p);
});
}

assertTrue(r.isValid());
}

Expand All @@ -186,15 +198,15 @@ public void testSerializedMetadataDoi() throws Exception {
metadata.getArticleMetadata().setDoi(URI.create(path));
sizedStream = underTest.serialize();
is = sizedStream.getInputStream();
node = builder.parse(is).getDocumentElement().getFirstChild().getNextSibling();
node = builder.parse(is).getDocumentElement();
doi = node.getAttributes().getNamedItem("doi").getTextContent();
is.close();
assertTrue(doi.contentEquals(path));

metadata.getArticleMetadata().setDoi(URI.create("http://dx.doi.org/" + path));
sizedStream = underTest.serialize();
is = sizedStream.getInputStream();
node = builder.parse(is).getDocumentElement().getFirstChild().getNextSibling();
node = builder.parse(is).getDocumentElement();
doi = node.getAttributes().getNamedItem("doi").getTextContent();
is.close();
assertTrue(doi.contentEquals(path));
Expand All @@ -208,9 +220,7 @@ public void completeIssnPubtype() throws IOException, ParserConfigurationExcepti
DepositMetadata metadata = new DepositMetadata();
DepositMetadata.Journal journalMd = new DepositMetadata.Journal();
String expectedIssn = "foo";
String expectedPubType = JournalPublicationType.EPUB.name()
.toLowerCase(); // remember OPUB is mapped to EPUB when
// serializing
String expectedPubType = "electronic";

DepositMetadata.IssnPubType issn = new DepositMetadata.IssnPubType(expectedIssn, JournalPublicationType.OPUB);
journalMd.setIssnPubTypes(new HashMap<>() {
Expand All @@ -236,7 +246,7 @@ public void completeIssnPubtype() throws IOException, ParserConfigurationExcepti
new RuntimeException(
"Missing expected <issn> element for " + expectedIssn + " and " + expectedPubType));

assertEquals(expectedPubType, actualIssn.getAttributes().getNamedItem("pub-type").getNodeValue());
assertEquals(expectedPubType, actualIssn.getAttributes().getNamedItem("issn-type").getNodeValue());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.eclipse.pass.deposit.provider.nihms;

import static java.util.Collections.singletonList;
import static org.eclipse.pass.deposit.provider.nihms.NihmsAssembler.SPEC_NIHMS_NATIVE_2017_07;
import static org.eclipse.pass.deposit.provider.nihms.NihmsAssembler.SPEC_NIHMS_NATIVE_2022_05;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -41,7 +41,7 @@ protected AbstractAssembler assemblerUnderTest() {
protected Map<String, Object> packageOptions() {
return new HashMap<>() {
{
put(PackageOptions.Spec.KEY, SPEC_NIHMS_NATIVE_2017_07);
put(PackageOptions.Spec.KEY, SPEC_NIHMS_NATIVE_2022_05);
put(PackageOptions.Archive.KEY, PackageOptions.Archive.OPTS.TAR);
put(PackageOptions.Compression.KEY, PackageOptions.Compression.OPTS.GZIP);
put(PackageOptions.Checksum.KEY, singletonList(PackageOptions.Checksum.OPTS.SHA256));
Expand Down
Loading
Loading