Fixed QueryTemplate model

This commit is contained in:
Luca Frosini 2021-10-25 18:12:04 +02:00
parent 28d1218876
commit 05b06ce6fa
8 changed files with 41 additions and 65 deletions

View File

@ -35,10 +35,8 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
import org.gcube.informationsystem.queries.templates.impl.properties.TemplatePropertyImpl;
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateProperty;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
@ -61,7 +59,6 @@ public enum AccessType {
PROPERTY_ELEMENT(PropertyElement.class, PropertyElement.NAME, PropertyElementImpl.class, null),
PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null),
PROPERTY_TYPE(PropertyType.class, PropertyType.NAME, PropertyTypeImpl.class, null),
TEMPLATE_PROPERTY(TemplateProperty.class, TemplateProperty.NAME, TemplatePropertyImpl.class, null),
TEMPLATE_VARIABLE(TemplateVariable.class, TemplateVariable.NAME, TemplateVariableImpl.class, null),
PROPERTY(Property.class, Property.NAME, PropertyImpl.class, null),

View File

@ -1,16 +1,21 @@
package org.gcube.informationsystem.queries.templates.impl.entities;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateProperty;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=QueryTemplate.NAME)
public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplate {
/**
@ -21,11 +26,14 @@ public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplat
protected String name;
protected String description;
protected TemplateProperty template;
protected ObjectMapper objectMapper;
protected JsonNode template;
protected Map<String, TemplateVariable> templateVariables;
public QueryTemplateImpl() {
this.templateVariables = new HashMap<>();
this.objectMapper = new ObjectMapper();
}
@Override
@ -49,12 +57,22 @@ public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplat
}
@Override
public TemplateProperty getTemplate() {
public String getTemplateAsString() throws JsonProcessingException {
return objectMapper.writeValueAsString(template);
}
@Override
public void setTemplate(String template) throws JsonProcessingException, IOException {
this.template = objectMapper.readTree(template);
}
@Override
public JsonNode getTemplate() {
return template;
}
@Override
public void setTemplate(TemplateProperty template) {
public void setTemplate(JsonNode template) {
this.template = template;
}

View File

@ -1,25 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.queries.templates.impl.properties;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateProperty;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=TemplateProperty.NAME)
public class TemplatePropertyImpl extends PropertyElementImpl implements TemplateProperty {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 2628113641100130640L;
public TemplatePropertyImpl() {
super();
}
}

View File

@ -5,13 +5,12 @@ package org.gcube.informationsystem.queries.templates.impl.properties;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateProperty;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=TemplateProperty.NAME)
@JsonTypeName(value=TemplateVariable.NAME)
public class TemplateVariableImpl extends PropertyElementImpl implements TemplateVariable {
/**

View File

@ -1,14 +1,17 @@
package org.gcube.informationsystem.queries.templates.reference.entities;
import java.io.IOException;
import java.util.Map;
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.JsonSetter;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateProperty;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
@ -44,10 +47,16 @@ public interface QueryTemplate extends EntityElement {
@JsonGetter(value = TEMPLATE_PROPERTY)
@ISProperty(name = TEMPLATE_PROPERTY, description = "The Query Template. It can contains query variables to be replaced to obtain a runnable query.", readonly = false, mandatory = true, nullable = false)
public TemplateProperty getTemplate();
public String getTemplateAsString() throws JsonProcessingException;
@JsonSetter(value = TEMPLATE_PROPERTY)
public void setTemplate(String template) throws JsonProcessingException, IOException;
@JsonIgnore
public void setTemplate(TemplateProperty templateProperty);
public JsonNode getTemplate();
@JsonIgnore
public void setTemplate(JsonNode template);
@JsonGetter(value = TEMPLATE_VARIABLES_PROPERTY)
@ISProperty(name = TEMPLATE_VARIABLES_PROPERTY, description = "The Query Template Variables. It can contains Query Template Variable to be replaced to obtain a runnable query.", readonly = false, mandatory = true, nullable = false)

View File

@ -1,20 +0,0 @@
package org.gcube.informationsystem.queries.templates.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.queries.templates.impl.properties.TemplatePropertyImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=TemplatePropertyImpl.class)
@TypeMetadata(name = TemplateProperty.NAME, description = "This is the class used to define the TemplateProperty", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface TemplateProperty extends PropertyElement {
public static final String NAME = "TemplateProperty"; // TemplateProperty.class.getSimpleName();
}

View File

@ -7,7 +7,6 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateProperty;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
@ -35,7 +34,6 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
propertyElementAccesTypes.add(PropertyElement.NAME);
propertyElementAccesTypes.add(LinkedEntity.NAME);
propertyElementAccesTypes.add(TemplateVariable.NAME);
propertyElementAccesTypes.add(TemplateProperty.NAME);
}

View File

@ -15,7 +15,7 @@ import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateProperty;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
@ -100,11 +100,6 @@ public class SerializationTest {
Assert.assertTrue(encrypted.getAccessType()==AccessType.PROPERTY);
logger.info(ElementMapper.marshal(encrypted));
@SuppressWarnings("unchecked")
PropertyType<TemplateProperty> templateProperty = (PropertyType<TemplateProperty>) TypeMapper.createTypeDefinition(TemplateProperty.class);
Assert.assertTrue(templateProperty.getAccessType()==AccessType.PROPERTY_ELEMENT);
logger.info(ElementMapper.marshal(templateProperty));
@SuppressWarnings("unchecked")
PropertyType<TemplateVariable> templateVariable = (PropertyType<TemplateVariable>) TypeMapper.createTypeDefinition(TemplateVariable.class);
Assert.assertTrue(templateVariable.getAccessType()==AccessType.PROPERTY_ELEMENT);
@ -144,6 +139,11 @@ public class SerializationTest {
EntityType facetType = (EntityType) TypeMapper.createTypeDefinition(FacetType.class);
Assert.assertTrue(facetType.getAccessType()==AccessType.ENTITY_TYPE);
logger.info(ElementMapper.marshal(facetType));
EntityType queryTemplateType = (EntityType) TypeMapper.createTypeDefinition(QueryTemplate.class);
Assert.assertTrue(queryTemplateType.getAccessType()==AccessType.QUERY_TEMPLATE);
logger.info(ElementMapper.marshal(queryTemplateType));
}
@Test