software-versions-processor.../src/main/java/org/gcube/common/software/model/SoftwareVersion.java

155 lines
4.0 KiB
Java

package org.gcube.common.software.model;
import java.net.URL;
import java.util.Date;
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.common.software.utils.Utils;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class SoftwareVersion extends SoftwareConcept {
public static final String VERSION_PROPERTY_NAME = "version";
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 VERSION_DOI_URL_PROPERTY_NAME = "version_doi_url";
@JsonIgnore
protected SoftwareVersion previous;
@JsonIgnore
protected SoftwareVersion next;
@JsonIgnore
protected Boolean newDeposition;
@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(VERSION_DOI_URL_PROPERTY_NAME)
protected URL versionDOIURL;
public SoftwareVersion() {
this.newDeposition = false;
}
@JsonIgnore
public SoftwareVersion getPrevious() {
return previous;
}
@JsonIgnore
public void setPrevious(SoftwareVersion previous) {
this.previous = previous;
}
@JsonIgnore
public SoftwareVersion getNext() {
return next;
}
@JsonIgnore
public void setNext(SoftwareVersion next) {
this.next = next;
}
@JsonIgnore
public Boolean isNewDeposition() {
return newDeposition;
}
@JsonIgnore
public void setNewDeposition(Boolean newVersion) {
this.newDeposition = newVersion;
}
@JsonIgnore
public Variables getVariables() throws Exception {
ObjectMapper objectMapper = Utils.getObjectMapper();
JsonNode jsonNode = objectMapper.valueToTree(this);
Variables variables = objectMapper.treeToValue(jsonNode, Variables.class);
Set<String> missingVariables = variables.parse();
int size = missingVariables.size();
if(size>0) {
throw new Exception("The following variables has been used but not defined or cannot be actualised" +
missingVariables.toArray(new String[size]).toString());
}
return variables;
}
@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;
}
@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;
}
@JsonGetter(VERSION_DOI_URL_PROPERTY_NAME)
public URL getVersionDOIURL() {
return versionDOIURL;
}
@JsonIgnore
public void setVersionDOIURL(URL versionDOIURL) {
this.versionDOIURL = versionDOIURL;
}
}