From a9a1ab83ceb57059722fd5dd406c90476f592ab5 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 24 Oct 2019 11:26:49 +0200 Subject: [PATCH] Reorganizing model --- .../informationsystem/base/impl/ERImpl.java | 19 +++ .../base/impl/ISManageableImpl.java | 14 +++ .../impl/properties/BasePropertyImpl.java | 24 ++++ .../impl/properties/HeaderImpl.java | 4 +- .../base/impl/relations/BaseRelationImpl.java | 31 ++++- .../base/impl/relations/RImpl.java | 65 ----------- .../base/reference/AccessType.java | 2 +- .../base/reference/entities/BaseEntity.java | 3 +- .../base/reference/entities/E.java | 15 --- .../reference/properties/BaseProperty.java | 20 ++++ .../base/reference/properties/Header.java | 4 +- .../reference/relations/BaseRelation.java | 28 ++++- .../base/reference/relations/R.java | 38 ------ .../context/impl/entities/ContextImpl.java | 2 +- .../model/impl/entities/DummyFacet.java | 2 +- .../model/impl/entities/DummyResource.java | 2 +- .../model/impl/entities/EntityImpl.java | 19 --- .../model/impl/entities/FacetImpl.java | 2 +- .../model/impl/properties/DummyProperty.java | 2 +- .../model/impl/properties/PropertyImpl.java | 2 +- .../model/impl/relations/RelationImpl.java | 2 +- .../model/reference/properties/Encrypted.java | 1 - .../properties/PropagationConstraint.java | 1 - .../reference/properties/Property.java | 7 +- .../gcube/informationsystem/types/Type.java | 64 +++++------ .../informationsystem/types/TypeBinder.java | 21 ++-- .../entities => }/TypeDefinitionImpl.java | 108 ++++++------------ .../entities/EntityTypeDefinitionImpl.java | 37 ++++++ .../properties/PropertyDefinitionImpl.java | 13 ++- .../PropertyTypeDefinitionImpl.java | 19 +++ .../relations/RelationTypeDefinitionImpl.java | 88 ++++++++++++++ .../types/reference/TypeDefinition.java | 8 +- .../reference/entities/EntityDefinition.java | 8 ++ .../properties/PropertyDefinition.java | 14 ++- .../properties/PropertyTypeDefiniton.java | 11 ++ .../relations/RelationDefinition.java | 15 +++ .../utils/AdditionalPropertiesSerializer.java | 2 +- .../utils/ObjectMappingERAction.java | 2 +- .../utils/discovery/ISMDiscovery.java | 2 +- .../utils/discovery/SchemaAction.java | 2 +- .../{model => }/ContextTest.java | 2 +- .../impl/properties/HeaderTest.java | 4 +- .../impl/properties/EncryptedTest.java | 6 +- .../types/EntitySchemaDefinition.java | 4 +- 44 files changed, 439 insertions(+), 300 deletions(-) create mode 100644 src/main/java/org/gcube/informationsystem/base/impl/properties/BasePropertyImpl.java rename src/main/java/org/gcube/informationsystem/{model => base}/impl/properties/HeaderImpl.java (88%) delete mode 100644 src/main/java/org/gcube/informationsystem/base/impl/relations/RImpl.java delete mode 100644 src/main/java/org/gcube/informationsystem/base/reference/entities/E.java create mode 100644 src/main/java/org/gcube/informationsystem/base/reference/properties/BaseProperty.java delete mode 100644 src/main/java/org/gcube/informationsystem/base/reference/relations/R.java rename src/main/java/org/gcube/informationsystem/{base => model}/reference/properties/Property.java (76%) rename src/main/java/org/gcube/informationsystem/types/{impl/entities => }/TypeDefinitionImpl.java (52%) create mode 100644 src/main/java/org/gcube/informationsystem/types/impl/entities/EntityTypeDefinitionImpl.java create mode 100644 src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyTypeDefinitionImpl.java create mode 100644 src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java create mode 100644 src/main/java/org/gcube/informationsystem/types/reference/entities/EntityDefinition.java create mode 100644 src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefiniton.java create mode 100644 src/main/java/org/gcube/informationsystem/types/reference/relations/RelationDefinition.java rename src/test/java/org/gcube/informationsystem/{model => }/ContextTest.java (98%) rename src/test/java/org/gcube/informationsystem/{model => base}/impl/properties/HeaderTest.java (87%) rename src/test/java/org/gcube/informationsystem/{model => }/impl/properties/EncryptedTest.java (94%) diff --git a/src/main/java/org/gcube/informationsystem/base/impl/ERImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/ERImpl.java index 2c77a02..92d9140 100644 --- a/src/main/java/org/gcube/informationsystem/base/impl/ERImpl.java +++ b/src/main/java/org/gcube/informationsystem/base/impl/ERImpl.java @@ -3,8 +3,11 @@ */ package org.gcube.informationsystem.base.impl; +import java.io.StringWriter; + import org.gcube.informationsystem.base.reference.ER; import org.gcube.informationsystem.base.reference.properties.Header; +import org.gcube.informationsystem.utils.ISMapper; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -34,4 +37,20 @@ public abstract class ERImpl extends ISManageableImpl implements ER { 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/base/impl/ISManageableImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/ISManageableImpl.java index c77a558..df97dac 100644 --- a/src/main/java/org/gcube/informationsystem/base/impl/ISManageableImpl.java +++ b/src/main/java/org/gcube/informationsystem/base/impl/ISManageableImpl.java @@ -3,7 +3,10 @@ */ package org.gcube.informationsystem.base.impl; +import java.io.StringWriter; + import org.gcube.informationsystem.base.reference.ISManageable; +import org.gcube.informationsystem.utils.ISMapper; /** * @author Luca Frosini (ISTI - CNR) @@ -19,4 +22,15 @@ public class ISManageableImpl implements ISManageable { public ISManageableImpl(){ } + + @Override + public String toString(){ + StringWriter stringWriter = new StringWriter(); + try { + ISMapper.marshal(this, stringWriter); + return stringWriter.toString(); + }catch(Exception e){ + return super.toString(); + } + } } diff --git a/src/main/java/org/gcube/informationsystem/base/impl/properties/BasePropertyImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/properties/BasePropertyImpl.java new file mode 100644 index 0000000..2a93950 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/base/impl/properties/BasePropertyImpl.java @@ -0,0 +1,24 @@ +package org.gcube.informationsystem.base.impl.properties; + +import org.gcube.informationsystem.base.impl.ISManageableImpl; +import org.gcube.informationsystem.base.reference.properties.BaseProperty; +import org.gcube.informationsystem.model.reference.properties.Property; + +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@JsonTypeName(value=BaseProperty.NAME) +public class BasePropertyImpl extends ISManageableImpl implements Property { + + /** + * Generated Serial Version UID + */ + private static final long serialVersionUID = 1396998430221747445L; + + public BasePropertyImpl() { + super(); + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/model/impl/properties/HeaderImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/properties/HeaderImpl.java similarity index 88% rename from src/main/java/org/gcube/informationsystem/model/impl/properties/HeaderImpl.java rename to src/main/java/org/gcube/informationsystem/base/impl/properties/HeaderImpl.java index 9950d42..8003dac 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/properties/HeaderImpl.java +++ b/src/main/java/org/gcube/informationsystem/base/impl/properties/HeaderImpl.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.informationsystem.model.impl.properties; +package org.gcube.informationsystem.base.impl.properties; import java.util.Date; import java.util.UUID; @@ -14,7 +14,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; * @author Luca Frosini (ISTI - CNR) */ @JsonTypeName(value=Header.NAME) -public class HeaderImpl extends PropertyImpl implements Header { +public final class HeaderImpl extends BasePropertyImpl implements Header { /** * Generated Serial Version UID 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 6db82f5..74f89f1 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 @@ -1,14 +1,15 @@ package org.gcube.informationsystem.base.impl.relations; +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 RImpl implements BaseRelation { - +public abstract class BaseRelationImpl extends ERImpl implements BaseRelation { + /** * Generated Serial Version UID */ - private static final long serialVersionUID = 5789078326714392972L; + private static final long serialVersionUID = 28704968813390512L; protected Out source; protected In target; @@ -18,7 +19,29 @@ public abstract class BaseRelationImpl extends ERImpl implements R { - - /** - * Generated Serial Version UID - */ - private static final long serialVersionUID = 28704968813390512L; - - protected Out source; - protected In target; - - protected RImpl() { - super(); - } - - protected RImpl(Out source, In target) { - this(); - this.source = source; - this.target = target; - } - - @Override - public Out getSource() { - return source; - } - - @Override - public void setSource(Out source) { - this.source = source; - } - - @Override - public In getTarget() { - return target; - } - - @Override - public void setTarget(In target) { - this.target = target; - } - - @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/base/reference/AccessType.java b/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java index 99e95f1..15c4ce0 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/AccessType.java @@ -5,7 +5,6 @@ package org.gcube.informationsystem.base.reference; import java.util.Arrays; -import org.gcube.informationsystem.base.reference.properties.Property; import org.gcube.informationsystem.context.impl.entities.ContextImpl; import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl; import org.gcube.informationsystem.context.reference.entities.Context; @@ -25,6 +24,7 @@ import org.gcube.informationsystem.model.impl.relations.RelationImpl; 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.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; 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 417c8c4..2a410bf 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,5 +1,6 @@ package org.gcube.informationsystem.base.reference.entities; +import org.gcube.informationsystem.base.reference.ER; import org.gcube.informationsystem.types.annotations.Abstract; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -7,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Abstract @JsonIgnoreProperties(ignoreUnknown=true) //@JsonDeserialize(as=BaseEntityImpl.class) Do not uncomment to manage subclasses -public interface BaseEntity extends E { +public interface BaseEntity extends ER { public static final String NAME = "BaseEntity"; //Entity.class.getSimpleName(); diff --git a/src/main/java/org/gcube/informationsystem/base/reference/entities/E.java b/src/main/java/org/gcube/informationsystem/base/reference/entities/E.java deleted file mode 100644 index b4b8a41..0000000 --- a/src/main/java/org/gcube/informationsystem/base/reference/entities/E.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.gcube.informationsystem.base.reference.entities; - -import org.gcube.informationsystem.base.reference.ER; -import org.gcube.informationsystem.types.annotations.Abstract; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@Abstract -@JsonIgnoreProperties(ignoreUnknown=true) -//@JsonDeserialize(as=EImpl.class) Do not uncomment to manage subclasses -public interface E extends ER { - - public static final String NAME = "E"; // Entity.class.getSimpleName(); - -} \ 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 new file mode 100644 index 0000000..0f9ab6d --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/base/reference/properties/BaseProperty.java @@ -0,0 +1,20 @@ +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) +public interface BaseProperty extends ISManageable { + + public static final String NAME = "BaseProperty"; //BaseProperty.class.getSimpleName(); + public static final String DESCRIPTION = "This is the very base class for Property"; + public static final String VERSION = "1.0.0"; + +} diff --git a/src/main/java/org/gcube/informationsystem/base/reference/properties/Header.java b/src/main/java/org/gcube/informationsystem/base/reference/properties/Header.java index 1f3e33c..c94939e 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/properties/Header.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/properties/Header.java @@ -6,8 +6,8 @@ package org.gcube.informationsystem.base.reference.properties; import java.util.Date; import java.util.UUID; +import org.gcube.informationsystem.base.impl.properties.HeaderImpl; import org.gcube.informationsystem.base.reference.ISConstants; -import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import org.gcube.informationsystem.types.annotations.ISProperty; import com.fasterxml.jackson.annotation.JsonFormat; @@ -18,7 +18,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Header */ @JsonDeserialize(as=HeaderImpl.class) -public interface Header extends Property { +public interface Header extends BaseProperty { public static final String NAME = "Header"; // Header.class.getSimpleName(); 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 d1d66ba..5ed2562 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 @@ -1,12 +1,38 @@ package org.gcube.informationsystem.base.reference.relations; +import org.gcube.informationsystem.base.reference.ER; 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.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; @Abstract //@JsonDeserialize(as=BaseRelationImpl.class) Do not uncomment to manage subclasses -public interface BaseRelation extends R { +public interface BaseRelation extends ER { public static final String NAME = "BaseRelation"; // BaseRelation.class.getSimpleName(); + public static final String SOURCE_PROPERTY = "source"; + public static final String TARGET_PROPERTY = "target"; + + /* Overriding getHeader method to create Header property in type */ + @ISProperty(name = HEADER_PROPERTY, mandatory = true, nullable = false) + @Override + public Header getHeader(); + + @JsonGetter(value=SOURCE_PROPERTY) + public Out getSource(); + + @JsonIgnore + public void setSource(Out source); + + @JsonGetter(value=TARGET_PROPERTY) + public In getTarget(); + + @JsonIgnore + public void setTarget(In target); + } \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/base/reference/relations/R.java b/src/main/java/org/gcube/informationsystem/base/reference/relations/R.java deleted file mode 100644 index f8ec19e..0000000 --- a/src/main/java/org/gcube/informationsystem/base/reference/relations/R.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.gcube.informationsystem.base.reference.relations; - -import org.gcube.informationsystem.base.reference.ER; -import org.gcube.informationsystem.base.reference.entities.E; -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.JsonGetter; -import com.fasterxml.jackson.annotation.JsonIgnore; - -@Abstract -//@JsonDeserialize(as=RImpl.class) Do not uncomment to manage subclasses -public interface R extends ER { - - public static final String NAME = "R"; // R.class.getSimpleName(); - - public static final String SOURCE_PROPERTY = "source"; - public static final String TARGET_PROPERTY = "target"; - - /* Overriding getHeader method to create Header property in type */ - @ISProperty(name = HEADER_PROPERTY, mandatory = true, nullable = false) - @Override - public Header getHeader(); - - @JsonGetter(value=SOURCE_PROPERTY) - public Out getSource(); - - @JsonIgnore - public void setSource(Out source); - - @JsonGetter(value=TARGET_PROPERTY) - public In getTarget(); - - @JsonIgnore - public void setTarget(In 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 725c286..92429d0 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 @@ -8,10 +8,10 @@ import java.util.List; import java.util.UUID; import org.gcube.informationsystem.base.impl.entities.BaseEntityImpl; +import org.gcube.informationsystem.base.impl.properties.HeaderImpl; import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl; import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.context.reference.relations.IsParentOf; -import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.JsonTypeName; diff --git a/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyFacet.java b/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyFacet.java index 89113b8..7968773 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyFacet.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyFacet.java @@ -5,7 +5,7 @@ package org.gcube.informationsystem.model.impl.entities; import java.util.UUID; -import org.gcube.informationsystem.model.impl.properties.HeaderImpl; +import org.gcube.informationsystem.base.impl.properties.HeaderImpl; import org.gcube.informationsystem.model.reference.entities.Facet; /** diff --git a/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyResource.java b/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyResource.java index bd48cd3..8149c07 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyResource.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/entities/DummyResource.java @@ -5,7 +5,7 @@ package org.gcube.informationsystem.model.impl.entities; import java.util.UUID; -import org.gcube.informationsystem.model.impl.properties.HeaderImpl; +import org.gcube.informationsystem.base.impl.properties.HeaderImpl; import org.gcube.informationsystem.model.reference.entities.Resource; /** diff --git a/src/main/java/org/gcube/informationsystem/model/impl/entities/EntityImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/entities/EntityImpl.java index f659176..be32a5f 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/entities/EntityImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/entities/EntityImpl.java @@ -3,11 +3,8 @@ */ package org.gcube.informationsystem.model.impl.entities; -import java.io.StringWriter; - import org.gcube.informationsystem.base.impl.entities.BaseEntityImpl; import org.gcube.informationsystem.model.reference.entities.Entity; -import org.gcube.informationsystem.utils.ISMapper; import com.fasterxml.jackson.annotation.JsonTypeName; @@ -27,20 +24,4 @@ public abstract class EntityImpl extends BaseEntityImpl implements Entity { this.header = null; } - @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/model/impl/entities/FacetImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/entities/FacetImpl.java index 076da25..3946ab4 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/entities/FacetImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/entities/FacetImpl.java @@ -9,8 +9,8 @@ import java.util.Map; import java.util.Set; import org.gcube.informationsystem.base.reference.ISManageable; -import org.gcube.informationsystem.base.reference.properties.Property; import org.gcube.informationsystem.model.reference.entities.Facet; +import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.utils.ISMapper; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/src/main/java/org/gcube/informationsystem/model/impl/properties/DummyProperty.java b/src/main/java/org/gcube/informationsystem/model/impl/properties/DummyProperty.java index ee4ba54..000dcd0 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/properties/DummyProperty.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/properties/DummyProperty.java @@ -3,7 +3,7 @@ */ package org.gcube.informationsystem.model.impl.properties; -import org.gcube.informationsystem.base.reference.properties.Property; +import org.gcube.informationsystem.model.reference.properties.Property; /** * @author Luca Frosini (ISTI - CNR) diff --git a/src/main/java/org/gcube/informationsystem/model/impl/properties/PropertyImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/properties/PropertyImpl.java index 7d10527..78a0d6e 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/properties/PropertyImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/properties/PropertyImpl.java @@ -4,7 +4,7 @@ package org.gcube.informationsystem.model.impl.properties; import org.gcube.informationsystem.base.impl.ISManageableImpl; -import org.gcube.informationsystem.base.reference.properties.Property; +import org.gcube.informationsystem.model.reference.properties.Property; import com.fasterxml.jackson.annotation.JsonTypeName; 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 b8739ab..ad6252f 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 @@ -10,9 +10,9 @@ import java.util.Set; import org.gcube.informationsystem.base.impl.relations.BaseRelationImpl; import org.gcube.informationsystem.base.reference.ISManageable; -import org.gcube.informationsystem.base.reference.properties.Property; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; +import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.utils.ISMapper; diff --git a/src/main/java/org/gcube/informationsystem/model/reference/properties/Encrypted.java b/src/main/java/org/gcube/informationsystem/model/reference/properties/Encrypted.java index 0a9a639..dae66d7 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/properties/Encrypted.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/properties/Encrypted.java @@ -1,6 +1,5 @@ package org.gcube.informationsystem.model.reference.properties; -import org.gcube.informationsystem.base.reference.properties.Property; import org.gcube.informationsystem.model.impl.properties.EncryptedImpl; import org.gcube.informationsystem.types.annotations.ISProperty; diff --git a/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java b/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java index 1655003..005b826 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java @@ -3,7 +3,6 @@ */ package org.gcube.informationsystem.model.reference.properties; -import org.gcube.informationsystem.base.reference.properties.Property; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; import org.gcube.informationsystem.types.annotations.ISProperty; diff --git a/src/main/java/org/gcube/informationsystem/base/reference/properties/Property.java b/src/main/java/org/gcube/informationsystem/model/reference/properties/Property.java similarity index 76% rename from src/main/java/org/gcube/informationsystem/base/reference/properties/Property.java rename to src/main/java/org/gcube/informationsystem/model/reference/properties/Property.java index 6f57788..6b7e791 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/properties/Property.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/properties/Property.java @@ -1,9 +1,9 @@ /** * */ -package org.gcube.informationsystem.base.reference.properties; +package org.gcube.informationsystem.model.reference.properties; -import org.gcube.informationsystem.base.reference.ISManageable; +import org.gcube.informationsystem.base.reference.properties.BaseProperty; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -12,10 +12,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; * 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) -public interface Property extends ISManageable { +public interface Property extends BaseProperty { public static final String NAME = "Property"; //Property.class.getSimpleName(); public static final String DESCRIPTION = "This is the base class for Property"; diff --git a/src/main/java/org/gcube/informationsystem/types/Type.java b/src/main/java/org/gcube/informationsystem/types/Type.java index 08a5d02..d38caac 100644 --- a/src/main/java/org/gcube/informationsystem/types/Type.java +++ b/src/main/java/org/gcube/informationsystem/types/Type.java @@ -30,8 +30,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import org.gcube.informationsystem.base.reference.properties.Property; - +import org.gcube.informationsystem.model.reference.properties.Property; /** * @author Lucio Lelii (ISTI - CNR) @@ -45,22 +44,22 @@ import org.gcube.informationsystem.base.reference.properties.Property; * and adapted for gCube purpose. */ public class Type { - + public enum OType { BOOLEAN("Boolean", 0), - + INTEGER("Integer", 1), - + SHORT("Short", 2), - + LONG("Long", 3), - + FLOAT("Float", 4), - + DOUBLE("Double", 5), - + DATETIME("Datetime", 6), - + STRING("String", 7), BYNARY("Bynary", 8), @@ -70,35 +69,35 @@ public class Type { PROPERTYLIST("Property List", 10), PROPERTYSET("Property Set", 11), - + PROPERTYMAP("Property Map", 12), BYTE("Byte", 17), BINARY("Binary", 8); - + private String stringValue; private int intValue; - - OType(String stringValue, int intValue){ + + OType(String stringValue, int intValue) { this.stringValue = stringValue; this.intValue = intValue; } - + public String getStringValue() { return stringValue; } - + public int getIntValue() { return intValue; } - + } - - protected static final Map, OType> TYPES_BY_CLASS = new HashMap, OType>(); - - static{ - + + protected static final Map,OType> TYPES_BY_CLASS = new HashMap,OType>(); + + static { + // This is made by hand because not all types should be add. TYPES_BY_CLASS.put(Boolean.TYPE, OType.BOOLEAN); TYPES_BY_CLASS.put(Boolean.class, OType.BOOLEAN); @@ -140,14 +139,13 @@ public class Type { TYPES_BY_CLASS.put(byte[].class, OType.BYNARY); TYPES_BY_CLASS.put(Byte[].class, OType.BYNARY); - TYPES_BY_CLASS.put(Enum.class, OType.STRING); TYPES_BY_CLASS.put(URI.class, OType.STRING); TYPES_BY_CLASS.put(URL.class, OType.STRING); TYPES_BY_CLASS.put(UUID.class, OType.STRING); } - + /** * Return the correspondent type by checking the "assignability" of the * class received as parameter. @@ -156,19 +154,17 @@ public class Type { * @return OType instance if found, otherwise null */ public static OType getTypeByClass(final Class iClass) { - if (iClass == null) { + if(iClass == null) { return null; } OType type = TYPES_BY_CLASS.get(iClass); - - if(type==null && Enum.class.isAssignableFrom(iClass)){ - type = TYPES_BY_CLASS.get(Enum.class); - } - return type; - } - - + if(type == null && Enum.class.isAssignableFrom(iClass)) { + type = TYPES_BY_CLASS.get(Enum.class); + } + + return type; + } + } - diff --git a/src/main/java/org/gcube/informationsystem/types/TypeBinder.java b/src/main/java/org/gcube/informationsystem/types/TypeBinder.java index ba2a810..acaf3fb 100644 --- a/src/main/java/org/gcube/informationsystem/types/TypeBinder.java +++ b/src/main/java/org/gcube/informationsystem/types/TypeBinder.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.List; import org.gcube.informationsystem.base.reference.ISManageable; -import org.gcube.informationsystem.types.impl.entities.TypeDefinitionImpl; import org.gcube.informationsystem.types.reference.TypeDefinition; import com.fasterxml.jackson.databind.JavaType; @@ -18,36 +17,38 @@ public class TypeBinder { private final static String NAME = "NAME"; - public static String serializeTypeDefinition(TypeDefinition typeDefinition) throws Exception{ + public static String serializeTypeDefinition(TypeDefinition typeDefinition) throws Exception{ ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(typeDefinition); return json; } - public static String serializeType(Class type) throws Exception{ - TypeDefinition typeDefinition = createTypeDefinition(type); + public static String serializeType(Class type) throws Exception{ + TypeDefinition typeDefinition = createTypeDefinition(type); return serializeTypeDefinition(typeDefinition); } - public static TypeDefinition deserializeTypeDefinition(String json) throws Exception{ + public static TypeDefinition deserializeTypeDefinition(String json) throws Exception{ ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(json, TypeDefinition.class); + @SuppressWarnings("unchecked") + TypeDefinition readValue = mapper.readValue(json, TypeDefinition.class); + return readValue; } - public static String serializeTypeDefinitions(List typeDefinitions) throws Exception{ + public static String serializeTypeDefinitions(List> typeDefinitions) throws Exception{ ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(typeDefinitions); return json; } - public static List deserializeTypeDefinitions(String json) throws Exception{ + 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); } - public static TypeDefinition createTypeDefinition(Class clz) { - TypeDefinition typeDefinition = new TypeDefinitionImpl(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/entities/TypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/TypeDefinitionImpl.java similarity index 52% rename from src/main/java/org/gcube/informationsystem/types/impl/entities/TypeDefinitionImpl.java rename to src/main/java/org/gcube/informationsystem/types/TypeDefinitionImpl.java index 3ceb722..0330b65 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/entities/TypeDefinitionImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/TypeDefinitionImpl.java @@ -1,22 +1,22 @@ -package org.gcube.informationsystem.types.impl.entities; +package org.gcube.informationsystem.types; import java.lang.reflect.Method; 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.reference.ISManageable; -import org.gcube.informationsystem.base.reference.properties.Property; -import org.gcube.informationsystem.model.reference.entities.Entity; -import org.gcube.informationsystem.model.reference.entities.Facet; +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.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.annotations.Abstract; import org.gcube.informationsystem.types.annotations.ISProperty; +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.TypeDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.slf4j.Logger; @@ -24,18 +24,19 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonIgnoreProperties(ignoreUnknown=true) -public class TypeDefinitionImpl implements TypeDefinition { +public abstract class TypeDefinitionImpl extends ERImpl implements TypeDefinition { + + /** + * Generated Serial Version UID + */ + private static final long serialVersionUID = 2698204820689338513L; private static Logger logger = LoggerFactory.getLogger(TypeDefinitionImpl.class); - private static final String EDGE_CLASS_NAME = "E"; - private static final String VERTEX_CLASS_NAME = "V"; - private final static String DESCRIPTION = "DESCRIPTION"; protected String name; @@ -45,12 +46,7 @@ public class TypeDefinitionImpl implements TypeDefinition { protected Set superClasses; protected Set properties; - @JsonInclude(JsonInclude.Include.NON_NULL) - protected String sourceType; - @JsonInclude(JsonInclude.Include.NON_NULL) - protected String targetType; - - private static Set retrieveSuperClasses(Class type, Class baseClass, String topSuperClass){ + protected static Set retrieveSuperClasses(Class type, Class baseClass, String topSuperClass){ Set interfaceList = new HashSet<>(); if(type==baseClass){ @@ -92,14 +88,27 @@ public class TypeDefinitionImpl implements TypeDefinition { return properties; } - private static Class getGenericClass(java.lang.reflect.Type type){ + protected static Class getGenericClass(java.lang.reflect.Type type){ TypeVariable typeVariable = (TypeVariable) type; java.lang.reflect.Type[] bounds = typeVariable.getBounds(); java.lang.reflect.Type t = bounds[0]; return (Class) t; } - public TypeDefinitionImpl(Class clz) { + @SuppressWarnings({"rawtypes", "unchecked"}) + public static TypeDefinition getInstance(Class clz) { + if(BaseEntity.class.isAssignableFrom(clz)) { + return new EntityTypeDefinitionImpl(clz); + } else if(BaseRelation.class.isAssignableFrom(clz)){ + return new RelationTypeDefinitionImpl(clz); + } else if(BaseProperty.class.isAssignableFrom(clz)){ + return new PropertyTypeDefinitionImpl(clz); + } else { + throw new RuntimeException("Serialization required"); + } + } + + protected TypeDefinitionImpl(Class clz) { this.name = TypeBinder.getType(clz); this.description = TypeBinder.getStaticStringFieldByName(clz, DESCRIPTION, ""); this.abstractType = false; @@ -108,40 +117,6 @@ public class TypeDefinitionImpl implements TypeDefinition { this.abstractType = true; } - if(Entity.class.isAssignableFrom(clz)) { - if(Resource.class.isAssignableFrom(clz)){ - this.superClasses = retrieveSuperClasses(clz, Resource.class, Entity.NAME); - }else{ - if(Facet.class.isAssignableFrom(clz)){ - this.superClasses = retrieveSuperClasses(clz, Facet.class, Entity.NAME); - } else { - this.superClasses = retrieveSuperClasses(clz, Entity.class, VERTEX_CLASS_NAME); - } - } - } else if(Relation.class.isAssignableFrom(clz)){ - if(IsRelatedTo.class.isAssignableFrom(clz)){ - this.superClasses = retrieveSuperClasses(clz, IsRelatedTo.class, Relation.NAME); - } else if(ConsistsOf.class.isAssignableFrom(clz)) { - this.superClasses = retrieveSuperClasses(clz, ConsistsOf.class, Relation.NAME); - } else { - this.superClasses = retrieveSuperClasses(clz, Relation.class, EDGE_CLASS_NAME); - } - - java.lang.reflect.Type[] typeParameters = clz.getTypeParameters(); - @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); - - } else if(Property.class.isAssignableFrom(clz)){ - this.superClasses = retrieveSuperClasses(clz, Property.class, clz == Property.class ? null : Property.NAME); - } else { - throw new RuntimeException("Serialization required"); - } - if(!Resource.class.isAssignableFrom(clz)){ this.properties = retrieveListOfProperties(clz); } @@ -150,43 +125,28 @@ public class TypeDefinitionImpl implements TypeDefinition { } @Override - public String toString() { - return "TypeDefinition [" - + "name=" + name - + (sourceType==null ? "" : "(" + sourceType + "->" + targetType + ")") - + ", description=" + description - + ", abstract=" + abstractType - + ", superClasses=" + superClasses - + ", properties=" + properties - + "]"; - } - public String getName() { return name; } + @Override public String getDescription() { return description; } + @Override public boolean isAbstract() { return abstractType; } + @Override public Set getSuperClasses() { return superClasses; } + @Override public Set getProperties() { return properties; } - - public String getSourceType() { - return sourceType; - } - - public String getTargetType() { - return targetType; - } } 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 new file mode 100644 index 0000000..d56a583 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/impl/entities/EntityTypeDefinitionImpl.java @@ -0,0 +1,37 @@ +package org.gcube.informationsystem.types.impl.entities; + +import org.gcube.informationsystem.base.reference.entities.BaseEntity; +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.TypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.entities.EntityDefinition; + +public class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements EntityDefinition { + + /** + * + */ + private static final long serialVersionUID = 2614315845213942880L; + + private static final String VERTEX_CLASS_NAME = "V"; + + 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 { + this.superClasses = retrieveSuperClasses(clz, BaseEntity.class, VERTEX_CLASS_NAME); + } + + + } + +} 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 7dad359..26f6b6a 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,12 +7,12 @@ import java.net.URL; import java.util.UUID; import org.gcube.informationsystem.base.reference.ISManageable; -import org.gcube.informationsystem.base.reference.properties.Property; +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; +import org.gcube.informationsystem.types.TypeDefinitionImpl; import org.gcube.informationsystem.types.annotations.ISProperty; -import org.gcube.informationsystem.types.impl.entities.TypeDefinitionImpl; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,7 +23,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) @JsonIgnoreProperties(ignoreUnknown=true) -public class PropertyDefinitionImpl implements PropertyDefinition { +public final class PropertyDefinitionImpl implements PropertyDefinition { + + /** + * Generated Serial Version UID + */ + private static final long serialVersionUID = -5925314595659292025L; private static Logger logger = LoggerFactory.getLogger(TypeDefinitionImpl.class); @@ -60,6 +65,8 @@ public class PropertyDefinitionImpl implements PropertyDefinition { return name; } + + public PropertyDefinitionImpl(ISProperty propertyAnnotation, Method method) { String name = propertyAnnotation.name().isEmpty()?getPropertyNameFromMethodName(method):propertyAnnotation.name(); this.name = name; 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 new file mode 100644 index 0000000..38c9bcc --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/impl/properties/PropertyTypeDefinitionImpl.java @@ -0,0 +1,19 @@ +package org.gcube.informationsystem.types.impl.properties; + +import org.gcube.informationsystem.base.reference.properties.BaseProperty; +import org.gcube.informationsystem.types.TypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefiniton; + +public class PropertyTypeDefinitionImpl

extends TypeDefinitionImpl

implements PropertyTypeDefiniton

{ + + /** + * + */ + private static final long serialVersionUID = 7532701373450638829L; + + public PropertyTypeDefinitionImpl(Class

clz) { + super(clz); + this.superClasses = retrieveSuperClasses(clz, BaseProperty.class, clz == BaseProperty.class ? null : BaseProperty.NAME); + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java new file mode 100644 index 0000000..19da0f2 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/impl/relations/RelationTypeDefinitionImpl.java @@ -0,0 +1,88 @@ +package org.gcube.informationsystem.types.impl.relations; + +import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.base.reference.relations.BaseRelation; +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.TypeDefinitionImpl; +import org.gcube.informationsystem.types.reference.entities.EntityDefinition; +import org.gcube.informationsystem.types.reference.relations.RelationDefinition; + +import com.fasterxml.jackson.annotation.JsonInclude; + +public class RelationTypeDefinitionImpl> + extends TypeDefinitionImpl implements RelationDefinition { + + /** + * + */ + 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; + + public RelationTypeDefinitionImpl(Class clz) { + super(clz); + + if(IsRelatedTo.class.isAssignableFrom(clz)){ + @SuppressWarnings({"unchecked", "rawtypes"}) + 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; + this.superClasses = retrieveSuperClasses(c, ConsistsOf.class, Relation.NAME); + } else { + this.superClasses = retrieveSuperClasses(clz, BaseRelation.class, EDGE_CLASS_NAME); + } + + java.lang.reflect.Type[] typeParameters = clz.getTypeParameters(); + @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); + } + + + public String getSourceType() { + return sourceType; + } + + public String getTargetType() { + return targetType; + } + + @Override + public EntityDefinition getSource() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setSource(EntityDefinition source) { + // TODO Auto-generated method stub + + } + + @Override + public EntityDefinition getTarget() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setTarget(EntityDefinition target) { + // TODO Auto-generated method stub + + } + +} 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 44f53d6..8bbe696 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/TypeDefinition.java @@ -2,9 +2,11 @@ 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.reference.properties.PropertyDefinition; -public interface TypeDefinition { +public interface TypeDefinition extends ER { public String getName(); @@ -15,9 +17,5 @@ public interface TypeDefinition { public Set getSuperClasses(); public Set getProperties(); - - public String getSourceType(); - - public String getTargetType(); } diff --git a/src/main/java/org/gcube/informationsystem/types/reference/entities/EntityDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/entities/EntityDefinition.java new file mode 100644 index 0000000..065460c --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/reference/entities/EntityDefinition.java @@ -0,0 +1,8 @@ +package org.gcube.informationsystem.types.reference.entities; + +import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.types.reference.TypeDefinition; + +public interface EntityDefinition extends TypeDefinition, BaseEntity { + +} diff --git a/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java index d6b07bb..cdd2fb3 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyDefinition.java @@ -1,5 +1,17 @@ package org.gcube.informationsystem.types.reference.properties; -public interface PropertyDefinition { +import org.gcube.informationsystem.base.reference.properties.BaseProperty; +import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * @author Luca Frosini (ISTI - CNR) + * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Header + */ +@JsonDeserialize(as = PropertyDefinitionImpl.class) +public interface PropertyDefinition extends BaseProperty { + + public static final String NAME = "PropertyDefinition"; // PropertyDefinition.class.getSimpleName(); } diff --git a/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefiniton.java b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefiniton.java new file mode 100644 index 0000000..79fcfe6 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/reference/properties/PropertyTypeDefiniton.java @@ -0,0 +1,11 @@ +package org.gcube.informationsystem.types.reference.properties; + +import org.gcube.informationsystem.base.reference.properties.BaseProperty; +import org.gcube.informationsystem.types.reference.TypeDefinition; + + +public interface PropertyTypeDefiniton

extends TypeDefinition

, BaseProperty { + + public static final String NAME = "PropertyTypeDefiniton"; // PropertyTypeDefiniton.class.getSimpleName(); + +} diff --git a/src/main/java/org/gcube/informationsystem/types/reference/relations/RelationDefinition.java b/src/main/java/org/gcube/informationsystem/types/reference/relations/RelationDefinition.java new file mode 100644 index 0000000..1131938 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/types/reference/relations/RelationDefinition.java @@ -0,0 +1,15 @@ +package org.gcube.informationsystem.types.reference.relations; + +import org.gcube.informationsystem.base.reference.entities.BaseEntity; +import org.gcube.informationsystem.base.reference.relations.BaseRelation; +import org.gcube.informationsystem.types.reference.TypeDefinition; +import org.gcube.informationsystem.types.reference.entities.EntityDefinition; + +public interface RelationDefinition> + extends TypeDefinition, BaseRelation,EntityDefinition> { + + public String getSourceType(); + + public String getTargetType(); + +} diff --git a/src/main/java/org/gcube/informationsystem/utils/AdditionalPropertiesSerializer.java b/src/main/java/org/gcube/informationsystem/utils/AdditionalPropertiesSerializer.java index 6a3f203..e76f63b 100644 --- a/src/main/java/org/gcube/informationsystem/utils/AdditionalPropertiesSerializer.java +++ b/src/main/java/org/gcube/informationsystem/utils/AdditionalPropertiesSerializer.java @@ -3,7 +3,7 @@ package org.gcube.informationsystem.utils; import java.io.IOException; import java.util.Map; -import org.gcube.informationsystem.base.reference.properties.Property; +import org.gcube.informationsystem.model.reference.properties.Property; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; diff --git a/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java b/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java index ce16b54..9a64d26 100644 --- a/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java +++ b/src/main/java/org/gcube/informationsystem/utils/ObjectMappingERAction.java @@ -3,8 +3,8 @@ */ package org.gcube.informationsystem.utils; -import org.gcube.informationsystem.base.reference.properties.Property; 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.utils.discovery.SchemaAction; 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 a73560d..0279012 100644 --- a/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java +++ b/src/main/java/org/gcube/informationsystem/utils/discovery/ISMDiscovery.java @@ -10,8 +10,8 @@ import java.util.List; import java.util.Objects; import org.gcube.informationsystem.base.reference.ISManageable; -import org.gcube.informationsystem.base.reference.properties.Property; 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.types.annotations.ISProperty; import org.slf4j.Logger; 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 3ca158f..f5ea503 100644 --- a/src/main/java/org/gcube/informationsystem/utils/discovery/SchemaAction.java +++ b/src/main/java/org/gcube/informationsystem/utils/discovery/SchemaAction.java @@ -3,8 +3,8 @@ */ package org.gcube.informationsystem.utils.discovery; -import org.gcube.informationsystem.base.reference.properties.Property; import org.gcube.informationsystem.model.reference.entities.Entity; +import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.model.reference.relations.Relation; /** diff --git a/src/test/java/org/gcube/informationsystem/model/ContextTest.java b/src/test/java/org/gcube/informationsystem/ContextTest.java similarity index 98% rename from src/test/java/org/gcube/informationsystem/model/ContextTest.java rename to src/test/java/org/gcube/informationsystem/ContextTest.java index e1d594e..cbdc991 100644 --- a/src/test/java/org/gcube/informationsystem/model/ContextTest.java +++ b/src/test/java/org/gcube/informationsystem/ContextTest.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.informationsystem.model; +package org.gcube.informationsystem; import java.io.IOException; import java.io.InputStream; diff --git a/src/test/java/org/gcube/informationsystem/model/impl/properties/HeaderTest.java b/src/test/java/org/gcube/informationsystem/base/impl/properties/HeaderTest.java similarity index 87% rename from src/test/java/org/gcube/informationsystem/model/impl/properties/HeaderTest.java rename to src/test/java/org/gcube/informationsystem/base/impl/properties/HeaderTest.java index 9863e52..d37ced6 100644 --- a/src/test/java/org/gcube/informationsystem/model/impl/properties/HeaderTest.java +++ b/src/test/java/org/gcube/informationsystem/base/impl/properties/HeaderTest.java @@ -1,11 +1,11 @@ -package org.gcube.informationsystem.model.impl.properties; +package org.gcube.informationsystem.base.impl.properties; import java.util.Calendar; import java.util.Date; import java.util.UUID; +import org.gcube.informationsystem.base.impl.properties.HeaderImpl; import org.gcube.informationsystem.base.reference.properties.Header; -import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import org.gcube.informationsystem.utils.ISMapper; import org.junit.Assert; import org.junit.Test; diff --git a/src/test/java/org/gcube/informationsystem/model/impl/properties/EncryptedTest.java b/src/test/java/org/gcube/informationsystem/impl/properties/EncryptedTest.java similarity index 94% rename from src/test/java/org/gcube/informationsystem/model/impl/properties/EncryptedTest.java rename to src/test/java/org/gcube/informationsystem/impl/properties/EncryptedTest.java index 653b3e7..603b9cd 100644 --- a/src/test/java/org/gcube/informationsystem/model/impl/properties/EncryptedTest.java +++ b/src/test/java/org/gcube/informationsystem/impl/properties/EncryptedTest.java @@ -1,14 +1,14 @@ -package org.gcube.informationsystem.model.impl.properties; +package org.gcube.informationsystem.impl.properties; import java.security.Key; import java.security.SecureRandom; import javax.crypto.KeyGenerator; -import org.gcube.informationsystem.base.reference.properties.Property; -import org.gcube.informationsystem.model.ContextTest; +import org.gcube.informationsystem.ContextTest; import org.gcube.informationsystem.model.impl.properties.EncryptedImpl; import org.gcube.informationsystem.model.reference.properties.Encrypted; +import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.utils.ISMapper; import org.junit.Assert; diff --git a/src/test/java/org/gcube/informationsystem/types/EntitySchemaDefinition.java b/src/test/java/org/gcube/informationsystem/types/EntitySchemaDefinition.java index 7caa135..0c24152 100644 --- a/src/test/java/org/gcube/informationsystem/types/EntitySchemaDefinition.java +++ b/src/test/java/org/gcube/informationsystem/types/EntitySchemaDefinition.java @@ -4,8 +4,8 @@ package org.gcube.informationsystem.types; import org.gcube.informationsystem.base.reference.ISManageable; +import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.base.reference.properties.Header; -import org.gcube.informationsystem.base.reference.properties.Property; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.junit.Test; @@ -23,7 +23,7 @@ public class EntitySchemaDefinition { @Test public void test() throws Exception { - Class clz = Header.class; + Class clz = Header.class; String json = TypeBinder.serializeType(clz); logger.trace(json); }