Generalised solution

This commit is contained in:
Luca Frosini 2023-01-16 15:05:42 +01:00
parent e056470957
commit 715091f304
8 changed files with 97 additions and 24 deletions

View File

@ -2,8 +2,6 @@ package org.gcube.common.software.analyser;
import java.io.File;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -63,6 +61,9 @@ public class SoftwareConfigAnalyser {
SoftwareConfig softwareConfig = objectMapper.treeToValue(originalGlobal, SoftwareConfig.class);
softwareConfig.setOriginalJson(originalGlobal);
ObjectNode global = originalGlobal.deepCopy();
global.remove(SoftwareConfig.EXPORT_FILENAME_PROPERTY_NAME);
ArrayNode versions = (ArrayNode) jsonNode.get(VERSIONS_PROPERTY_NAME);
SoftwareVersionConfig previous = null;
@ -76,7 +77,7 @@ public class SoftwareConfigAnalyser {
exportingVersions.add(originalVersion);
JsonNode version = Utils.merge(originalGlobal, originalVersion);
JsonNode version = Utils.merge(global, originalVersion);
SoftwareVersionConfig softwareVersion = actualize(version);
softwareVersion.setOriginalJson(originalVersion);
@ -149,8 +150,7 @@ public class SoftwareConfigAnalyser {
toBeExported.replace(VERSIONS_PROPERTY_NAME, exportingVersions);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String fileName = simpleDateFormat.format(Calendar.getInstance().getTime());
String fileName = softwareConfig.getExportFileName();
File file = new File(fileName+EXPORT_FILENAME_EXTENSION);
objectMapper.writeValue(file, toBeExported);

View File

@ -1,11 +1,15 @@
package org.gcube.common.software.model;
import java.text.SimpleDateFormat;
import java.util.Calendar;
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.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
@ -14,6 +18,11 @@ import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
*/
public class SoftwareConfig {
public static final String EXPORT_FILENAME_PROPERTY_NAME = "export_filename";
@JsonProperty(EXPORT_FILENAME_PROPERTY_NAME)
protected String exportFileName;
protected Map<String, JsonNode> additionalProperties;
@JsonIgnore
@ -23,6 +32,24 @@ public class SoftwareConfig {
this.additionalProperties = new LinkedHashMap<>();
}
@JsonIgnore
public String getExportFileName() {
if(exportFileName==null) {
if(additionalProperties.containsKey(EXPORT_FILENAME_PROPERTY_NAME)) {
exportFileName = additionalProperties.get(EXPORT_FILENAME_PROPERTY_NAME).asText();
}else {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
exportFileName = simpleDateFormat.format(Calendar.getInstance().getTime());
}
}
return exportFileName;
}
@JsonSetter(EXPORT_FILENAME_PROPERTY_NAME)
public void setExportFileName(String exportFileName) {
this.exportFileName = exportFileName;
}
@JsonIgnore
public ObjectNode getOriginalJson() {
return originalJson;
@ -33,7 +60,6 @@ public class SoftwareConfig {
this.originalJson = originalJson;
}
@JsonAnyGetter
public Map<String, JsonNode> getAdditionalProperties() {
return additionalProperties;

View File

@ -2,22 +2,26 @@ package org.gcube.common.software.model;
import java.net.URL;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
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;
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.ObjectNode;
import org.gcube.common.software.utils.Utils;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class SoftwareVersionConfig extends SoftwareConfig {
public class SoftwareVersionConfig {
public static final String NAME_PROPERTY_NAME = "name";
public static final String VERSION_PROPERTY_NAME = "version";
@ -44,6 +48,9 @@ public class SoftwareVersionConfig extends SoftwareConfig {
@JsonIgnore
protected Boolean newDeposition;
@JsonIgnore
protected ObjectNode originalJson;
@JsonProperty(NAME_PROPERTY_NAME)
protected String name;
@ -87,8 +94,11 @@ public class SoftwareVersionConfig extends SoftwareConfig {
@JsonProperty(EXPORTERS_PROPERTY_NAME)
protected Map<String,ProcessorConfig> exporters;
protected Map<String, JsonNode> additionalProperties;
public SoftwareVersionConfig() {
this.newDeposition = false;
this.additionalProperties = new LinkedHashMap<>();
}
@JsonIgnore
@ -135,6 +145,16 @@ public class SoftwareVersionConfig extends SoftwareConfig {
return variables;
}
@JsonIgnore
public ObjectNode getOriginalJson() {
return originalJson;
}
@JsonIgnore
public void setOriginalJson(ObjectNode originalJson) {
this.originalJson = originalJson;
}
public String getName() {
return name;
}
@ -199,4 +219,19 @@ public class SoftwareVersionConfig extends SoftwareConfig {
return exporters;
}
@JsonAnyGetter
public Map<String, JsonNode> getAdditionalProperties() {
return additionalProperties;
}
@JsonAnySetter
public void addAdditionalProperty(String key, JsonNode value) {
this.additionalProperties.put(key, value);
}
@JsonIgnore
public JsonNode getAdditionalProperty(String key) {
return this.additionalProperties.get(key);
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.common.software.process;
import org.gcube.common.software.model.ProcessorConfig;
import org.gcube.common.software.model.SoftwareConfig;
import org.gcube.common.software.model.SoftwareVersionConfig;
/**
@ -8,25 +9,25 @@ import org.gcube.common.software.model.SoftwareVersionConfig;
*/
public abstract class SoftwareVersionProcessor {
protected SoftwareConfig softwareConfig;
protected SoftwareVersionConfig softwareVersion;
protected ProcessorConfig processorConfig;
protected boolean first;
public SoftwareVersionConfig getSoftwareVersion() {
public SoftwareConfig getSoftwareConfig() {
return softwareConfig;
}
public void setSoftwareConfig(SoftwareConfig softwareConfig) {
this.softwareConfig = softwareConfig;
}
public SoftwareVersionConfig getSoftwareVersionConfig() {
return softwareVersion;
}
public void setSoftwareVersion(SoftwareVersionConfig softwareVersion) {
this.softwareVersion = softwareVersion;
}
public boolean isFirst() {
return first;
}
public void setFirst(boolean first) {
this.first = first;
public void setSoftwareVersion(SoftwareVersionConfig softwareVersionConfig) {
this.softwareVersion = softwareVersionConfig;
}
public ProcessorConfig getProcessorConfig() {
@ -36,5 +37,13 @@ public abstract class SoftwareVersionProcessor {
public void setProcessorConfig(ProcessorConfig processorConfig) {
this.processorConfig = processorConfig;
}
public boolean isFirst() {
return first;
}
public void setFirst(boolean first) {
this.first = first;
}
}

View File

@ -183,8 +183,8 @@ public class BibLaTeXSoftwareVersionExporter extends SoftwareVersionExporter {
}
protected File getExportFile() {
String name = softwareVersion.getName();
File file = new File(name + EXPORT_FILENAME_EXTENSION);
String fileName = softwareConfig.getExportFileName();
File file = new File(fileName + EXPORT_FILENAME_EXTENSION);
return file;
}

View File

@ -151,7 +151,8 @@
"BibLaTeXSoftwareVersionExporter": {
"elaboration": "ALL"
}
}
},
"export_filename": "{{name}}"
},
"versions":
[

View File

@ -141,7 +141,8 @@
"BibLaTeXSoftwareVersionExporter": {
"elaboration": "ALL"
}
}
},
"export_filename": "{{name}}"
},
"versions": [
{

View File

@ -141,7 +141,8 @@
"BibLaTeXSoftwareVersionExporter": {
"elaboration": "ALL"
}
}
},
"export_filename": "{{name}}"
},
"versions": [
{