Enhancing solution

This commit is contained in:
Luca Frosini 2024-06-05 18:18:26 +02:00
parent 36b6f4f665
commit 68b108429c
11 changed files with 118 additions and 137 deletions

View File

@ -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;
}
}

View File

@ -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());
}

View File

@ -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),

View File

@ -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);
}

View File

@ -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<PropertyFullInfo> {
public interface PropertyVariable extends Property, Comparable<PropertyVariable> {
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<Property
public static final String MIN_PROPERTY = "min";
public static final String REGEX_PROPERTY = "regexp";
public static final String PROPERTY_TYPE_PROPERTY = "propertyType";
public static final String DEFAULT_VALUE_PROPERTY = "defaultValue";
@ISProperty(name = MANDATORY_PROPERTY, readonly = false, mandatory = true, nullable = false)
@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 = MANDATORY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false")
public boolean isMandatory();
@ISProperty(name = READ_ONLY_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = READ_ONLY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false")
public boolean isReadonly();
@ISProperty(name = NOT_NULL_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = NOT_NULL_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue="false")
public boolean isNotnull();
@ISProperty(name = MAX_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ -48,4 +62,9 @@ public interface PropertyFullInfo extends PropertyBasicInfo, Comparable<Property
@ISProperty(name = PROPERTY_TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getPropertyType();
@ISProperty(name = DEFAULT_VALUE_PROPERTY, description = "The default value of the Property/Variable", readonly = false, mandatory = false, nullable = true)
public Object getDefaultValue();
public void setDefaultValue(Object defaultValue);
}

View File

@ -4,14 +4,14 @@
package org.gcube.informationsystem.queries.templates.impl.properties;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.properties.PropertyBasicInfoImpl;
import org.gcube.informationsystem.base.impl.properties.PropertyVariableImpl;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=TemplateVariable.NAME)
public class TemplateVariableImpl extends PropertyBasicInfoImpl implements TemplateVariable {
public class TemplateVariableImpl extends PropertyVariableImpl implements TemplateVariable {
/**
* Generated Serial Version UID

View File

@ -1,7 +1,7 @@
package org.gcube.informationsystem.queries.templates.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.properties.PropertyBasicInfo;
import org.gcube.informationsystem.base.reference.properties.PropertyVariable;
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.Changelog;
@ -14,10 +14,10 @@ import org.gcube.informationsystem.utils.Version;
@JsonDeserialize(as=TemplateVariableImpl.class)
@TypeMetadata(name = TemplateVariable.NAME, description = "This is the class used to define the a TemplateVariable", version = TemplateVariable.VERSION)
@Changelog ({
@Change(version = TemplateVariable.VERSION, description = "The type now is a subclass of @link{PropertyBasicInfo}"),
@Change(version = TemplateVariable.VERSION, description = "The type now is a subclass of @link{PropertyVariable}"),
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
})
public interface TemplateVariable extends PropertyBasicInfo {
public interface TemplateVariable extends PropertyVariable {
public static final String NAME = "TemplateVariable"; // TemplateVariable.class.getSimpleName();
public static final String VERSION = "2.0.0";

View File

@ -53,6 +53,8 @@ public class PropertyTypeName {
public enum BaseType {
ANY("Any"),
BOOLEAN("Boolean"),
INTEGER("Integer"),
@ -123,8 +125,9 @@ public class PropertyTypeName {
static {
BASE_PROPERTY_TYPES_BY_CLASS = new HashMap<>();
// 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);

View File

@ -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);

View File

@ -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";
}

View File

@ -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