From 68b108429c6e6142fbfe61b6859fef55cad0c9b5 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 5 Jun 2024 18:18:26 +0200 Subject: [PATCH] Enhancing solution --- .../properties/PropertyBasicInfoImpl.java | 58 -------------- ...nfoImpl.java => PropertyVariableImpl.java} | 78 +++++++++++++++---- .../base/reference/AccessType.java | 6 +- .../properties/PropertyBasicInfo.java | 39 ---------- ...rtyFullInfo.java => PropertyVariable.java} | 33 ++++++-- .../impl/properties/TemplateVariableImpl.java | 4 +- .../properties/TemplateVariable.java | 6 +- .../types/PropertyTypeName.java | 5 +- .../properties/PropertyDefinitionImpl.java | 11 +-- .../properties/PropertyDefinition.java | 11 ++- .../types/SerializationTest.java | 4 +- 11 files changed, 118 insertions(+), 137 deletions(-) delete mode 100644 src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyBasicInfoImpl.java rename src/main/java/org/gcube/informationsystem/base/impl/properties/{PropertyFullInfoImpl.java => PropertyVariableImpl.java} (81%) delete mode 100644 src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyBasicInfo.java rename src/main/java/org/gcube/informationsystem/base/reference/properties/{PropertyFullInfo.java => PropertyVariable.java} (56%) diff --git a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyBasicInfoImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyBasicInfoImpl.java deleted file mode 100644 index 85a23cd..0000000 --- a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyBasicInfoImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - */ -package org.gcube.informationsystem.base.impl.properties; - -import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; -import org.gcube.informationsystem.base.reference.properties.PropertyBasicInfo; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -@JsonTypeName(value=PropertyBasicInfo.NAME) -public class PropertyBasicInfoImpl extends PropertyElementImpl implements PropertyBasicInfo { - - /** - * Generated Serial Version UID - */ - private static final long serialVersionUID = -2023568034206025789L; - - protected String name; - protected String description; - protected String defaultValue; - - public PropertyBasicInfoImpl() { - super(); - } - - @Override - 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 String getDefaultValue() { - return defaultValue; - } - - @Override - public void setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue; - } - -} diff --git a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyFullInfoImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableImpl.java similarity index 81% rename from src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyFullInfoImpl.java rename to src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableImpl.java index 83c706f..4aff468 100644 --- a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyFullInfoImpl.java +++ b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyVariableImpl.java @@ -12,10 +12,10 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; 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.PropertyFullInfo; +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.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +23,8 @@ import org.slf4j.LoggerFactory; * @author Luca Frosini (ISTI - CNR) */ // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) -@JsonTypeName(value=PropertyFullInfo.NAME) -public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements PropertyFullInfo { +@JsonTypeName(value=PropertyVariable.NAME) +public class PropertyVariableImpl extends PropertyImpl implements PropertyVariable { /** * Generated Serial Version UID @@ -33,16 +33,20 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope protected Logger logger = LoggerFactory.getLogger(this.getClass()); + 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; - protected String defaultValue=null; + protected PropertyTypeName propertyTypeName = null; - - protected PropertyFullInfoImpl() { + + protected Object defaultValue=null; + + protected PropertyVariableImpl() { } @@ -69,7 +73,7 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope return defaultValueAsString; } - public static Object evaluateDefaultValue(BaseType baseType, String defaultValueAsString) { + protected static Object evaluateDefaultValueStringAccordingBaseType(BaseType baseType, String defaultValueAsString) { if(defaultValueAsString==null || defaultValueAsString.compareTo("null")==0) { return null; @@ -136,48 +140,83 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope 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 boolean isMandatory() { return mandatory; } + + public void setMandatory(boolean mandatory) { + this.mandatory = mandatory; + } @Override public boolean isReadonly() { return readonly; } + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } + @Override public boolean isNotnull() { return notnull; } + public void setNotnull(boolean notnull) { + this.notnull = notnull; + } + @Override public Integer getMax() { return max; } + public void setMax(Integer max) { + this.max = max; + } + @Override public Integer getMin() { return min; } + public void setMin(Integer min) { + this.min = min; + } + @Override public String getRegexp() { return regexp; } + public void setRegexp(String regexp) { + PropertyVariableImpl.checkRegex(regexp, null); + this.regexp = regexp; + } + @Override public String getPropertyType() { return propertyTypeName.toString(); } - @JsonSetter(value = PropertyDefinition.PROPERTY_TYPE_PROPERTY) + @JsonSetter(value = PropertyVariable.PROPERTY_TYPE_PROPERTY) public void setPropertyType(String type) { this.propertyTypeName = new PropertyTypeName(type); } @@ -187,6 +226,17 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope return propertyTypeName; } + @Override + public Object getDefaultValue() { + return defaultValue; + } + + @Override + public void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; + } + + @Override public String toString() { return "Property [" @@ -219,7 +269,7 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope if (getClass() != obj.getClass()) { return false; } - PropertyFullInfoImpl other = (PropertyFullInfoImpl) obj; + PropertyVariableImpl other = (PropertyVariableImpl) obj; return Objects.equals(name, other.name) && Objects.equals(description, other.description) && mandatory == other.mandatory && @@ -239,7 +289,7 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope } @Override - public int compareTo(PropertyFullInfo other) { + public int compareTo(PropertyVariable other) { if (this == other) { return 0; } @@ -250,7 +300,7 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope return -1; } - PropertyFullInfoImpl o = (PropertyFullInfoImpl) other; + PropertyVariableImpl o = (PropertyVariableImpl) other; int ret = 0; ret = name.compareTo(o.name); @@ -309,7 +359,7 @@ public class PropertyFullInfoImpl extends PropertyBasicInfoImpl implements Prope return ret; } - return defaultValue.compareTo(o.defaultValue); + return defaultValue.toString().compareTo(o.defaultValue.toString()); } diff --git a/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java b/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java index 8176358..686ea50 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java @@ -8,12 +8,12 @@ import java.util.HashSet; import java.util.Set; import org.gcube.informationsystem.base.impl.entities.EntityElementImpl; -import org.gcube.informationsystem.base.impl.properties.PropertyBasicInfoImpl; import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl; +import org.gcube.informationsystem.base.impl.properties.PropertyVariableImpl; import org.gcube.informationsystem.base.impl.relations.RelationElementImpl; import org.gcube.informationsystem.base.reference.entities.EntityElement; -import org.gcube.informationsystem.base.reference.properties.PropertyBasicInfo; import org.gcube.informationsystem.base.reference.properties.PropertyElement; +import org.gcube.informationsystem.base.reference.properties.PropertyVariable; import org.gcube.informationsystem.base.reference.relations.RelationElement; import org.gcube.informationsystem.contexts.impl.entities.ContextImpl; import org.gcube.informationsystem.contexts.impl.relations.IsParentOfImpl; @@ -59,7 +59,7 @@ import org.slf4j.LoggerFactory; public enum AccessType { PROPERTY_ELEMENT(PropertyElement.class, PropertyElement.NAME, PropertyElementImpl.class, null), - PROPERTY_BASIC_INFO(PropertyBasicInfo.class, PropertyBasicInfo.NAME, PropertyBasicInfoImpl.class, null), + PROPERTY_FULL_INFO(PropertyVariable.class, PropertyVariable.NAME, PropertyVariableImpl.class, null), PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null), PROPERTY_TYPE(PropertyType.class, PropertyType.NAME, PropertyTypeImpl.class, null), TEMPLATE_VARIABLE(TemplateVariable.class, TemplateVariable.NAME, TemplateVariableImpl.class, null), diff --git a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyBasicInfo.java b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyBasicInfo.java deleted file mode 100644 index aaf6b17..0000000 --- a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyBasicInfo.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.gcube.informationsystem.base.reference.properties; - -import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.gcube.informationsystem.base.impl.properties.PropertyBasicInfoImpl; -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) - */ -@JsonDeserialize(as=PropertyBasicInfoImpl.class) -@TypeMetadata(name = PropertyBasicInfo.NAME, description = "This is the class used to define any property or variable", version = Version.MINIMAL_VERSION_STRING) -@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) -public interface PropertyBasicInfo extends PropertyElement { - - public static final String NAME = "PropertyBasicInfo"; // PropertyBasicInfo.class.getSimpleName(); - - public static final String NAME_PROPERTY = "name"; - public static final String DESCRIPTION_PROPERTY = "description"; - public static final String DEFAULT_VALUE_PROPERTY = "defaultValue"; - - @ISProperty(name = NAME_PROPERTY, description = "The name of the Property/Variable.", readonly = true, mandatory = true, nullable = false) - public String getName(); - - public void setName(String name); - - @ISProperty(name = DESCRIPTION_PROPERTY, description = "The description of the Property/Variable.", readonly = false, mandatory = true, nullable = false) - public String getDescription(); - - public void setDescription(String description); - - @ISProperty(name = DEFAULT_VALUE_PROPERTY, description = "The default value of the Property/Variable. The default value is used as is. If the value needs quotation or escaping please include them to the default value. The default value of 'defaultValue' is null which is defined using the string 'null'", readonly = false, mandatory = false, nullable = true) - public String getDefaultValue(); - - public void setDefaultValue(String defaultValue); - -} diff --git a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyFullInfo.java b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariable.java similarity index 56% rename from src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyFullInfo.java rename to src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariable.java index 2c6b5f5..d3213fa 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyFullInfo.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyVariable.java @@ -2,8 +2,9 @@ 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.impl.properties.PropertyDefinitionImpl; import org.gcube.informationsystem.types.reference.Change; import org.gcube.informationsystem.types.reference.TypeMetadata; import org.gcube.informationsystem.utils.Version; @@ -12,13 +13,15 @@ import org.gcube.informationsystem.utils.Version; * @author Luca Frosini (ISTI - CNR) */ @JsonIgnoreProperties(ignoreUnknown = true) -@JsonDeserialize(as = PropertyDefinitionImpl.class) -@TypeMetadata(name = PropertyFullInfo.NAME, description = "This type provides full information for the definition of any properties", version = Version.MINIMAL_VERSION_STRING) +@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) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) -public interface PropertyFullInfo extends PropertyBasicInfo, Comparable { +public interface PropertyVariable extends Property, Comparable { public static final String NAME = "PropertyFullInfo"; // PropertyFullInfo.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"; @@ -26,14 +29,25 @@ public interface PropertyFullInfo extends PropertyBasicInfo, Comparable(); - // This is made by hand because not all types should be add. + BASE_PROPERTY_TYPES_BY_CLASS.put(Object.class, BaseType.ANY); + BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.TYPE, BaseType.BOOLEAN); BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.class, BaseType.BOOLEAN); 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 688b11f..9012001 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 @@ -3,7 +3,7 @@ package org.gcube.informationsystem.types.impl.properties; import java.lang.reflect.Method; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; -import org.gcube.informationsystem.base.impl.properties.PropertyFullInfoImpl; +import org.gcube.informationsystem.base.impl.properties.PropertyVariableImpl; import org.gcube.informationsystem.types.PropertyTypeName; import org.gcube.informationsystem.types.PropertyTypeName.BaseType; import org.gcube.informationsystem.types.annotations.ISProperty; @@ -14,7 +14,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyDefinition */ // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonTypeName(value=PropertyDefinition.NAME) -public final class PropertyDefinitionImpl extends PropertyFullInfoImpl implements PropertyDefinition { +public final class PropertyDefinitionImpl extends PropertyVariableImpl implements PropertyDefinition { /** * Generated Serial Version UID @@ -53,10 +53,11 @@ public final class PropertyDefinitionImpl extends PropertyFullInfoImpl implement } this.propertyTypeName = new PropertyTypeName(method); - String defaultValueString = propertyAnnotation.defaultValue(); - this.defaultValue = evaluateNullForDefaultValue(defaultValueString); + String defaultValueAsString = propertyAnnotation.defaultValue(); + defaultValueAsString = evaluateNullForDefaultValue(defaultValueAsString); + // The default value is evaluated to test if compliant with the declared type - PropertyFullInfoImpl.evaluateDefaultValue(propertyTypeName.getBaseType(), defaultValue); + this.defaultValue = PropertyVariableImpl.evaluateDefaultValueStringAccordingBaseType(propertyTypeName.getBaseType(), defaultValueAsString); Class clz = method.getReturnType(); logger.trace("Return Type for method {} is {}", method, clz); 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 8ba9e3f..11beaf9 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,10 +2,11 @@ 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.PropertyFullInfo; +import org.gcube.informationsystem.base.reference.properties.PropertyVariable; import org.gcube.informationsystem.types.annotations.Final; import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl; import org.gcube.informationsystem.types.reference.Change; +import org.gcube.informationsystem.types.reference.Changelog; import org.gcube.informationsystem.types.reference.TypeMetadata; import org.gcube.informationsystem.utils.Version; @@ -15,10 +16,14 @@ import org.gcube.informationsystem.utils.Version; @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = PropertyDefinitionImpl.class) @TypeMetadata(name = PropertyDefinition.NAME, description = "This type provides information for the definition of any properties", version = Version.MINIMAL_VERSION_STRING) -@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) +@Changelog ({ + @Change(version = PropertyDefinition.VERSION, description = "The type now is a subclass of @link{PropertyVariable}"), + @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) +}) @Final -public interface PropertyDefinition extends PropertyFullInfo { +public interface PropertyDefinition extends PropertyVariable { 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/types/SerializationTest.java b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java index 67e91fa..ac76523 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -5,8 +5,8 @@ import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.entities.EntityElement; -import org.gcube.informationsystem.base.reference.properties.PropertyBasicInfo; import org.gcube.informationsystem.base.reference.properties.PropertyElement; +import org.gcube.informationsystem.base.reference.properties.PropertyVariable; import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.contexts.reference.relations.IsParentOf; import org.gcube.informationsystem.model.reference.entities.Entity; @@ -60,7 +60,7 @@ public class SerializationTest { @Test public void serializePropertyBasicInfo() throws Exception{ - TypeMapper.serializeType(PropertyBasicInfo.class); + TypeMapper.serializeType(PropertyVariable.class); } @Test