Adding types to support query templates

This commit is contained in:
Luca Frosini 2021-10-20 19:16:48 +02:00
parent 18b9124e86
commit 833b2f5805
2 changed files with 104 additions and 27 deletions

View File

@ -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<TypeVersion, String> changelog;
protected TemplateProperty templateProperty;
protected Set<TemplateVariable> 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<String, String> getChangelogWithVersionAsString() {
Map<String, String> 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<String, String> changelog) {
@Override
public void setChangelog(Map<TypeVersion, String> changelog) {
this.changelog = changelog;
}
@Override
public void setChangelogWithVersionAsString(Map<String, String> 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<TemplateVariable> getQueryVariables() {
// TODO Auto-generated method stub
return null;
public Set<TemplateVariable> getQueryTemplatesVariables() {
return templateVariables;
}
@Override
public void setQueryTemplateVariables(Set<TemplateVariable> templateVariables) {
this.templateVariables = templateVariables;
}
@Override
public String setName() {
// TODO Auto-generated method stub
return null;
public void addQueryTemplateVariable(TemplateVariable templateVariable) {
this.templateVariables.add(templateVariable);
}
}

View File

@ -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<TypeVersion, String> getChangelog();
@JsonIgnore
public void setChangelog(Map<TypeVersion, String> 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<String, String> getChangelogWithVersionAsString();
@JsonIgnore
@JsonSetter(value=CHANGELOG_PROPERTY)
public void setChangelogWithVersionAsString(Map<String, String> 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<TemplateVariable> getQueryVariables();
public Set<TemplateVariable> getQueryTemplatesVariables();
@JsonIgnore
public void setQueryTemplateVariables(Set<TemplateVariable> templateVariables);
@JsonIgnore
public void addQueryTemplateVariable(TemplateVariable templateVariables);
}