package org.gcube.informationsystem.types.impl.properties; import java.lang.reflect.Method; import java.net.URI; import java.net.URL; import java.util.List; import java.util.Objects; import java.util.UUID; 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.types.PropertyTypeName; import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.informationsystem.utils.TypeUtility; import org.gcube.informationsystem.utils.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonTypeName(value=PropertyDefinition.NAME) public final class PropertyDefinitionImpl implements PropertyDefinition { /** * Generated Serial Version UID */ private static final long serialVersionUID = -5925314595659292025L; private static Logger logger = LoggerFactory.getLogger(PropertyDefinitionImpl.class); public final static String UUID_REGEX = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$"; public final static String URI_REGEX = null; public final static String URL_REGEX = null; private List supertypes; private String name= ""; private String description= ""; private boolean mandatory = false; private boolean readonly = false; private boolean notnull = false; private Integer max= null; private Integer min= null; private String regexp= null; private PropertyTypeName propertyTypeName = null; private static String getPropertyNameFromMethodName(Method method){ String name = method.getName(); if(name.startsWith("get")){ name = name.replace("get", ""); } if(name.startsWith("is")){ name = name.replace("is", ""); } if(name.length() > 0){ name = Character.toLowerCase(name.charAt(0)) + (name.length() > 1 ? name.substring(1) : ""); } return name; } protected PropertyDefinitionImpl() { } public PropertyDefinitionImpl(ISProperty propertyAnnotation, Method method) { String name = propertyAnnotation.name().isEmpty()?getPropertyNameFromMethodName(method):propertyAnnotation.name(); this.name = name; this.description = propertyAnnotation.description(); this.mandatory= propertyAnnotation.mandatory(); this.notnull = !propertyAnnotation.nullable(); this.readonly = propertyAnnotation.readonly(); if(propertyAnnotation.max()>0) { this.max = propertyAnnotation.max(); } if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) { this.min = propertyAnnotation.min(); } this.propertyTypeName = new PropertyTypeName(method); Class clz = method.getReturnType(); logger.trace("Return Type for method {} is {}", method, clz); if(!propertyAnnotation.regexpr().isEmpty()) this.regexp = propertyAnnotation.regexpr(); if(this.regexp==null || this.regexp.compareTo("")==0 ){ if(Enum.class.isAssignableFrom(clz)){ Object[] constants = clz.getEnumConstants(); StringBuilder stringBuilder = new StringBuilder("^("); for(int i=0; i getSupertypes() { return this.supertypes; } }