diff --git a/src/main/java/org/gcube/informationsystem/types/TypeBinder.java b/src/main/java/org/gcube/informationsystem/types/TypeBinder.java index f13cf90..95ef275 100644 --- a/src/main/java/org/gcube/informationsystem/types/TypeBinder.java +++ b/src/main/java/org/gcube/informationsystem/types/TypeBinder.java @@ -7,6 +7,7 @@ import java.util.List; import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; import org.gcube.informationsystem.types.reference.TypeDefinition; +import org.gcube.informationsystem.utils.ISMapper; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; @@ -19,14 +20,17 @@ public class TypeBinder { private final static String NAME = "NAME"; public static String serializeTypeDefinition(TypeDefinition typeDefinition) throws Exception{ + /* ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(typeDefinition); + */ + String json = ISMapper.marshal(typeDefinition); return json; } public static String serializeType(Class type) throws Exception{ TypeDefinition typeDefinition = createTypeDefinition(type); - return serializeTypeDefinition(typeDefinition); + return ISMapper.marshal(typeDefinition); } public static TypeDefinition deserializeTypeDefinition(String json) throws Exception{ diff --git a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java index 1dce934..06ad821 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java @@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonTypeName(value=TypeDefinition.NAME) -public abstract class TypeDefinitionImpl extends ISManageableImpl implements TypeDefinition { +public class TypeDefinitionImpl extends ISManageableImpl implements TypeDefinition { /** * Generated Serial Version UID @@ -103,6 +103,8 @@ public abstract class TypeDefinitionImpl extends ISMan return new RelationTypeDefinitionImpl(clz); } else if(BaseProperty.class.isAssignableFrom(clz)){ return new PropertyTypeDefinitionImpl(clz); + } else if(TypeDefinition.class.isAssignableFrom(clz)) { + return new TypeDefinitionImpl(clz); } else { throw new RuntimeException("Serialization required"); } diff --git a/src/main/java/org/gcube/informationsystem/types/impl/entities/EntityTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/entities/EntityTypeDefinitionImpl.java index 2c36e5c..bee6e51 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/entities/EntityTypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/entities/EntityTypeDefinitionImpl.java @@ -4,10 +4,12 @@ import java.io.StringWriter; import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.properties.Header; +import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.TypeDefinition; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; import org.gcube.informationsystem.utils.ISMapper; @@ -34,8 +36,13 @@ public class EntityTypeDefinitionImpl extends TypeDefiniti @SuppressWarnings({"unchecked"}) Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, Facet.class, Entity.NAME); - } else { + } else if(EntityTypeDefinition.class.isAssignableFrom(clz)){ this.superClasses = retrieveSuperClasses(clz, BaseEntity.class, VERTEX_CLASS_NAME); + this.superClasses.add(TypeDefinition.class.getSimpleName()); + } else if(Context.class.isAssignableFrom(clz)){ + this.superClasses = retrieveSuperClasses(clz, BaseEntity.class, VERTEX_CLASS_NAME); + } else { + throw new RuntimeException("Type Hierachy Error"); } diff --git a/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyTypeDefinitionImpl.java index 101b79a..a72517a 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyTypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyTypeDefinitionImpl.java @@ -2,6 +2,7 @@ package org.gcube.informationsystem.types.impl.properties; import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.TypeDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefiniton; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -17,6 +18,9 @@ public class PropertyTypeDefinitionImpl

extends TypeDefi public PropertyTypeDefinitionImpl(Class

clz) { super(clz); this.superClasses = retrieveSuperClasses(clz, BaseProperty.class, clz == BaseProperty.class ? null : BaseProperty.NAME); + if(PropertyTypeDefiniton.class.isAssignableFrom(clz)) { + this.superClasses.add(TypeDefinition.class.getSimpleName()); + } } } \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java index 500dcba..0399a4d 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java @@ -5,11 +5,13 @@ import java.io.StringWriter; import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.properties.Header; import org.gcube.informationsystem.base.reference.relations.BaseRelation; +import org.gcube.informationsystem.context.reference.relations.IsParentOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.TypeDefinition; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import org.gcube.informationsystem.utils.ISMapper; @@ -44,8 +46,13 @@ public class RelationTypeDefinitionImpl c = (Class) clz; this.superClasses = retrieveSuperClasses(c, ConsistsOf.class, Relation.NAME); - } else { + } else if(RelationTypeDefinition.class.isAssignableFrom(clz)){ this.superClasses = retrieveSuperClasses(clz, BaseRelation.class, EDGE_CLASS_NAME); + this.superClasses.add(TypeDefinition.class.getSimpleName()); + } else if(IsParentOf.class.isAssignableFrom(clz)){ + this.superClasses = retrieveSuperClasses(clz, BaseRelation.class, EDGE_CLASS_NAME); + } else { + throw new RuntimeException("Type Hierachy Error"); } java.lang.reflect.Type[] typeParameters = clz.getTypeParameters(); diff --git a/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java index b63470b..4c8f953 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java @@ -4,6 +4,7 @@ import java.util.Set; import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.types.annotations.Abstract; +import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -13,16 +14,27 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; //@JsonDeserialize(as=TypeDefinitionImpl.class) Do not uncomment to manage subclasses public interface TypeDefinition extends ISManageable { - public static final String NAME = "TypeDefinition"; //Entity.class.getSimpleName(); + public static final String NAME = "TypeDefinition"; //TypeDefinition.class.getSimpleName(); + public static final String NAME_PROPERTY = "name"; + public static final String DESCRIPTION_PROPERTY = "description"; + public static final String ABSTRACT_PROPERTY = "abstract"; + public static final String SUPERCLASSES_PROPERTY = "superClasses"; + public static final String PROPERTIES_PROPERTY = "properties"; + + @ISProperty(name = NAME_PROPERTY, readonly = true, mandatory = true, nullable = false) public String getName(); - + + @ISProperty(name = DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false) public String getDescription(); - + + @ISProperty(name = ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false) public boolean isAbstract(); + @ISProperty(name = SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false) public Set getSuperClasses(); + @ISProperty(name = PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) public Set getProperties(); } 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 29b38ff..559029f 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 @@ -16,4 +16,29 @@ public interface PropertyDefinition extends BaseProperty { public static final String NAME = "PropertyDefinition"; // PropertyDefinition.class.getSimpleName(); + + + + public String getName(); + + public String getDescription(); + + public boolean isMandatory(); + + public boolean isReadonly(); + + public boolean isNotnull(); + + public Integer getMax(); + + public Integer getMin(); + + public String getRegexp(); + + public Integer getLinkedType(); + + public String getLinkedClass(); + + public Integer getType(); + }