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
/gcat.bib
/gcat.json
/gcat/

View File

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

View File

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

View File

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

View File

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