Improving solution

This commit is contained in:
Luca Frosini 2023-01-30 17:32:50 +01:00
parent 074d783c7c
commit d75bbb53e8
6 changed files with 52 additions and 37 deletions

1
.gitignore vendored
View File

@ -31,3 +31,4 @@ replay_pid*
/exported-zenodo-deposit.json /exported-zenodo-deposit.json
/gcat.bib /gcat.bib
/gcat.json /gcat.json
/gcat/

View File

@ -255,8 +255,8 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
} }
} }
protected URL createZenodoDOIURLFromID(String id) throws MalformedURLException { protected String createZenodoDOIURLFromID(String id) throws MalformedURLException {
return new URL(doiBaseURL + id); return doiBaseURL + id;
} }
public void create() throws Exception { public void create() throws Exception {
@ -273,13 +273,10 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(Utils.getObjectMapper().writeValueAsString(metadata)); HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(Utils.getObjectMapper().writeValueAsString(metadata));
response = getResponse(httpURLConnection); response = getResponse(httpURLConnection);
URL conceptDOIURL = createZenodoDOIURLFromID(response.get("conceptrecid").asText()); String conceptDOIURL = createZenodoDOIURLFromID(response.get("conceptrecid").asText());
softwareVersionConfig.setConceptDOIURL(conceptDOIURL); softwareVersionConfig.setConceptDOIURL(conceptDOIURL);
softwareVersionConfig.getOriginalJson().put(SoftwareVersionConfig.CONCEPT_DOI_URL_PROPERTY_NAME, conceptDOIURL.toString()); String versionDOIURL = createZenodoDOIURLFromID(response.get("id").asText());
URL doiURL = new URL(doiBaseURL + response.get("id").asText()); softwareVersionConfig.setVersionDOIURL(versionDOIURL);
softwareVersionConfig.setVersionDOIURL(doiURL);
softwareVersionConfig.getOriginalJson().put(SoftwareVersionConfig.VERSION_DOI_URL_PROPERTY_NAME, doiURL.toString());
finalize(); finalize();
} }
@ -406,6 +403,9 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
gxHTTPStringRequest.queryParams(getAccessTokenQueryParamters()); gxHTTPStringRequest.queryParams(getAccessTokenQueryParamters());
gxHTTPStringRequest.header("Content-Type", "application/json"); gxHTTPStringRequest.header("Content-Type", "application/json");
gxHTTPStringRequest.header("Accept", "application/json"); gxHTTPStringRequest.header("Accept", "application/json");
String conceptDOI = softwareVersionConfig.getConceptDOIURL();
String conceptID = getZenodoIDFromDOIURL(softwareVersionConfig.getConceptDOIURL()); String conceptID = getZenodoIDFromDOIURL(softwareVersionConfig.getConceptDOIURL());
gxHTTPStringRequest.path(RECORD_PATH.replace(":id", conceptID)); gxHTTPStringRequest.path(RECORD_PATH.replace(":id", conceptID));
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
@ -459,9 +459,8 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
response = getResponse(httpURLConnection); response = getResponse(httpURLConnection);
// The reserved DOI of this created new version will be // The reserved DOI of this created new version will be
URL doiURL = new URL(response.get("doi_url").asText()); String newVersionDOIURL = response.get("doi_url").asText();
softwareVersionConfig.setVersionDOIURL(doiURL); softwareVersionConfig.setVersionDOIURL(newVersionDOIURL);
softwareVersionConfig.getOriginalJson().put(SoftwareVersionConfig.VERSION_DOI_URL_PROPERTY_NAME, doiURL.toString());
// Remove previous depositionFiles // Remove previous depositionFiles
deletePreviousFiles(); deletePreviousFiles();
@ -491,12 +490,20 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
public void export() throws Exception { public void export() throws Exception {
getZenodoConnectionConfig(); getZenodoConnectionConfig();
if(first) {
File exportFile = super.getOutputFile();
if(exportFile.exists()) {
exportFile.delete();
}
exportFile.createNewFile();
}
String title = softwareVersionConfig.getTitle(); String title = softwareVersionConfig.getTitle();
ElaborationType publish = processorConfig.getElaboration(); ElaborationType publish = processorConfig.getElaboration();
if(publish==ElaborationType.NONE) { if(publish==ElaborationType.NONE) {
logger.info("Deposit is disabled for {}.",title); logger.info("Zenodo Deposit is disabled for {}.",title);
return; return;
} }
@ -532,12 +539,20 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
protected ObjectNode getObjectNode() throws Exception { protected ObjectNode getObjectNode() throws Exception {
ObjectMapper objectMapper = Utils.getObjectMapper(); ObjectMapper objectMapper = Utils.getObjectMapper();
ObjectNode toBeExported = objectMapper.createObjectNode(); ObjectNode toBeExported = objectMapper.createObjectNode();
toBeExported.replace(AnalyserFactory.GLOBAL_PROPERTY_NAME, globalConfig.getOriginalJson()); toBeExported.replace(AnalyserFactory.GLOBAL_PROPERTY_NAME, globalConfig.getOriginalJson().deepCopy());
ArrayNode array = objectMapper.createArrayNode(); ArrayNode array = objectMapper.createArrayNode();
SoftwareVersionConfig previous = softwareVersionConfig; SoftwareVersionConfig previous = softwareVersionConfig;
boolean firstNode = true;
while(previous!=null){ while(previous!=null){
array.insert(0, softwareVersionConfig.getOriginalJson()); ObjectNode node = previous.getOriginalJson().deepCopy();
previous = softwareVersionConfig.getPrevious(); node.put(SoftwareVersionConfig.CONCEPT_DOI_URL_PROPERTY_NAME, previous.getConceptDOIURL());
if(firstNode) {
toBeExported.put(SoftwareVersionConfig.CONCEPT_DOI_URL_PROPERTY_NAME, previous.getConceptDOIURL());
firstNode = false;
}
node.put(SoftwareVersionConfig.VERSION_DOI_URL_PROPERTY_NAME, previous.getVersionDOIURL());
array.insert(0, node);
previous = previous.getPrevious();
} }
toBeExported.replace(AnalyserFactory.VERSIONS_PROPERTY_NAME, array); toBeExported.replace(AnalyserFactory.VERSIONS_PROPERTY_NAME, array);
return toBeExported; return toBeExported;
@ -552,21 +567,10 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
@Override @Override
public File getOutputFile() throws Exception { public File getOutputFile() throws Exception {
File exportFile = super.getOutputFile(); File exportFile = super.getOutputFile();
if(last) { if(last) {
if(exportFile.exists()) {
exportFile.delete();
}
if(!exportFile.exists()) {
exportFile.createNewFile();
}
ObjectNode toBeExported = getObjectNode(); ObjectNode toBeExported = getObjectNode();
writeObjectNodeToFile(toBeExported, exportFile); writeObjectNodeToFile(toBeExported, exportFile);
} }
return exportFile; return exportFile;
} }

View File

@ -20,7 +20,7 @@ public class GlobalConfig {
public static final String EXPORT_FILENAME_PROPERTY_NAME = "export_filename"; public static final String EXPORT_FILENAME_PROPERTY_NAME = "export_filename";
public static final String EXPORTERS_PROPERTY_NAME = "availableExporters"; public static final String EXPORTERS_PROPERTY_NAME = "exporters";
@JsonProperty(EXPORTERS_PROPERTY_NAME) @JsonProperty(EXPORTERS_PROPERTY_NAME)
protected Map<String,ExporterConfig> exporters; protected Map<String,ExporterConfig> exporters;

View File

@ -1,6 +1,5 @@
package org.gcube.common.software.model; package org.gcube.common.software.model;
import java.net.URL;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -40,6 +39,9 @@ public class SoftwareVersionConfig {
@JsonIgnore @JsonIgnore
protected SoftwareVersionConfig previous; protected SoftwareVersionConfig previous;
@JsonIgnore
protected SoftwareVersionConfig next;
@JsonIgnore @JsonIgnore
protected Boolean newDeposition; protected Boolean newDeposition;
@ -72,10 +74,10 @@ public class SoftwareVersionConfig {
protected String codeLocation; protected String codeLocation;
@JsonProperty(CONCEPT_DOI_URL_PROPERTY_NAME) @JsonProperty(CONCEPT_DOI_URL_PROPERTY_NAME)
protected URL conceptDOIURL; protected String conceptDOIURL;
@JsonProperty(VERSION_DOI_URL_PROPERTY_NAME) @JsonProperty(VERSION_DOI_URL_PROPERTY_NAME)
protected URL versionDOIURL; protected String versionDOIURL;
@JsonProperty(GRANTS_PROPERTY_NAME) @JsonProperty(GRANTS_PROPERTY_NAME)
protected JsonNode grants; protected JsonNode grants;
@ -97,8 +99,16 @@ public class SoftwareVersionConfig {
@JsonIgnore @JsonIgnore
public void setPrevious(SoftwareVersionConfig previous) { public void setPrevious(SoftwareVersionConfig previous) {
this.previous = previous; this.previous = previous;
if(previous!=null) {
this.previous.next = this;
}
} }
@JsonIgnore
public SoftwareVersionConfig getNext() {
return next;
}
@JsonIgnore @JsonIgnore
public Boolean isNewDeposition() { public Boolean isNewDeposition() {
return newDeposition; return newDeposition;
@ -165,19 +175,19 @@ public class SoftwareVersionConfig {
return codeLocation; return codeLocation;
} }
public URL getConceptDOIURL() { public String getConceptDOIURL() {
return conceptDOIURL; return conceptDOIURL;
} }
public void setConceptDOIURL(URL doiURL) { public void setConceptDOIURL(String conceptDOIURL) {
this.conceptDOIURL = doiURL; this.conceptDOIURL = conceptDOIURL;
} }
public URL getVersionDOIURL() { public String getVersionDOIURL() {
return versionDOIURL; return versionDOIURL;
} }
public void setVersionDOIURL(URL versionDOIURL) { public void setVersionDOIURL(String versionDOIURL) {
this.versionDOIURL = versionDOIURL; this.versionDOIURL = versionDOIURL;
} }

View File

@ -128,7 +128,7 @@
"url": "https://cordis.europa.eu/project/id/871042" "url": "https://cordis.europa.eu/project/id/871042"
} }
], ],
"export_filename" = "{{name}}", "export_filename": "{{name}}",
"exporters": { "exporters": {
"ZenodoSoftwareVersionExporter": { "ZenodoSoftwareVersionExporter": {
"elaboration": "NONE", "elaboration": "NONE",

View File

@ -129,7 +129,7 @@
"url": "https://cordis.europa.eu/project/id/871042" "url": "https://cordis.europa.eu/project/id/871042"
} }
], ],
"export_filename" = "{{name}}", "export_filename": "{{name}}",
"exporters": { "exporters": {
"ZenodoSoftwareVersionExporter": { "ZenodoSoftwareVersionExporter": {
"elaboration": "NONE", "elaboration": "NONE",