Changed CLASS and SUPERCLASSES constant names
This commit is contained in:
parent
49c04191db
commit
a5f2953fe7
|
@ -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<String, Object> map = (Map<String,Object>) 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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String, Object> map = (Map<String,Object>) 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;
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
|
|||
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<S extends Resource, T extends Entity>
|
|||
if(value instanceof Map<?,?>) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String,Object>) 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;
|
||||
|
|
|
@ -60,7 +60,7 @@ public class ElementDeserializer<ISM extends Element> extends StdDeserializer<IS
|
|||
|
||||
try {
|
||||
JsonNode superClassesTreeNode = objectNode
|
||||
.get(Element.SUPERCLASSES_PROPERTY);
|
||||
.get(Element.SUPERTYPES_PROPERTY);
|
||||
if (superClassesTreeNode != null
|
||||
&& superClassesTreeNode.isArray()) {
|
||||
ArrayNode arrayNode = (ArrayNode) superClassesTreeNode;
|
||||
|
@ -120,7 +120,7 @@ public class ElementDeserializer<ISM extends Element> extends StdDeserializer<IS
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
String typeName = TypeMapper.getType((Class<? extends Element>) 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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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\","
|
||||
|
|
|
@ -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\"," +
|
||||
|
|
|
@ -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<Metadata> metadataType = (PropertyType<Metadata>) TypeMapper.deserializeTypeDefinition(json);
|
||||
|
|
Loading…
Reference in New Issue