From a5f2953fe7c9b4b726745262cfaaba486e507623 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 27 Apr 2023 10:40:36 +0200 Subject: [PATCH] Changed CLASS and SUPERCLASSES constant names --- .../impl/properties/PropertyElementImpl.java | 4 ++-- .../base/reference/Element.java | 6 +++--- .../model/impl/entities/FacetImpl.java | 4 ++-- .../model/impl/relations/RelationImpl.java | 4 ++-- .../serialization/ElementDeserializer.java | 4 ++-- .../serialization/ElementMapper.java | 10 +++++----- .../informationsystem/utils/TypeUtility.java | 4 ++-- .../model/impl/properties/MetadataTest.java | 2 +- .../properties/PropagationConstraintTest.java | 18 +++++++++--------- .../types/SerializationTest.java | 2 +- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyElementImpl.java b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyElementImpl.java index 2d35a12..597d9ad 100644 --- a/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyElementImpl.java +++ b/src/main/java/org/gcube/informationsystem/base/impl/properties/PropertyElementImpl.java @@ -37,7 +37,7 @@ public class PropertyElementImpl extends ElementImpl implements Property { super(); this.additionalProperties = new HashMap<>(); this.allowedAdditionalKeys = new HashSet<>(); - this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY); + this.allowedAdditionalKeys.add(SUPERTYPES_PROPERTY); } @Override @@ -75,7 +75,7 @@ public class PropertyElementImpl extends ElementImpl implements Property { if(value instanceof Map) { @SuppressWarnings("unchecked") Map map = (Map) value; - if(map.containsKey(Element.CLASS_PROPERTY)) { + if(map.containsKey(Element.TYPE_PROPERTY)) { String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map); Property property = ElementMapper.unmarshal(Property.class, reserialized); value = property; diff --git a/src/main/java/org/gcube/informationsystem/base/reference/Element.java b/src/main/java/org/gcube/informationsystem/base/reference/Element.java index 7b2c288..31d9a92 100644 --- a/src/main/java/org/gcube/informationsystem/base/reference/Element.java +++ b/src/main/java/org/gcube/informationsystem/base/reference/Element.java @@ -15,7 +15,7 @@ import org.gcube.informationsystem.utils.Version; * @author Luca Frosini (ISTI - CNR) */ @Abstract -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.CLASS_PROPERTY) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.TYPE_PROPERTY) // @JsonTypeIdResolver(ElementTypeIdResolver.class) @TypeMetadata(name = Element.NAME, description = "This is the base type for Element", version = Version.MINIMAL_VERSION_STRING) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) @@ -23,9 +23,9 @@ public interface Element extends Serializable { public static final String NAME = "Element"; //Element.class.getSimpleName(); - public static final String CLASS_PROPERTY = "type"; + public static final String TYPE_PROPERTY = "type"; - public static final String SUPERCLASSES_PROPERTY = "@superClasses"; + public static final String SUPERTYPES_PROPERTY = "supertypes"; /** * DateTime Pattern to be used to serialize Dates in every element 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 ed9ba14..48a26d3 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 @@ -39,7 +39,7 @@ public abstract class FacetImpl extends EntityImpl implements Facet { super(); this.additionalProperties = new HashMap<>(); this.allowedAdditionalKeys = new HashSet<>(); - this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY); + this.allowedAdditionalKeys.add(SUPERTYPES_PROPERTY); } @Override @@ -77,7 +77,7 @@ public abstract class FacetImpl extends EntityImpl implements Facet { if(value instanceof Map) { @SuppressWarnings("unchecked") Map map = (Map) value; - if(map.containsKey(Element.CLASS_PROPERTY)) { + if(map.containsKey(Element.TYPE_PROPERTY)) { String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map); Property property = ElementMapper.unmarshal(Property.class, reserialized); value = property; 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 99775bd..0142565 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 @@ -45,7 +45,7 @@ public abstract class RelationImpl super(); this.additionalProperties = new HashMap<>(); this.allowedAdditionalKeys = new HashSet<>(); - this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY); + this.allowedAdditionalKeys.add(SUPERTYPES_PROPERTY); } protected RelationImpl(S source, T target, @@ -105,7 +105,7 @@ public abstract class RelationImpl if(value instanceof Map) { @SuppressWarnings("unchecked") Map map = (Map) value; - if(map.containsKey(Element.CLASS_PROPERTY)) { + if(map.containsKey(Element.TYPE_PROPERTY)) { String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map); Property property = ElementMapper.unmarshal(Property.class, reserialized); value = property; diff --git a/src/main/java/org/gcube/informationsystem/serialization/ElementDeserializer.java b/src/main/java/org/gcube/informationsystem/serialization/ElementDeserializer.java index 13a4283..308a993 100644 --- a/src/main/java/org/gcube/informationsystem/serialization/ElementDeserializer.java +++ b/src/main/java/org/gcube/informationsystem/serialization/ElementDeserializer.java @@ -60,7 +60,7 @@ public class ElementDeserializer extends StdDeserializer extends StdDeserializer) candidatedSuperClass); - objectNode.set(Element.CLASS_PROPERTY, new TextNode(typeName)); + objectNode.set(Element.TYPE_PROPERTY, new TextNode(typeName)); JsonParser jsonParser = jsonFactory.createParser(objectNode .toString()); jsonParser.nextToken(); diff --git a/src/main/java/org/gcube/informationsystem/serialization/ElementMapper.java b/src/main/java/org/gcube/informationsystem/serialization/ElementMapper.java index af67a5d..4a1a8cc 100644 --- a/src/main/java/org/gcube/informationsystem/serialization/ElementMapper.java +++ b/src/main/java/org/gcube/informationsystem/serialization/ElementMapper.java @@ -193,14 +193,14 @@ public abstract class ElementMapper { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(unknownType); stringBuffer.append(" is an unknown type. Please provide "); - stringBuffer.append(Element.SUPERCLASSES_PROPERTY); + stringBuffer.append(Element.SUPERTYPES_PROPERTY); stringBuffer.append(" property as string array to allow to instantiate the most appropriated class."); return stringBuffer; } protected static JsonNode setAvailableSuperclass(JsonNode jsonNode) { - String unknownType = jsonNode.get(Element.CLASS_PROPERTY).asText(); - ArrayNode arrayNode = (ArrayNode) jsonNode.get(Element.SUPERCLASSES_PROPERTY); + String unknownType = jsonNode.get(Element.TYPE_PROPERTY).asText(); + ArrayNode arrayNode = (ArrayNode) jsonNode.get(Element.SUPERTYPES_PROPERTY); // TODO save original class and superclasses @@ -227,7 +227,7 @@ public abstract class ElementMapper { } if(candidatedSuperClass!=null) { - ((ObjectNode) jsonNode).set(Element.CLASS_PROPERTY, new TextNode(candidatedSuperClass)); + ((ObjectNode) jsonNode).set(Element.TYPE_PROPERTY, new TextNode(candidatedSuperClass)); return jsonNode; } @@ -237,7 +237,7 @@ public abstract class ElementMapper { } protected static JsonNode analizeFullJson(JsonNode jsonNode) { - String cls = jsonNode.get(Element.CLASS_PROPERTY).asText(); + String cls = jsonNode.get(Element.TYPE_PROPERTY).asText(); if(!knownTypes.containsKey(cls)) { jsonNode = setAvailableSuperclass(jsonNode); } diff --git a/src/main/java/org/gcube/informationsystem/utils/TypeUtility.java b/src/main/java/org/gcube/informationsystem/utils/TypeUtility.java index 474c095..fb6a6d9 100644 --- a/src/main/java/org/gcube/informationsystem/utils/TypeUtility.java +++ b/src/main/java/org/gcube/informationsystem/utils/TypeUtility.java @@ -13,8 +13,8 @@ import org.gcube.informationsystem.types.TypeMapper; public class TypeUtility { public static String getTypeName(JsonNode jsonNode){ - if(jsonNode.has(Element.CLASS_PROPERTY)) { - return jsonNode.get(Element.CLASS_PROPERTY).asText(); + if(jsonNode.has(Element.TYPE_PROPERTY)) { + return jsonNode.get(Element.TYPE_PROPERTY).asText(); } return null; } 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 038ffb3..8719713 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 @@ -54,7 +54,7 @@ public class MetadataTest { String metadataJson = "{" - + "\"" + Element.CLASS_PROPERTY + "\":\"Metadata\"," + + "\"" + Element.TYPE_PROPERTY + "\":\"Metadata\"," + "\"createdBy\":\"UNKNOWN_USER\"," + "\"lastUpdateBy\":\"UNKNOWN_USER\"," + "\"creationTime\":\"2020-11-09 10:01:25.415 +0000\"," diff --git a/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java b/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java index 389ceb6..59dd62d 100644 --- a/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java +++ b/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java @@ -77,8 +77,8 @@ public class PropagationConstraintTest { RemoveConstraint removeConstraint = RemoveConstraint.cascade; DeleteConstraint deleteConstraint = DeleteConstraint.keep; String marshalled = "{\"" + - Element.CLASS_PROPERTY + "\":\"MyPropagationConstraint\",\"" + - Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + + Element.TYPE_PROPERTY + "\":\"MyPropagationConstraint\",\"" + + Element.SUPERTYPES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\""+ PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\",\""+ PropagationConstraint.DELETE_PROPERTY + "\":\"" + deleteConstraint + @@ -108,8 +108,8 @@ public class PropagationConstraintTest { DeleteConstraint deleteConstraint = DeleteConstraint.keep; String pcString = "{" + - "\"" + Element.CLASS_PROPERTY + "\":\"My" + PropagationConstraint.NAME + "\"," + - "\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + + "\"" + Element.TYPE_PROPERTY + "\":\"My" + PropagationConstraint.NAME + "\"," + + "\"" + Element.SUPERTYPES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\"" + PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\",\"" + PropagationConstraint.DELETE_PROPERTY + "\":\"" + deleteConstraint + "\"" + @@ -126,19 +126,19 @@ public class PropagationConstraintTest { String consistsOfString = "{" + - "\"" + Element.CLASS_PROPERTY + "\":\"" + ConsistsOf.NAME + "\"," + + "\"" + Element.TYPE_PROPERTY + "\":\"" + ConsistsOf.NAME + "\"," + "\"" + ConsistsOf.PROPAGATION_CONSTRAINT_PROPERTY + "\":"+ pcString + "," + "\"" + ConsistsOf.METADATA_PROPERTY + "\": " + hString + "," + "\"" + ConsistsOf.SOURCE_PROPERTY + "\":{" + "\"" + IdentifiableElement.UUID_PROPERTY + "\":\"4a971915-ca90-48cf-9975-63ee2dd28605\"," + - "\"" + Element.CLASS_PROPERTY + "\":\"MyEService\"," + - "\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"EService\", \"Service\", \"Resource\"]," + + "\"" + Element.TYPE_PROPERTY + "\":\"MyEService\"," + + "\"" + Element.SUPERTYPES_PROPERTY + "\":[\"EService\", \"Service\", \"Resource\"]," + "\"" + ConsistsOf.METADATA_PROPERTY + "\": " + hString + "}," + "\"" + ConsistsOf.TARGET_PROPERTY + "\":{" + "\"" + IdentifiableElement.UUID_PROPERTY + "\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\"," + - "\"" + Element.CLASS_PROPERTY + "\":\"MySoftwareFacet\"," + - "\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\"]," + + "\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\"," + + "\"" + Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\"]," + "\"" + ConsistsOf.METADATA_PROPERTY + "\": " + hString + "," + "\"name\":\"WhnManager\"," + "\"group\":\"VREManagement\"," + diff --git a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java index 893f8d1..4acc41c 100644 --- a/src/test/java/org/gcube/informationsystem/types/SerializationTest.java +++ b/src/test/java/org/gcube/informationsystem/types/SerializationTest.java @@ -207,7 +207,7 @@ public class SerializationTest { logger.debug("Version {}", typeVersion.toString()); logger.info(ElementMapper.marshal(propertyType)); - String json = "{\"" + Element.CLASS_PROPERTY + "\":\"PropertyType\",\"metadata\":null,\"name\":\"Metadata\",\"description\":\"This class provides metadata per every IdentifiableElement\",\"superClasses\":[\"Property\"],\"properties\":[{\"" + Element.CLASS_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"creationTime\",\"description\":\"Creation time. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"Date\"},{\"" + Element.CLASS_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"lastUpdateTime\",\"description\":\"Last Update time. At creation time it assumes the same value of creationTime. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"Date\"},{\"" + Element.CLASS_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"createdBy\",\"description\":\"The user that created the Entity or the Relation. It is initialized at creation time. \",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"String\"},{\"" + Element.CLASS_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"uuid\",\"description\":\"This UUID is be used to identify the Entity or the Relation univocally.\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":\"^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$\",\"propertyType\":\"String\"},{\"" + Element.CLASS_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"lastUpdateBy\",\"description\":\"The user that made the last update to the Entity or the Relation. At creation time, it assumes the same value of creator.\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"String\"}],\"accessType\":\"PROPERTY\",\"abstract\":false,\"version\":\"1.0.0\",\"changelog\":{\"1.0.0\":\"First Version\"}}"; + String json = "{\"" + Element.TYPE_PROPERTY + "\":\"PropertyType\",\"metadata\":null,\"name\":\"Metadata\",\"description\":\"This class provides metadata per every IdentifiableElement\",\"superClasses\":[\"Property\"],\"properties\":[{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"creationTime\",\"description\":\"Creation time. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"Date\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"lastUpdateTime\",\"description\":\"Last Update time. At creation time it assumes the same value of creationTime. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"Date\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"createdBy\",\"description\":\"The user that created the Entity or the Relation. It is initialized at creation time. \",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"String\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"uuid\",\"description\":\"This UUID is be used to identify the Entity or the Relation univocally.\",\"mandatory\":true,\"readonly\":true,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":\"^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$\",\"propertyType\":\"String\"},{\"" + Element.TYPE_PROPERTY + "\":\"PropertyDefinition\",\"name\":\"lastUpdateBy\",\"description\":\"The user that made the last update to the Entity or the Relation. At creation time, it assumes the same value of creator.\",\"mandatory\":true,\"readonly\":false,\"notnull\":true,\"max\":null,\"min\":null,\"regexp\":null,\"propertyType\":\"String\"}],\"accessType\":\"PROPERTY\",\"abstract\":false,\"version\":\"1.0.0\",\"changelog\":{\"1.0.0\":\"First Version\"}}"; logger.info(json); @SuppressWarnings("unchecked") PropertyType metadataType = (PropertyType) TypeMapper.deserializeTypeDefinition(json);