From d77456ad984f83338bf2d96770396d4890c9267c Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 24 Oct 2019 19:50:43 +0200 Subject: [PATCH] Fixing model redefintion --- .../base/reference/AccessType.java | 16 +++- .../base/reference/entities/BaseEntity.java | 7 ++ .../reference/properties/BaseProperty.java | 5 +- .../model/impl/entities/ResourceImpl.java | 3 +- .../model/impl/relations/IsRelatedToImpl.java | 2 +- .../model/reference/entities/Entity.java | 10 -- .../model/reference/entities/Resource.java | 5 +- .../model/reference/properties/Property.java | 6 +- .../reference/relations/IsRelatedTo.java | 2 + .../types/impl/TypeDefinitionImpl.java | 6 +- .../entities/EntityTypeDefinitionImpl.java | 39 ++++++++ .../properties/PropertyDefinitionImpl.java | 3 +- .../relations/RelationTypeDefinitionImpl.java | 57 +++++++++-- .../types/reference/TypeDefinition.java | 3 +- .../entities/EntityTypeDefinition.java | 2 +- .../utils/ObjectMappingERAction.java | 12 +-- .../utils/discovery/ISMDiscovery.java | 95 ++++++++++--------- .../utils/discovery/ReflectionUtility.java | 1 + .../utils/discovery/SchemaAction.java | 12 +-- .../types/SerializationTest.java | 1 + 20 files changed, 190 insertions(+), 97 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java b/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java index 15c4ce0..c7f3daa 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java @@ -17,7 +17,6 @@ import org.gcube.informationsystem.model.impl.entities.ResourceImpl; import org.gcube.informationsystem.model.impl.properties.DummyProperty; import org.gcube.informationsystem.model.impl.properties.PropertyImpl; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; -import org.gcube.informationsystem.model.impl.relations.DummyConsistsOf; import org.gcube.informationsystem.model.impl.relations.DummyIsRelatedTo; import org.gcube.informationsystem.model.impl.relations.IsRelatedToImpl; import org.gcube.informationsystem.model.impl.relations.RelationImpl; @@ -28,6 +27,14 @@ import org.gcube.informationsystem.model.reference.properties.Property; 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.entities.EntityTypeDefinitionImpl; +import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl; +import org.gcube.informationsystem.types.impl.properties.PropertyTypeDefinitionImpl; +import org.gcube.informationsystem.types.impl.relations.RelationTypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; +import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; +import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefiniton; +import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,18 +45,23 @@ import org.slf4j.LoggerFactory; */ public enum AccessType { + PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null), + PROPERTY_TYPE_DEFINITION(PropertyTypeDefiniton.class, PropertyTypeDefiniton.NAME, PropertyTypeDefinitionImpl.class, null), PROPERTY(Property.class, Property.NAME, PropertyImpl.class, DummyProperty.class), CONTEXT(Context.class, Context.NAME, ContextImpl.class, null), IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.class, null), + ENTITY_TYPE_DEFINITION(EntityTypeDefinition.class, EntityTypeDefinition.NAME, EntityTypeDefinitionImpl.class, null), + RELATION_TYPE_DEFINITION(RelationTypeDefinition.class, RelationTypeDefinition.NAME, RelationTypeDefinitionImpl.class, null), + ENTITY(Entity.class, Entity.NAME, EntityImpl.class, null), RESOURCE(Resource.class, Resource.NAME, ResourceImpl.class, DummyResource.class), FACET(Facet.class, Facet.NAME, FacetImpl.class, DummyFacet.class), RELATION(Relation.class, Relation.NAME, RelationImpl.class, null), IS_RELATED_TO(IsRelatedTo.class, IsRelatedTo.NAME, IsRelatedToImpl.class, DummyIsRelatedTo.class), - CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME, ConsistsOfImpl.class, DummyConsistsOf.class); + CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME, ConsistsOfImpl.class, null); private static Logger logger = LoggerFactory.getLogger(AccessType.class); diff --git a/src/main/java/org/gcube/informationsystem/base/reference/entities/BaseEntity.java b/src/main/java/org/gcube/informationsystem/base/reference/entities/BaseEntity.java index 2a410bf..24bb255 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/entities/BaseEntity.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/entities/BaseEntity.java @@ -1,7 +1,9 @@ package org.gcube.informationsystem.base.reference.entities; import org.gcube.informationsystem.base.reference.ER; +import org.gcube.informationsystem.base.reference.properties.Header; import org.gcube.informationsystem.types.annotations.Abstract; +import org.gcube.informationsystem.types.annotations.ISProperty; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -11,5 +13,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; public interface BaseEntity extends ER { public static final String NAME = "BaseEntity"; //Entity.class.getSimpleName(); + + /* Overriding getHeader method to create Header property in type */ + @ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false) + @Override + public Header getHeader(); } \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/base/reference/properties/BaseProperty.java b/src/main/java/org/gcube/informationsystem/base/reference/properties/BaseProperty.java index 0f9ab6d..ddc3c69 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/properties/BaseProperty.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/properties/BaseProperty.java @@ -2,15 +2,12 @@ package org.gcube.informationsystem.base.reference.properties; import org.gcube.informationsystem.base.reference.ISManageable; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - /** * @author Luca Frosini (ISTI - CNR) * Root Class for Property types. It creates a base common type, which is useful * for management purpose. */ -// @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = ISManageable.CLASS_PROPERTY) -@JsonIgnoreProperties(ignoreUnknown=true) +// @JsonDeserialize(as=BasePropertympl.class) Do not uncomment to manage subclasses public interface BaseProperty extends ISManageable { public static final String NAME = "BaseProperty"; //BaseProperty.class.getSimpleName(); diff --git a/src/main/java/org/gcube/informationsystem/model/impl/entities/ResourceImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/entities/ResourceImpl.java index 283aad4..daf1cf0 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/entities/ResourceImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/entities/ResourceImpl.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.UUID; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; -import org.gcube.informationsystem.model.impl.relations.IsRelatedToImpl; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; @@ -152,6 +151,7 @@ public abstract class ResourceImpl extends EntityImpl implements Resource { */ } + /* @Override public void attachResource(UUID uuid) { Resource resource = new DummyResource(uuid); @@ -163,6 +163,7 @@ public abstract class ResourceImpl extends EntityImpl implements Resource { IsRelatedTo isRelatedTo = new IsRelatedToImpl(this, resource, null); attachResource(isRelatedTo); } + */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) 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 a3656f5..e5005ca 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,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=IsRelatedTo.NAME) -public class IsRelatedToImpl extends +public abstract class IsRelatedToImpl extends RelationImpl implements IsRelatedTo { /** diff --git a/src/main/java/org/gcube/informationsystem/model/reference/entities/Entity.java b/src/main/java/org/gcube/informationsystem/model/reference/entities/Entity.java index 6374a5a..d4e2446 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/entities/Entity.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/entities/Entity.java @@ -4,11 +4,7 @@ package org.gcube.informationsystem.model.reference.entities; import org.gcube.informationsystem.base.reference.entities.BaseEntity; -import org.gcube.informationsystem.base.reference.properties.Header; import org.gcube.informationsystem.types.annotations.Abstract; -import org.gcube.informationsystem.types.annotations.ISProperty; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** @@ -16,15 +12,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Basic_Concepts */ @Abstract -@JsonIgnoreProperties(ignoreUnknown=true) //@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses public interface Entity extends BaseEntity { public static final String NAME = "Entity"; //Entity.class.getSimpleName(); - /* Overriding getHeader method to create Header property in type */ - @ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false) - @Override - public Header getHeader(); - } diff --git a/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java b/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java index 9cac2a2..b4f8907 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/entities/Resource.java @@ -11,12 +11,14 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.types.annotations.Abstract; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * @author Luca Frosini (ISTI - CNR) * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Resources */ @Abstract +@JsonIgnoreProperties(ignoreUnknown=true) // @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses public interface Resource extends Entity { @@ -62,10 +64,11 @@ public interface Resource extends Entity { public > void addFacet(C relation); - + /* public void attachResource(UUID uuid); public void attachResource(R resource); + */ public > void attachResource(I relation); diff --git a/src/main/java/org/gcube/informationsystem/model/reference/properties/Property.java b/src/main/java/org/gcube/informationsystem/model/reference/properties/Property.java index 6b7e791..552ca55 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/properties/Property.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/properties/Property.java @@ -5,15 +5,13 @@ package org.gcube.informationsystem.model.reference.properties; import org.gcube.informationsystem.base.reference.properties.BaseProperty; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - /** * @author Luca Frosini (ISTI - CNR) * Root Class for Property types. It creates a base common type, which is useful * for management purpose. */ -// @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = ISManageable.CLASS_PROPERTY) -@JsonIgnoreProperties(ignoreUnknown=true) +// @JsonIgnoreProperties(ignoreUnknown=true) +// @JsonDeserialize(as=PropertyImpl.class) Do not uncomment to manage subclasses public interface Property extends BaseProperty { public static final String NAME = "Property"; //Property.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 7432c3e..e4ba8dd 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 @@ -4,12 +4,14 @@ package org.gcube.informationsystem.model.reference.relations; import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.types.annotations.Abstract; /** * @author Luca Frosini (ISTI - CNR) * This Relation is for internal use only * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isRelatedTo */ +@Abstract // @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses public interface IsRelatedTo extends Relation { 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 b8662a9..1dce934 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/TypeDefinitionImpl.java @@ -5,7 +5,7 @@ import java.lang.reflect.TypeVariable; import java.util.HashSet; import java.util.Set; -import org.gcube.informationsystem.base.impl.ERImpl; +import org.gcube.informationsystem.base.impl.ISManageableImpl; import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.base.reference.entities.BaseEntity; import org.gcube.informationsystem.base.reference.properties.BaseProperty; @@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; // @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonTypeName(value=TypeDefinition.NAME) -public abstract class TypeDefinitionImpl extends ERImpl implements TypeDefinition { +public abstract class TypeDefinitionImpl extends ISManageableImpl implements TypeDefinition { /** * Generated Serial Version UID @@ -37,7 +37,7 @@ public abstract class TypeDefinitionImpl extends ERImp private static Logger logger = LoggerFactory.getLogger(TypeDefinitionImpl.class); - private final static String DESCRIPTION = "DESCRIPTION"; + public final static String DESCRIPTION = "DESCRIPTION"; protected String name; protected String description; 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 7449718..2c36e5c 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 @@ -1,11 +1,15 @@ package org.gcube.informationsystem.types.impl.entities; +import java.io.StringWriter; + import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.base.reference.properties.Header; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; +import org.gcube.informationsystem.utils.ISMapper; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -37,4 +41,39 @@ public class EntityTypeDefinitionImpl extends TypeDefiniti } + + /* + * Java does not support 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; + + @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(); + } + } + } + } 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 2d6c26e..caffbbb 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 @@ -7,6 +7,7 @@ import java.net.URL; 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; @@ -82,7 +83,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition { Class type = (Class) method.getReturnType(); this.type = OType.PROPERTY.getIntValue(); - if(Property.class.isAssignableFrom(type)){ + if(BaseProperty.class.isAssignableFrom(type)){ if(type != Property.class){ this.linkedClass = TypeBinder.getType(type); } 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 5c79db1..500dcba 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,6 +1,9 @@ package org.gcube.informationsystem.types.impl.relations; +import java.io.StringWriter; + import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.base.reference.properties.Header; import org.gcube.informationsystem.base.reference.relations.BaseRelation; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; @@ -9,6 +12,7 @@ import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; 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; @@ -63,28 +67,65 @@ public class RelationTypeDefinitionImpl source; + protected EntityTypeDefinition target; + @Override public EntityTypeDefinition getSource() { - // TODO Auto-generated method stub - return null; + return source; } + @Override public void setSource(EntityTypeDefinition source) { - // TODO Auto-generated method stub - + this.source = source; } + @Override public EntityTypeDefinition getTarget() { - // TODO Auto-generated method stub - return null; + return target; } + @Override public void setTarget(EntityTypeDefinition target) { - // TODO Auto-generated method stub - + 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 46de7cb..b63470b 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java @@ -2,7 +2,6 @@ package org.gcube.informationsystem.types.reference; import java.util.Set; -import org.gcube.informationsystem.base.reference.ER; import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.types.annotations.Abstract; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; @@ -12,7 +11,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 ER { +public interface TypeDefinition extends ISManageable { public static final String NAME = "TypeDefinition"; //Entity.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 345a161..f5e586b 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 @@ -11,6 +11,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonDeserialize(as = EntityTypeDefinitionImpl.class) public interface EntityTypeDefinition extends TypeDefinition, BaseEntity { - public static final String NAME = "EntityDefinition"; //EntityDefinition.class.getSimpleName(); + public static final String NAME = "EntityTypeDefinition"; //EntityTypeDefinition.class.getSimpleName(); } diff --git a/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java b/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java index 9a64d26..0da8e67 100644 --- a/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java +++ b/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java @@ -3,9 +3,9 @@ */ package org.gcube.informationsystem.utils; -import org.gcube.informationsystem.model.reference.entities.Entity; -import org.gcube.informationsystem.model.reference.properties.Property; -import org.gcube.informationsystem.model.reference.relations.Relation; +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.utils.discovery.SchemaAction; import com.fasterxml.jackson.databind.ObjectMapper; @@ -22,19 +22,19 @@ class ObjectMappingERAction implements SchemaAction { } @Override - public void managePropertyClass(Class e) + public

void managePropertyClass(Class

e) throws Exception { objectMapper.registerSubtypes(e); } @Override - public void manageEntityClass(Class e) + public void manageEntityClass(Class e) throws Exception { objectMapper.registerSubtypes(e); } @Override - public > void manageRelationClass( + public > void manageRelationClass( Class r) throws Exception { objectMapper.registerSubtypes(r); } 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 0279012..8a3f509 100644 --- a/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java +++ b/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java @@ -10,9 +10,10 @@ import java.util.List; import java.util.Objects; import org.gcube.informationsystem.base.reference.ISManageable; -import org.gcube.informationsystem.model.reference.entities.Entity; +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.properties.Property; -import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.types.annotations.ISProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,17 +22,17 @@ import org.slf4j.LoggerFactory; * @author Luca Frosini (ISTI - CNR) */ public class ISMDiscovery { - + private static Logger logger = LoggerFactory.getLogger(ISMDiscovery.class); - + protected final Class root; protected final List packages; protected final List> discovered; - + public List> getDiscovered() { return discovered; } - + public ISMDiscovery(Class root) { this.root = root; this.packages = new ArrayList<>(); @@ -39,111 +40,111 @@ public class ISMDiscovery { this.discovered = new ArrayList<>(); add(root); } - + public void addPackage(Package p) { packages.add(p); } - + protected void add(Class clz) { discovered.add(clz); logger.trace("+ Added {}.", clz); } - + protected void analizeISM(Class clz) { logger.trace("Analizyng {}", clz); - - if (!clz.isInterface()) { + + if(!clz.isInterface()) { logger.trace("- Discarding {} that is not an interface", clz); return; } - - if (!root.isAssignableFrom(clz)) { + + if(!root.isAssignableFrom(clz)) { logger.trace("- Discarding {} because is not a {}", clz, root.getSimpleName()); return; } - - if (discovered.contains(clz)) { + + if(discovered.contains(clz)) { logger.trace("- Discarding {} because was already managed", clz); return; } - + Class[] interfaces = clz.getInterfaces(); - - for (Class interfaceClass : interfaces) { + + for(Class interfaceClass : interfaces) { @SuppressWarnings("unchecked") Class parent = (Class) interfaceClass; analizeISM(parent); } - - if (root == Property.class) { - - for (Method m : clz.getDeclaredMethods()) { + + if(root == Property.class) { + + for(Method m : clz.getDeclaredMethods()) { m.setAccessible(true); - if (m.isAnnotationPresent(ISProperty.class)) { - if (root.isAssignableFrom(m.getReturnType())) { + if(m.isAnnotationPresent(ISProperty.class)) { + if(root.isAssignableFrom(m.getReturnType())) { @SuppressWarnings("unchecked") Class type = (Class) m.getReturnType(); analizeISM(type); } } - + } } add(clz); } - + public void discover() throws Exception { - for (Package p : packages) { + for(Package p : packages) { List> classes = ReflectionUtility.getClassesForPackage(p); - for (Class clz : classes) { + for(Class clz : classes) { @SuppressWarnings("unchecked") Class ism = (Class) clz; analizeISM(ism); } } - + } - + public static void manageISM(SchemaAction schemaAction, List packages) throws Exception { - if (Objects.nonNull(packages) && packages.size() > 0) { + if(Objects.nonNull(packages) && packages.size() > 0) { manageISM(schemaAction, packages.stream().toArray(Package[]::new)); } else { manageISM(schemaAction); } } - + @SuppressWarnings("unchecked") public static void manageISM(SchemaAction schemaAction, Package... packages) throws Exception { - ISMDiscovery propertyDiscovery = new ISMDiscovery<>(Property.class); - if (Objects.nonNull(packages)) + ISMDiscovery propertyDiscovery = new ISMDiscovery<>(BaseProperty.class); + if(Objects.nonNull(packages)) Arrays.stream(packages).forEach(p -> propertyDiscovery.addPackage(p)); propertyDiscovery.discover(); - for (Class property : propertyDiscovery.getDiscovered()) { + for(Class property : propertyDiscovery.getDiscovered()) { logger.trace("Going to manage : {}", property); schemaAction.managePropertyClass(property); } - - ISMDiscovery entityDiscovery = new ISMDiscovery<>(Entity.class); - if (Objects.nonNull(packages)) + + ISMDiscovery entityDiscovery = new ISMDiscovery<>(BaseEntity.class); + if(Objects.nonNull(packages)) Arrays.stream(packages).forEach(p -> entityDiscovery.addPackage(p)); entityDiscovery.discover(); - - for (Class entity : entityDiscovery.getDiscovered()) { + + for(Class entity : entityDiscovery.getDiscovered()) { logger.trace("Going to manage : {}", entity); schemaAction.manageEntityClass(entity); } - + @SuppressWarnings("rawtypes") - ISMDiscovery relationDiscovery = new ISMDiscovery<>(Relation.class); - if (Objects.nonNull(packages)) + ISMDiscovery relationDiscovery = new ISMDiscovery(BaseRelation.class); + if(Objects.nonNull(packages)) Arrays.stream(packages).forEach(p -> relationDiscovery.addPackage(p)); relationDiscovery.discover(); - - for (@SuppressWarnings("rawtypes") - Class relation : relationDiscovery.getDiscovered()) { + + for(@SuppressWarnings("rawtypes") + Class relation : relationDiscovery.getDiscovered()) { logger.trace("Going to manage : {}", relation); schemaAction.manageRelationClass(relation); } } - + } diff --git a/src/main/java/org/gcube/informationsystem/utils/discovery/ReflectionUtility.java b/src/main/java/org/gcube/informationsystem/utils/discovery/ReflectionUtility.java index 86153f9..c5fece7 100644 --- a/src/main/java/org/gcube/informationsystem/utils/discovery/ReflectionUtility.java +++ b/src/main/java/org/gcube/informationsystem/utils/discovery/ReflectionUtility.java @@ -139,6 +139,7 @@ public class ReflectionUtility { * @throws ClassNotFoundException * if something went wrong */ + @SuppressWarnings("restriction") public static List> getClassesForPackage(String pckgname) throws ClassNotFoundException { final List> classes = new ArrayList>(); diff --git a/src/main/java/org/gcube/informationsystem/utils/discovery/SchemaAction.java b/src/main/java/org/gcube/informationsystem/utils/discovery/SchemaAction.java index f5ea503..0e22813 100644 --- a/src/main/java/org/gcube/informationsystem/utils/discovery/SchemaAction.java +++ b/src/main/java/org/gcube/informationsystem/utils/discovery/SchemaAction.java @@ -3,9 +3,9 @@ */ package org.gcube.informationsystem.utils.discovery; -import org.gcube.informationsystem.model.reference.entities.Entity; -import org.gcube.informationsystem.model.reference.properties.Property; -import org.gcube.informationsystem.model.reference.relations.Relation; +import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.base.reference.properties.BaseProperty; +import org.gcube.informationsystem.base.reference.relations.BaseRelation; /** * @author Luca Frosini (ISTI - CNR) @@ -13,10 +13,10 @@ import org.gcube.informationsystem.model.reference.relations.Relation; */ public interface SchemaAction { - public void managePropertyClass(Class e) throws Exception; + public

void managePropertyClass(Class

e) throws Exception; - public void manageEntityClass(Class e) throws Exception; + public void manageEntityClass(Class e) throws Exception; - public > void manageRelationClass(Class r) throws Exception; + public > void manageRelationClass(Class r) throws Exception; } diff --git a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java index 9e41ea0..bfbbd80 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -55,4 +55,5 @@ public class SerializationTest { String serialized = TypeBinder.serializeType(Header.class); logger.info(serialized); } + }