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 8470a97..d409878 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java @@ -105,9 +105,9 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition { @SuppressWarnings({"rawtypes", "unchecked"}) public static TypeDefinition getInstance(Class clz) { if(BaseEntity.class.isAssignableFrom(clz)) { - return new EntityTypeDefinitionImpl(clz); + return new EntityTypeDefinitionImpl((Class) clz); } else if(BaseRelation.class.isAssignableFrom(clz)){ - return new RelationTypeDefinitionImpl(clz); + return new RelationTypeDefinitionImpl((Class>) clz); } else if(BaseProperty.class.isAssignableFrom(clz)){ return new PropertyTypeDefinitionImpl(clz); } else if(TypeDefinition.class.isAssignableFrom(clz)) { 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 bd8d3f4..34db1a7 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 @@ -15,7 +15,7 @@ import org.gcube.informationsystem.utils.ISMapper; import com.fasterxml.jackson.annotation.JsonTypeName; @JsonTypeName(value=EntityTypeDefinition.NAME) -public final class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements EntityTypeDefinition { +public final class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements EntityTypeDefinition { /** * Generated Serial Version UID @@ -28,20 +28,23 @@ public final class EntityTypeDefinitionImpl extends TypeDe super(); } - @SuppressWarnings({"rawtypes", "unchecked"}) - public EntityTypeDefinitionImpl(Class clz) { + public EntityTypeDefinitionImpl(Class clz) { super(clz); if(Resource.class.isAssignableFrom(clz)){ + @SuppressWarnings("unchecked") Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, Resource.class, Entity.NAME); } else if(Facet.class.isAssignableFrom(clz)){ + @SuppressWarnings("unchecked") Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, Facet.class, Entity.NAME); } else if(EntityTypeDefinition.class.isAssignableFrom(clz)){ + @SuppressWarnings("unchecked") Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, EntityTypeDefinition.class, BaseEntity.NAME); } else if(Context.class.isAssignableFrom(clz)){ + @SuppressWarnings("unchecked") Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, Context.class, BaseEntity.NAME); } else if(BaseEntity.class.isAssignableFrom(clz)){ 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 25740d0..2b28d27 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 @@ -8,7 +8,6 @@ import java.util.UUID; import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.base.reference.properties.BaseProperty; -import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.types.Type; import org.gcube.informationsystem.types.Type.OType; import org.gcube.informationsystem.types.TypeBinder; @@ -86,7 +85,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition { this.type = OType.PROPERTY.getIntValue(); if(BaseProperty.class.isAssignableFrom(type)){ - if(type != Property.class){ + if(type != BaseProperty.class){ this.linkedClass = TypeBinder.getType(type); } }else if (Type.getTypeByClass(type)!=null) { 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 1e1157e..70056e1 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 @@ -1,10 +1,8 @@ package org.gcube.informationsystem.types.impl.relations; -import java.io.StringWriter; import java.lang.reflect.ParameterizedType; 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.entities.Facet; @@ -12,52 +10,40 @@ 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.TypeBinder; 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.relations.RelationTypeDefinition; -import org.gcube.informationsystem.utils.ISMapper; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonTypeName; @JsonTypeName(value=RelationTypeDefinition.NAME) -public final class RelationTypeDefinitionImpl, ET extends EntityTypeDefinition, S extends BaseEntity, T extends BaseEntity> - extends TypeDefinitionImpl implements RelationTypeDefinition { +public final class RelationTypeDefinitionImpl + extends TypeDefinitionImpl implements RelationTypeDefinition { /** * Generated Serial Version UID */ private static final long serialVersionUID = 2221831081869571296L; - // private static final String EDGE_CLASS_NAME = "E"; - - @JsonInclude(JsonInclude.Include.NON_NULL) - protected String sourceType; - @JsonInclude(JsonInclude.Include.NON_NULL) - protected String targetType; - protected RelationTypeDefinitionImpl() { super(); } - public RelationTypeDefinitionImpl(Class> clz) { + @SuppressWarnings("unchecked") + public RelationTypeDefinitionImpl(Class> clz) { super(clz); if(IsRelatedTo.class.isAssignableFrom(clz)){ - @SuppressWarnings({"unchecked"}) Class> c = (Class>) clz; this.superClasses = retrieveSuperClasses(c, IsRelatedTo.class, Relation.NAME); } 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", "rawtypes"}) - Class c = (Class) clz; + Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, RelationTypeDefinition.class, BaseRelation.NAME); } 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)){ @@ -67,93 +53,51 @@ public final class RelationTypeDefinitionImpl } java.lang.reflect.Type[] typeParameters = clz.getTypeParameters(); + Class sourceClass; + Class targetClass; if(typeParameters.length==0) { typeParameters = ((ParameterizedType) clz.getGenericInterfaces()[0]).getActualTypeArguments(); - @SuppressWarnings("unchecked") - Class sourceClass = (Class) typeParameters[0]; - @SuppressWarnings("unchecked") - Class targetClass = (Class) typeParameters[1]; - this.sourceType = TypeBinder.getType(sourceClass); - this.targetType = TypeBinder.getType(targetClass); + sourceClass = (Class) typeParameters[0]; + targetClass = (Class) typeParameters[1]; }else { - @SuppressWarnings("unchecked") - Class sourceClass = (Class) getGenericClass(typeParameters[0]); - @SuppressWarnings("unchecked") - Class targetClass = (Class) getGenericClass(typeParameters[1]); - this.sourceType = TypeBinder.getType(sourceClass); - this.targetType = TypeBinder.getType(targetClass); + sourceClass = (Class) getGenericClass(typeParameters[0]); + targetClass = (Class) getGenericClass(typeParameters[1]); } + this.source = new EntityTypeDefinitionImpl(sourceClass); + this.target = new EntityTypeDefinitionImpl(targetClass); } - - - public String getSourceType() { - return sourceType; - } - - public String getTargetType() { - return targetType; - } - /* - * Java does not support multiple inheritance. + * 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 Header header; + protected EntityTypeDefinition source; + protected EntityTypeDefinition target; @Override - public Header getHeader() { - return header; - } - - @Override - public void setHeader(Header header){ - this.header = header; - } - - @Override - public String toString(){ - StringWriter stringWriter = new StringWriter(); - try { - ISMapper.marshal(this, stringWriter); - return stringWriter.toString(); - }catch(Exception e){ - try { - ISMapper.marshal(this.header, stringWriter); - return stringWriter.toString(); - } catch(Exception e1){ - return super.toString(); - } - } - } - - protected ES source; - protected ET target; - - @Override - public ES getSource() { + public EntityTypeDefinition getSource() { return source; } @Override - public void setSource(ES source) { + public void setSource(EntityTypeDefinition source) { this.source = source; } @Override - public ET getTarget() { + public EntityTypeDefinition getTarget() { return target; } @Override - public void setTarget(ET target) { + public void setTarget(EntityTypeDefinition target) { this.target = target; } - + } 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 ce0d445..19c9eb6 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 @@ -13,7 +13,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = EntityTypeDefinitionImpl.class) -public interface EntityTypeDefinition extends TypeDefinition, BaseEntity { +public interface EntityTypeDefinition extends TypeDefinition, BaseEntity { public static final String NAME = "EntityTypeDefinition"; //EntityTypeDefinition.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 e996592..fb0b7e2 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 @@ -2,7 +2,6 @@ package org.gcube.informationsystem.types.reference.relations; import java.util.Set; -import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.relations.BaseRelation; import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.impl.relations.RelationTypeDefinitionImpl; @@ -10,14 +9,12 @@ import org.gcube.informationsystem.types.reference.TypeDefinition; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = RelationTypeDefinitionImpl.class) -public interface RelationTypeDefinition, ET extends EntityTypeDefinition, S extends BaseEntity, T extends BaseEntity> - extends TypeDefinition, BaseRelation { +public interface RelationTypeDefinition extends TypeDefinition, BaseRelation { public static final String NAME = "RelationTypeDefinition"; // PropertyTypeDefiniton.class.getSimpleName(); @@ -43,24 +40,17 @@ public interface RelationTypeDefinition, ET e @ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) public Set getProperties(); - /* @Override - @JsonIgnore - public Header getHeader(); - */ + public EntityTypeDefinition getSource(); @Override - @JsonIgnore - public ES getSource(); - - @Override - @JsonIgnore - public ET getTarget(); + public EntityTypeDefinition 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(); - public String getTargetType(); + @JsonGetter(value=TARGET_PROPERTY) + public String getTargetType();*/ } 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 9f7a29f..4f3e8e8 100644 --- a/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java +++ b/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java @@ -18,6 +18,8 @@ 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; @@ -49,8 +51,10 @@ public class ISMDiscovery { } protected void add(Class clz) { - discovered.add(clz); - logger.trace("+ Added {}.", clz); + if(!discovered.contains(clz)) { + discovered.add(clz); + logger.info("+ Added {}.", clz); + } } protected void analizeISM(Class clz) { @@ -151,6 +155,9 @@ 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") @@ -163,6 +170,9 @@ 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 47cd8cc..d934bf2 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -28,15 +28,12 @@ public class SerializationTest { @Test public void getISParentOfSchema() throws Exception{ - @SuppressWarnings("rawtypes") RelationTypeDefinition relationTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedTo.class); logger.info(ISMapper.marshal(relationTypeDefinition)); - @SuppressWarnings("rawtypes") RelationTypeDefinition rtd = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsParentOf.class); logger.info(ISMapper.marshal(rtd)); - @SuppressWarnings("rawtypes") RelationTypeDefinition rtdSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(RelationTypeDefinition.class); logger.info(ISMapper.marshal(rtdSelf));