diff --git a/src/main/java/org/gcube/informationsystem/querytemplates/impl/entities/QueryTemplatesImpl.java b/src/main/java/org/gcube/informationsystem/querytemplates/impl/entities/QueryTemplatesImpl.java index 37acca3..f367dc5 100644 --- a/src/main/java/org/gcube/informationsystem/querytemplates/impl/entities/QueryTemplatesImpl.java +++ b/src/main/java/org/gcube/informationsystem/querytemplates/impl/entities/QueryTemplatesImpl.java @@ -4,11 +4,9 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.gcube.com.fasterxml.jackson.annotation.JsonGetter; import org.gcube.com.fasterxml.jackson.annotation.JsonInclude; import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include; import org.gcube.com.fasterxml.jackson.annotation.JsonProperty; -import org.gcube.com.fasterxml.jackson.annotation.JsonSetter; import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.querytemplates.reference.entities.QueryTemplate; import org.gcube.informationsystem.querytemplates.reference.properties.TemplateProperty; @@ -30,11 +28,17 @@ public class QueryTemplatesImpl implements QueryTemplate { protected String name; protected String description; protected TypeVersion version; - - @JsonProperty(value = CHANGELOG_PROPERTY, required = false) + @JsonProperty(value = CHANGELOG_PROPERTY, required = true) @JsonInclude(Include.NON_NULL) protected Map changelog; + + protected TemplateProperty templateProperty; + protected Set templateVariables; + public QueryTemplatesImpl() { + this.changelog = new HashMap<>(); + } + @Override public Header getHeader() { return header; @@ -49,23 +53,38 @@ public class QueryTemplatesImpl implements QueryTemplate { public String getName() { return name; } + + @Override + public void setName(String name) { + this.name = name; + } @Override public String getDescription() { return description; } + @Override + public void setDescription(String description) { + this.description = description; + } + @Override public TypeVersion getVersion() { return version; } + + @Override + public void setVersion(TypeVersion typeVersion) { + this.version = typeVersion; + } - @JsonGetter(value = VERSION_PROPERTY) + @Override public String getVersionAsString() { return version.toString(); } - - @JsonSetter(value = VERSION_PROPERTY) + + @Override public void setVersion(String version) { this.version = new TypeVersion(version); } @@ -75,8 +94,15 @@ public class QueryTemplatesImpl implements QueryTemplate { return changelog; } - @JsonGetter(value = CHANGELOG_PROPERTY) - @JsonInclude(Include.NON_NULL) + @Override + public void addChangelog(TypeVersion typeVersion, String changeDescription) { + if(changelog.get(typeVersion)!=null) { + throw new RuntimeException("Changelog for version " + typeVersion.toString() + " alread exists"); + } + changelog.put(typeVersion, changeDescription); + } + + @Override public Map getChangelogWithVersionAsString() { Map map = new HashMap<>(); for (TypeVersion typeVersion : changelog.keySet()) { @@ -85,30 +111,48 @@ public class QueryTemplatesImpl implements QueryTemplate { return map; } - @JsonSetter(value=CHANGELOG_PROPERTY) - public void setChangelog(Map changelog) { + @Override + public void setChangelog(Map changelog) { + this.changelog = changelog; + } + + @Override + public void setChangelogWithVersionAsString(Map changelog) { this.changelog = new HashMap<>(); for (String version : changelog.keySet()) { this.changelog.put(new TypeVersion(version), changelog.get(version)); } } + + @Override + public void addChangelog(String version, String changeDescription) { + TypeVersion typeVersion = new TypeVersion(version); + addChangelog(typeVersion, changeDescription); + } @Override public TemplateProperty getQueryTemplate() { - // TODO Auto-generated method stub - return null; + return templateProperty; + } + + @Override + public void setQueryTemplate(TemplateProperty templateProperty) { + this.templateProperty = templateProperty; } @Override - public Set getQueryVariables() { - // TODO Auto-generated method stub - return null; + public Set getQueryTemplatesVariables() { + return templateVariables; + } + + @Override + public void setQueryTemplateVariables(Set templateVariables) { + this.templateVariables = templateVariables; } @Override - public String setName() { - // TODO Auto-generated method stub - return null; + public void addQueryTemplateVariable(TemplateVariable templateVariable) { + this.templateVariables.add(templateVariable); } } diff --git a/src/main/java/org/gcube/informationsystem/querytemplates/reference/entities/QueryTemplate.java b/src/main/java/org/gcube/informationsystem/querytemplates/reference/entities/QueryTemplate.java index ff28928..4f0a9b6 100644 --- a/src/main/java/org/gcube/informationsystem/querytemplates/reference/entities/QueryTemplate.java +++ b/src/main/java/org/gcube/informationsystem/querytemplates/reference/entities/QueryTemplate.java @@ -6,6 +6,9 @@ import java.util.Set; import org.gcube.com.fasterxml.jackson.annotation.JsonGetter; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.gcube.com.fasterxml.jackson.annotation.JsonInclude; +import org.gcube.com.fasterxml.jackson.annotation.JsonSetter; +import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include; import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.querytemplates.impl.entities.QueryTemplatesImpl; @@ -23,7 +26,7 @@ import org.gcube.informationsystem.utils.TypeVersion; @Abstract @JsonIgnoreProperties(ignoreUnknown=true) @JsonDeserialize(as=QueryTemplatesImpl.class) -@TypeMetadata(name = QueryTemplate.NAME, description = "The type used to store QueryTemplates", version = TypeVersion.MINIMAL_VERSION_STRING) +@TypeMetadata(name = QueryTemplate.NAME, description = "The type used to store Query Templates", version = TypeVersion.MINIMAL_VERSION_STRING) @Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION) public interface QueryTemplate extends IdentifiableElement { @@ -37,33 +40,63 @@ public interface QueryTemplate extends IdentifiableElement { public static final String QUERY_TEMPLATE_PROPERTY = "queryTemplate"; public static final String QUERY_VARIABLES_PROPERTY = "queryVariables"; - @ISProperty(name = NAME_PROPERTY, description = "The name of the JSON Query Template. Among UUID univocally identifiy the JSON Query Template.", readonly = true, mandatory = true, nullable = false) + @ISProperty(name = NAME_PROPERTY, description = "The name of the Query Template. Among UUID univocally identifiy the Query Template.", readonly = true, mandatory = true, nullable = false) public String getName(); - public String setName(); + public void setName(String name); - @ISProperty(name = DESCRIPTION_PROPERTY, description = "The description of the JSON Query Template.", readonly = false, mandatory = true, nullable = false) + @ISProperty(name = DESCRIPTION_PROPERTY, description = "The description of the Query Template.", readonly = false, mandatory = true, nullable = false) public String getDescription(); + + public void setDescription(String description); @JsonIgnore public TypeVersion getVersion(); + public void setVersion(TypeVersion typeVersion); + @JsonGetter(value = VERSION_PROPERTY) - @ISProperty(name = VERSION_PROPERTY, description = "The version of the JSON Query Template.", readonly = false, mandatory = true, nullable = false) + @ISProperty(name = VERSION_PROPERTY, description = "The version of the Query Template.", readonly = false, mandatory = true, nullable = false) public String getVersionAsString(); + @JsonSetter(value = VERSION_PROPERTY) + public void setVersion(String version); + @JsonIgnore public Map getChangelog(); + @JsonIgnore + public void setChangelog(Map changelog); + + @JsonIgnore + public void addChangelog(TypeVersion typeVersion, String changeDescription); + @JsonGetter(value = CHANGELOG_PROPERTY) - @ISProperty(name = CHANGELOG_PROPERTY, description = "Provides the changelog of changes made to the JSON Query Temaplate.", readonly = false, mandatory = true, nullable = false) + @JsonInclude(Include.NON_NULL) + @ISProperty(name = CHANGELOG_PROPERTY, description = "Provides the changelog of changes made to the Query Temaplate.", readonly = false, mandatory = true, nullable = false) public Map getChangelogWithVersionAsString(); + @JsonIgnore + @JsonSetter(value=CHANGELOG_PROPERTY) + public void setChangelogWithVersionAsString(Map changelog); + + @JsonIgnore + public void addChangelog(String version, String changeDescription); + @JsonGetter(value = QUERY_TEMPLATE_PROPERTY) - @ISProperty(name = QUERY_TEMPLATE_PROPERTY, description = "The JSON Query Temaplate. It can contains QueryVariable which when evaluated", readonly = false, mandatory = true, nullable = false) + @ISProperty(name = QUERY_TEMPLATE_PROPERTY, description = "The Query Template. It can contains QueryVariable to be replaced to obtain a runnable query.", readonly = false, mandatory = true, nullable = false) public TemplateProperty getQueryTemplate(); + @JsonIgnore + public void setQueryTemplate(TemplateProperty templateProperty); + @JsonGetter(value = QUERY_VARIABLES_PROPERTY) - public Set getQueryVariables(); + public Set getQueryTemplatesVariables(); + + @JsonIgnore + public void setQueryTemplateVariables(Set templateVariables); + + @JsonIgnore + public void addQueryTemplateVariable(TemplateVariable templateVariables); }