Ordering Json Properties

This commit is contained in:
Luca Frosini 2023-04-27 16:30:10 +02:00
parent ad6018d5fb
commit a79ed8fd56
11 changed files with 79 additions and 26 deletions

View File

@ -4,6 +4,7 @@
package org.gcube.informationsystem.base.impl; package org.gcube.informationsystem.base.impl;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.List;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.Element;
@ -21,6 +22,18 @@ public class ElementImpl implements Element {
*/ */
private static final long serialVersionUID = 7338083489551084860L; private static final long serialVersionUID = 7338083489551084860L;
private List<String> supertypes;
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
@Override
public List<String> getSupertypes() {
return this.supertypes;
}
@Override @Override
public String toString(){ public String toString(){
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
@ -32,9 +45,4 @@ public class ElementImpl implements Element {
} }
} }
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
} }

View File

@ -4,8 +4,13 @@
package org.gcube.informationsystem.base.reference; package org.gcube.informationsystem.base.reference;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo; import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.gcube.informationsystem.types.annotations.Abstract; import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change; import org.gcube.informationsystem.types.reference.Change;
@ -16,6 +21,7 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
@Abstract @Abstract
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY })
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.TYPE_PROPERTY) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.TYPE_PROPERTY)
// @JsonTypeIdResolver(ElementTypeIdResolver.class) // @JsonTypeIdResolver(ElementTypeIdResolver.class)
@TypeMetadata(name = Element.NAME, description = "This is the base type for Element", version = Version.MINIMAL_VERSION_STRING) @TypeMetadata(name = Element.NAME, description = "This is the base type for Element", version = Version.MINIMAL_VERSION_STRING)
@ -36,4 +42,8 @@ public interface Element extends Serializable {
@JsonIgnore @JsonIgnore
public String getTypeName(); public String getTypeName();
@JsonInclude(Include.NON_NULL)
@JsonGetter(value = SUPERTYPES_PROPERTY)
public List<String> getSupertypes();
} }

View File

@ -3,6 +3,7 @@ package org.gcube.informationsystem.base.reference.entities;
import java.util.UUID; import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.properties.Metadata; import org.gcube.informationsystem.model.reference.properties.Metadata;
@ -17,6 +18,7 @@ import org.gcube.informationsystem.utils.Version;
*/ */
@Abstract @Abstract
@JsonIgnoreProperties(ignoreUnknown=true) @JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.UUID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
//@JsonDeserialize(as=EntityElementImpl.class) Do not uncomment to manage subclasses //@JsonDeserialize(as=EntityElementImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = EntityElement.NAME, description = "This is the base type for any EntityElement", version = Version.MINIMAL_VERSION_STRING) @TypeMetadata(name = EntityElement.NAME, description = "This is the base type for any EntityElement", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)

View File

@ -19,6 +19,10 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro
*/ */
private static final long serialVersionUID = -4708881022038107688L; private static final long serialVersionUID = -4708881022038107688L;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=ADD_PROPERTY)
protected AddConstraint addConstraint;
@JsonFormat(shape=JsonFormat.Shape.STRING) @JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=DELETE_PROPERTY) @JsonProperty(value=DELETE_PROPERTY)
protected DeleteConstraint deleteConstraint; protected DeleteConstraint deleteConstraint;
@ -27,14 +31,20 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro
@JsonProperty(value=REMOVE_PROPERTY) @JsonProperty(value=REMOVE_PROPERTY)
protected RemoveConstraint removeConstraint; protected RemoveConstraint removeConstraint;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=ADD_PROPERTY)
protected AddConstraint addConstraint;
public PropagationConstraintImpl(){ public PropagationConstraintImpl(){
super(); super();
} }
@Override
public AddConstraint getAddConstraint() {
return this.addConstraint;
}
@Override
public void setAddConstraint(AddConstraint addConstraint) {
this.addConstraint = addConstraint;
}
@Override @Override
public DeleteConstraint getDeleteConstraint() { public DeleteConstraint getDeleteConstraint() {
return this.deleteConstraint; return this.deleteConstraint;
@ -55,14 +65,4 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro
this.removeConstraint = removeConstraint; this.removeConstraint = removeConstraint;
} }
@Override
public AddConstraint getAddConstraint() {
return this.addConstraint;
}
@Override
public void setAddConstraint(AddConstraint addConstraint) {
this.addConstraint = addConstraint;
}
} }

View File

