From 770155d5c596bae21e7a076891c3d80c4ea9887c Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 4 Nov 2019 18:06:46 +0100 Subject: [PATCH] Fixing model --- .../base/impl/relations/BaseRelationImpl.java | 16 +++--- .../reference/relations/BaseRelation.java | 10 ++-- .../context/impl/entities/ContextImpl.java | 26 ++++----- .../impl/relations/IsParentOfImpl.java | 5 +- .../context/reference/entities/Context.java | 8 +-- .../reference/relations/IsParentOf.java | 10 ++-- .../model/impl/relations/ConsistsOfImpl.java | 6 +-- .../model/impl/relations/DummyConsistsOf.java | 6 +-- .../impl/relations/DummyIsRelatedTo.java | 6 +-- .../impl/relations/IsIdentifiedByImpl.java | 6 +-- .../model/impl/relations/IsRelatedToImpl.java | 6 +-- .../model/impl/relations/RelationImpl.java | 7 +-- .../model/reference/relations/ConsistsOf.java | 4 +- .../reference/relations/IsIdentifiedBy.java | 4 +- .../reference/relations/IsRelatedTo.java | 4 +- .../model/reference/relations/Relation.java | 10 ++-- .../informationsystem/types/TypeBinder.java | 30 ++--------- .../types/impl/TypeDefinitionImpl.java | 11 ++-- .../entities/EntityTypeDefinitionImpl.java | 2 +- .../PropertyTypeDefinitionImpl.java | 2 +- .../relations/RelationTypeDefinitionImpl.java | 53 ++++++++++++------- .../types/reference/TypeDefinition.java | 2 +- .../entities/EntityTypeDefinition.java | 2 +- .../properties/PropertyTypeDefinition.java | 2 +- .../relations/RelationTypeDefinition.java | 19 ++++++- .../informationsystem/utils/ISMapper.java | 1 - .../types/SerializationTest.java | 22 +++++++- 27 files changed, 155 insertions(+), 125 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/base/impl/relations/BaseRelationImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/relations/BaseRelationImpl.java index 74f89f1..05f4024 100644 --- a/src/main/java/org/gcube/informationsystem/base/impl/relations/BaseRelationImpl.java +++ b/src/main/java/org/gcube/informationsystem/base/impl/relations/BaseRelationImpl.java @@ -4,43 +4,43 @@ import org.gcube.informationsystem.base.impl.ERImpl; import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.relations.BaseRelation; -public abstract class BaseRelationImpl extends ERImpl implements BaseRelation { +public abstract class BaseRelationImpl extends ERImpl implements BaseRelation { /** * Generated Serial Version UID */ private static final long serialVersionUID = 28704968813390512L; - protected Out source; - protected In target; + protected S source; + protected T target; protected BaseRelationImpl() { super(); } - protected BaseRelationImpl(Out source, In target) { + protected BaseRelationImpl(S source, T target) { this(); this.source = source; this.target = target; } @Override - public Out getSource() { + public S getSource() { return source; } @Override - public void setSource(Out source) { + public void setSource(S source) { this.source = source; } @Override - public In getTarget() { + public T getTarget() { return target; } @Override - public void setTarget(In target) { + public void setTarget(T target) { this.target = target; } diff --git a/src/main/java/org/gcube/informationsystem/base/reference/relations/BaseRelation.java b/src/main/java/org/gcube/informationsystem/base/reference/relations/BaseRelation.java index 5ed2562..42ecf3a 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/relations/BaseRelation.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/relations/BaseRelation.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; @Abstract //@JsonDeserialize(as=BaseRelationImpl.class) Do not uncomment to manage subclasses -public interface BaseRelation extends ER { +public interface BaseRelation extends ER { public static final String NAME = "BaseRelation"; // BaseRelation.class.getSimpleName(); @@ -24,15 +24,15 @@ public interface BaseRelation ext public Header getHeader(); @JsonGetter(value=SOURCE_PROPERTY) - public Out getSource(); + public S getSource(); @JsonIgnore - public void setSource(Out source); + public void setSource(S source); @JsonGetter(value=TARGET_PROPERTY) - public In getTarget(); + public T getTarget(); @JsonIgnore - public void setTarget(In target); + public void setTarget(T target); } \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/context/impl/entities/ContextImpl.java b/src/main/java/org/gcube/informationsystem/context/impl/entities/ContextImpl.java index 92429d0..0dc6903 100644 --- a/src/main/java/org/gcube/informationsystem/context/impl/entities/ContextImpl.java +++ b/src/main/java/org/gcube/informationsystem/context/impl/entities/ContextImpl.java @@ -31,8 +31,8 @@ public final class ContextImpl extends BaseEntityImpl implements Context { protected String name; - protected IsParentOf parent; - protected List> children; + protected IsParentOf parent; + protected List children; protected ContextImpl() { super(); @@ -64,7 +64,7 @@ public final class ContextImpl extends BaseEntityImpl implements Context { } @Override - public IsParentOf getParent() { + public IsParentOf getParent() { return parent; } @@ -81,15 +81,15 @@ public final class ContextImpl extends BaseEntityImpl implements Context { @Override public void setParent(Context context) { - IsParentOf isParentOf = null; + IsParentOf isParentOf = null; if(context!=null) { - isParentOf = new IsParentOfImpl(context, this); + isParentOf = new IsParentOfImpl(context, this); } setParent(isParentOf); } @JsonSetter(value=PARENT_PROPERTY) - protected void setParentFromJson(IsParentOf isParentOf) throws JsonProcessingException { + protected void setParentFromJson(IsParentOf isParentOf) throws JsonProcessingException { if(isParentOf!=null) { Context parent = isParentOf.getSource(); isParentOf.setTarget(this); @@ -99,23 +99,23 @@ public final class ContextImpl extends BaseEntityImpl implements Context { } @Override - public void setParent(IsParentOf isParentOf) { + public void setParent(IsParentOf isParentOf) { this.parent = isParentOf; } @Override - public List> getChildren() { + public List getChildren() { return children; } @JsonSetter(value=CHILDREN_PROPERTY) - protected void setChildrenFromJson(List> children) throws JsonProcessingException { - for(IsParentOf isParentOf : children){ + protected void setChildrenFromJson(List children) throws JsonProcessingException { + for(IsParentOf isParentOf : children){ addChildFromJson(isParentOf); } } - protected void addChildFromJson(IsParentOf isParentOf) throws JsonProcessingException { + protected void addChildFromJson(IsParentOf isParentOf) throws JsonProcessingException { isParentOf.setSource(this); addChild(isParentOf); } @@ -129,12 +129,12 @@ public final class ContextImpl extends BaseEntityImpl implements Context { @Override public void addChild(Context child) { - IsParentOf isParentOf = new IsParentOfImpl(this, child); + IsParentOf isParentOf = new IsParentOfImpl(this, child); this.addChild(isParentOf); } @Override - public void addChild(IsParentOf isParentOf) { + public void addChild(IsParentOf isParentOf) { ((ContextImpl) isParentOf.getTarget()).setParent(this); children.add(isParentOf); } diff --git a/src/main/java/org/gcube/informationsystem/context/impl/relations/IsParentOfImpl.java b/src/main/java/org/gcube/informationsystem/context/impl/relations/IsParentOfImpl.java index 2ddc968..50a4bed 100644 --- a/src/main/java/org/gcube/informationsystem/context/impl/relations/IsParentOfImpl.java +++ b/src/main/java/org/gcube/informationsystem/context/impl/relations/IsParentOfImpl.java @@ -13,8 +13,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=IsParentOf.NAME) -public final class IsParentOfImpl extends - BaseRelationImpl implements IsParentOf { +public final class IsParentOfImpl extends BaseRelationImpl implements IsParentOf { /** * @@ -25,7 +24,7 @@ public final class IsParentOfImpl exten super(); } - public IsParentOfImpl(Out source, In target) { + public IsParentOfImpl(Context source, Context target) { super(source, target); } diff --git a/src/main/java/org/gcube/informationsystem/context/reference/entities/Context.java b/src/main/java/org/gcube/informationsystem/context/reference/entities/Context.java index 19d1de7..9ca700e 100644 --- a/src/main/java/org/gcube/informationsystem/context/reference/entities/Context.java +++ b/src/main/java/org/gcube/informationsystem/context/reference/entities/Context.java @@ -37,7 +37,7 @@ public interface Context extends BaseEntity { @JsonGetter @JsonIgnoreProperties({ Relation.TARGET_PROPERTY }) - public IsParentOf getParent(); + public IsParentOf getParent(); @JsonIgnore public void setParent(UUID uuid); @@ -46,16 +46,16 @@ public interface Context extends BaseEntity { public void setParent(Context context); @JsonIgnore - public void setParent(IsParentOf isParentOf); + public void setParent(IsParentOf isParentOf); @JsonGetter @JsonIgnoreProperties({ Relation.SOURCE_PROPERTY }) - public List> getChildren(); + public List getChildren(); public void addChild(UUID uuid); public void addChild(Context child); - public void addChild(IsParentOf isParentOf); + public void addChild(IsParentOf isParentOf); } diff --git a/src/main/java/org/gcube/informationsystem/context/reference/relations/IsParentOf.java b/src/main/java/org/gcube/informationsystem/context/reference/relations/IsParentOf.java index ef2752e..82f1e61 100644 --- a/src/main/java/org/gcube/informationsystem/context/reference/relations/IsParentOf.java +++ b/src/main/java/org/gcube/informationsystem/context/reference/relations/IsParentOf.java @@ -17,22 +17,22 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isParentOf */ @JsonDeserialize(as = IsParentOfImpl.class) -public interface IsParentOf extends BaseRelation { +public interface IsParentOf extends BaseRelation { public static final String NAME = "IsParentOf"; //IsParentOf.class.getSimpleName(); @JsonIgnoreProperties({Context.PARENT_PROPERTY, Context.CHILDREN_PROPERTY}) @JsonGetter(value = SOURCE_PROPERTY) - public Out getSource(); + public Context getSource(); @JsonIgnore - public void setSource(Out source); + public void setSource(Context source); @JsonIgnoreProperties({Context.PARENT_PROPERTY, Context.CHILDREN_PROPERTY}) @JsonGetter(value = TARGET_PROPERTY) - public In getTarget(); + public Context getTarget(); @JsonIgnore - public void setTarget(In target); + public void setTarget(Context target); } diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java index 00e933d..c59dd15 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java @@ -14,8 +14,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=ConsistsOf.NAME) -public class ConsistsOfImpl extends - RelationImpl implements ConsistsOf { +public class ConsistsOfImpl extends + RelationImpl implements ConsistsOf { /** * Generated Serial Version UID @@ -26,7 +26,7 @@ public class ConsistsOfImpl extends super(); } - public ConsistsOfImpl(Out source, In target, + public ConsistsOfImpl(S source, T target, PropagationConstraint propagationConstraint) { super(source, target, propagationConstraint); } diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyConsistsOf.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyConsistsOf.java index c0d6788..fc7d013 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyConsistsOf.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyConsistsOf.java @@ -14,8 +14,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=ConsistsOf.NAME) -public class DummyConsistsOf extends - ConsistsOfImpl implements ConsistsOf { +public class DummyConsistsOf extends + ConsistsOfImpl implements ConsistsOf { /** * Generated Serial Version UID @@ -26,7 +26,7 @@ public class DummyConsistsOf extends super(); } - public DummyConsistsOf(Out source, In target, + public DummyConsistsOf(S source, T target, PropagationConstraint propagationConstraint) { super(source, target, propagationConstraint); } diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyIsRelatedTo.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyIsRelatedTo.java index 302b5e6..ba04deb 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyIsRelatedTo.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/DummyIsRelatedTo.java @@ -13,8 +13,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=IsRelatedTo.NAME) -public class DummyIsRelatedTo - extends IsRelatedToImpl implements IsRelatedTo{ +public class DummyIsRelatedTo + extends IsRelatedToImpl implements IsRelatedTo{ /** * Generated Serial Version UID @@ -25,7 +25,7 @@ public class DummyIsRelatedTo super(); } - public DummyIsRelatedTo(Out source, In target, + public DummyIsRelatedTo(S source, T target, PropagationConstraint propagationConstraint) { super(source, target, propagationConstraint); } diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/IsIdentifiedByImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/IsIdentifiedByImpl.java index c2d3e12..44f0d29 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/IsIdentifiedByImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/IsIdentifiedByImpl.java @@ -14,8 +14,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=IsIdentifiedBy.NAME) -public class IsIdentifiedByImpl extends - ConsistsOfImpl implements IsIdentifiedBy { +public class IsIdentifiedByImpl extends + ConsistsOfImpl implements IsIdentifiedBy { /** * Generated Serial Version UID @@ -26,7 +26,7 @@ public class IsIdentifiedByImpl extends super(); } - public IsIdentifiedByImpl(Out source, In target, + public IsIdentifiedByImpl(S source, T target, PropagationConstraint propagationConstraint) { super(source, target, propagationConstraint); } diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java index e5005ca..723aaf1 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java @@ -13,8 +13,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=IsRelatedTo.NAME) -public abstract class IsRelatedToImpl extends - RelationImpl implements IsRelatedTo { +public abstract class IsRelatedToImpl extends + RelationImpl implements IsRelatedTo { /** * Generated Serial Version UID @@ -25,7 +25,7 @@ public abstract class IsRelatedToImpl super(); } - public IsRelatedToImpl(Out source, In target, + public IsRelatedToImpl(S source, T target, PropagationConstraint propagationConstraint) { super(source, target, propagationConstraint); } diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/RelationImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/RelationImpl.java index ad6252f..a05b68f 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/RelationImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/RelationImpl.java @@ -11,6 +11,7 @@ import java.util.Set; import org.gcube.informationsystem.base.impl.relations.BaseRelationImpl; import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.model.reference.entities.Entity; +import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.model.reference.relations.Relation; @@ -23,8 +24,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value = Relation.NAME) -public abstract class RelationImpl - extends BaseRelationImpl implements Relation { +public abstract class RelationImpl + extends BaseRelationImpl implements Relation { /** * @@ -48,7 +49,7 @@ public abstract class RelationImpl this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY); } - protected RelationImpl(Out source, In target, + protected RelationImpl(S source, T target, PropagationConstraint propagationConstraint) { this(); this.source = source; diff --git a/src/main/java/org/gcube/informationsystem/model/reference/relations/ConsistsOf.java b/src/main/java/org/gcube/informationsystem/model/reference/relations/ConsistsOf.java index 4daeb31..ed3137a 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/relations/ConsistsOf.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/relations/ConsistsOf.java @@ -11,8 +11,8 @@ import org.gcube.informationsystem.model.reference.entities.Resource; * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#consistsOf */ // @JsonDeserialize(as=ConsistsOfImpl.class) Do not uncomment to manage subclasses -public interface ConsistsOf - extends Relation { +public interface ConsistsOf + extends Relation { public static final String NAME = "ConsistsOf"; //ConsistsOf.class.getSimpleName(); diff --git a/src/main/java/org/gcube/informationsystem/model/reference/relations/IsIdentifiedBy.java b/src/main/java/org/gcube/informationsystem/model/reference/relations/IsIdentifiedBy.java index 364938b..0f84458 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/relations/IsIdentifiedBy.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/relations/IsIdentifiedBy.java @@ -14,8 +14,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isIdentifiedBy */ @JsonDeserialize(as=IsIdentifiedByImpl.class) -public interface IsIdentifiedBy - extends ConsistsOf { +public interface IsIdentifiedBy + extends ConsistsOf { public static final String NAME = "IsIdentifiedBy"; //IsIdentifiedBy.class.getSimpleName(); diff --git a/src/main/java/org/gcube/informationsystem/model/reference/relations/IsRelatedTo.java b/src/main/java/org/gcube/informationsystem/model/reference/relations/IsRelatedTo.java index e4ba8dd..62b7bd0 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/relations/IsRelatedTo.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/relations/IsRelatedTo.java @@ -13,8 +13,8 @@ import org.gcube.informationsystem.types.annotations.Abstract; */ @Abstract // @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses -public interface IsRelatedTo - extends Relation { +public interface IsRelatedTo + extends Relation { public static final String NAME = "IsRelatedTo"; //IsRelatedTo.class.getSimpleName(); diff --git a/src/main/java/org/gcube/informationsystem/model/reference/relations/Relation.java b/src/main/java/org/gcube/informationsystem/model/reference/relations/Relation.java index d506e8c..68d058c 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/relations/Relation.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/relations/Relation.java @@ -26,7 +26,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; */ @Abstract // @JsonDeserialize(as=RelationImpl.class) Do not uncomment to manage subclasses -public interface Relation extends BaseRelation { +public interface Relation extends BaseRelation { public static final String NAME = "Relation"; //Relation.class.getSimpleName(); @@ -34,16 +34,16 @@ public interface Relation extends BaseRel @JsonIgnoreProperties({Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY}) @JsonGetter(value = SOURCE_PROPERTY) - public Out getSource(); + public S getSource(); @JsonIgnore - public void setSource(Out source); + public void setSource(S source); @JsonGetter(value = TARGET_PROPERTY) - public In getTarget(); + public T getTarget(); @JsonIgnore - public void setTarget(In target); + public void setTarget(T target); @ISProperty(name = PROPAGATION_CONSTRAINT) public PropagationConstraint getPropagationConstraint(); diff --git a/src/main/java/org/gcube/informationsystem/types/TypeBinder.java b/src/main/java/org/gcube/informationsystem/types/TypeBinder.java index c74ecc5..04b617d 100644 --- a/src/main/java/org/gcube/informationsystem/types/TypeBinder.java +++ b/src/main/java/org/gcube/informationsystem/types/TypeBinder.java @@ -15,56 +15,34 @@ public class TypeBinder { private final static String NAME = "NAME"; - @SuppressWarnings("rawtypes") 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); + TypeDefinition typeDefinition = createTypeDefinition(type); return ISMapper.marshal(typeDefinition); } - @SuppressWarnings("rawtypes") public static TypeDefinition deserializeTypeDefinition(String json) throws Exception{ - /* - ObjectMapper mapper = new ObjectMapper(); - @SuppressWarnings("unchecked") - TypeDefinition readValue = mapper.readValue(json, TypeDefinition.class); - */ TypeDefinition readValue = ISMapper.unmarshal(TypeDefinition.class, json); return readValue; } - public static String serializeTypeDefinitions(List> typeDefinitions) throws Exception{ - /* - ObjectMapper mapper = new ObjectMapper(); - String json = mapper.writeValueAsString(typeDefinitions); - return json; - */ + public static String serializeTypeDefinitions(List typeDefinitions) throws Exception{ String json = ISMapper.marshal(typeDefinitions); return json; } - @SuppressWarnings("rawtypes") public static List deserializeTypeDefinitions(String json) throws Exception{ - /* - ObjectMapper mapper = new ObjectMapper(); - JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, TypeDefinition.class) ; - return mapper.readValue(json, type); - */ List list = ISMapper.unmarshalList(TypeDefinition.class, json); return list; } - public static TypeDefinition createTypeDefinition(Class clz) { - TypeDefinition typeDefinition = TypeDefinitionImpl.getInstance(clz); + public static TypeDefinition createTypeDefinition(Class clz) { + TypeDefinition typeDefinition = TypeDefinitionImpl.getInstance(clz); return typeDefinition; } 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 d0fd9ff..3f6611a 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java @@ -1,6 +1,7 @@ package org.gcube.informationsystem.types.impl; import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.TypeVariable; import java.util.HashSet; import java.util.Set; @@ -28,7 +29,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonTypeName(value=TypeDefinition.NAME) -public class TypeDefinitionImpl extends ISManageableImpl implements TypeDefinition { +public class TypeDefinitionImpl extends ISManageableImpl implements TypeDefinition { /** * Generated Serial Version UID @@ -94,11 +95,15 @@ public class TypeDefinitionImpl extends ISManageableIm TypeVariable typeVariable = (TypeVariable) type; java.lang.reflect.Type[] bounds = typeVariable.getBounds(); java.lang.reflect.Type t = bounds[0]; + if(t instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) t; + return (Class) parameterizedType.getRawType(); + } return (Class) t; } @SuppressWarnings({"rawtypes", "unchecked"}) - public static TypeDefinition getInstance(Class clz) { + public static TypeDefinition getInstance(Class clz) { if(BaseEntity.class.isAssignableFrom(clz)) { return new EntityTypeDefinitionImpl(clz); } else if(BaseRelation.class.isAssignableFrom(clz)){ @@ -114,7 +119,7 @@ public class TypeDefinitionImpl extends ISManageableIm protected TypeDefinitionImpl() {} - protected TypeDefinitionImpl(Class clz) { + protected TypeDefinitionImpl(Class clz) { this.name = TypeBinder.getType(clz); this.description = TypeBinder.getStaticStringFieldByName(clz, DESCRIPTION, ""); this.abstractType = false; 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 45c88c6..bd8d3f4 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 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 5f094b5..b00c699 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 @@ -7,7 +7,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefini import com.fasterxml.jackson.annotation.JsonTypeName; @JsonTypeName(value=PropertyTypeDefinition.NAME) -public final class PropertyTypeDefinitionImpl

extends TypeDefinitionImpl

implements PropertyTypeDefinition

{ +public final class PropertyTypeDefinitionImpl

extends TypeDefinitionImpl implements PropertyTypeDefinition

{ /** * Generated Serial Version UID 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 5023948..1e1157e 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,11 +1,14 @@ 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; +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; @@ -19,8 +22,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonTypeName; @JsonTypeName(value=RelationTypeDefinition.NAME) -public final class RelationTypeDefinitionImpl> - extends TypeDefinitionImpl implements RelationTypeDefinition { +public final class RelationTypeDefinitionImpl, ET extends EntityTypeDefinition, S extends BaseEntity, T extends BaseEntity> + extends TypeDefinitionImpl implements RelationTypeDefinition { /** * Generated Serial Version UID @@ -38,23 +41,23 @@ public final class RelationTypeDefinitionImpl clz) { + public RelationTypeDefinitionImpl(Class> clz) { super(clz); if(IsRelatedTo.class.isAssignableFrom(clz)){ - @SuppressWarnings({"unchecked", "rawtypes"}) - Class c = (Class) clz; + @SuppressWarnings({"unchecked"}) + Class> c = (Class>) clz; this.superClasses = retrieveSuperClasses(c, IsRelatedTo.class, Relation.NAME); } else if(ConsistsOf.class.isAssignableFrom(clz)) { - @SuppressWarnings({"unchecked", "rawtypes"}) - Class c = (Class) 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; this.superClasses = retrieveSuperClasses(c, RelationTypeDefinition.class, BaseRelation.NAME); } else if(IsParentOf.class.isAssignableFrom(clz)){ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked"}) Class c = (Class) clz; this.superClasses = retrieveSuperClasses(c, IsParentOf.class, BaseRelation.NAME); } else if(BaseRelation.class.isAssignableFrom(clz)){ @@ -64,13 +67,23 @@ public final class RelationTypeDefinitionImpl sourceClass = (Class) getGenericClass(typeParameters[0]); - @SuppressWarnings("unchecked") - Class targetClass = (Class) getGenericClass(typeParameters[1]); + 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); + }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); + } - this.sourceType = TypeBinder.getType(sourceClass); - this.targetType = TypeBinder.getType(targetClass); } @@ -117,29 +130,29 @@ public final class RelationTypeDefinitionImpl source; - protected EntityTypeDefinition target; + protected ES source; + protected ET target; @Override - public EntityTypeDefinition getSource() { + public ES getSource() { return source; } @Override - public void setSource(EntityTypeDefinition source) { + public void setSource(ES source) { this.source = source; } @Override - public EntityTypeDefinition getTarget() { + public ET getTarget() { return target; } @Override - public void setTarget(EntityTypeDefinition target) { + public void setTarget(ET target) { this.target = target; } 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 91879bc..2ef7295 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Abstract @JsonIgnoreProperties(ignoreUnknown=true) //@JsonDeserialize(as=TypeDefinitionImpl.class) Do not uncomment to manage subclasses -public interface TypeDefinition extends ISManageable { +public interface TypeDefinition extends ISManageable { public static final String NAME = "TypeDefinition"; //TypeDefinition.class.getSimpleName(); 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 5a698f6..ce0d445 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/properties/PropertyTypeDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefinition.java index aa52eb1..19660e4 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 @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(as = PropertyTypeDefinitionImpl.class) -public interface PropertyTypeDefinition

extends TypeDefinition

, BaseProperty { +public interface PropertyTypeDefinition

extends TypeDefinition, BaseProperty { public static final String NAME = "PropertyTypeDefinition"; // PropertyTypeDefinition.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 8caeccf..e996592 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 @@ -10,13 +10,14 @@ 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> - extends TypeDefinition, BaseRelation,EntityTypeDefinition> { +public interface RelationTypeDefinition, ET extends EntityTypeDefinition, S extends BaseEntity, T extends BaseEntity> + extends TypeDefinition, BaseRelation { public static final String NAME = "RelationTypeDefinition"; // PropertyTypeDefiniton.class.getSimpleName(); @@ -42,6 +43,20 @@ public interface RelationTypeDefinition getProperties(); + /* + @Override + @JsonIgnore + public Header getHeader(); + */ + + @Override + @JsonIgnore + public ES getSource(); + + @Override + @JsonIgnore + public ET getTarget(); + /* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */ public String getSourceType(); diff --git a/src/main/java/org/gcube/informationsystem/utils/ISMapper.java b/src/main/java/org/gcube/informationsystem/utils/ISMapper.java index 2653544..2c29f8d 100644 --- a/src/main/java/org/gcube/informationsystem/utils/ISMapper.java +++ b/src/main/java/org/gcube/informationsystem/utils/ISMapper.java @@ -50,7 +50,6 @@ public abstract class ISMapper { List packages = new ArrayList(); - @SuppressWarnings("rawtypes") Class tdClz = TypeDefinition.class; ISMapper.registerSubtypes(tdClz); packages.add(tdClz.getPackage()); diff --git a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java index bfbbd80..c065714 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -1,11 +1,14 @@ package org.gcube.informationsystem.types; import org.gcube.informationsystem.base.reference.properties.Header; +import org.gcube.informationsystem.context.reference.relations.IsParentOf; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; 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.types.TypeBinder; +import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; +import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; +import org.gcube.informationsystem.utils.ISMapper; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,6 +24,23 @@ public class SerializationTest { TypeBinder.serializeType(EntityTest.class); } + + @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)); + } + + @Test public void testGetEnumcostants(){ Class clz = PropagationConstraint.RemoveConstraint.class;