diff --git a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableDefinitionImpl.java new file mode 100644 index 0000000..a403525 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableDefinitionImpl.java @@ -0,0 +1,114 @@ +package org.gcube.informationsystem.base.impl.properties; + +import java.util.Objects; + +import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; +import org.gcube.informationsystem.base.reference.properties.PropertyVariable; +import org.gcube.informationsystem.base.reference.properties.PropertyVariableDefinition; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +// @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) +@JsonTypeName(value=PropertyVariableDefinition.NAME) +public class PropertyVariableDefinitionImpl extends PropertyVariableImpl implements PropertyVariableDefinition { + + /** + * Generated Serial Version UID + */ + private static final long serialVersionUID = -5925314595659292025L; + + protected boolean mandatory = false; + protected boolean readonly = false; + protected boolean notnull = false; + + public PropertyVariableDefinitionImpl() { + super(); + } + + @Override + public boolean isMandatory() { + return mandatory; + } + + @Override + public void setMandatory(boolean mandatory) { + this.mandatory = mandatory; + } + + @Override + public boolean isReadonly() { + return readonly; + } + + @Override + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } + + @Override + public boolean isNotnull() { + return notnull; + } + + @Override + public void setNotnull(boolean notnull) { + this.notnull = notnull; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(mandatory, notnull, readonly); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + PropertyVariableDefinitionImpl other = (PropertyVariableDefinitionImpl) obj; + return mandatory == other.mandatory && notnull == other.notnull && readonly == other.readonly; + } + + public int compareTo(PropertyVariableDefinition other) { + if (this == other) { + return 0; + } + if (other == null) { + return -1; + } + if (getClass() != other.getClass()) { + return -1; + } + + PropertyVariableDefinitionImpl o = (PropertyVariableDefinitionImpl) other; + + int ret = super.compareTo((PropertyVariable) other); + if(ret != 0) { + return ret; + } + + ret = Boolean.compare(mandatory, o.mandatory); + if(ret != 0) { + return ret; + } + + ret = Boolean.compare(readonly, o.readonly); + if(ret != 0) { + return ret; + } + + ret = Boolean.compare(notnull, o.notnull); + if(ret != 0) { + return ret; + } + + return ret; + } +} diff --git a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableImpl.java index a7119a6..b640d08 100644 --- a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableImpl.java +++ b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableImpl.java @@ -9,11 +9,11 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; 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.annotation.JsonTypeName; import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.properties.PropertyVariable; -import org.gcube.informationsystem.model.impl.properties.PropertyImpl; import org.gcube.informationsystem.types.PropertyTypeName; import org.gcube.informationsystem.types.PropertyTypeName.BaseType; import org.slf4j.Logger; @@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory; */ // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonTypeName(value=PropertyVariable.NAME) -public class PropertyVariableImpl extends PropertyImpl implements PropertyVariable { +public class PropertyVariableImpl extends PropertyElementImpl implements PropertyVariable { /** * Generated Serial Version UID @@ -35,9 +35,6 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab protected String name; protected String description; - protected boolean mandatory = false; - protected boolean readonly = false; - protected boolean notnull = false; protected Integer max= null; protected Integer min= null; protected String regexp= null; @@ -139,6 +136,7 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab } + @JsonProperty(index=10) @Override public String getName() { return name; @@ -149,6 +147,7 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab this.name = name; } + @JsonProperty(index=20) @Override public String getDescription() { return description; @@ -159,36 +158,35 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab this.description = description; } + @JsonProperty(value =PropertyVariable.PROPERTY_TYPE_PROPERTY, index=30) @Override - public boolean isMandatory() { - return mandatory; + public String getPropertyType() { + return propertyTypeName.toString(); } + @JsonSetter(value = PropertyVariable.PROPERTY_TYPE_PROPERTY) @Override - public void setMandatory(boolean mandatory) { - this.mandatory = mandatory; + public void setPropertyType(String type) { + this.propertyTypeName = new PropertyTypeName(type); + } + + @JsonIgnore + public PropertyTypeName getPropertyTypeName() { + return propertyTypeName; + } + + @JsonProperty(index=20) + @Override + public Object getDefaultValue() { + return defaultValue; } @Override - public boolean isReadonly() { - return readonly; + public void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; } - @Override - public void setReadonly(boolean readonly) { - this.readonly = readonly; - } - - @Override - public boolean isNotnull() { - return notnull; - } - - @Override - public void setNotnull(boolean notnull) { - this.notnull = notnull; - } - + @JsonProperty(index=40) @Override public Integer getMax() { return max; @@ -199,6 +197,7 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab this.max = max; } + @JsonProperty(index=50) @Override public Integer getMin() { return min; @@ -209,6 +208,7 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab this.min = min; } + @JsonProperty(index=60) @Override public String getRegexp() { return regexp; @@ -220,41 +220,11 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab this.regexp = regexp; } - @Override - public String getPropertyType() { - return propertyTypeName.toString(); - } - - @JsonSetter(value = PropertyVariable.PROPERTY_TYPE_PROPERTY) - @Override - public void setPropertyType(String type) { - this.propertyTypeName = new PropertyTypeName(type); - } - - @JsonIgnore - public PropertyTypeName getPropertyTypeName() { - return propertyTypeName; - } - - @Override - public Object getDefaultValue() { - return defaultValue; - } - - @Override - public void setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; - } - - @Override public String toString() { return "Property [" + "name=" + name + ", description=" + description - + ", mandatory=" + mandatory - + ", readonly=" + readonly - + ", notnull=" + notnull + ", max=" + max + ", min=" + min + ", regexpr=" + regexp @@ -265,7 +235,7 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab @Override public int hashCode() { - return Objects.hash(name, description, mandatory, readonly, notnull, max, min, regexp, propertyTypeName.toString(), defaultValue); + return Objects.hash(name, description, max, min, regexp, propertyTypeName.toString(), defaultValue); } @Override @@ -282,9 +252,6 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab PropertyVariableImpl other = (PropertyVariableImpl) obj; return Objects.equals(name, other.name) && Objects.equals(description, other.description) && - mandatory == other.mandatory && - readonly == other.readonly && - notnull == other.notnull && Objects.equals(max, other.max) && Objects.equals(min, other.min) && Objects.equals(regexp, other.regexp) && @@ -323,21 +290,6 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab return ret; } - ret = Boolean.compare(mandatory, o.mandatory); - if(ret != 0) { - return ret; - } - - ret = Boolean.compare(readonly, o.readonly); - if(ret != 0) { - return ret; - } - - ret = Boolean.compare(notnull, o.notnull); - if(ret != 0) { - return ret; - } - ret = compareIntegers(max, o.max); if(ret != 0) { return ret; @@ -386,7 +338,7 @@ public class PropertyVariableImpl extends PropertyImpl implements PropertyVariab // TODO } - return 0; + return ret; } diff --git a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariable.java b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariable.java index 3c2a016..8591e2c 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariable.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariable.java @@ -3,7 +3,6 @@ package org.gcube.informationsystem.base.reference.properties; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.gcube.informationsystem.base.impl.properties.PropertyVariableImpl; -import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.reference.Change; import org.gcube.informationsystem.types.reference.TypeMetadata; @@ -14,17 +13,14 @@ import org.gcube.informationsystem.utils.Version; */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = PropertyVariableImpl.class) -@TypeMetadata(name = PropertyVariable.NAME, description = "This type provides the information for the definition of any properties", version = Version.MINIMAL_VERSION_STRING) +@TypeMetadata(name = PropertyVariable.NAME, description = "This type provides the basic information for the definition of attributes and and variables", version = Version.MINIMAL_VERSION_STRING) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) -public interface PropertyVariable extends Property, Comparable { +public interface PropertyVariable extends PropertyElement, Comparable { public static final String NAME = "PropertyVariable"; // PropertyVariable.class.getSimpleName(); public static final String NAME_PROPERTY = "name"; public static final String DESCRIPTION_PROPERTY = "description"; - public static final String MANDATORY_PROPERTY = "mandatory"; - public static final String READ_ONLY_PROPERTY = "readonly"; - public static final String NOT_NULL_PROPERTY = "notnull"; public static final String MAX_PROPERTY = "max"; public static final String MIN_PROPERTY = "min"; public static final String REGEX_PROPERTY = "regexp"; @@ -41,37 +37,7 @@ public interface PropertyVariable extends Property, Comparable public void setDescription(String description); - @ISProperty(name = MANDATORY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false") - public boolean isMandatory(); - - public void setMandatory(boolean mandatory); - - @ISProperty(name = READ_ONLY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false") - public boolean isReadonly(); - - public void setReadonly(boolean readonly); - - @ISProperty(name = NOT_NULL_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false") - public boolean isNotnull(); - - public void setNotnull(boolean notnull); - - @ISProperty(name = MAX_PROPERTY, readonly = false, mandatory = true, nullable = false) - public Integer getMax(); - - public void setMax(Integer max); - - @ISProperty(name = MIN_PROPERTY, readonly = false, mandatory = true, nullable = false) - public Integer getMin(); - - public void setMin(Integer min); - - @ISProperty(name = REGEX_PROPERTY, readonly = false, mandatory = true, nullable = false) - public String getRegexp(); - - public void setRegexp(String regexp); - - @ISProperty(name = PROPERTY_TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false) + @ISProperty(name = PROPERTY_TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue = "String") public String getPropertyType(); public void setPropertyType(String type); @@ -81,4 +47,19 @@ public interface PropertyVariable extends Property, Comparable public void setDefaultValue(Object defaultValue); + @ISProperty(name = MAX_PROPERTY, readonly = false, mandatory = true, nullable = true) + public Integer getMax(); + + public void setMax(Integer max); + + @ISProperty(name = MIN_PROPERTY, readonly = false, mandatory = true, nullable = true) + public Integer getMin(); + + public void setMin(Integer min); + + @ISProperty(name = REGEX_PROPERTY, readonly = false, mandatory = true, nullable = true) + public String getRegexp(); + + public void setRegexp(String regexp); + } diff --git a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariableDefinition.java b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariableDefinition.java new file mode 100644 index 0000000..812f313 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariableDefinition.java @@ -0,0 +1,40 @@ +package org.gcube.informationsystem.base.reference.properties; + +import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.gcube.informationsystem.base.impl.properties.PropertyVariableDefinitionImpl; +import org.gcube.informationsystem.types.annotations.ISProperty; +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) + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonDeserialize(as = PropertyVariableDefinitionImpl.class) +@TypeMetadata(name = PropertyVariableDefinition.NAME, description = "This type provides all the information for the definition of attributes and and variables", version = Version.MINIMAL_VERSION_STRING) +@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) +public interface PropertyVariableDefinition extends PropertyVariable { + + public static final String NAME = "PropertyVariableDefinition"; // PropertyVariableDefinition.class.getSimpleName(); + + public static final String MANDATORY_PROPERTY = "mandatory"; + public static final String READ_ONLY_PROPERTY = "readonly"; + public static final String NOT_NULL_PROPERTY = "notnull"; + + @ISProperty(name = MANDATORY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false") + public boolean isMandatory(); + + public void setMandatory(boolean mandatory); + + @ISProperty(name = READ_ONLY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false") + public boolean isReadonly(); + + public void setReadonly(boolean readonly); + + @ISProperty(name = NOT_NULL_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false") + public boolean isNotnull(); + + public void setNotnull(boolean notnull); +} diff --git a/src/main/java/org/gcube/informationsystem/queries/templates/impl/properties/TemplateVariableImpl.java b/src/main/java/org/gcube/informationsystem/queries/templates/impl/properties/TemplateVariableImpl.java index 736f4da..b27852a 100644 --- a/src/main/java/org/gcube/informationsystem/queries/templates/impl/properties/TemplateVariableImpl.java +++ b/src/main/java/org/gcube/informationsystem/queries/templates/impl/properties/TemplateVariableImpl.java @@ -3,14 +3,17 @@ */ package org.gcube.informationsystem.queries.templates.impl.properties; +import org.gcube.com.fasterxml.jackson.annotation.JsonInclude; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; import org.gcube.informationsystem.base.impl.properties.PropertyVariableImpl; import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable; +import org.gcube.informationsystem.types.PropertyTypeName.BaseType; /** * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=TemplateVariable.NAME) +@JsonInclude(JsonInclude.Include.NON_NULL) public class TemplateVariableImpl extends PropertyVariableImpl implements TemplateVariable { /** @@ -22,5 +25,12 @@ public class TemplateVariableImpl extends PropertyVariableImpl implements Templa super(); } - + @Override + public String getPropertyType() { + // Added for backwards compatibility + if(propertyTypeName==null) { + return BaseType.STRING.toString(); + } + return propertyTypeName.toString(); + } } diff --git a/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyDefinitionImpl.java index 40c3799..c068e58 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyDefinitionImpl.java @@ -1,9 +1,12 @@ package org.gcube.informationsystem.types.impl.properties; import java.lang.reflect.Method; +import java.util.Objects; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; +import org.gcube.informationsystem.base.impl.properties.PropertyVariableDefinitionImpl; import org.gcube.informationsystem.base.impl.properties.PropertyVariableImpl; +import org.gcube.informationsystem.base.reference.properties.PropertyVariableDefinition; import org.gcube.informationsystem.types.PropertyTypeName; import org.gcube.informationsystem.types.PropertyTypeName.BaseType; import org.gcube.informationsystem.types.annotations.ISProperty; @@ -14,7 +17,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyDefinition */ // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonTypeName(value=PropertyDefinition.NAME) -public final class PropertyDefinitionImpl extends PropertyVariableImpl implements PropertyDefinition { +public final class PropertyDefinitionImpl extends PropertyVariableDefinitionImpl implements PropertyDefinition { /** * Generated Serial Version UID @@ -90,4 +93,72 @@ public final class PropertyDefinitionImpl extends PropertyVariableImpl implement } + @Override + public boolean isMandatory() { + return mandatory; + } + + @Override + public void setMandatory(boolean mandatory) { + this.mandatory = mandatory; + } + + @Override + public boolean isReadonly() { + return readonly; + } + + @Override + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } + + @Override + public boolean isNotnull() { + return notnull; + } + + @Override + public void setNotnull(boolean notnull) { + this.notnull = notnull; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(mandatory, notnull, readonly); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + PropertyDefinitionImpl other = (PropertyDefinitionImpl) obj; + return mandatory == other.mandatory && notnull == other.notnull && readonly == other.readonly; + } + + public int compareTo(PropertyDefinition other) { + if (this == other) { + return 0; + } + if (other == null) { + return -1; + } + if (getClass() != other.getClass()) { + return -1; + } + + PropertyDefinitionImpl o = (PropertyDefinitionImpl) other; + + int ret = super.compareTo((PropertyVariableDefinition) other); + + return ret; + } + } diff --git a/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java index eebadfb..5160690 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java @@ -2,7 +2,7 @@ package org.gcube.informationsystem.types.reference.properties; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.gcube.informationsystem.base.reference.properties.PropertyVariable; +import org.gcube.informationsystem.base.reference.properties.PropertyVariableDefinition; import org.gcube.informationsystem.types.annotations.Final; import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl; import org.gcube.informationsystem.types.reference.Change; @@ -21,7 +21,7 @@ import org.gcube.informationsystem.utils.Version; @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) }) @Final -public interface PropertyDefinition extends PropertyVariable { +public interface PropertyDefinition extends PropertyVariableDefinition { public static final String NAME = "PropertyDefinition"; // PropertyDefinition.class.getSimpleName(); public static final String VERSION = "2.0.0"; diff --git a/src/test/java/org/gcube/informationsystem/queries/templates/QueryTemplateTest.java b/src/test/java/org/gcube/informationsystem/queries/templates/QueryTemplateTest.java index a97669e..910c6ad 100644 --- a/src/test/java/org/gcube/informationsystem/queries/templates/QueryTemplateTest.java +++ b/src/test/java/org/gcube/informationsystem/queries/templates/QueryTemplateTest.java @@ -48,7 +48,7 @@ public class QueryTemplateTest { stateTemplateVariable.setName(stateVariableName); stateTemplateVariable.setDescription("StateFacet value"); stateTemplateVariable.setDefaultValue("running"); - stateTemplateVariable.setPropertyType("String"); + //stateTemplateVariable.setPropertyType("String"); queryTemplate.addTemplateVariable(stateTemplateVariable); TemplateVariable nameTemplateVariable = new TemplateVariableImpl(); @@ -56,7 +56,7 @@ public class QueryTemplateTest { nameTemplateVariable.setName(nameVariableName); nameTemplateVariable.setDescription("SoftwareFacet name"); nameTemplateVariable.setDefaultValue("resource-registry"); - nameTemplateVariable.setPropertyType("String"); + //nameTemplateVariable.setPropertyType("String"); queryTemplate.addTemplateVariable(nameTemplateVariable); TemplateVariable groupTemplateVariable = new TemplateVariableImpl(); @@ -64,7 +64,7 @@ public class QueryTemplateTest { groupTemplateVariable.setName(groupVariableName); groupTemplateVariable.setDescription("SoftwareFacet group"); groupTemplateVariable.setDefaultValue("information-system"); - groupTemplateVariable.setPropertyType("String"); + //groupTemplateVariable.setPropertyType("String"); queryTemplate.addTemplateVariable(groupTemplateVariable); String json = ElementMapper.marshal(queryTemplate);