@ -3,6 +3,9 @@
*/ */
package org.gcube.informationsystem.model.reference.entities; 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.base.reference.entities.EntityElement;
import org.gcube.informationsystem.model.reference.ERElement; import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.types.annotations.Abstract; import org.gcube.informationsystem.types.annotations.Abstract;
@ -16,6 +19,7 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
@Abstract @Abstract
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.UUID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
//@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses //@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) @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) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)

View File

@ -4,7 +4,10 @@ import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter; import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter; import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.SchemaMixedElement; import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer; import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.annotations.Abstract; import org.gcube.informationsystem.types.annotations.Abstract;
@ -18,6 +21,8 @@ import org.gcube.informationsystem.utils.Version;
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Facet * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Facet
*/ */
@Abstract @Abstract
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.UUID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
// @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses // @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) @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) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)

View File

@ -8,6 +8,9 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
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.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.annotations.Abstract; import org.gcube.informationsystem.types.annotations.Abstract;
@ -25,6 +28,7 @@ import org.gcube.informationsystem.utils.Version;
*/ */
@Abstract @Abstract
@JsonIgnoreProperties(ignoreUnknown=true) @JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.UUID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY })
// @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses // @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses
@ResourceSchema( @ResourceSchema(
facets={ facets={

View File

@ -107,6 +107,12 @@ public interface PropagationConstraint extends Property {
unpropagate 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();
public void setAddConstraint(AddConstraint addConstraint);
@ISProperty(name=DELETE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'delete' action is performed on the source Resource. Delet action is the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false) @ISProperty(name=DELETE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'delete' action is performed on the source Resource. Delet action is the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false)
public DeleteConstraint getDeleteConstraint(); public DeleteConstraint getDeleteConstraint();
@ -119,10 +125,4 @@ public interface PropagationConstraint extends Property {
public void setRemoveConstraint(RemoveConstraint removeConstraint); public void setRemoveConstraint(RemoveConstraint removeConstraint);
@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();
public void setAddConstraint(AddConstraint addConstraint);
} }

View File

@ -10,7 +10,12 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter; import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.SchemaMixedElement; import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement; import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.ERElement; import org.gcube.informationsystem.model.reference.ERElement;
@ -30,6 +35,7 @@ import org.gcube.informationsystem.utils.Version;
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Relation * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Relation
*/ */
@Abstract @Abstract
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.UUID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, Relation.PROPAGATION_CONSTRAINT_PROPERTY })
// @JsonDeserialize(as=RelationImpl.class) Do not uncomment to manage subclasses // @JsonDeserialize(as=RelationImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = Relation.NAME, description = "This is the base type for any Relation", version = Version.MINIMAL_VERSION_STRING) @TypeMetadata(name = Relation.NAME, description = "This is the base type for any Relation", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@ -39,6 +45,7 @@ public interface Relation<S extends Resource, T extends Entity> extends Relation
public static final String PROPAGATION_CONSTRAINT_PROPERTY = "propagationConstraint"; public static final String PROPAGATION_CONSTRAINT_PROPERTY = "propagationConstraint";
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties({Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY}) @JsonIgnoreProperties({Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY})
@JsonGetter(value = SOURCE_PROPERTY) @JsonGetter(value = SOURCE_PROPERTY)
@Override @Override

View File

@ -5,6 +5,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable; import java.lang.reflect.TypeVariable;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -61,7 +62,8 @@ public class TypeImpl implements Type {
protected UUID uuid; protected UUID uuid;
protected Metadata metadata; protected Metadata metadata;
private List<String> supertypes;
protected String name; protected String name;
protected String description; protected String description;
protected Version version; protected Version version;
@ -295,4 +297,8 @@ public class TypeImpl implements Type {
return TypeUtility.getTypeName(this.getClass()); return TypeUtility.getTypeName(this.getClass());
} }
@Override
public List<String> getSupertypes() {
return this.supertypes;
}
} }

View File

@ -3,6 +3,7 @@ package org.gcube.informationsystem.types.impl.properties;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -35,6 +36,8 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
public final static String URI_REGEX = null; public final static String URI_REGEX = null;
public final static String URL_REGEX = null; public final static String URL_REGEX = null;
private List<String> supertypes;
private String name= ""; private String name= "";
private String description= ""; private String description= "";
private boolean mandatory = false; private boolean mandatory = false;
@ -287,4 +290,8 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
return TypeUtility.getTypeName(this.getClass()); return TypeUtility.getTypeName(this.getClass());
} }
@Override
public List<String> getSupertypes() {
return this.supertypes;
}
} }