From 5c3209d07e703f039c25c72b28c0f781e0718c42 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 16 Jan 2023 13:58:51 +0100 Subject: [PATCH] Generalised solution --- ...lyser.java => SoftwareConfigAnalyser.java} | 90 +++++++++---------- .../analyser/SoftwareVersionAnalyser.java | 75 ---------------- .../SoftwareVersionConfigAnalyser.java | 89 ++++++++++++++++++ .../software/model/ProcessorConfig.java | 49 ++++++++++ ...Concept.java => SoftwareGlobalConfig.java} | 41 ++++++--- ...ersion.java => SoftwareVersionConfig.java} | 16 ++-- .../common/software/model/Variables.java | 11 ++- .../process/SoftwareVersionProcessor.java | 21 +++-- .../BibLaTeXSoftwareVersionExporter.java | 2 +- .../ZenodoSoftwareVersionPublisher.java | 63 +++++++------ .../analyser/SoftwareConceptAnalyserTest.java | 2 +- .../resources/exported-gcat-from-scratch.json | 33 ++++--- src/test/resources/gcat-from-scratch.json | 29 +++--- src/test/resources/gcat-test-sandbox.json | 30 ++++--- 14 files changed, 323 insertions(+), 228 deletions(-) rename src/main/java/org/gcube/common/software/analyser/{SoftwareConceptAnalyser.java => SoftwareConfigAnalyser.java} (54%) delete mode 100644 src/main/java/org/gcube/common/software/analyser/SoftwareVersionAnalyser.java create mode 100644 src/main/java/org/gcube/common/software/analyser/SoftwareVersionConfigAnalyser.java create mode 100644 src/main/java/org/gcube/common/software/model/ProcessorConfig.java rename src/main/java/org/gcube/common/software/model/{SoftwareConcept.java => SoftwareGlobalConfig.java} (73%) rename src/main/java/org/gcube/common/software/model/{SoftwareVersion.java => SoftwareVersionConfig.java} (90%) diff --git a/src/main/java/org/gcube/common/software/analyser/SoftwareConceptAnalyser.java b/src/main/java/org/gcube/common/software/analyser/SoftwareConfigAnalyser.java similarity index 54% rename from src/main/java/org/gcube/common/software/analyser/SoftwareConceptAnalyser.java rename to src/main/java/org/gcube/common/software/analyser/SoftwareConfigAnalyser.java index 8f87326..388b2db 100644 --- a/src/main/java/org/gcube/common/software/analyser/SoftwareConceptAnalyser.java +++ b/src/main/java/org/gcube/common/software/analyser/SoftwareConfigAnalyser.java @@ -8,10 +8,9 @@ import java.util.concurrent.TimeUnit; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; -import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType; import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; -import org.gcube.common.software.model.SoftwareConcept; -import org.gcube.common.software.model.SoftwareVersion; +import org.gcube.common.software.model.SoftwareGlobalConfig; +import org.gcube.common.software.model.SoftwareVersionConfig; import org.gcube.common.software.model.Variables; import org.gcube.common.software.utils.Utils; import org.slf4j.Logger; @@ -20,31 +19,29 @@ import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ -public class SoftwareConceptAnalyser { +public class SoftwareConfigAnalyser { - private static final Logger logger = LoggerFactory.getLogger(SoftwareConceptAnalyser.class); + private static final Logger logger = LoggerFactory.getLogger(SoftwareConfigAnalyser.class); - public static final String CONCEPT_FILENAME_EXTENSION = ".json"; + public static final String EXPORT_FILENAME_EXTENSION = ".json"; - public static final String CONCEPT_PROPERTY_NAME = "concept"; + public static final String GLOBAL_PROPERTY_NAME = "global"; public static final String VERSIONS_PROPERTY_NAME = "versions"; - public static final String PUBLISHERS_PROPERTY_NAME = "publishers"; - public static final String EXPORTERS_PROPERTY_NAME = "exporters"; protected ObjectMapper objectMapper; protected JsonNode jsonNode; - public SoftwareConceptAnalyser(File jsonFile) throws Exception { + public SoftwareConfigAnalyser(File jsonFile) throws Exception { this.objectMapper = Utils.getObjectMapper(); this.jsonNode = objectMapper.readTree(jsonFile); } - public SoftwareConceptAnalyser(String json) throws Exception { + public SoftwareConfigAnalyser(String json) throws Exception { this.objectMapper = Utils.getObjectMapper(); this.jsonNode = objectMapper.readTree(json); } - protected SoftwareVersion actualize(JsonNode version) throws Exception { + protected SoftwareVersionConfig actualize(JsonNode version) throws Exception { Variables variables = objectMapper.treeToValue(version, Variables.class); Set missingVariables = variables.parse(); int size = missingVariables.size(); @@ -53,18 +50,20 @@ public class SoftwareConceptAnalyser { missingVariables.toArray(new String[size]).toString()); } JsonNode swVersion = objectMapper.convertValue(variables.getProperties(), JsonNode.class); - SoftwareVersion softwareVersion = objectMapper.treeToValue(swVersion, SoftwareVersion.class); + SoftwareVersionConfig softwareVersion = objectMapper.treeToValue(swVersion, SoftwareVersionConfig.class); // softwareVersion.setVariables(variables); return softwareVersion; } public void analyse() throws Exception { - ObjectNode concept = (ObjectNode) jsonNode.get(CONCEPT_PROPERTY_NAME).deepCopy(); - SoftwareConcept softwareConcept = objectMapper.treeToValue(concept, SoftwareConcept.class); + ObjectNode originalGlobal = (ObjectNode) jsonNode.get(GLOBAL_PROPERTY_NAME).deepCopy(); + SoftwareGlobalConfig softwareGlobalConfig = objectMapper.treeToValue(originalGlobal, SoftwareGlobalConfig.class); + softwareGlobalConfig.setOriginalJson(originalGlobal); + ArrayNode versions = (ArrayNode) jsonNode.get(VERSIONS_PROPERTY_NAME); - String name = softwareConcept.getName(); - SoftwareVersion previous = null; + String name = softwareGlobalConfig.getName(); + SoftwareVersionConfig previous = null; int i = 0; @@ -73,9 +72,11 @@ public class SoftwareConceptAnalyser { for(i=0; i svfs = softwareVersion.getFiles(); - for(SoftwareVersionFile svf : svfs) { - URL url = svf.getURL(); - String urlString = variables.replaceAllVariables(url.toString()); - svf.setURL(new URL(urlString)); - String desiredName = svf.getDesiredName(); - desiredName = variables.replaceAllVariables(desiredName); - svf.setDesiredName(desiredName); - } - - ObjectNode publishers = (ObjectNode) originalJson.get(SoftwareConceptAnalyser.PUBLISHERS_PROPERTY_NAME).deepCopy(); - List svps = SoftwareVersionPublisher.getPublishers(); - for(SoftwareVersionPublisher svp: svps) { - JsonNode conf = publishers.get(svp.getClass().getSimpleName()); - svp.setSpecificConfiguration(conf); - svp.setSoftwareVersion(softwareVersion); - svp.setFirst(first); - svp.publish(); - } - - ObjectNode exporters = (ObjectNode) originalJson.get(SoftwareConceptAnalyser.EXPORTERS_PROPERTY_NAME).deepCopy(); - List sves = SoftwareVersionExporter.getExporters(); - for(SoftwareVersionExporter sve: sves) { - JsonNode conf = publishers.get(exporters.getClass().getSimpleName()); - sve.setSpecificConfiguration(conf); - sve.setSoftwareVersion(softwareVersion); - sve.setFirst(first); - sve.export(); - } - - } - - - -} diff --git a/src/main/java/org/gcube/common/software/analyser/SoftwareVersionConfigAnalyser.java b/src/main/java/org/gcube/common/software/analyser/SoftwareVersionConfigAnalyser.java new file mode 100644 index 0000000..b52cbe9 --- /dev/null +++ b/src/main/java/org/gcube/common/software/analyser/SoftwareVersionConfigAnalyser.java @@ -0,0 +1,89 @@ +package org.gcube.common.software.analyser; + +import java.net.URL; +import java.util.List; +import java.util.Map; + +import org.gcube.common.software.model.ProcessorConfig; +import org.gcube.common.software.model.SoftwareGlobalConfig; +import org.gcube.common.software.model.SoftwareVersionConfig; +import org.gcube.common.software.model.SoftwareVersionFile; +import org.gcube.common.software.model.Variables; +import org.gcube.common.software.process.export.SoftwareVersionExporter; +import org.gcube.common.software.process.publish.SoftwareVersionPublisher; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class SoftwareVersionConfigAnalyser { + + protected SoftwareGlobalConfig softwareGlobalConfig; + protected SoftwareVersionConfig softwareVersionConfig; + protected boolean first; + + public SoftwareVersionConfigAnalyser(SoftwareVersionConfig softwareVersionConfig) { + this.softwareVersionConfig = softwareVersionConfig; + } + + public SoftwareGlobalConfig getSoftwareGlobalConfig() { + return softwareGlobalConfig; + } + + public void setSoftwareGlobalConfig(SoftwareGlobalConfig softwareGlobalConfig) { + this.softwareGlobalConfig = softwareGlobalConfig; + } + + public SoftwareVersionConfig getSoftwareVersionConfig() { + return softwareVersionConfig; + } + + public void setSoftwareVersionConfig(SoftwareVersionConfig softwareVersionConfig) { + this.softwareVersionConfig = softwareVersionConfig; + } + + public boolean isFirst() { + return first; + } + + public void setFirst(boolean first) { + this.first = first; + } + + public void analyse() throws Exception { + Variables variables = softwareVersionConfig.getVariables(); + List svfs = softwareVersionConfig.getFiles(); + for(SoftwareVersionFile svf : svfs) { + URL url = svf.getURL(); + String urlString = variables.replaceAllVariables(url.toString()); + svf.setURL(new URL(urlString)); + String desiredName = svf.getDesiredName(); + desiredName = variables.replaceAllVariables(desiredName); + svf.setDesiredName(desiredName); + } + + Map processors = softwareVersionConfig.getPublishers(); + List svps = SoftwareVersionPublisher.getPublishers(); + for(SoftwareVersionPublisher svp: svps) { + ProcessorConfig processorConfig = processors.get(svp.getClass().getSimpleName()); + svp.setProcessorConfig(processorConfig); + svp.setSoftwareVersion(softwareVersionConfig); + svp.setFirst(first); + svp.publish(); + } + + + Map exporters = softwareVersionConfig.getExporters(); + List sves = SoftwareVersionExporter.getExporters(); + for(SoftwareVersionExporter sve: sves) { + ProcessorConfig processorConfig = exporters.get(sve.getClass().getSimpleName()); + sve.setProcessorConfig(processorConfig); + sve.setSoftwareVersion(softwareVersionConfig); + sve.setFirst(first); + sve.export(); + } + + } + + + +} diff --git a/src/main/java/org/gcube/common/software/model/ProcessorConfig.java b/src/main/java/org/gcube/common/software/model/ProcessorConfig.java new file mode 100644 index 0000000..a73434b --- /dev/null +++ b/src/main/java/org/gcube/common/software/model/ProcessorConfig.java @@ -0,0 +1,49 @@ +package org.gcube.common.software.model; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter; +import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter; +import org.gcube.com.fasterxml.jackson.annotation.JsonFormat; +import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; +import org.gcube.com.fasterxml.jackson.annotation.JsonProperty; +import org.gcube.com.fasterxml.jackson.databind.JsonNode; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class ProcessorConfig { + + public static final String ELABORATION_PROPERTY_NAME = "elaboration"; + + @JsonProperty(ELABORATION_PROPERTY_NAME) + @JsonFormat(shape=JsonFormat.Shape.STRING) + protected ElaborationType elaboration; + + protected Map properties; + + public ProcessorConfig() { + properties = new LinkedHashMap<>(); + } + + public ElaborationType getElaboration() { + return elaboration; + } + + @JsonAnyGetter + public Map getProperties() { + return properties; + } + + @JsonAnySetter + public void addProperty(String key, JsonNode value) { + this.properties.put(key, value); + } + + @JsonIgnore + public JsonNode getProperty(String key) { + return this.properties.get(key); + } + +} diff --git a/src/main/java/org/gcube/common/software/model/SoftwareConcept.java b/src/main/java/org/gcube/common/software/model/SoftwareGlobalConfig.java similarity index 73% rename from src/main/java/org/gcube/common/software/model/SoftwareConcept.java rename to src/main/java/org/gcube/common/software/model/SoftwareGlobalConfig.java index da18461..6aa215a 100644 --- a/src/main/java/org/gcube/common/software/model/SoftwareConcept.java +++ b/src/main/java/org/gcube/common/software/model/SoftwareGlobalConfig.java @@ -2,17 +2,19 @@ package org.gcube.common.software.model; import java.net.URL; import java.util.List; +import java.util.Map; import java.util.Set; -import org.gcube.com.fasterxml.jackson.annotation.JsonFormat; +import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; import org.gcube.com.fasterxml.jackson.annotation.JsonProperty; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; +import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; /** * @author Luca Frosini (ISTI - CNR) */ -public class SoftwareConcept { +public class SoftwareGlobalConfig { public static final String NAME_PROPERTY_NAME = "name"; public static final String GROUP_PROPERTY_NAME = "group"; @@ -25,9 +27,12 @@ public class SoftwareConcept { public static final String CODE_LOCATION_PROPERTY_NAME = "code_location"; public static final String DOI_URL_PROPERTY_NAME = "doi_url"; public static final String GRANTS_PROPERTY_NAME = "grants"; - public static final String PUBLISH_PROPERTY_NAME = "publish"; - public static final String EXPORT_PROPERTY_NAME = "export"; + public static final String PUBLISHERS_PROPERTY_NAME = "publishers"; + public static final String EXPORTERS_PROPERTY_NAME = "exporters"; + @JsonIgnore + protected ObjectNode originalJson; + @JsonProperty(NAME_PROPERTY_NAME) protected String name; @@ -61,14 +66,22 @@ public class SoftwareConcept { @JsonProperty(GRANTS_PROPERTY_NAME) protected JsonNode grants; - @JsonProperty(PUBLISH_PROPERTY_NAME) - @JsonFormat(shape=JsonFormat.Shape.STRING) - protected ElaborationType publish; + @JsonProperty(PUBLISHERS_PROPERTY_NAME) + protected Map publishers; - @JsonProperty(EXPORT_PROPERTY_NAME) - @JsonFormat(shape=JsonFormat.Shape.STRING) - protected ElaborationType export; + @JsonProperty(EXPORTERS_PROPERTY_NAME) + protected Map exporters; + @JsonIgnore + public ObjectNode getOriginalJson() { + return originalJson; + } + + @JsonIgnore + public void setOriginalJson(ObjectNode originalJson) { + this.originalJson = originalJson; + } + public String getName() { return name; } @@ -117,12 +130,12 @@ public class SoftwareConcept { return grants; } - public ElaborationType getPublish() { - return publish; + public Map getPublishers() { + return publishers; } - public ElaborationType getExport() { - return export; + public Map getExporters() { + return exporters; } } diff --git a/src/main/java/org/gcube/common/software/model/SoftwareVersion.java b/src/main/java/org/gcube/common/software/model/SoftwareVersionConfig.java similarity index 90% rename from src/main/java/org/gcube/common/software/model/SoftwareVersion.java rename to src/main/java/org/gcube/common/software/model/SoftwareVersionConfig.java index d9a7a81..fb00908 100644 --- a/src/main/java/org/gcube/common/software/model/SoftwareVersion.java +++ b/src/main/java/org/gcube/common/software/model/SoftwareVersionConfig.java @@ -16,7 +16,7 @@ import org.gcube.common.software.utils.Utils; /** * @author Luca Frosini (ISTI - CNR) */ -public class SoftwareVersion extends SoftwareConcept { +public class SoftwareVersionConfig extends SoftwareGlobalConfig { public static final String VERSION_PROPERTY_NAME = "version"; public static final String DATE_PROPERTY_NAME = "date"; @@ -25,10 +25,10 @@ public class SoftwareVersion extends SoftwareConcept { public static final String VERSION_DOI_URL_PROPERTY_NAME = "version_doi_url"; @JsonIgnore - protected SoftwareVersion previous; + protected SoftwareVersionConfig previous; @JsonIgnore - protected SoftwareVersion next; + protected SoftwareVersionConfig next; @JsonIgnore protected Boolean newDeposition; @@ -50,27 +50,27 @@ public class SoftwareVersion extends SoftwareConcept { protected URL versionDOIURL; - public SoftwareVersion() { + public SoftwareVersionConfig() { this.newDeposition = false; } @JsonIgnore - public SoftwareVersion getPrevious() { + public SoftwareVersionConfig getPrevious() { return previous; } @JsonIgnore - public void setPrevious(SoftwareVersion previous) { + public void setPrevious(SoftwareVersionConfig previous) { this.previous = previous; } @JsonIgnore - public SoftwareVersion getNext() { + public SoftwareVersionConfig getNext() { return next; } @JsonIgnore - public void setNext(SoftwareVersion next) { + public void setNext(SoftwareVersionConfig next) { this.next = next; } diff --git a/src/main/java/org/gcube/common/software/model/Variables.java b/src/main/java/org/gcube/common/software/model/Variables.java index a9d0e47..41845e9 100644 --- a/src/main/java/org/gcube/common/software/model/Variables.java +++ b/src/main/java/org/gcube/common/software/model/Variables.java @@ -54,14 +54,19 @@ public class Variables { Set variableNames = findVariables(value); for(String variableName : variableNames) { if(properties.containsKey(variableName)) { - String variableValue = properties.get(variableName).toString(); - value = Utils.replaceVariable(variableName, variableValue, value); + try { + String variableValue = properties.get(variableName).toString(); + value = Utils.replaceVariable(variableName, variableValue, value); + }catch (Exception e) { + missingVariables.add(variableName); + } + }else { missingVariables.add(variableName); } } if(missingVariables.size()>0) { - throw new Exception("The following varibles cannot be replaced because they don't exists " + missingVariables.toString()); + throw new Exception("The following variables cannot be replaced because they don't exists " + missingVariables.toString()); } return value; } diff --git a/src/main/java/org/gcube/common/software/process/SoftwareVersionProcessor.java b/src/main/java/org/gcube/common/software/process/SoftwareVersionProcessor.java index c2437ff..5803989 100644 --- a/src/main/java/org/gcube/common/software/process/SoftwareVersionProcessor.java +++ b/src/main/java/org/gcube/common/software/process/SoftwareVersionProcessor.java @@ -1,22 +1,23 @@ package org.gcube.common.software.process; -import org.gcube.com.fasterxml.jackson.databind.JsonNode; -import org.gcube.common.software.model.SoftwareVersion; +import org.gcube.common.software.model.ProcessorConfig; +import org.gcube.common.software.model.SoftwareVersionConfig; /** * @author Luca Frosini (ISTI - CNR) */ public abstract class SoftwareVersionProcessor { - protected SoftwareVersion softwareVersion; - protected JsonNode configuration; + protected SoftwareVersionConfig softwareVersion; + protected ProcessorConfig processorConfig; + protected boolean first; - public SoftwareVersion getSoftwareVersion() { + public SoftwareVersionConfig getSoftwareVersion() { return softwareVersion; } - public void setSoftwareVersion(SoftwareVersion softwareVersion) { + public void setSoftwareVersion(SoftwareVersionConfig softwareVersion) { this.softwareVersion = softwareVersion; } @@ -28,8 +29,12 @@ public abstract class SoftwareVersionProcessor { this.first = first; } - public void setSpecificConfiguration(JsonNode conf) { - this.configuration = conf; + public ProcessorConfig getProcessorConfig() { + return processorConfig; + } + + public void setProcessorConfig(ProcessorConfig processorConfig) { + this.processorConfig = processorConfig; } } diff --git a/src/main/java/org/gcube/common/software/process/export/biblatex/BibLaTeXSoftwareVersionExporter.java b/src/main/java/org/gcube/common/software/process/export/biblatex/BibLaTeXSoftwareVersionExporter.java index 7e2bfff..5d5171a 100644 --- a/src/main/java/org/gcube/common/software/process/export/biblatex/BibLaTeXSoftwareVersionExporter.java +++ b/src/main/java/org/gcube/common/software/process/export/biblatex/BibLaTeXSoftwareVersionExporter.java @@ -30,7 +30,7 @@ public class BibLaTeXSoftwareVersionExporter extends SoftwareVersionExporter { public void export() throws Exception { String name = softwareVersion.getName(); - ElaborationType export = softwareVersion.getExport(); + ElaborationType export = processorConfig.getElaboration(); switch (export) { case ALL: diff --git a/src/main/java/org/gcube/common/software/process/publish/zenodo/ZenodoSoftwareVersionPublisher.java b/src/main/java/org/gcube/common/software/process/publish/zenodo/ZenodoSoftwareVersionPublisher.java index c217d0a..e2059b2 100644 --- a/src/main/java/org/gcube/common/software/process/publish/zenodo/ZenodoSoftwareVersionPublisher.java +++ b/src/main/java/org/gcube/common/software/process/publish/zenodo/ZenodoSoftwareVersionPublisher.java @@ -25,6 +25,7 @@ import javax.ws.rs.core.Response; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; +import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType; import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.common.gxhttp.request.GXHTTPStringRequest; import org.gcube.common.software.config.Config; @@ -48,13 +49,17 @@ public class ZenodoSoftwareVersionPublisher extends SoftwareVersionPublisher { public static final String GUCBE_ZENODO_SOFTWARE_DEPOSIT = "gCubeSoftwareDeposit"; + public static final String HTML_DESCRIPTION_CONFIG_FIELD_NAME = "html_description"; + public static final String HTML_CODE_LOCATION_CONFIG_FIELD_NAME = "html_code_location"; + public static final String SKIP_GRANTS_CONFIG_FIELD_NAME = "skip_grants"; + public static final String METADATA_FIELD_NAME = "metadata"; - private static final String SANDBOX_BASE_PATH = "https://sandbox.zenodo.org"; - private static final String SANDBOX_DOI_URL_BASE_PATH = "https://doi.org/10.5072/zenodo."; - - private static final String PRODUCTION_BASE_PATH = "https://zenodo.org"; - private static final String PRODUCTION_DOI_URL_BASE_PATH = "https://doi.org/10.5281/zenodo."; +// private static final String SANDBOX_BASE_PATH = "https://sandbox.zenodo.org"; +// private static final String SANDBOX_DOI_URL_BASE_PATH = "https://doi.org/10.5072/zenodo."; +// +// private static final String PRODUCTION_BASE_PATH = "https://zenodo.org"; +// private static final String PRODUCTION_DOI_URL_BASE_PATH = "https://doi.org/10.5281/zenodo."; public static final String DEPOSITIONS_COLLECTION_PATH = "/api/deposit/depositions"; public static final String DEPOSITION_PATH = DEPOSITIONS_COLLECTION_PATH + "/:id"; @@ -88,24 +93,7 @@ public class ZenodoSoftwareVersionPublisher extends SoftwareVersionPublisher { return map; } - public ZenodoSoftwareVersionPublisher() { - try { - this.zenodoBaseURL = new URL(Config.getProperties().getProperty("zenodo_base_url")); - this.accessToken = Config.getProperties().getProperty("zenodo_access_token"); - this.doiBaseURL = Config.getProperties().getProperty("doi_base_url"); - if(doiBaseURL==null) { - if(zenodoBaseURL.toString().compareTo(SANDBOX_BASE_PATH)==0) { - doiBaseURL = SANDBOX_DOI_URL_BASE_PATH; - }else if(zenodoBaseURL.toString().compareTo(PRODUCTION_BASE_PATH)==0) { - doiBaseURL = PRODUCTION_DOI_URL_BASE_PATH; - }else { - throw new RuntimeException("Please set 'doi_base_url' in your config file"); - } - } - }catch (Exception e) { - throw new RuntimeException(e); - } - } + public ZenodoSoftwareVersionPublisher() {} protected void addFilesToDeposition(List files ) throws Exception { String depositID = getZenodoIDFromDOIURL(softwareVersion.getVersionDOIURL()); @@ -298,11 +286,11 @@ public class ZenodoSoftwareVersionPublisher extends SoftwareVersionPublisher { private String getDescription() { StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(configuration.get("html_description").asText()); + stringBuffer.append(processorConfig.getProperty(HTML_DESCRIPTION_CONFIG_FIELD_NAME).asText()); String codeLocation = softwareVersion.getCodeLocation(); if(codeLocation!=null) { - String htmlCodeLocation = configuration.get("html_code_location").asText(); + String htmlCodeLocation = processorConfig.getProperty(HTML_CODE_LOCATION_CONFIG_FIELD_NAME).asText(); htmlCodeLocation = Utils.replaceVariable("code_location", codeLocation, htmlCodeLocation); stringBuffer.append(htmlCodeLocation); } @@ -313,7 +301,7 @@ public class ZenodoSoftwareVersionPublisher extends SoftwareVersionPublisher { private ArrayNode getGrants(){ ObjectMapper objectMapper = Utils.getObjectMapper(); ArrayNode grants = objectMapper.createArrayNode(); - ArrayNode arrayNode = (ArrayNode) configuration.get("skip_grants"); + ArrayNode arrayNode = (ArrayNode) processorConfig.getProperty(SKIP_GRANTS_CONFIG_FIELD_NAME); Set idToSkip = new HashSet<>(); for(JsonNode idNode : arrayNode) { idToSkip.add(idNode.asText()); @@ -476,10 +464,31 @@ public class ZenodoSoftwareVersionPublisher extends SoftwareVersionPublisher { finalize(); } + protected String getConfig(String propertyName) throws Exception { + String conf = null; + JsonNode node = processorConfig.getProperty(propertyName); + if(node == null || node.getNodeType()==JsonNodeType.NULL) { + conf = Config.getProperties().getProperty(propertyName); + } + if(conf==null) { + throw new Exception("No configuration '" + propertyName + "' property found."); + } + return conf; + } + + protected void getZenodoConnectionConfig() throws Exception { + this.zenodoBaseURL = new URL(getConfig("zenodo_base_url")); + this.accessToken = getConfig("zenodo_access_token"); + this.doiBaseURL = getConfig("doi_base_url"); + } + + @Override public void publish() throws Exception { + getZenodoConnectionConfig(); + String name = softwareVersion.getName(); - ElaborationType publish = softwareVersion.getPublish(); + ElaborationType publish = processorConfig.getElaboration(); if(publish==ElaborationType.NONE) { logger.info("Deposit is disabled for {} {}.", diff --git a/src/test/java/org/gcube/common/software/analyser/SoftwareConceptAnalyserTest.java b/src/test/java/org/gcube/common/software/analyser/SoftwareConceptAnalyserTest.java index bbf32e5..6f26430 100644 --- a/src/test/java/org/gcube/common/software/analyser/SoftwareConceptAnalyserTest.java +++ b/src/test/java/org/gcube/common/software/analyser/SoftwareConceptAnalyserTest.java @@ -17,7 +17,7 @@ public class SoftwareConceptAnalyserTest { @Test public void testUsingTestFile() throws Exception { File file = FileUtils.getFileFromFilename(FILENAME); - SoftwareConceptAnalyser softwareConceptAnalyser = new SoftwareConceptAnalyser(file); + SoftwareConfigAnalyser softwareConceptAnalyser = new SoftwareConfigAnalyser(file); softwareConceptAnalyser.analyse(); } diff --git a/src/test/resources/exported-gcat-from-scratch.json b/src/test/resources/exported-gcat-from-scratch.json index 4d44b99..05be9d0 100644 --- a/src/test/resources/exported-gcat-from-scratch.json +++ b/src/test/resources/exported-gcat-from-scratch.json @@ -1,5 +1,5 @@ { - "concept": + "global": { "name": "gcat", "group": "data-catalogue", @@ -139,8 +139,19 @@ "url": "https://cordis.europa.eu/project/id/871042" } ], - "publish": "NONE", - "export": "ALL" + "publishers": { + "ZenodoSoftwareVersionPublisher": { + "elaboration": "NONE", + "html_description": "

gCube Catalogue (gCat) Service allows any client to publish items in the gCube Catalogue.

\n\n

gCube is an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments, such as the D4Science Infrastructure, by favouring the realisation of reuse-oriented policies.

\n\n

gCube has been used to successfully build and operate infrastructures and virtual research environments for application domains ranging from biodiversity to environmental data management and cultural heritage.

\n\n

gCube offers components supporting typical data management workflows including data access, curation, processing, and visualisation on a large set of data typologies ranging from primary biodiversity data to geospatial and tabular data.

\n\n

D4Science is a Hybrid Data Infrastructure combining over 500 software components and integrating data from more than 50 different data providers into a coherent and managed system of hardware, software, and data resources. The D4Science infrastructure drastically reduces the cost of ownership, maintenance, and operation thanks to the exploitation of gCube.

\n\n

 

", + "html_code_location": "\n\n

The official source code location of this software version is available at:

\n\n

{{code_location}}

", + "skip_grants": ["004260"] + } + }, + "exporters": { + "BibLaTeXSoftwareVersionExporter": { + "elaboration": "ALL" + } + } }, "versions": [ @@ -327,19 +338,5 @@ "version_doi_url": "https://doi.org/10.5072/zenodo.1145788", "code_location": "https://code-repo.d4science.org/gCubeSystem/{{name}}/releases/tag/v{{version}}" } - ], - "publishers": - { - "ZenodoSoftwareVersionPublisher": - { - "html_description": "

gCube Catalogue (gCat) Service allows any client to publish items in the gCube Catalogue.

\n\n

gCube is an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments, such as the D4Science Infrastructure, by favouring the realisation of reuse-oriented policies.

\n\n

gCube has been used to successfully build and operate infrastructures and virtual research environments for application domains ranging from biodiversity to environmental data management and cultural heritage.

\n\n

gCube offers components supporting typical data management workflows including data access, curation, processing, and visualisation on a large set of data typologies ranging from primary biodiversity data to geospatial and tabular data.

\n\n

D4Science is a Hybrid Data Infrastructure combining over 500 software components and integrating data from more than 50 different data providers into a coherent and managed system of hardware, software, and data resources. The D4Science infrastructure drastically reduces the cost of ownership, maintenance, and operation thanks to the exploitation of gCube.

\n\n

 

", - "html_code_location": "\n\n

The official source code location of this software version is available at:

\n\n

{{code_location}}

", - "skip_grants": - [ - "004260" - ] - } - }, - "exporters": - {} + ] } \ No newline at end of file diff --git a/src/test/resources/gcat-from-scratch.json b/src/test/resources/gcat-from-scratch.json index b082b01..b1212b9 100644 --- a/src/test/resources/gcat-from-scratch.json +++ b/src/test/resources/gcat-from-scratch.json @@ -1,5 +1,5 @@ { - "concept": { + "global": { "name": "gcat", "group": "data-catalogue", "title": "gCube Catalogue (gCat) Service {{version}}", @@ -129,8 +129,19 @@ "url": "https://cordis.europa.eu/project/id/871042" } ], - "publish": "NONE", - "export": "ALL" + "publishers": { + "ZenodoSoftwareVersionPublisher": { + "elaboration": "NONE", + "html_description": "

gCube Catalogue (gCat) Service allows any client to publish items in the gCube Catalogue.

\n\n

gCube is an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments, such as the D4Science Infrastructure, by favouring the realisation of reuse-oriented policies.

\n\n

gCube has been used to successfully build and operate infrastructures and virtual research environments for application domains ranging from biodiversity to environmental data management and cultural heritage.

\n\n

gCube offers components supporting typical data management workflows including data access, curation, processing, and visualisation on a large set of data typologies ranging from primary biodiversity data to geospatial and tabular data.

\n\n

D4Science is a Hybrid Data Infrastructure combining over 500 software components and integrating data from more than 50 different data providers into a coherent and managed system of hardware, software, and data resources. The D4Science infrastructure drastically reduces the cost of ownership, maintenance, and operation thanks to the exploitation of gCube.

\n\n

 

", + "html_code_location": "\n\n

The official source code location of this software version is available at:

\n\n

{{code_location}}

", + "skip_grants": ["004260"] + } + }, + "exporters": { + "BibLaTeXSoftwareVersionExporter": { + "elaboration": "ALL" + } + } }, "versions": [ { @@ -303,15 +314,5 @@ "version_doi_url": null, "code_location": "https://code-repo.d4science.org/gCubeSystem/{{name}}/releases/tag/v{{version}}" } - ], - "publishers": { - "ZenodoSoftwareVersionPublisher" :{ - "html_description": "

gCube Catalogue (gCat) Service allows any client to publish items in the gCube Catalogue.

\n\n

gCube is an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments, such as the D4Science Infrastructure, by favouring the realisation of reuse-oriented policies.

\n\n

gCube has been used to successfully build and operate infrastructures and virtual research environments for application domains ranging from biodiversity to environmental data management and cultural heritage.

\n\n

gCube offers components supporting typical data management workflows including data access, curation, processing, and visualisation on a large set of data typologies ranging from primary biodiversity data to geospatial and tabular data.

\n\n

D4Science is a Hybrid Data Infrastructure combining over 500 software components and integrating data from more than 50 different data providers into a coherent and managed system of hardware, software, and data resources. The D4Science infrastructure drastically reduces the cost of ownership, maintenance, and operation thanks to the exploitation of gCube.

\n\n

 

", - "html_code_location": "\n\n

The official source code location of this software version is available at:

\n\n

{{code_location}}

", - "skip_grants": ["004260"] - } - }, - "exporters": { - - } + ] } \ No newline at end of file diff --git a/src/test/resources/gcat-test-sandbox.json b/src/test/resources/gcat-test-sandbox.json index 16dbd12..4b9d546 100644 --- a/src/test/resources/gcat-test-sandbox.json +++ b/src/test/resources/gcat-test-sandbox.json @@ -1,6 +1,7 @@ { - "concept": { + "global": { "name": "gcat", + "group": "data-catalogue", "title": "gCube Catalogue (gCat) Service {{version}}", "license": { "id": "EUPL-1.1", @@ -128,8 +129,19 @@ "url": "https://cordis.europa.eu/project/id/871042" } ], - "publish": "NONE", - "export": "ALL" + "publishers": { + "ZenodoSoftwareVersionPublisher": { + "elaboration": "NONE", + "html_description": "

gCube Catalogue (gCat) Service allows any client to publish items in the gCube Catalogue.

\n\n

gCube is an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments, such as the D4Science Infrastructure, by favouring the realisation of reuse-oriented policies.

\n\n

gCube has been used to successfully build and operate infrastructures and virtual research environments for application domains ranging from biodiversity to environmental data management and cultural heritage.

\n\n

gCube offers components supporting typical data management workflows including data access, curation, processing, and visualisation on a large set of data typologies ranging from primary biodiversity data to geospatial and tabular data.

\n\n

D4Science is a Hybrid Data Infrastructure combining over 500 software components and integrating data from more than 50 different data providers into a coherent and managed system of hardware, software, and data resources. The D4Science infrastructure drastically reduces the cost of ownership, maintenance, and operation thanks to the exploitation of gCube.

\n\n

 

", + "html_code_location": "\n\n

The official source code location of this software version is available at:

\n\n

{{code_location}}

", + "skip_grants": ["004260"] + } + }, + "exporters": { + "BibLaTeXSoftwareVersionExporter": { + "elaboration": "ALL" + } + } }, "versions": [ { @@ -312,15 +324,5 @@ "version_doi_url" : "https://doi.org/10.5072/zenodo.1144799", "code_location": "https://code-repo.d4science.org/gCubeSystem/{{name}}/releases/tag/v{{version}}" } - ], - "publishers": { - "ZenodoSoftwareVersionPublisher" :{ - "html_description": "

gCube Catalogue (gCat) Service allows any client to publish items in the gCube Catalogue.

\n\n

gCube is an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments, such as the D4Science Infrastructure, by favouring the realisation of reuse-oriented policies.

\n\n

gCube has been used to successfully build and operate infrastructures and virtual research environments for application domains ranging from biodiversity to environmental data management and cultural heritage.

\n\n

gCube offers components supporting typical data management workflows including data access, curation, processing, and visualisation on a large set of data typologies ranging from primary biodiversity data to geospatial and tabular data.

\n\n

D4Science is a Hybrid Data Infrastructure combining over 500 software components and integrating data from more than 50 different data providers into a coherent and managed system of hardware, software, and data resources. The D4Science infrastructure drastically reduces the cost of ownership, maintenance, and operation thanks to the exploitation of gCube.

\n\n

 

", - "html_code_location": "\n\n

The official source code location of this software version is available at:

\n\n

{{code_location}}

", - "skip_grants": ["004260"] - } - }, - "exporters": { - - } + ] } \ No newline at end of file