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.Map;
import java.util.Set; 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;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include; import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty; 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.model.reference.properties.Header;
import org.gcube.informationsystem.querytemplates.reference.entities.QueryTemplate; import org.gcube.informationsystem.querytemplates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.querytemplates.reference.properties.TemplateProperty; import org.gcube.informationsystem.querytemplates.reference.properties.TemplateProperty;
@ -30,11 +28,17 @@ public class QueryTemplatesImpl implements QueryTemplate {
protected String name; protected String name;
protected String description; protected String description;
protected TypeVersion version; protected TypeVersion version;
@JsonProperty(value = CHANGELOG_PROPERTY, required = true)
@JsonProperty(value = CHANGELOG_PROPERTY, required = false)
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
protected Map<TypeVersion, String> changelog; protected Map<TypeVersion, String> changelog;
protected TemplateProperty templateProperty;
protected Set<TemplateVariable> templateVariables;
public QueryTemplatesImpl() {
this.changelog = new HashMap<>();
}
@Override @Override
public Header getHeader() { public Header getHeader() {
return header; return header;
@ -49,23 +53,38 @@ public class QueryTemplatesImpl implements QueryTemplate {
public String getName() { public String getName() {
return name; return name;
} }
@Override
public void setName(String name) {
this.name = name;
}
@Override @Override
public String getDescription() { public String getDescription() {
return description; return description;
} }
@Override
public void setDescription(String description) {
this.description = description;
}
@Override @Override
public TypeVersion getVersion() { public TypeVersion getVersion() {
return version; return version;
} }
@Override
public void setVersion(TypeVersion typeVersion) {
this.version = typeVersion;
}
@JsonGetter(value = VERSION_PROPERTY) @Override
public String getVersionAsString() { public String getVersionAsString() {
return version.toString(); return version.toString();
} }
@JsonSetter(value = VERSION_PROPERTY) @Override
public void setVersion(String version) { public void setVersion(String version) {
this.version = new TypeVersion(version); this.version = new TypeVersion(version);
} }
@ -75,8 +94,15 @@ public class QueryTemplatesImpl implements QueryTemplate {
return changelog; return changelog;
} }
@JsonGetter(value = CHANGELOG_PROPERTY) @Override
@JsonInclude(Include.NON_NULL) 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() { public Map<String, String> getChangelogWithVersionAsString() {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
for (TypeVersion typeVersion : changelog.keySet()) { for (TypeVersion typeVersion : changelog.keySet()) {
@ -85,30 +111,48 @@ public class QueryTemplatesImpl implements QueryTemplate {
return map; return map;
} }
@JsonSetter(value=CHANGELOG_PROPERTY) @Override
public void setChangelog(Map<String, String> changelog) { public void setChangelog(Map<TypeVersion, String> changelog) {
this.changelog = changelog;
}
@Override
public void setChangelogWithVersionAsString(Map<String, String> changelog) {
this.changelog = new HashMap<>(); this.changelog = new HashMap<>();
for (String version : changelog.keySet()) { for (String version : changelog.keySet()) {
this.changelog.put(new TypeVersion(version), changelog.get(version)); 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 @Override
public TemplateProperty getQueryTemplate() { public TemplateProperty getQueryTemplate() {
// TODO Auto-generated method stub return templateProperty;
return null; }
@Override
public void setQueryTemplate(TemplateProperty templateProperty) {
this.templateProperty = templateProperty;
} }
@Override @Override
public Set<TemplateVariable> getQueryVariables() { public Set<TemplateVariable> getQueryTemplatesVariables() {
// TODO Auto-generated method stub return templateVariables;
return null; }
@Override
public void setQueryTemplateVariables(Set<TemplateVariable> templateVariables) {
this.templateVariables = templateVariables;
} }
@Override @Override
public String setName() { public void addQueryTemplateVariable(TemplateVariable templateVariable) {
// TODO Auto-generated method stub this.templateVariables.add(templateVariable);
return null;
} }
} }

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.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; 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.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.querytemplates.impl.entities.QueryTemplatesImpl; import org.gcube.informationsystem.querytemplates.impl.entities.QueryTemplatesImpl;
@ -23,7 +26,7 @@ import org.gcube.informationsystem.utils.TypeVersion;
@Abstract @Abstract
@JsonIgnoreProperties(ignoreUnknown=true) @JsonIgnoreProperties(ignoreUnknown=true)
@JsonDeserialize(as=QueryTemplatesImpl.class) @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) @Change(version = TypeVersion.MINIMAL_VERSION_STRING, description = TypeVersion.MINIMAL_VERSION_DESCRIPTION)
public interface QueryTemplate extends IdentifiableElement { 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_TEMPLATE_PROPERTY = "queryTemplate";
public static final String QUERY_VARIABLES_PROPERTY = "queryVariables"; 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 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 String getDescription();
public void setDescription(String description);
@JsonIgnore @JsonIgnore
public TypeVersion getVersion(); public TypeVersion getVersion();
public void setVersion(TypeVersion typeVersion);
@JsonGetter(value = VERSION_PROPERTY) @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(); public String getVersionAsString();
@JsonSetter(value = VERSION_PROPERTY)
public void setVersion(String version);
@JsonIgnore @JsonIgnore
public Map<TypeVersion, String> getChangelog(); 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) @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(); 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) @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(); public TemplateProperty getQueryTemplate();
@JsonIgnore
public void setQueryTemplate(TemplateProperty templateProperty);
@JsonGetter(value = QUERY_VARIABLES_PROPERTY) @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);
} }