Skip to content

Commit

Permalink
add Zenodo context to DarkTaxon streamer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Sep 6, 2024
1 parent 1c9b8af commit d231ce6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public boolean handle(IRI version, InputStream is) throws ContentStreamException
if (jsonNode.has(fieldName)) {
String type = jsonNode.get(fieldName).asText();
if ("http://rs.tdwg.org/ac/terms/Multimedia".equals(type)) {
writeDeposit(DarkTaxonUtil.toPhotoDeposit(jsonNode, publicationDateFactory, communities));
writeDeposit(DarkTaxonUtil.toPhotoDeposit(jsonNode, publicationDateFactory, ctx));
} else if ("http://rs.tdwg.org/dwc/terms/Occurrence".equals(type)) {
writeDeposit(DarkTaxonUtil.toPhysicalObjectDeposit(withNewline(line), publicationDateFactory, communities));
writeDeposit(DarkTaxonUtil.toPhysicalObjectDeposit(withNewline(line), publicationDateFactory, ctx));
} else if ("http://rs.tdwg.org/dwc/terms/Event".equals(type)) {
writeDeposit(DarkTaxonUtil.toEventDeposit(withNewline(line), publicationDateFactory, communities));
writeDeposit(DarkTaxonUtil.toEventDeposit(withNewline(line), publicationDateFactory, ctx));
}
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import bio.guoda.preston.Hasher;
import bio.guoda.preston.RefNodeFactory;
import bio.guoda.preston.store.HashKeyUtil;
import bio.guoda.preston.zenodo.ZenodoConfig;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -52,7 +53,8 @@ public static void setDescription(ObjectNode objectNode, String description) {
objectNode.put("description", description);
}

public static ObjectNode toPhotoDeposit(JsonNode multimediaRecord, PublicationDateFactory publicationDateFactory, List<String> communities) throws MissingMetadataFieldException {
public static ObjectNode toPhotoDeposit(JsonNode multimediaRecord, PublicationDateFactory publicationDateFactory, ZenodoConfig ctx) throws MissingMetadataFieldException {

String formatText = getValueOrThrow(multimediaRecord, "http://purl.org/dc/elements/1.1/format");

String filename = getValueOrThrow(multimediaRecord, "http://purl.org/dc/terms/identifier");
Expand Down Expand Up @@ -94,7 +96,7 @@ public static ObjectNode toPhotoDeposit(JsonNode multimediaRecord, PublicationDa
imageContentId.getIRIString(),
"image/" + formatText,
publicationDateFactory,
communities,
ctx.getCommunities(),
title,
description,
creators
Expand All @@ -119,7 +121,7 @@ private static String getValueOrThrow(JsonNode multimediaRecord, String fieldNam
return StringUtils.trim(node.asText());
}

static ObjectNode toEventDeposit(String jsonString, PublicationDateFactory publicationDateFactory, List<String> communities) throws JsonProcessingException, MissingMetadataFieldException {
static ObjectNode toEventDeposit(String jsonString, PublicationDateFactory publicationDateFactory, ZenodoConfig ctx) throws JsonProcessingException, MissingMetadataFieldException {
JsonNode multimedia = new ObjectMapper().readTree(jsonString);
ObjectNode zenodoMetadata = new ObjectMapper().createObjectNode();

Expand Down Expand Up @@ -148,7 +150,7 @@ static ObjectNode toEventDeposit(String jsonString, PublicationDateFactory publi
ZenodoMetaUtil.setValue(zenodoMetadata, ZenodoMetaUtil.UPLOAD_TYPE, ZenodoMetaUtil.UPLOAD_TYPE_EVENT);
ZenodoMetaUtil.setCreators(zenodoMetadata, Arrays.asList("Museum für Naturkunde Berlin"));
ZenodoMetaUtil.setValue(zenodoMetadata, PUBLICATION_DATE, publicationDateFactory.getPublicationDate());
ZenodoMetaUtil.setCommunities(zenodoMetadata, communities.stream());
ZenodoMetaUtil.setCommunities(zenodoMetadata, ctx.getCommunities().stream());
addReferences(zenodoMetadata);


Expand All @@ -160,7 +162,7 @@ private static void addReferences(ObjectNode zenodoMetadata) {
ZenodoMetaUtil.append(zenodoMetadata, ZenodoMetaUtil.REFERENCES, "Srivathsan, A., Meier, R. (2024). Scalable, Cost-Effective, and Decentralized DNA Barcoding with Oxford Nanopore Sequencing. In: DeSalle, R. (eds) DNA Barcoding. Methods in Molecular Biology, vol 2744. Humana, New York, NY. https://doi.org/10.1007/978-1-0716-3581-0_14");
}

public static ObjectNode toPhysicalObjectDeposit(String jsonString, PublicationDateFactory publicationDateFactory, List<String> communities) throws JsonProcessingException, MissingMetadataFieldException {
public static ObjectNode toPhysicalObjectDeposit(String jsonString, PublicationDateFactory publicationDateFactory, ZenodoConfig ctx) throws JsonProcessingException, MissingMetadataFieldException {
JsonNode multimedia = new ObjectMapper().readTree(jsonString);

ObjectNode zenodoMetadata = new ObjectMapper().createObjectNode();
Expand Down Expand Up @@ -218,7 +220,7 @@ public static ObjectNode toPhysicalObjectDeposit(String jsonString, PublicationD
ZenodoMetaUtil.setValue(zenodoMetadata, ZenodoMetaUtil.UPLOAD_TYPE, ZenodoMetaUtil.UPLOAD_TYPE_PHYSICAL_OBJECT);
ZenodoMetaUtil.setCreators(zenodoMetadata, Arrays.asList("Museum für Naturkunde Berlin"));
ZenodoMetaUtil.setValue(zenodoMetadata, PUBLICATION_DATE, publicationDateFactory.getPublicationDate());
ZenodoMetaUtil.setCommunities(zenodoMetadata, communities.stream());
ZenodoMetaUtil.setCommunities(zenodoMetadata, ctx.getCommunities().stream());
addReferences(zenodoMetadata);

return ZenodoMetaUtil.wrap(zenodoMetadata);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bio.guoda.preston.cmd;

import bio.guoda.preston.store.TestUtil;
import bio.guoda.preston.zenodo.ZenodoContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -23,7 +24,7 @@ public void photoDeposit() throws IOException, MissingMetadataFieldException {
JsonNode multimedia = new ObjectMapper().readTree(getClass().getResourceAsStream("darktaxon/multimedia.json"));
assertNotNull(multimedia);

ObjectNode zenodoDeposit = DarkTaxonUtil.toPhotoDeposit(multimedia, getPublicationDateFactory(), Arrays.asList("mfn-test"));
ObjectNode zenodoDeposit = DarkTaxonUtil.toPhotoDeposit(multimedia, getPublicationDateFactory(), getTestConfig());

String actual = zenodoDeposit.toPrettyString();

Expand All @@ -36,7 +37,7 @@ public void photoDepositMissingData() throws IOException, MissingMetadataFieldEx
JsonNode multimedia = new ObjectMapper().readTree(getClass().getResourceAsStream("darktaxon/multimedia-missing-lsid.json"));
assertNotNull(multimedia);

DarkTaxonUtil.toPhotoDeposit(multimedia, getPublicationDateFactory(), Arrays.asList("mfn-test"));
DarkTaxonUtil.toPhotoDeposit(multimedia, getPublicationDateFactory(), getTestConfig());

}

Expand All @@ -51,7 +52,7 @@ public void eventDeposit() throws IOException, MissingMetadataFieldException {
public String getPublicationDate() {
return "1999-12-31";
}
}, Arrays.asList("mfn-test"));
}, getTestConfig());
String actual = zenodoDeposit.toPrettyString();

assertThat(actual, Is.is(IOUtils.toString(getClass().getResourceAsStream("darktaxon/event-zenodo.json"), StandardCharsets.UTF_8)));
Expand All @@ -69,15 +70,19 @@ public void eventDepositMissingData() throws IOException, MissingMetadataFieldEx
public String getPublicationDate() {
return "1999-12-31";
}
}, Arrays.asList("mfn-test"));
}, getTestConfig());
}

private ZenodoContext getTestConfig() {
return new ZenodoContext("SECRET", "https://example.org", Arrays.asList("mfn-test"));
}

@Test
public void physicalObjectDeposit() throws IOException, MissingMetadataFieldException {
InputStream resourceAsStream = getClass().getResourceAsStream("darktaxon/occurrence.json");
assertNotNull(resourceAsStream);
String jsonString = TestUtil.removeCarriageReturn(IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8));
ObjectNode zenodoDeposit = DarkTaxonUtil.toPhysicalObjectDeposit(jsonString, getPublicationDateFactory(), Arrays.asList("mfn-test"));
ObjectNode zenodoDeposit = DarkTaxonUtil.toPhysicalObjectDeposit(jsonString, getPublicationDateFactory(), getTestConfig());
String actual = zenodoDeposit.toPrettyString();

assertThat(actual, Is.is(IOUtils.toString(getClass().getResourceAsStream("darktaxon/occurrence-zenodo.json"), StandardCharsets.UTF_8)));
Expand All @@ -89,7 +94,7 @@ public void physicalObjectDepositMissingData() throws IOException, MissingMetada
InputStream resourceAsStream = getClass().getResourceAsStream("darktaxon/occurrence-missing-lsid.json");
assertNotNull(resourceAsStream);
String jsonString = TestUtil.removeCarriageReturn(IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8));
ObjectNode zenodoDeposit = DarkTaxonUtil.toPhysicalObjectDeposit(jsonString, getPublicationDateFactory(), Arrays.asList("mfn-test"));
ObjectNode zenodoDeposit = DarkTaxonUtil.toPhysicalObjectDeposit(jsonString, getPublicationDateFactory(), getTestConfig());
String actual = zenodoDeposit.toPrettyString();

assertThat(actual, Is.is(IOUtils.toString(getClass().getResourceAsStream("darktaxon/occurrence-zenodo.json"), StandardCharsets.UTF_8)));
Expand All @@ -100,7 +105,7 @@ public void physicalObjectDepositWithKeyImage() throws IOException, MissingMetad
InputStream resourceAsStream = getClass().getResourceAsStream("darktaxon/occurrence-with-key-image.json");
assertNotNull(resourceAsStream);
String jsonString = TestUtil.removeCarriageReturn(IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8));
ObjectNode zenodoDeposit = DarkTaxonUtil.toPhysicalObjectDeposit(jsonString, getPublicationDateFactory(), Arrays.asList("mfn-test"));
ObjectNode zenodoDeposit = DarkTaxonUtil.toPhysicalObjectDeposit(jsonString, getPublicationDateFactory(), getTestConfig());
String actual = zenodoDeposit.toPrettyString();

assertThat(actual, Is.is(IOUtils.toString(getClass().getResourceAsStream("darktaxon/occurrence-with-key-image-zenodo.json"), StandardCharsets.UTF_8)));
Expand Down

0 comments on commit d231ce6

Please sign in to comment.