Reorganizing property order

This commit is contained in:
Luca Frosini 2023-04-28 14:34:29 +02:00
parent 86f015cb21
commit 4333855ebc
10 changed files with 70 additions and 90 deletions

View File

@ -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<UUID,String> contexts;
protected EntityImpl(){
super();
this.metadata = null;
}
public Map<UUID,String> getContexts(){
return this.contexts;
}
@JsonSetter(value = ERElement.CONTEXTS_PROPERTY)
protected void setContexts(Map<UUID,String> contexts) {
this.contexts = contexts;
}
}

View File

@ -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<S extends Resource, T extends Entity>
*/
private static final long serialVersionUID = -6249979476879235053L;
protected Map<UUID,String> contexts;
protected PropagationConstraint propagationConstraint;
@JsonIgnore
@ -56,6 +61,15 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
this.propagationConstraint = propagationConstraint;
}
public Map<UUID,String> getContexts(){
return this.contexts;
}
@JsonSetter(value = ERElement.CONTEXTS_PROPERTY)
protected void setContexts(Map<UUID,String> contexts) {
this.contexts = contexts;
}
@Override
public PropagationConstraint getPropagationConstraint() {
return this.propagationConstraint;

View File

@ -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<UUID,String> getContexts();
}

View File

@ -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)

View File

@ -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)

View File

@ -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();

View File

@ -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();

View File

@ -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)

View File

@ -201,32 +201,4 @@ public class TypeMapper {
return map;
}
/*
private final static String NAME = "NAME";
public static String getStaticStringFieldByName(Class<? extends Element> 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 extends Object> O getStaticFieldByName(Class<? extends Element> 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;
}
}
*/
}

View File

@ -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<String,String> contexts = (Map<String, String>) h.getAdditionalProperty(Metadata.__CONTEXTS);
logger.debug("Contexts IDs are {}", contexts);
}
}