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 39b669a..408c561 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java @@ -11,6 +11,7 @@ import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.base.reference.relations.BaseRelation; +import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.types.annotations.Abstract; import org.gcube.informationsystem.types.annotations.ISProperty; @@ -45,6 +46,8 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition { protected boolean abstractType; protected Set superClasses; + protected Set properties; + protected Set retrieveSuperClasses(Class type, Class baseClass, String topSuperClass){ Set interfaceList = new HashSet<>(); @@ -108,7 +111,7 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition { typeDefinition = EntityTypeDefinitionImpl.getEntityTypeDefinitionInstance((Class) clz); return typeDefinition; } else if(BaseRelation.class.isAssignableFrom(clz)){ - typeDefinition = new RelationTypeDefinitionImpl((Class>) clz); + typeDefinition = RelationTypeDefinitionImpl.getRelationTypeDefinitionInstance((Class>) clz); return typeDefinition; } else if(BaseProperty.class.isAssignableFrom(clz)){ typeDefinition = new PropertyTypeDefinitionImpl(clz); @@ -137,6 +140,10 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition { this.abstractType = true; } + if(!Resource.class.isAssignableFrom(clz)) { + this.properties = retrieveListOfProperties(clz); + } + } @Override @@ -159,4 +166,9 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition { return superClasses; } + @Override + public Set getProperties() { + return properties; + } + } 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 972392e..d272f75 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 @@ -13,6 +13,9 @@ import org.gcube.informationsystem.utils.ISMapper; import com.fasterxml.jackson.annotation.JsonTypeName; +/** + * @author Luca Frosini (ISTI - CNR) + */ @JsonTypeName(value=EntityTypeDefinition.NAME) public class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements EntityTypeDefinition { @@ -24,21 +27,16 @@ public class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements Enti // private static final String VERTEX_CLASS_NAME = "V"; public static EntityTypeDefinition getEntityTypeDefinitionInstance(Class clz) { - EntityTypeDefinition entityTypeDefinition; if(Resource.class.isAssignableFrom(clz)) { @SuppressWarnings("unchecked") Class c = (Class) clz; - entityTypeDefinition = new ResourceTypeDefinitionImpl(c); - return entityTypeDefinition; + return new ResourceTypeDefinitionImpl((Class) c); } else if(Facet.class.isAssignableFrom(clz)){ @SuppressWarnings("unchecked") Class c = (Class) clz; - entityTypeDefinition = new FacetTypeDefinitionImpl(c); - return entityTypeDefinition; - } else { - entityTypeDefinition = new EntityTypeDefinitionImpl(clz); - } - return entityTypeDefinition; + return new FacetTypeDefinitionImpl(c); + } + return new EntityTypeDefinitionImpl(clz); } @@ -62,7 +60,6 @@ public class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements Enti } else { throw new RuntimeException("Type Hierachy Error for class " + clz.getSimpleName()); } - } diff --git a/src/main/java/org/gcube/informationsystem/types/impl/entities/FacetTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/entities/FacetTypeDefinitionImpl.java index 9e773e3..5a2a707 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/entities/FacetTypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/entities/FacetTypeDefinitionImpl.java @@ -1,14 +1,14 @@ package org.gcube.informationsystem.types.impl.entities; -import java.util.Set; - import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.types.reference.entities.FacetTypeDefinition; -import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import com.fasterxml.jackson.annotation.JsonTypeName; +/** + * @author Luca Frosini (ISTI - CNR) + */ @JsonTypeName(value=FacetTypeDefinition.NAME) public class FacetTypeDefinitionImpl extends EntityTypeDefinitionImpl implements FacetTypeDefinition { @@ -16,8 +16,6 @@ public class FacetTypeDefinitionImpl extends EntityTypeDefinitionImpl implements * Generated Serial Version UID */ private static final long serialVersionUID = 6268161046955738969L; - - protected Set properties; protected FacetTypeDefinitionImpl() { super(); @@ -26,14 +24,8 @@ public class FacetTypeDefinitionImpl extends EntityTypeDefinitionImpl implements public FacetTypeDefinitionImpl(Class clz) { super(clz); - Class c = (Class) clz; - this.superClasses = retrieveSuperClasses(c, Facet.class, Entity.NAME); + this.superClasses = retrieveSuperClasses(clz, Facet.class, Entity.NAME); - this.properties = retrieveListOfProperties(clz); } - @Override - public Set getProperties() { - return properties; - } } diff --git a/src/main/java/org/gcube/informationsystem/types/impl/entities/ResourceTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/entities/ResourceTypeDefinitionImpl.java index 0befae7..bfe289e 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/entities/ResourceTypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/entities/ResourceTypeDefinitionImpl.java @@ -3,6 +3,7 @@ package org.gcube.informationsystem.types.impl.entities; import java.util.ArrayList; import java.util.List; +import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.types.annotations.ResourceSchema; @@ -14,6 +15,9 @@ import org.gcube.informationsystem.types.reference.properties.ResourceEntryDefin import com.fasterxml.jackson.annotation.JsonTypeName; +/** + * @author Luca Frosini (ISTI - CNR) + */ @JsonTypeName(value=ResourceTypeDefinition.NAME) public class ResourceTypeDefinitionImpl extends EntityTypeDefinitionImpl implements ResourceTypeDefinition { @@ -31,6 +35,9 @@ public class ResourceTypeDefinitionImpl extends EntityTypeDefinitionImpl impleme public ResourceTypeDefinitionImpl(Class clz) { super(clz); + + this.superClasses = retrieveSuperClasses(clz, Resource.class, Entity.NAME); + setResourceSchemaEntries(clz); } 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 67cc533..276cd0d 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 @@ -1,10 +1,7 @@ package org.gcube.informationsystem.types.impl.properties; -import java.util.Set; - import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; -import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -18,8 +15,6 @@ public final class PropertyTypeDefinitionImpl

extends Ty */ private static final long serialVersionUID = 7532701373450638829L; - protected Set properties; - protected PropertyTypeDefinitionImpl() { super(); } @@ -28,12 +23,6 @@ public final class PropertyTypeDefinitionImpl

extends Ty super(clz); this.superClasses = retrieveSuperClasses(clz, BaseProperty.class, clz == BaseProperty.class ? null : BaseProperty.NAME); - this.properties = retrieveListOfProperties(clz); - } - - @Override - public Set getProperties() { - return properties; } } \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/types/impl/relations/ConsistsOfTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/relations/ConsistsOfTypeDefinitionImpl.java new file mode 100644 index 0000000..d09e9e9 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/impl/relations/ConsistsOfTypeDefinitionImpl.java @@ -0,0 +1,60 @@ +package org.gcube.informationsystem.types.impl.relations; + +import java.lang.reflect.Type; + +import org.gcube.informationsystem.model.reference.entities.Facet; +import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.model.reference.relations.ConsistsOf; +import org.gcube.informationsystem.model.reference.relations.Relation; +import org.gcube.informationsystem.types.impl.entities.FacetTypeDefinitionImpl; +import org.gcube.informationsystem.types.impl.entities.ResourceTypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.entities.FacetTypeDefinition; +import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition; +import org.gcube.informationsystem.types.reference.relations.ConsistsOfTypeDefinition; + +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@JsonTypeName(value=ConsistsOfTypeDefinition.NAME) +public class ConsistsOfTypeDefinitionImpl extends RelationTypeDefinitionImpl implements ConsistsOfTypeDefinition { + + /** + * Generated Serial Version UID + */ + private static final long serialVersionUID = 2891976493165330476L; + + protected ConsistsOfTypeDefinitionImpl() { + super(); + } + + public ConsistsOfTypeDefinitionImpl(Class> clz) { + super(clz); + + this.superClasses = retrieveSuperClasses(clz, ConsistsOf.class, Relation.NAME); + + this.properties = retrieveListOfProperties(clz); + + discoverSourceAndTarget(clz); + } + + @SuppressWarnings("unchecked") + private void discoverSourceAndTarget(Class> clz) { + Type[] typeParameters = clz.getTypeParameters(); + + Class sourceClass; + Class targetClass; + if(typeParameters.length==0) { + typeParameters = getParametersFromSuperClasses(clz); + sourceClass = (Class) typeParameters[0]; + targetClass = (Class) typeParameters[1]; + }else { + sourceClass = (Class) getGenericClass(typeParameters[0]); + targetClass = (Class) getGenericClass(typeParameters[1]); + } + + this.source = new ResourceTypeDefinitionImpl((Class) sourceClass); + this.target = new FacetTypeDefinitionImpl((Class) targetClass); + } +} diff --git a/src/main/java/org/gcube/informationsystem/types/impl/relations/IsRelatedToTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/relations/IsRelatedToTypeDefinitionImpl.java new file mode 100644 index 0000000..48ac7a2 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/impl/relations/IsRelatedToTypeDefinitionImpl.java @@ -0,0 +1,57 @@ +package org.gcube.informationsystem.types.impl.relations; + +import java.lang.reflect.Type; + +import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; +import org.gcube.informationsystem.model.reference.relations.Relation; +import org.gcube.informationsystem.types.impl.entities.ResourceTypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition; +import org.gcube.informationsystem.types.reference.relations.IsRelatedToTypeDefinition; + +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@JsonTypeName(value=IsRelatedToTypeDefinition.NAME) +public class IsRelatedToTypeDefinitionImpl extends RelationTypeDefinitionImpl implements IsRelatedToTypeDefinition { + + /** + * Generated Serial Version UID + */ + private static final long serialVersionUID = 8448665395204514722L; + + protected IsRelatedToTypeDefinitionImpl() { + super(); + } + + public IsRelatedToTypeDefinitionImpl(Class> clz) { + super(clz); + + this.superClasses = retrieveSuperClasses(clz, IsRelatedTo.class, Relation.NAME); + + this.properties = retrieveListOfProperties(clz); + + discoverSourceAndTarget(clz); + } + + @SuppressWarnings("unchecked") + private void discoverSourceAndTarget(Class> clz) { + Type[] typeParameters = clz.getTypeParameters(); + + Class sourceClass; + Class targetClass; + if(typeParameters.length==0) { + typeParameters = getParametersFromSuperClasses(clz); + sourceClass = (Class) typeParameters[0]; + targetClass = (Class) typeParameters[1]; + }else { + sourceClass = (Class) getGenericClass(typeParameters[0]); + targetClass = (Class) getGenericClass(typeParameters[1]); + } + + this.source = new ResourceTypeDefinitionImpl((Class) sourceClass); + this.target = new ResourceTypeDefinitionImpl((Class) targetClass); + } +} 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 0daf2d8..b545a84 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 @@ -2,7 +2,6 @@ package org.gcube.informationsystem.types.impl.relations; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.Set; import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.relations.BaseRelation; @@ -11,129 +10,122 @@ import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; 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.impl.TypeDefinitionImpl; import org.gcube.informationsystem.types.impl.entities.EntityTypeDefinitionImpl; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; -import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import com.fasterxml.jackson.annotation.JsonTypeName; -@JsonTypeName(value=RelationTypeDefinition.NAME) -public final class RelationTypeDefinitionImpl extends TypeDefinitionImpl implements RelationTypeDefinition { - +@JsonTypeName(value = RelationTypeDefinition.NAME) +public class RelationTypeDefinitionImpl + extends TypeDefinitionImpl implements RelationTypeDefinition { + /** * Generated Serial Version UID */ private static final long serialVersionUID = 2221831081869571296L; - protected Set properties; - protected RelationTypeDefinitionImpl() { super(); } - public RelationTypeDefinitionImpl(Class> clz) { - super(clz); - - if(IsRelatedTo.class.isAssignableFrom(clz)){ + public static RelationTypeDefinition getRelationTypeDefinitionInstance( + Class> clz) { + if(IsRelatedTo.class.isAssignableFrom(clz)) { @SuppressWarnings("unchecked") - Class> c = (Class>) clz; - this.superClasses = retrieveSuperClasses(c, IsRelatedTo.class, Relation.NAME); + Class> c = (Class>) clz; + return new IsRelatedToTypeDefinitionImpl(c); } else if(ConsistsOf.class.isAssignableFrom(clz)) { @SuppressWarnings("unchecked") - Class> c = (Class>) clz; - this.superClasses = retrieveSuperClasses(c, ConsistsOf.class, Relation.NAME); - } else if(RelationTypeDefinition.class.isAssignableFrom(clz)){ - @SuppressWarnings("unchecked") + Class> c = (Class>) clz; + return new ConsistsOfTypeDefinitionImpl(c); + } + return new RelationTypeDefinitionImpl(clz); + } + + public RelationTypeDefinitionImpl(Class> clz) { + super(clz); + + if(RelationTypeDefinition.class.isAssignableFrom(clz)) { + @SuppressWarnings({"unchecked", "rawtypes"}) Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, RelationTypeDefinition.class, BaseRelation.NAME); - } else if(IsParentOf.class.isAssignableFrom(clz)){ + } else if(IsParentOf.class.isAssignableFrom(clz)) { @SuppressWarnings("unchecked") Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, IsParentOf.class, BaseRelation.NAME); - } else if(BaseRelation.class.isAssignableFrom(clz)){ + } else if(BaseRelation.class.isAssignableFrom(clz)) { this.superClasses = retrieveSuperClasses(clz, BaseRelation.class, null); } else { throw new RuntimeException("Type Hierachy Error"); } - this.properties = retrieveListOfProperties(clz); - discoverSourceAndTarget(clz); } @SuppressWarnings("unchecked") - protected Type[] getParametersFromSuperClasses(Class> clz) { - for(Type t : clz.getGenericInterfaces()){ + protected Type[] getParametersFromSuperClasses(Class> clz) { + for(Type t : clz.getGenericInterfaces()) { if(t instanceof ParameterizedType) { if(BaseRelation.class.isAssignableFrom((Class) ((ParameterizedType) t).getRawType())) { return ((ParameterizedType) t).getActualTypeArguments(); } - }else if(BaseRelation.class.isAssignableFrom((Class) t)){ - return getParametersFromSuperClasses((Class>) t); + } else if(BaseRelation.class.isAssignableFrom((Class) t)) { + return getParametersFromSuperClasses((Class>) t); } } throw new RuntimeException("Unable to find Generic Parameters From SuperClasses to set source and target"); } @SuppressWarnings("unchecked") - private void discoverSourceAndTarget(Class> clz) { + private void discoverSourceAndTarget(Class> clz) { Type[] typeParameters = clz.getTypeParameters(); Class sourceClass; Class targetClass; - if(typeParameters.length==0) { + if(typeParameters.length == 0) { typeParameters = getParametersFromSuperClasses(clz); sourceClass = (Class) typeParameters[0]; targetClass = (Class) typeParameters[1]; - }else { + } else { sourceClass = (Class) getGenericClass(typeParameters[0]); targetClass = (Class) getGenericClass(typeParameters[1]); } - this.source = new EntityTypeDefinitionImpl(sourceClass); - this.target = new EntityTypeDefinitionImpl(targetClass); + this.source = (S) new EntityTypeDefinitionImpl(sourceClass); + this.target = (T) new EntityTypeDefinitionImpl(targetClass); + } - @Override - public Set getProperties() { - return properties; - } - - /* * Java does not support class multiple inheritance. * TypeDefinitionImpl is the superclass so that this class does not inherits the methods and field of BaseRelationImpl * We need to copy them. */ - protected EntityTypeDefinition source; - protected EntityTypeDefinition target; + protected S source; + protected T target; @Override - public EntityTypeDefinition getSource() { + public S getSource() { return source; } - - + @Override - public void setSource(EntityTypeDefinition source) { + public void setSource(S source) { this.source = source; } - - + @Override - public EntityTypeDefinition getTarget() { + public T getTarget() { return target; } - - + @Override - public void setTarget(EntityTypeDefinition target) { + public void setTarget(T target) { this.target = target; } - + } diff --git a/src/main/java/org/gcube/informationsystem/types/reference/PropertyCapableTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/PropertyCapableTypeDefinition.java deleted file mode 100644 index 79ded0b..0000000 --- a/src/main/java/org/gcube/informationsystem/types/reference/PropertyCapableTypeDefinition.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.gcube.informationsystem.types.reference; - -import java.util.Set; - -import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; - -/** - * @author Luca Frosini (ISTI - CNR) - * This is just an useful interface to capture all type definition having properties - * such as FacetTypeDefinition, PropertyTypeDefinition, RelationTypeDefinition - */ -public interface PropertyCapableTypeDefinition { - - public static final String PROPERTIES_PROPERTY = "properties"; - - public Set getProperties(); -} 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 433f277..46e04e7 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java @@ -5,6 +5,7 @@ import java.util.Set; import org.gcube.informationsystem.base.reference.ER; 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; @@ -19,6 +20,7 @@ public interface TypeDefinition extends ER { public static final String DESCRIPTION_PROPERTY = "description"; public static final String ABSTRACT_PROPERTY = "abstract"; public static final String TYPE_SUPERCLASSES_PROPERTY = "superClasses"; + public static final String PROPERTIES_PROPERTY = "properties"; @ISProperty(name = NAME_PROPERTY, readonly = true, mandatory = true, nullable = false) public String getName(); @@ -32,4 +34,7 @@ public interface TypeDefinition extends ER { @ISProperty(name = TYPE_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/entities/EntityTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/entities/EntityTypeDefinition.java index 328c1a7..94367cf 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/entities/EntityTypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/entities/EntityTypeDefinition.java @@ -6,12 +6,13 @@ import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.impl.entities.EntityTypeDefinitionImpl; import org.gcube.informationsystem.types.reference.TypeDefinition; +import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonIgnoreProperties(ignoreUnknown = true) -@JsonDeserialize(as = EntityTypeDefinitionImpl.class) // Do not uncomment to manage subclasses +@JsonDeserialize(as = EntityTypeDefinitionImpl.class) public interface EntityTypeDefinition extends TypeDefinition, BaseEntity { public static final String NAME = "EntityTypeDefinition"; //EntityTypeDefinition.class.getSimpleName(); @@ -34,6 +35,9 @@ public interface EntityTypeDefinition extends TypeDefinition, BaseEntity { @ISProperty(name = TypeDefinition.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false) public Set getSuperClasses(); + @Override + @ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) + public Set getProperties(); /* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */ diff --git a/src/main/java/org/gcube/informationsystem/types/reference/entities/FacetTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/entities/FacetTypeDefinition.java index b97ca73..f0beeeb 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/entities/FacetTypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/entities/FacetTypeDefinition.java @@ -1,25 +1,15 @@ package org.gcube.informationsystem.types.reference.entities; -import java.util.Set; - import org.gcube.informationsystem.base.reference.entities.BaseEntity; -import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.impl.entities.FacetTypeDefinitionImpl; -import org.gcube.informationsystem.types.reference.PropertyCapableTypeDefinition; -import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = FacetTypeDefinitionImpl.class) -public interface FacetTypeDefinition extends EntityTypeDefinition, BaseEntity, PropertyCapableTypeDefinition { +public interface FacetTypeDefinition extends EntityTypeDefinition, BaseEntity { public static final String NAME = "FacetTypeDefinition"; //FacetTypeDefinition.class.getSimpleName(); - @Override - @ISProperty(name = PropertyCapableTypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) - public Set getProperties(); - - } diff --git a/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefinition.java index e8377c5..e803c7a 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefinition.java @@ -7,7 +7,6 @@ import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.impl.properties.PropertyTypeDefinitionImpl; -import org.gcube.informationsystem.types.reference.PropertyCapableTypeDefinition; import org.gcube.informationsystem.types.reference.TypeDefinition; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -15,7 +14,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = PropertyTypeDefinitionImpl.class) -public interface PropertyTypeDefinition

extends TypeDefinition, BaseProperty, PropertyCapableTypeDefinition { +public interface PropertyTypeDefinition

extends TypeDefinition, BaseProperty { public static final String NAME = "PropertyTypeDefinition"; // PropertyTypeDefinition.class.getSimpleName(); @@ -43,7 +42,7 @@ public interface PropertyTypeDefinition

extends TypeDefi public Set getSuperClasses(); @Override - @ISProperty(name = PropertyCapableTypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) + @ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) public Set getProperties(); /* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */ diff --git a/src/main/java/org/gcube/informationsystem/types/reference/relations/ConsistsOfTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/relations/ConsistsOfTypeDefinition.java new file mode 100644 index 0000000..63188e8 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/reference/relations/ConsistsOfTypeDefinition.java @@ -0,0 +1,17 @@ +package org.gcube.informationsystem.types.reference.relations; + +import org.gcube.informationsystem.types.impl.relations.ConsistsOfTypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.entities.FacetTypeDefinition; +import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@JsonDeserialize(as = ConsistsOfTypeDefinitionImpl.class) +public interface ConsistsOfTypeDefinition extends RelationTypeDefinition { + + public static final String NAME = "ConsistsOfTypeDefinition"; // ConsistsOfTypeDefinition.class.getSimpleName(); + +} diff --git a/src/main/java/org/gcube/informationsystem/types/reference/relations/IsRelatedToTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/relations/IsRelatedToTypeDefinition.java new file mode 100644 index 0000000..576f4b0 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/reference/relations/IsRelatedToTypeDefinition.java @@ -0,0 +1,16 @@ +package org.gcube.informationsystem.types.reference.relations; + +import org.gcube.informationsystem.types.impl.relations.IsRelatedToTypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@JsonDeserialize(as = IsRelatedToTypeDefinitionImpl.class) +public interface IsRelatedToTypeDefinition extends RelationTypeDefinition { + + public static final String NAME = "IsRelatedToTypeDefinition"; // IsRelatedToTypeDefinition.class.getSimpleName(); + +} diff --git a/src/main/java/org/gcube/informationsystem/types/reference/relations/RelationTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/relations/RelationTypeDefinition.java index 64df936..16af82b 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/relations/RelationTypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/relations/RelationTypeDefinition.java @@ -5,7 +5,6 @@ import java.util.Set; import org.gcube.informationsystem.base.reference.relations.BaseRelation; import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.impl.relations.RelationTypeDefinitionImpl; -import org.gcube.informationsystem.types.reference.PropertyCapableTypeDefinition; import org.gcube.informationsystem.types.reference.TypeDefinition; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; @@ -15,9 +14,10 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = RelationTypeDefinitionImpl.class) -public interface RelationTypeDefinition extends TypeDefinition, BaseRelation, PropertyCapableTypeDefinition { +public interface RelationTypeDefinition + extends TypeDefinition, BaseRelation { - public static final String NAME = "RelationTypeDefinition"; // PropertyTypeDefiniton.class.getSimpleName(); + public static final String NAME = "RelationTypeDefinition"; // RelationTypeDefinition.class.getSimpleName(); /* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */ @@ -32,21 +32,21 @@ public interface RelationTypeDefinition extends TypeDefinition, BaseRelation getSuperClasses(); - + @Override - @ISProperty(name = PropertyCapableTypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) + @ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) public Set getProperties(); @Override - public EntityTypeDefinition getSource(); + public S getSource(); @Override - public EntityTypeDefinition getTarget(); - + public T getTarget(); + /* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */ /*@JsonGetter(value=SOURCE_PROPERTY) public String getSourceType(); diff --git a/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java b/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java index 4f3e8e8..bcbde6e 100644 --- a/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java +++ b/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java @@ -18,8 +18,6 @@ import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.base.reference.relations.BaseRelation; import org.gcube.informationsystem.types.annotations.ISProperty; -import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; -import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -155,9 +153,11 @@ public class ISMDiscovery { for(Class entity : entityDiscovery.getDiscovered()) { logger.trace("Going to manage : {}", entity); schemaAction.manageEntityClass(entity); + /* if(entity.getName().compareTo(BaseEntity.class.getName())==0 ) { schemaAction.manageEntityClass(EntityTypeDefinition.class); } + */ } @SuppressWarnings("rawtypes") @@ -170,9 +170,11 @@ public class ISMDiscovery { Class relation : relationDiscovery.getDiscovered()) { logger.trace("Going to manage : {}", relation); schemaAction.manageRelationClass(relation); + /* if(relation.getName().compareTo(BaseRelation.class.getName())==0 ) { schemaAction.manageRelationClass(RelationTypeDefinition.class); } + */ } } diff --git a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java index 34be399..289ac1c 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -1,13 +1,24 @@ package org.gcube.informationsystem.types; +import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.context.reference.relations.IsParentOf; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; +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.model.reference.properties.Header; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; +import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; -import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition; +import org.gcube.informationsystem.model.reference.relations.Relation; +import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; +import org.gcube.informationsystem.types.reference.entities.FacetTypeDefinition; +import org.gcube.informationsystem.types.reference.entities.ResourceTypeDefinition; +import org.gcube.informationsystem.types.reference.relations.ConsistsOfTypeDefinition; +import org.gcube.informationsystem.types.reference.relations.IsRelatedToTypeDefinition; import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import org.gcube.informationsystem.utils.ISMapper; import org.junit.Test; @@ -25,23 +36,67 @@ public class SerializationTest { TypeBinder.serializeType(EntityTest.class); } - @Test - public void getISParentOfSchema() throws Exception{ - RelationTypeDefinition relationTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedTo.class); - logger.info(ISMapper.marshal(relationTypeDefinition)); - - RelationTypeDefinition rtd = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsParentOf.class); - logger.info(ISMapper.marshal(rtd)); - - RelationTypeDefinition rtdSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(RelationTypeDefinition.class); - logger.info(ISMapper.marshal(rtdSelf)); - - @SuppressWarnings("rawtypes") - PropertyTypeDefinition ptd = (PropertyTypeDefinition) TypeBinder.createTypeDefinition(PropertyTypeDefinition.class); - logger.info(ISMapper.marshal(ptd)); + public void makeTypeDefinition() throws Exception{ + EntityTypeDefinition resourceTypeDefinitionSelf = (EntityTypeDefinition) TypeBinder.createTypeDefinition(ResourceTypeDefinition.class); + logger.info(ISMapper.marshal(resourceTypeDefinitionSelf)); } + @Test + public void testEntityTypeDefinition() throws Exception{ + EntityTypeDefinition baseEntityTypeDefinition = (EntityTypeDefinition) TypeBinder.createTypeDefinition(BaseEntity.class); + logger.info(ISMapper.marshal(baseEntityTypeDefinition)); + + EntityTypeDefinition entityTypeDefinition = (EntityTypeDefinition) TypeBinder.createTypeDefinition(Entity.class); + logger.info(ISMapper.marshal(entityTypeDefinition)); + + ResourceTypeDefinition resourceTypeDefinition = (ResourceTypeDefinition) TypeBinder.createTypeDefinition(Resource.class); + logger.info(ISMapper.marshal(resourceTypeDefinition)); + + FacetTypeDefinition facetTypeDefinition = (FacetTypeDefinition) TypeBinder.createTypeDefinition(Facet.class); + logger.info(ISMapper.marshal(facetTypeDefinition)); + + EntityTypeDefinition contextTypeDefinition = (EntityTypeDefinition) TypeBinder.createTypeDefinition(Context.class); + logger.info(ISMapper.marshal(contextTypeDefinition)); + + EntityTypeDefinition entityTypeDefinitionSelf = (EntityTypeDefinition) TypeBinder.createTypeDefinition(EntityTypeDefinition.class); + logger.info(ISMapper.marshal(entityTypeDefinitionSelf)); + + EntityTypeDefinition resourceTypeDefinitionSelf = (EntityTypeDefinition) TypeBinder.createTypeDefinition(ResourceTypeDefinition.class); + logger.info(ISMapper.marshal(resourceTypeDefinitionSelf)); + + EntityTypeDefinition facetTypeDefinitionSelf = (EntityTypeDefinition) TypeBinder.createTypeDefinition(FacetTypeDefinition.class); + logger.info(ISMapper.marshal(facetTypeDefinitionSelf)); + } + + @Test + public void testRelationTypeDefinition() throws Exception{ + @SuppressWarnings("unchecked") + RelationTypeDefinition relationTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(Relation.class); + logger.info(ISMapper.marshal(relationTypeDefinition)); + + IsRelatedToTypeDefinition isRelatedToTypeDefinition = (IsRelatedToTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedTo.class); + logger.info(ISMapper.marshal(isRelatedToTypeDefinition)); + + ConsistsOfTypeDefinition consistsOfTypeDefinition = (ConsistsOfTypeDefinition) TypeBinder.createTypeDefinition(ConsistsOf.class); + logger.info(ISMapper.marshal(consistsOfTypeDefinition)); + + @SuppressWarnings("unchecked") + RelationTypeDefinition isParentOfTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsParentOf.class); + logger.info(ISMapper.marshal(isParentOfTypeDefinition)); + + @SuppressWarnings("unchecked") + RelationTypeDefinition rtdSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(RelationTypeDefinition.class); + logger.info(ISMapper.marshal(rtdSelf)); + + @SuppressWarnings("unchecked") + RelationTypeDefinition isRelatedToTypeDefinitionSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedToTypeDefinition.class); + logger.info(ISMapper.marshal(isRelatedToTypeDefinitionSelf)); + + @SuppressWarnings("unchecked") + RelationTypeDefinition consistsOfTypeDefinitionSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(ConsistsOfTypeDefinition.class); + logger.info(ISMapper.marshal(consistsOfTypeDefinitionSelf)); + } @Test public void testGetEnumcostants(){ @@ -60,18 +115,14 @@ public class SerializationTest { propagationConstraint.setAddConstraint(AddConstraint.propagate); propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); - ObjectMapper mapper = new ObjectMapper(); String pg = mapper.writeValueAsString(propagationConstraint); - PropagationConstraint pgUnm = mapper.readValue(pg, PropagationConstraint.class); logger.debug("{}", pgUnm); } - - @Test public void testTypeSerialization() throws Exception { String serialized = TypeBinder.serializeType(Header.class);