Skip to content

Commit

Permalink
do not allow zenodo pubs without publication date by default; provide…
Browse files Browse the repository at this point in the history
… an override; associated with #303
  • Loading branch information
Jorrit Poelen committed Sep 5, 2024
1 parent 39ff2f2 commit abc049a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CmdZenodo extends LoggingPersisting implements Runnable {
private List<String> communities = Collections.emptyList();

@CommandLine.Option(
names = {"--restricted-only"},
names = {"--restricted-access-only"},
description = "always set [access_right] to [restricted]"
)
private boolean publishRestrictedOnly = false;
Expand All @@ -58,6 +58,12 @@ public class CmdZenodo extends LoggingPersisting implements Runnable {
)
private boolean updateMetadataOnly;

@CommandLine.Option(
names = {"--allow-empty-publication-date"},
description = "Zenodo accepts deposits with empty publication dates. On accepting a deposit without publication date, Zenodo sets the publication date to current date/time by default."
)
private boolean allowEmptyPublicationDate;


@Override
public void run() {
Expand All @@ -82,6 +88,7 @@ public void run(BlobStoreReadOnly blobStoreReadOnly) {
zenodoContext.setCreateNewVersionForExisting(createNewVersionForExisting);
zenodoContext.setPublishRestrictedOnly(publishRestrictedOnly);
zenodoContext.setUpdateMetadataOnly(updateMetadataOnly);
zenodoContext.setAllowEmptyPublicationDate(allowEmptyPublicationDate);
StatementsListener textMatcher = new ZenodoMetadataFileExtractor(
this,
blobStoreReadOnly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public interface ZenodoConfig {
void setUpdateMetadataOnly(boolean updateMetadataOnly);

boolean shouldUpdateMetadataOnly();

void setAllowEmptyPublicationDate(boolean allowEmptyPublicationDate);

boolean shouldAllowEmptyPublicationDate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public class ZenodoContext implements ZenodoConfig {


private boolean createNewVersionForExisting = false;
private boolean restrictedOnly;
private boolean updateMetadataOnly;
private boolean restrictedOnly = false;
private boolean updateMetadataOnly = false;
private boolean allowEmptyPublicationDate = false;

public ZenodoContext(String accessToken) {
this(accessToken, "https://sandbox.zenodo.org");
Expand Down Expand Up @@ -111,4 +112,14 @@ public void setUpdateMetadataOnly(boolean updateMetadataOnly) {
public boolean shouldUpdateMetadataOnly() {
return updateMetadataOnly;
}

@Override
public void setAllowEmptyPublicationDate(boolean allowEmptyPublicationDate) {
this.allowEmptyPublicationDate = allowEmptyPublicationDate;
}

@Override
public boolean shouldAllowEmptyPublicationDate() {
return allowEmptyPublicationDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ private void createNewVersion(IRI coordinate, JsonNode zenodoMetadata, List<Stri

ZenodoContext ctxLocal = new ZenodoContext(this.ctx);

if (hasAllowedPublicationDate(zenodoMetadata, ctx)) {
throw new IOException("missing publication date for [" + zenodoMetadata.toPrettyString() + "]");
}

if (ctx.shouldPublishRestrictedOnly()) {
JsonNode at = zenodoMetadata.at("/metadata");
if (at.isObject()) {
Expand Down Expand Up @@ -193,6 +197,11 @@ private void createNewVersion(IRI coordinate, JsonNode zenodoMetadata, List<Stri
}
}

public static boolean hasAllowedPublicationDate(JsonNode zenodoMetadata, ZenodoConfig ctx) {
return !zenodoMetadata.at("/metadata/publication_date").isMissingNode()
|| ctx.shouldAllowEmptyPublicationDate();
}

private void emitRefreshed(ZenodoContext ctxLocal) {
emitter.emit(
RefNodeFactory.toStatement(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package bio.guoda.preston.zenodo;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.*;

public class ZenodoMetadataFileStreamHandlerTest {

@Test
public void allowedDefinedPubDate() throws IOException {
JsonNode jsonNode = new ObjectMapper().readTree(getClass().getResourceAsStream("batlit-data/example-batlit.json"));

ZenodoContext contextDefault = new ZenodoContext("bla");
assertTrue(ZenodoMetadataFileStreamHandler.hasAllowedPublicationDate(jsonNode, contextDefault));
}

@Test
public void allowedEmptyPubDate() throws IOException {
JsonNode jsonNode = new ObjectMapper().readTree(getClass().getResourceAsStream("batlit-data/example-batlit-no-pubdate.json"));

ZenodoContext contextDefault = new ZenodoContext("bla");
contextDefault.setAllowEmptyPublicationDate(true);
assertTrue(ZenodoMetadataFileStreamHandler.hasAllowedPublicationDate(jsonNode, contextDefault));
}

@Test
public void nonEmptyPubDateAllowed() throws IOException {
JsonNode jsonNode = new ObjectMapper().readTree(getClass().getResourceAsStream("batlit-data/example-batlit.json"));

ZenodoContext contextDefault = new ZenodoContext("bla");
contextDefault.setAllowEmptyPublicationDate(false);
assertTrue(ZenodoMetadataFileStreamHandler.hasAllowedPublicationDate(jsonNode, contextDefault));
}

@Test
public void emptyPubDateNotAllowed() throws IOException {
JsonNode jsonNode = new ObjectMapper().readTree(getClass().getResourceAsStream("batlit-data/example-batlit-no-pubdate.json"));

ZenodoContext contextDefault = new ZenodoContext("bla");
assertFalse(ZenodoMetadataFileStreamHandler.hasAllowedPublicationDate(jsonNode, contextDefault));
}

@Test
public void emptyPubDateNotAllowed2() throws IOException {
JsonNode jsonNode = new ObjectMapper().readTree(getClass().getResourceAsStream("batlit-data/example-batlit-no-pubdate.json"));

ZenodoContext contextDefault = new ZenodoContext("bla");
contextDefault.setAllowEmptyPublicationDate(false);
assertFalse(ZenodoMetadataFileStreamHandler.hasAllowedPublicationDate(jsonNode, contextDefault));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"metadata":{"filename":"Thomas - 1912 - XXII.— A new Vespertilionine bat from Angolai.pdf","related_identifiers":[{"relation":"isAlternateIdentifier","identifier":"hash://md5/4c64e5b3477ea92404d0c915eaf06da3"},{"relation":"isAlternateIdentifier","identifier":"urn:lsid:zotero.org:groups:5435545:items:BF9WCVE5"},{"relation":"hasVersion","identifier":"hash://md5/4c64e5b3477ea92404d0c915eaf06da3"},{"relation":"hasVersion","identifier":"hash://sha256/691316c043fb8e6d686b034dd604cfd5e78e60205d4b2c0f404ce0cb81af9764"},{"relation":"isDerivedFrom","identifier":"zotero://select/groups/5435545/items/BF9WCVE5"},{"relation":"isDerivedFrom","identifier":"https://zotero.org/groups/5435545/items/BF9WCVE5"},{"relation":"isDerivedFrom","identifier":"https://linker.bio/cut:hash://md5/bd79ea31e23eae8897a9291bf4d7f24a!/b164740-167173"},{"relation":"isPartOf","identifier":"hash://md5/26f7ce5dd404e33c6570edd4ba250d20"},{"relation":"isAlternateIdentifier","identifier":"10.1080/00222931208693218"},{"relation":"isCompiledBy","identifier":"10.5281/zenodo.1410543","resource_type":"software"}],"communities":[{"identifier":"batlit"},{"identifier":"biosyslit"}],"http://www.w3.org/ns/prov#wasDerivedFrom":"https://linker.bio/cut:hash://md5/bd79ea31e23eae8897a9291bf4d7f24a!/b164740-167173","upload_type":"publication","http://www.w3.org/1999/02/22-rdf-syntax-ns#type":"application/json","referenceId":"https://api.zotero.org/groups/5435545/items/BF9WCVE5","creators":[{"name":"Thomas, Oldfield"}],"publication_type":"article","title":"A new Vespertilionine bat from Angola","journal_title":"Annals and Magazine of Natural History","journal_volume":"10","journal_issue":"56","journal_pages":"204-206","keywords":["Biodiversity","Mammalia","Chiroptera","Chordata","Animalia","bats","bat"],"custom":{"dwc:kingdom":["Animalia"],"dwc:phylum":["Chordata"],"dwc:class":["Mammalia"],"dwc:order":["Chiroptera"]},"description":"(Uploaded by Plazi for the Bat Literature Project) No abstract provided."}}

0 comments on commit abc049a

Please sign in to comment.