Generalised solution
This commit is contained in:
parent
5c3209d07e
commit
e056470957
|
@ -2,6 +2,8 @@ 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;
|
||||
|
||||
|
@ -9,7 +11,8 @@ 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.model.SoftwareGlobalConfig;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
||||
import org.gcube.common.software.model.SoftwareConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionConfig;
|
||||
import org.gcube.common.software.model.Variables;
|
||||
import org.gcube.common.software.utils.Utils;
|
||||
|
@ -57,12 +60,11 @@ public class SoftwareConfigAnalyser {
|
|||
|
||||
public void analyse() throws Exception {
|
||||
ObjectNode originalGlobal = (ObjectNode) jsonNode.get(GLOBAL_PROPERTY_NAME).deepCopy();
|
||||
SoftwareGlobalConfig softwareGlobalConfig = objectMapper.treeToValue(originalGlobal, SoftwareGlobalConfig.class);
|
||||
softwareGlobalConfig.setOriginalJson(originalGlobal);
|
||||
SoftwareConfig softwareConfig = objectMapper.treeToValue(originalGlobal, SoftwareConfig.class);
|
||||
softwareConfig.setOriginalJson(originalGlobal);
|
||||
|
||||
ArrayNode versions = (ArrayNode) jsonNode.get(VERSIONS_PROPERTY_NAME);
|
||||
|
||||
String name = softwareGlobalConfig.getName();
|
||||
SoftwareVersionConfig previous = null;
|
||||
|
||||
int i = 0;
|
||||
|
@ -90,12 +92,12 @@ public class SoftwareConfigAnalyser {
|
|||
|
||||
|
||||
logger.trace("Going to process {} {} (previous version {})",
|
||||
name, softwareVersion.getVersion(),
|
||||
softwareVersion.getName(), softwareVersion.getVersion(),
|
||||
softwareVersion.getPrevious()!=null ? softwareVersion.getPrevious().getVersion(): null);
|
||||
|
||||
try {
|
||||
SoftwareVersionConfigAnalyser softwareVersionAnalyser = new SoftwareVersionConfigAnalyser(softwareVersion);
|
||||
softwareVersionAnalyser.setSoftwareGlobalConfig(softwareGlobalConfig);
|
||||
softwareVersionAnalyser.setSoftwareConfig(softwareConfig);
|
||||
softwareVersionAnalyser.setFirst(i==0);
|
||||
softwareVersionAnalyser.analyse();
|
||||
|
||||
|
@ -113,8 +115,8 @@ public class SoftwareConfigAnalyser {
|
|||
}
|
||||
|
||||
if(newDOI) {
|
||||
softwareGlobalConfig.setDOIURL(doiURL);
|
||||
originalGlobal.put(SoftwareGlobalConfig.DOI_URL_PROPERTY_NAME, doiURL.toString());
|
||||
softwareConfig.addAdditionalProperty(SoftwareVersionConfig.DOI_URL_PROPERTY_NAME, new TextNode(doiURL.toString()));
|
||||
originalGlobal.put(SoftwareVersionConfig.DOI_URL_PROPERTY_NAME, doiURL.toString());
|
||||
}
|
||||
}
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
|
||||
|
@ -147,7 +149,10 @@ public class SoftwareConfigAnalyser {
|
|||
|
||||
toBeExported.replace(VERSIONS_PROPERTY_NAME, exportingVersions);
|
||||
|
||||
File file = new File(name+EXPORT_FILENAME_EXTENSION);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||
String fileName = simpleDateFormat.format(Calendar.getInstance().getTime());
|
||||
|
||||
File file = new File(fileName+EXPORT_FILENAME_EXTENSION);
|
||||
objectMapper.writeValue(file, toBeExported);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ 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.SoftwareConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionFile;
|
||||
import org.gcube.common.software.model.Variables;
|
||||
|
@ -17,7 +17,7 @@ import org.gcube.common.software.process.publish.SoftwareVersionPublisher;
|
|||
*/
|
||||
public class SoftwareVersionConfigAnalyser {
|
||||
|
||||
protected SoftwareGlobalConfig softwareGlobalConfig;
|
||||
protected SoftwareConfig softwareConfig;
|
||||
protected SoftwareVersionConfig softwareVersionConfig;
|
||||
protected boolean first;
|
||||
|
||||
|
@ -25,12 +25,12 @@ public class SoftwareVersionConfigAnalyser {
|
|||
this.softwareVersionConfig = softwareVersionConfig;
|
||||
}
|
||||
|
||||
public SoftwareGlobalConfig getSoftwareGlobalConfig() {
|
||||
return softwareGlobalConfig;
|
||||
public SoftwareConfig getSoftwareConfig() {
|
||||
return softwareConfig;
|
||||
}
|
||||
|
||||
public void setSoftwareGlobalConfig(SoftwareGlobalConfig softwareGlobalConfig) {
|
||||
this.softwareGlobalConfig = softwareGlobalConfig;
|
||||
public void setSoftwareConfig(SoftwareConfig softwareConfig) {
|
||||
this.softwareConfig = softwareConfig;
|
||||
}
|
||||
|
||||
public SoftwareVersionConfig getSoftwareVersionConfig() {
|
||||
|
@ -50,6 +50,7 @@ public class SoftwareVersionConfigAnalyser {
|
|||
}
|
||||
|
||||
public void analyse() throws Exception {
|
||||
|
||||
Variables variables = softwareVersionConfig.getVariables();
|
||||
List<SoftwareVersionFile> svfs = softwareVersionConfig.getFiles();
|
||||
for(SoftwareVersionFile svf : svfs) {
|
||||
|
@ -84,6 +85,4 @@ public class SoftwareVersionConfigAnalyser {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
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.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SoftwareConfig {
|
||||
|
||||
protected Map<String, JsonNode> additionalProperties;
|
||||
|
||||
@JsonIgnore
|
||||
protected ObjectNode originalJson;
|
||||
|
||||
public SoftwareConfig() {
|
||||
this.additionalProperties = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public ObjectNode getOriginalJson() {
|
||||
return originalJson;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setOriginalJson(ObjectNode originalJson) {
|
||||
this.originalJson = originalJson;
|
||||
}
|
||||
|
||||
|
||||
@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,141 +0,0 @@
|
|||
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.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 SoftwareGlobalConfig {
|
||||
|
||||
public static final String NAME_PROPERTY_NAME = "name";
|
||||
public static final String GROUP_PROPERTY_NAME = "group";
|
||||
public static final String TITLE_PROPERTY_NAME = "title";
|
||||
public static final String LICENSE_PROPERTY_NAME = "license";
|
||||
public static final String KEYWORDS_PROPERTY_NAME = "keywords";
|
||||
public static final String DESCRIPTION_PROPERTY_NAME = "description";
|
||||
public static final String AUTHORS_PROPERTY_NAME = "authors";
|
||||
public static final String FILES_PROPERTY_NAME = "files";
|
||||
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 PUBLISHERS_PROPERTY_NAME = "publishers";
|
||||
public static final String EXPORTERS_PROPERTY_NAME = "exporters";
|
||||
|
||||
@JsonIgnore
|
||||
protected ObjectNode originalJson;
|
||||
|
||||
@JsonProperty(NAME_PROPERTY_NAME)
|
||||
protected String name;
|
||||
|
||||
@JsonProperty(GROUP_PROPERTY_NAME)
|
||||
protected String group;
|
||||
|
||||
@JsonProperty(TITLE_PROPERTY_NAME)
|
||||
protected String title;
|
||||
|
||||
@JsonProperty(LICENSE_PROPERTY_NAME)
|
||||
protected JsonNode license;
|
||||
|
||||
@JsonProperty(KEYWORDS_PROPERTY_NAME)
|
||||
protected Set<String> keywords;
|
||||
|
||||
@JsonProperty(DESCRIPTION_PROPERTY_NAME)
|
||||
protected String description;
|
||||
|
||||
@JsonProperty(AUTHORS_PROPERTY_NAME)
|
||||
protected ArrayNode authors;
|
||||
|
||||
@JsonProperty(FILES_PROPERTY_NAME)
|
||||
protected List<SoftwareVersionFile> files;
|
||||
|
||||
@JsonProperty(CODE_LOCATION_PROPERTY_NAME)
|
||||
protected String codeLocation;
|
||||
|
||||
@JsonProperty(DOI_URL_PROPERTY_NAME)
|
||||
protected URL doiURL;
|
||||
|
||||
@JsonProperty(GRANTS_PROPERTY_NAME)
|
||||
protected JsonNode grants;
|
||||
|
||||
@JsonProperty(PUBLISHERS_PROPERTY_NAME)
|
||||
protected Map<String,ProcessorConfig> publishers;
|
||||
|
||||
@JsonProperty(EXPORTERS_PROPERTY_NAME)
|
||||
protected Map<String,ProcessorConfig> exporters;
|
||||
|
||||
@JsonIgnore
|
||||
public ObjectNode getOriginalJson() {
|
||||
return originalJson;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setOriginalJson(ObjectNode originalJson) {
|
||||
this.originalJson = originalJson;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public JsonNode getLicense() {
|
||||
return license;
|
||||
}
|
||||
|
||||
public Set<String> getKeywords() {
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public ArrayNode getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public List<SoftwareVersionFile> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public String getCodeLocation() {
|
||||
return codeLocation;
|
||||
}
|
||||
|
||||
public URL getDOIURL() {
|
||||
return doiURL;
|
||||
}
|
||||
|
||||
public void setDOIURL(URL doiURL) {
|
||||
this.doiURL = doiURL;
|
||||
}
|
||||
|
||||
public JsonNode getGrants() {
|
||||
return grants;
|
||||
}
|
||||
|
||||
public Map<String,ProcessorConfig> getPublishers() {
|
||||
return publishers;
|
||||
}
|
||||
|
||||
public Map<String,ProcessorConfig> getExporters() {
|
||||
return exporters;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,27 +2,38 @@ package org.gcube.common.software.model;
|
|||
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
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.JsonGetter;
|
||||
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.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.common.software.utils.Utils;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SoftwareVersionConfig extends SoftwareGlobalConfig {
|
||||
public class SoftwareVersionConfig extends SoftwareConfig {
|
||||
|
||||
public static final String NAME_PROPERTY_NAME = "name";
|
||||
public static final String VERSION_PROPERTY_NAME = "version";
|
||||
public static final String TITLE_PROPERTY_NAME = "title";
|
||||
public static final String DATE_PROPERTY_NAME = "date";
|
||||
public static final String GCUBE_RELEASE_VERSION_PROPERTY_NAME = "gcube_release_version";
|
||||
public static final String GCUBE_RELEASE_TICKET_PROPERTY_NAME = "gcube_release_ticket";
|
||||
public static final String LICENSE_PROPERTY_NAME = "license";
|
||||
public static final String KEYWORDS_PROPERTY_NAME = "keywords";
|
||||
public static final String DESCRIPTION_PROPERTY_NAME = "description";
|
||||
public static final String AUTHORS_PROPERTY_NAME = "authors";
|
||||
public static final String FILES_PROPERTY_NAME = "files";
|
||||
public static final String CODE_LOCATION_PROPERTY_NAME = "code_location";
|
||||
public static final String DOI_URL_PROPERTY_NAME = "doi_url";
|
||||
public static final String VERSION_DOI_URL_PROPERTY_NAME = "version_doi_url";
|
||||
public static final String GRANTS_PROPERTY_NAME = "grants";
|
||||
public static final String PUBLISHERS_PROPERTY_NAME = "publishers";
|
||||
public static final String EXPORTERS_PROPERTY_NAME = "exporters";
|
||||
|
||||
@JsonIgnore
|
||||
protected SoftwareVersionConfig previous;
|
||||
|
@ -33,22 +44,48 @@ public class SoftwareVersionConfig extends SoftwareGlobalConfig {
|
|||
@JsonIgnore
|
||||
protected Boolean newDeposition;
|
||||
|
||||
@JsonProperty(NAME_PROPERTY_NAME)
|
||||
protected String name;
|
||||
|
||||
@JsonProperty(VERSION_PROPERTY_NAME)
|
||||
protected String version;
|
||||
|
||||
@JsonProperty(DATE_PROPERTY_NAME)
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Utils.DATETIME_PATTERN)
|
||||
protected Date date;
|
||||
|
||||
@JsonProperty(GCUBE_RELEASE_VERSION_PROPERTY_NAME)
|
||||
protected String gCubeReleaseVersion;
|
||||
|
||||
@JsonProperty(GCUBE_RELEASE_TICKET_PROPERTY_NAME)
|
||||
protected URL gCubeReleaseTicket;
|
||||
|
||||
|
||||
@JsonProperty(TITLE_PROPERTY_NAME)
|
||||
protected String title;
|
||||
|
||||
@JsonProperty(LICENSE_PROPERTY_NAME)
|
||||
protected JsonNode license;
|
||||
|
||||
@JsonProperty(KEYWORDS_PROPERTY_NAME)
|
||||
protected Set<String> keywords;
|
||||
|
||||
@JsonProperty(AUTHORS_PROPERTY_NAME)
|
||||
protected ArrayNode authors;
|
||||
|
||||
@JsonProperty(FILES_PROPERTY_NAME)
|
||||
protected List<SoftwareVersionFile> files;
|
||||
|
||||
@JsonProperty(CODE_LOCATION_PROPERTY_NAME)
|
||||
protected String codeLocation;
|
||||
|
||||
@JsonProperty(DOI_URL_PROPERTY_NAME)
|
||||
protected URL doiURL;
|
||||
|
||||
@JsonProperty(VERSION_DOI_URL_PROPERTY_NAME)
|
||||
protected URL versionDOIURL;
|
||||
|
||||
|
||||
@JsonProperty(GRANTS_PROPERTY_NAME)
|
||||
protected JsonNode grants;
|
||||
|
||||
@JsonProperty(PUBLISHERS_PROPERTY_NAME)
|
||||
protected Map<String,ProcessorConfig> publishers;
|
||||
|
||||
@JsonProperty(EXPORTERS_PROPERTY_NAME)
|
||||
protected Map<String,ProcessorConfig> exporters;
|
||||
|
||||
public SoftwareVersionConfig() {
|
||||
this.newDeposition = false;
|
||||
|
@ -97,58 +134,69 @@ public class SoftwareVersionConfig extends SoftwareGlobalConfig {
|
|||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@JsonGetter(value = VERSION_PROPERTY_NAME)
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@JsonSetter(value = VERSION_PROPERTY_NAME)
|
||||
public void setVersion(String version) {
|
||||
if(version==null || version.length()==0) {
|
||||
throw new RuntimeException("Invalid version");
|
||||
}
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@JsonGetter(value = DATE_PROPERTY_NAME)
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@JsonSetter(value = DATE_PROPERTY_NAME)
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@JsonGetter(value = GCUBE_RELEASE_VERSION_PROPERTY_NAME)
|
||||
public String getGCubeReleaseVersion() {
|
||||
return gCubeReleaseVersion;
|
||||
}
|
||||
|
||||
@JsonSetter(value = GCUBE_RELEASE_VERSION_PROPERTY_NAME)
|
||||
public void setGCubeReleaseVersion(String gCubeReleaseVersion) {
|
||||
this.gCubeReleaseVersion = gCubeReleaseVersion;
|
||||
}
|
||||
|
||||
@JsonGetter(value = GCUBE_RELEASE_TICKET_PROPERTY_NAME)
|
||||
public URL getGCubeReleaseTicket() {
|
||||
return gCubeReleaseTicket;
|
||||
}
|
||||
|
||||
@JsonSetter(value = GCUBE_RELEASE_TICKET_PROPERTY_NAME)
|
||||
public void setGCubeReleaseTicket(URL gCubeReleaseTicket) {
|
||||
this.gCubeReleaseTicket = gCubeReleaseTicket;
|
||||
public JsonNode getLicense() {
|
||||
return license;
|
||||
}
|
||||
|
||||
public Set<String> getKeywords() {
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public ArrayNode getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public List<SoftwareVersionFile> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public String getCodeLocation() {
|
||||
return codeLocation;
|
||||
}
|
||||
|
||||
public URL getDOIURL() {
|
||||
return doiURL;
|
||||
}
|
||||
|
||||
public void setDOIURL(URL doiURL) {
|
||||
this.doiURL = doiURL;
|
||||
}
|
||||
|
||||
@JsonGetter(VERSION_DOI_URL_PROPERTY_NAME)
|
||||
public URL getVersionDOIURL() {
|
||||
return versionDOIURL;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setVersionDOIURL(URL versionDOIURL) {
|
||||
this.versionDOIURL = versionDOIURL;
|
||||
}
|
||||
|
||||
public JsonNode getGrants() {
|
||||
return grants;
|
||||
}
|
||||
|
||||
}
|
||||
public Map<String,ProcessorConfig> getPublishers() {
|
||||
return publishers;
|
||||
}
|
||||
|
||||
public Map<String,ProcessorConfig> getExporters() {
|
||||
return exporters;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue