From 2c46cbbdc86a768249f3e82246447e9c150cfaa4 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 4 Jun 2024 17:35:05 +0200 Subject: [PATCH] fixing code --- .../properties/PropertyBasicInfo.java | 2 +- .../properties/TemplateVariable.java | 5 +++-- .../types/annotations/ISProperty.java | 2 +- .../properties/PropertyDefinitionImpl.java | 10 ++++++++- .../informationsystem/types/EntityTest.java | 2 +- .../types/SerializationTest.java | 11 ++++++++++ .../types/knowledge/ModelKnowledgeTest.java | 21 ++++++++++++++++++- 7 files changed, 46 insertions(+), 7 deletions(-) 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 index c3aa180..aaf6b17 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyBasicInfo.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/properties/PropertyBasicInfo.java @@ -31,7 +31,7 @@ public interface PropertyBasicInfo extends PropertyElement { 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", readonly = false, mandatory = true, nullable = false) + @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/queries/templates/reference/properties/TemplateVariable.java b/src/main/java/org/gcube/informationsystem/queries/templates/reference/properties/TemplateVariable.java index f78de74..4b4b08c 100644 --- a/src/main/java/org/gcube/informationsystem/queries/templates/reference/properties/TemplateVariable.java +++ b/src/main/java/org/gcube/informationsystem/queries/templates/reference/properties/TemplateVariable.java @@ -12,13 +12,14 @@ import org.gcube.informationsystem.utils.Version; * @author Luca Frosini (ISTI - CNR) */ @JsonDeserialize(as=TemplateVariableImpl.class) -@TypeMetadata(name = TemplateVariable.NAME, description = "This is the class used to define the a TemplateVariable", version = Version.MINIMAL_VERSION_STRING) +@TypeMetadata(name = TemplateVariable.NAME, description = "This is the class used to define the a TemplateVariable", version = TemplateVariable.VERSION) @Changelog ({ - @Change(version = "2.0.0", description = "The type now is a subclass of @link{PropertyBasicInfo}"), + @Change(version = TemplateVariable.VERSION, description = "The type now is a subclass of @link{PropertyBasicInfo}"), @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) }) public interface TemplateVariable extends PropertyBasicInfo { public static final String NAME = "TemplateVariable"; // TemplateVariable.class.getSimpleName(); + public static final String VERSION = "2.0.0"; } diff --git a/src/main/java/org/gcube/informationsystem/types/annotations/ISProperty.java b/src/main/java/org/gcube/informationsystem/types/annotations/ISProperty.java index f66dd2b..7910180 100644 --- a/src/main/java/org/gcube/informationsystem/types/annotations/ISProperty.java +++ b/src/main/java/org/gcube/informationsystem/types/annotations/ISProperty.java @@ -31,6 +31,6 @@ public @interface ISProperty { int min() default -1; int max() default -1; String regexpr() default ""; - String defaultValue() default ""; + String defaultValue() default "null"; } 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 a56babf..a28cc23 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 @@ -82,6 +82,13 @@ public final class PropertyDefinitionImpl extends PropertyBasicInfoImpl implemen } } + public static String evaluateNullForDefaultValue(String defaultValueAsString) { + if(defaultValueAsString==null || defaultValueAsString.compareTo("null")==0) { + return null; + } + return defaultValueAsString; + } + public static Object evaluateDefaultValue(BaseType baseType, String defaultValueAsString) { if(defaultValueAsString==null || defaultValueAsString.compareTo("null")==0) { @@ -160,7 +167,8 @@ public final class PropertyDefinitionImpl extends PropertyBasicInfoImpl implemen } this.propertyTypeName = new PropertyTypeName(method); - this.defaultValue = propertyAnnotation.defaultValue(); + String defaultValueString = propertyAnnotation.defaultValue(); + this.defaultValue = evaluateNullForDefaultValue(defaultValueString); // The default value is evaluated to test if compliant with the declared type PropertyDefinitionImpl.evaluateDefaultValue(propertyTypeName.getBaseType(), defaultValue); diff --git a/src/test/java/org/gcube/informationsystem/types/EntityTest.java b/src/test/java/org/gcube/informationsystem/types/EntityTest.java index 9af3d45..58ccb25 100644 --- a/src/test/java/org/gcube/informationsystem/types/EntityTest.java +++ b/src/test/java/org/gcube/informationsystem/types/EntityTest.java @@ -15,7 +15,7 @@ public interface EntityTest extends EntityParent { @ISProperty(nullable=false) public String getNotnullable(); - @ISProperty(mandatory=true) + @ISProperty(mandatory=true, defaultValue = "true") public String getMandatory(); @ISProperty(name="different", description="desc") diff --git a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java index aa1e6da..67e91fa 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -5,6 +5,7 @@ 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.contexts.reference.entities.Context; import org.gcube.informationsystem.contexts.reference.relations.IsParentOf; @@ -52,6 +53,16 @@ public class SerializationTest { TypeMapper.serializeType(EntityTest.class); } + @Test + public void serializePropertyDefinition() throws Exception{ + TypeMapper.serializeType(PropertyDefinition.class); + } + + @Test + public void serializePropertyBasicInfo() throws Exception{ + TypeMapper.serializeType(PropertyBasicInfo.class); + } + @Test public void makeFacetTypeDefinition() throws Exception{ EntityType facetTypeDefinitionSelf = (EntityType) TypeMapper.createTypeDefinition(FacetType.class); diff --git a/src/test/java/org/gcube/informationsystem/types/knowledge/ModelKnowledgeTest.java b/src/test/java/org/gcube/informationsystem/types/knowledge/ModelKnowledgeTest.java index b4fa2ff..0816618 100644 --- a/src/test/java/org/gcube/informationsystem/types/knowledge/ModelKnowledgeTest.java +++ b/src/test/java/org/gcube/informationsystem/types/knowledge/ModelKnowledgeTest.java @@ -106,7 +106,26 @@ public class ModelKnowledgeTest{ } } }); + + + tree.elaborate(new NodeElaborator() { + + @Override + public void elaborate(Node node, int level) throws Exception { + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i < level; ++i) { + stringBuffer.append(Node.INDENTATION); + } + + Type type = node.getNodeElement(); + String typeName = type.getName(); + + String definition = TypeMapper.serializeTypeDefinition(type); + + logger.info("{}- {}{} {}", stringBuffer.toString(), typeName, level==0 ? " (ROOT) " : "", definition); + + } + }); } - } }