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 87a6f43..1bf9125 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,8 +3,13 @@ */ package org.gcube.informationsystem.model.impl.entities; +import java.util.Map; +import java.util.UUID; + +import org.gcube.com.fasterxml.jackson.annotation.JsonSetter; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; import org.gcube.informationsystem.base.impl.entities.EntityElementImpl; +import org.gcube.informationsystem.model.reference.ERElement; import org.gcube.informationsystem.model.reference.entities.Entity; /** @@ -18,9 +23,19 @@ public abstract class EntityImpl extends EntityElementImpl implements Entity { */ private static final long serialVersionUID = -4488771434017342703L; + protected Map contexts; + protected EntityImpl(){ super(); this.metadata = null; } + public Map getContexts(){ + return this.contexts; + } + + @JsonSetter(value = ERElement.CONTEXTS_PROPERTY) + protected void setContexts(Map contexts) { + this.contexts = contexts; + } } 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 0142565..360ca22 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 @@ -7,11 +7,14 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.UUID; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; +import org.gcube.com.fasterxml.jackson.annotation.JsonSetter; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; import org.gcube.informationsystem.base.impl.relations.RelationElementImpl; import org.gcube.informationsystem.base.reference.Element; +import org.gcube.informationsystem.model.reference.ERElement; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; @@ -31,6 +34,8 @@ public abstract class RelationImpl */ private static final long serialVersionUID = -6249979476879235053L; + protected Map contexts; + protected PropagationConstraint propagationConstraint; @JsonIgnore @@ -56,6 +61,15 @@ public abstract class RelationImpl this.propagationConstraint = propagationConstraint; } + public Map getContexts(){ + return this.contexts; + } + + @JsonSetter(value = ERElement.CONTEXTS_PROPERTY) + protected void setContexts(Map contexts) { + this.contexts = contexts; + } + @Override public PropagationConstraint getPropagationConstraint() { return this.propagationConstraint; diff --git a/src/main/java/org/gcube/informationsystem/model/reference/ERElement.java b/src/main/java/org/gcube/informationsystem/model/reference/ERElement.java index 7594a77..8defc21 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/ERElement.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/ERElement.java @@ -1,5 +1,13 @@ package org.gcube.informationsystem.model.reference; +import java.util.Map; +import java.util.UUID; + +import org.gcube.com.fasterxml.jackson.annotation.JsonGetter; +import org.gcube.com.fasterxml.jackson.annotation.JsonInclude; +import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include; +import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.IdentifiableElement; /** @@ -8,6 +16,16 @@ import org.gcube.informationsystem.base.reference.IdentifiableElement; * * @author Luca Frosini (ISTI - CNR) */ +@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY }) public interface ERElement extends IdentifiableElement { + /** + * Used when requested to include contexts in metadata. + * This is not a native property (it is just generated by server for administration clients convenience) + */ + public static final String CONTEXTS_PROPERTY = "contexts"; + + @JsonInclude(Include.NON_NULL) + @JsonGetter(value = CONTEXTS_PROPERTY) + public Map getContexts(); } 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 71cbe74..9c87440 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 @@ -3,9 +3,6 @@ */ package org.gcube.informationsystem.model.reference.entities; -import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.gcube.informationsystem.base.reference.Element; -import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.entities.EntityElement; import org.gcube.informationsystem.model.reference.ERElement; import org.gcube.informationsystem.types.annotations.Abstract; @@ -19,7 +16,6 @@ import org.gcube.informationsystem.utils.Version; * @author Luca Frosini (ISTI - CNR) */ @Abstract -@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY }) //@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses @TypeMetadata(name = Entity.NAME, description = "This is the base type for any Entity", version = Version.MINIMAL_VERSION_STRING) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) diff --git a/src/main/java/org/gcube/informationsystem/model/reference/entities/Facet.java b/src/main/java/org/gcube/informationsystem/model/reference/entities/Facet.java index ac66463..8789f99 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/entities/Facet.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/entities/Facet.java @@ -22,7 +22,6 @@ import org.gcube.informationsystem.utils.Version; */ @Abstract @JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY }) - // @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses @TypeMetadata(name = "Facet", description = "This is the base type for any Facet", version = Version.MINIMAL_VERSION_STRING) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) diff --git a/src/main/java/org/gcube/informationsystem/model/reference/properties/Metadata.java b/src/main/java/org/gcube/informationsystem/model/reference/properties/Metadata.java index 3b7a298..efc1912 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/properties/Metadata.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/properties/Metadata.java @@ -36,12 +36,6 @@ public interface Metadata extends Property { public static final String LAST_UPDATE_BY_PROPERTY = "lastUpdateBy"; public static final String LAST_UPDATE_TIME_PROPERTY = "lastUpdateTime"; - /** - * Used when requested to include contexts in metadata. - * This is not a native property (it is just generated by server for administration clients convenience) - */ - public static final String __CONTEXTS = "contexts"; - @ISProperty(name = CREATED_BY_PROPERTY, description = "The user that created the Entity or the Relation. It is initialized at Creation Time.", readonly = true, mandatory = true, nullable = false) public String getCreatedBy(); 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 1cdd5be..4c60177 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 @@ -34,10 +34,28 @@ import org.gcube.informationsystem.utils.Version; public interface PropagationConstraint extends Property { public static final String NAME = "PropagationConstraint"; // PropagationConstraint.class.getSimpleName(); - + + public static final String ADD_PROPERTY = "add"; public static final String DELETE_PROPERTY = "delete"; public static final String REMOVE_PROPERTY = "remove"; - public static final String ADD_PROPERTY = "add"; + + public enum AddConstraint { + + /** + * When an 'add' action is performed on the source Entity of the relation, + * or directly on the relation, then the same 'add' action is performed on + * the relation and its target Entity. + */ + propagate, + + /** + * When an 'add' action is performed on the source Entity of the relation, + * is performed on source relation only. Trying to perform an 'add' action on + * the relation has no effects. + */ + unpropagate + + } public enum DeleteConstraint { @@ -89,24 +107,6 @@ public interface PropagationConstraint extends Property { keep } - - public enum AddConstraint { - - /** - * When an 'add' action is performed on the source Entity of the relation, - * or directly on the relation, then the same 'add' action is performed on - * the relation and its target Entity. - */ - propagate, - - /** - * When an 'add' action is performed on the source Entity of the relation, - * is performed on source relation only. Trying to perform an 'add' action on - * the relation has no effects. - */ - unpropagate - - } @ISProperty(name=ADD_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when an 'add' action is performed on the source Resource. Add action is the operation of adding an instance to a context.", mandatory = true, nullable = false) public AddConstraint getAddConstraint(); 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 1edf01e..df56b62 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 @@ -7,8 +7,10 @@ import java.util.Map; import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter; import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter; +import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder; import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.SchemaMixedElement; import org.gcube.informationsystem.base.reference.properties.PropertyElement; import org.gcube.informationsystem.model.impl.properties.PropertyImpl; @@ -24,6 +26,7 @@ import org.gcube.informationsystem.utils.Version; * @author Luca Frosini (ISTI - CNR) */ // @JsonIgnoreProperties(ignoreUnknown=true) +@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY }) @JsonDeserialize(as=PropertyImpl.class) @TypeMetadata(name = Property.NAME, description = "This is the base type for any Property", version = Version.MINIMAL_VERSION_STRING) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) diff --git a/src/main/java/org/gcube/informationsystem/types/TypeMapper.java b/src/main/java/org/gcube/informationsystem/types/TypeMapper.java index f89722b..b914efd 100644 --- a/src/main/java/org/gcube/informationsystem/types/TypeMapper.java +++ b/src/main/java/org/gcube/informationsystem/types/TypeMapper.java @@ -201,32 +201,4 @@ public class TypeMapper { return map; } - /* - - private final static String NAME = "NAME"; - - public static String getStaticStringFieldByName(Class clz, String fieldName, String defaultValue){ - Field field; - try { - field = clz.getDeclaredField(fieldName); - field.setAccessible(true); - return (String) field.get(null); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - return defaultValue; - } - } - - @SuppressWarnings("unchecked") - public static O getStaticFieldByName(Class clz, String fieldName, O defaultValue){ - Field field; - try { - field = clz.getDeclaredField(fieldName); - field.setAccessible(true); - return (O) field.get(null); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - return defaultValue; - } - } - */ - } diff --git a/src/test/java/org/gcube/informationsystem/model/impl/properties/MetadataTest.java b/src/test/java/org/gcube/informationsystem/model/impl/properties/MetadataTest.java index 0a7a961..a05a81b 100644 --- a/src/test/java/org/gcube/informationsystem/model/impl/properties/MetadataTest.java +++ b/src/test/java/org/gcube/informationsystem/model/impl/properties/MetadataTest.java @@ -1,13 +1,8 @@ package org.gcube.informationsystem.model.impl.properties; -import java.io.IOException; import java.util.Calendar; import java.util.Date; -import java.util.Map; -import org.gcube.com.fasterxml.jackson.core.JsonParseException; -import org.gcube.com.fasterxml.jackson.databind.JsonMappingException; -import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.model.reference.properties.Metadata; import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.serialization.ElementMapper; @@ -49,30 +44,4 @@ public class MetadataTest { logger.debug(ElementMapper.marshal(h)); } - @Test - public void testContextsInMetadata() throws JsonParseException, JsonMappingException, IOException { - - String metadataJson = - "{" - + "\"" + Element.TYPE_PROPERTY + "\":\"Metadata\"," - + "\"createdBy\":\"UNKNOWN_USER\"," - + "\"lastUpdateBy\":\"UNKNOWN_USER\"," - + "\"creationTime\":\"2020-11-09 10:01:25.415 +0000\"," - + "\"lastUpdateTime\":\"2020-11-09 10:01:25.415 +0000\"," - + "\"contexts\": {" - + "\"bad5f350-345c-11e9-9f49-cef9b1608c3f\": \"/gcube/devNext/NextNext\"" - + "}" - + "}"; - - Property property = ElementMapper.unmarshal(Property.class, metadataJson); - logger.debug("{}", property); - - Metadata h = ElementMapper.unmarshal(Metadata.class, metadataJson); - logger.debug("{}", h); - - @SuppressWarnings("unchecked") - Map contexts = (Map) h.getAdditionalProperty(Metadata.__CONTEXTS); - logger.debug("Contexts IDs are {}", contexts); - } - }