Generalised solution
This commit is contained in:
parent
e056470957
commit
715091f304
|
@ -2,8 +2,6 @@ package org.gcube.common.software.analyser;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -63,6 +61,9 @@ public class SoftwareConfigAnalyser {
|
||||||
SoftwareConfig softwareConfig = objectMapper.treeToValue(originalGlobal, SoftwareConfig.class);
|
SoftwareConfig softwareConfig = objectMapper.treeToValue(originalGlobal, SoftwareConfig.class);
|
||||||
softwareConfig.setOriginalJson(originalGlobal);
|
softwareConfig.setOriginalJson(originalGlobal);
|
||||||
|
|
||||||
|
ObjectNode global = originalGlobal.deepCopy();
|
||||||
|
global.remove(SoftwareConfig.EXPORT_FILENAME_PROPERTY_NAME);
|
||||||
|
|
||||||
ArrayNode versions = (ArrayNode) jsonNode.get(VERSIONS_PROPERTY_NAME);
|
ArrayNode versions = (ArrayNode) jsonNode.get(VERSIONS_PROPERTY_NAME);
|
||||||
|
|
||||||
SoftwareVersionConfig previous = null;
|
SoftwareVersionConfig previous = null;
|
||||||
|
@ -76,7 +77,7 @@ public class SoftwareConfigAnalyser {
|
||||||
exportingVersions.add(originalVersion);
|
exportingVersions.add(originalVersion);
|
||||||
|
|
||||||
|
|
||||||
JsonNode version = Utils.merge(originalGlobal, originalVersion);
|
JsonNode version = Utils.merge(global, originalVersion);
|
||||||
SoftwareVersionConfig softwareVersion = actualize(version);
|
SoftwareVersionConfig softwareVersion = actualize(version);
|
||||||
softwareVersion.setOriginalJson(originalVersion);
|
softwareVersion.setOriginalJson(originalVersion);
|
||||||
|
|
||||||
|
@ -149,8 +150,7 @@ public class SoftwareConfigAnalyser {
|
||||||
|
|
||||||
toBeExported.replace(VERSIONS_PROPERTY_NAME, exportingVersions);
|
toBeExported.replace(VERSIONS_PROPERTY_NAME, exportingVersions);
|
||||||
|
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
String fileName = softwareConfig.getExportFileName();
|
||||||
String fileName = simpleDateFormat.format(Calendar.getInstance().getTime());
|
|
||||||
|
|
||||||
File file = new File(fileName+EXPORT_FILENAME_EXTENSION);
|
File file = new File(fileName+EXPORT_FILENAME_EXTENSION);
|
||||||
objectMapper.writeValue(file, toBeExported);
|
objectMapper.writeValue(file, toBeExported);
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package org.gcube.common.software.model;
|
package org.gcube.common.software.model;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
|
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
|
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
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.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
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 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;
|
protected Map<String, JsonNode> additionalProperties;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
@ -23,6 +32,24 @@ public class SoftwareConfig {
|
||||||
this.additionalProperties = new LinkedHashMap<>();
|
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
|
@JsonIgnore
|
||||||
public ObjectNode getOriginalJson() {
|
public ObjectNode getOriginalJson() {
|
||||||
return originalJson;
|
return originalJson;
|
||||||
|
@ -33,7 +60,6 @@ public class SoftwareConfig {
|
||||||
this.originalJson = originalJson;
|
this.originalJson = originalJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonAnyGetter
|
@JsonAnyGetter
|
||||||
public Map<String, JsonNode> getAdditionalProperties() {
|
public Map<String, JsonNode> getAdditionalProperties() {
|
||||||
return additionalProperties;
|
return additionalProperties;
|
||||||
|
|
|
@ -2,22 +2,26 @@ package org.gcube.common.software.model;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.JsonFormat;
|
||||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
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.ArrayNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.gcube.common.software.utils.Utils;
|
import org.gcube.common.software.utils.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @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 NAME_PROPERTY_NAME = "name";
|
||||||
public static final String VERSION_PROPERTY_NAME = "version";
|
public static final String VERSION_PROPERTY_NAME = "version";
|
||||||
|
@ -44,6 +48,9 @@ public class SoftwareVersionConfig extends SoftwareConfig {
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
protected Boolean newDeposition;
|
protected Boolean newDeposition;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
protected ObjectNode originalJson;
|
||||||
|
|
||||||
@JsonProperty(NAME_PROPERTY_NAME)
|
@JsonProperty(NAME_PROPERTY_NAME)
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
@ -87,8 +94,11 @@ public class SoftwareVersionConfig extends SoftwareConfig {
|
||||||
@JsonProperty(EXPORTERS_PROPERTY_NAME)
|
@JsonProperty(EXPORTERS_PROPERTY_NAME)
|
||||||
protected Map<String,ProcessorConfig> exporters;
|
protected Map<String,ProcessorConfig> exporters;
|
||||||
|
|
||||||
|
protected Map<String, JsonNode> additionalProperties;
|
||||||
|
|
||||||
public SoftwareVersionConfig() {
|
public SoftwareVersionConfig() {
|
||||||
this.newDeposition = false;
|
this.newDeposition = false;
|
||||||
|
this.additionalProperties = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
@ -135,6 +145,16 @@ public class SoftwareVersionConfig extends SoftwareConfig {
|
||||||
return variables;
|
return variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public ObjectNode getOriginalJson() {
|
||||||
|
return originalJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public void setOriginalJson(ObjectNode originalJson) {
|
||||||
|
this.originalJson = originalJson;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -199,4 +219,19 @@ public class SoftwareVersionConfig extends SoftwareConfig {
|
||||||
return exporters;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.common.software.process;
|
package org.gcube.common.software.process;
|
||||||
|
|
||||||
import org.gcube.common.software.model.ProcessorConfig;
|
import org.gcube.common.software.model.ProcessorConfig;
|
||||||
|
import org.gcube.common.software.model.SoftwareConfig;
|
||||||
import org.gcube.common.software.model.SoftwareVersionConfig;
|
import org.gcube.common.software.model.SoftwareVersionConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,25 +9,25 @@ import org.gcube.common.software.model.SoftwareVersionConfig;
|
||||||
*/
|
*/
|
||||||
public abstract class SoftwareVersionProcessor {
|
public abstract class SoftwareVersionProcessor {
|
||||||
|
|
||||||
|
protected SoftwareConfig softwareConfig;
|
||||||
protected SoftwareVersionConfig softwareVersion;
|
protected SoftwareVersionConfig softwareVersion;
|
||||||
protected ProcessorConfig processorConfig;
|
protected ProcessorConfig processorConfig;
|
||||||
|
|
||||||
protected boolean first;
|
protected boolean first;
|
||||||
|
|
||||||
public SoftwareVersionConfig getSoftwareVersion() {
|
public SoftwareConfig getSoftwareConfig() {
|
||||||
|
return softwareConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSoftwareConfig(SoftwareConfig softwareConfig) {
|
||||||
|
this.softwareConfig = softwareConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoftwareVersionConfig getSoftwareVersionConfig() {
|
||||||
return softwareVersion;
|
return softwareVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSoftwareVersion(SoftwareVersionConfig softwareVersion) {
|
public void setSoftwareVersion(SoftwareVersionConfig softwareVersionConfig) {
|
||||||
this.softwareVersion = softwareVersion;
|
this.softwareVersion = softwareVersionConfig;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFirst() {
|
|
||||||
return first;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirst(boolean first) {
|
|
||||||
this.first = first;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessorConfig getProcessorConfig() {
|
public ProcessorConfig getProcessorConfig() {
|
||||||
|
@ -37,4 +38,12 @@ public abstract class SoftwareVersionProcessor {
|
||||||
this.processorConfig = processorConfig;
|
this.processorConfig = processorConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFirst() {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirst(boolean first) {
|
||||||
|
this.first = first;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,8 +183,8 @@ public class BibLaTeXSoftwareVersionExporter extends SoftwareVersionExporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected File getExportFile() {
|
protected File getExportFile() {
|
||||||
String name = softwareVersion.getName();
|
String fileName = softwareConfig.getExportFileName();
|
||||||
File file = new File(name + EXPORT_FILENAME_EXTENSION);
|
File file = new File(fileName + EXPORT_FILENAME_EXTENSION);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,8 @@
|
||||||
"BibLaTeXSoftwareVersionExporter": {
|
"BibLaTeXSoftwareVersionExporter": {
|
||||||
"elaboration": "ALL"
|
"elaboration": "ALL"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"export_filename": "{{name}}"
|
||||||
},
|
},
|
||||||
"versions":
|
"versions":
|
||||||
[
|
[
|
||||||
|
|
|
@ -141,7 +141,8 @@
|
||||||
"BibLaTeXSoftwareVersionExporter": {
|
"BibLaTeXSoftwareVersionExporter": {
|
||||||
"elaboration": "ALL"
|
"elaboration": "ALL"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"export_filename": "{{name}}"
|
||||||
},
|
},
|
||||||
"versions": [
|
"versions": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -141,7 +141,8 @@
|
||||||
"BibLaTeXSoftwareVersionExporter": {
|
"BibLaTeXSoftwareVersionExporter": {
|
||||||
"elaboration": "ALL"
|
"elaboration": "ALL"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"export_filename": "{{name}}"
|
||||||
},
|
},
|
||||||
"versions": [
|
"versions": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue