Added expectedtype property to keep track of original type
This commit is contained in:
parent
21407336bb
commit
4b06b1b6bc
|
@ -22,8 +22,9 @@ public class ElementImpl implements Element {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 7338083489551084860L;
|
private static final long serialVersionUID = 7338083489551084860L;
|
||||||
|
|
||||||
private List<String> supertypes;
|
protected List<String> supertypes;
|
||||||
|
protected String expectedtype;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeName() {
|
public String getTypeName() {
|
||||||
return TypeUtility.getTypeName(this.getClass());
|
return TypeUtility.getTypeName(this.getClass());
|
||||||
|
@ -34,6 +35,11 @@ public class ElementImpl implements Element {
|
||||||
return this.supertypes;
|
return this.supertypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExpectedtype() {
|
||||||
|
return this.expectedtype;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
|
@ -21,7 +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 })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_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)
|
||||||
|
@ -34,6 +34,13 @@ public interface Element extends Serializable {
|
||||||
|
|
||||||
public static final String SUPERTYPES_PROPERTY = "supertypes";
|
public static final String SUPERTYPES_PROPERTY = "supertypes";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the key used by the deserializer to indicate the expected type
|
||||||
|
* which instead has been deserialized using the best available
|
||||||
|
* supertype
|
||||||
|
*/
|
||||||
|
public static final String EXPECTED_TYPE_PROPERTY = "expectedtype";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DateTime Pattern to be used to serialize Dates in every element
|
* DateTime Pattern to be used to serialize Dates in every element
|
||||||
*/
|
*/
|
||||||
|
@ -46,4 +53,8 @@ public interface Element extends Serializable {
|
||||||
@JsonGetter(value = SUPERTYPES_PROPERTY)
|
@JsonGetter(value = SUPERTYPES_PROPERTY)
|
||||||
public List<String> getSupertypes();
|
public List<String> getSupertypes();
|
||||||
|
|
||||||
|
@JsonInclude(Include.NON_EMPTY)
|
||||||
|
@JsonGetter(value = EXPECTED_TYPE_PROPERTY)
|
||||||
|
public String getExpectedtype();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||||
*
|
*
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
|
||||||
public interface IdentifiableElement extends Element {
|
public interface IdentifiableElement extends Element {
|
||||||
|
|
||||||
public static final String ID_PROPERTY = "id";
|
public static final String ID_PROPERTY = "id";
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.gcube.informationsystem.utils.Version;
|
||||||
*/
|
*/
|
||||||
@Abstract
|
@Abstract
|
||||||
@JsonIgnoreProperties(ignoreUnknown=true)
|
@JsonIgnoreProperties(ignoreUnknown=true)
|
||||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_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)
|
||||||
|
|
|
@ -16,7 +16,7 @@ import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
*
|
*
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
|
||||||
public interface ERElement extends IdentifiableElement {
|
public interface ERElement extends IdentifiableElement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +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.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_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)
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.gcube.informationsystem.utils.Version;
|
||||||
*/
|
*/
|
||||||
@Abstract
|
@Abstract
|
||||||
@JsonIgnoreProperties(ignoreUnknown=true)
|
@JsonIgnoreProperties(ignoreUnknown=true)
|
||||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY, Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_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={
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.gcube.informationsystem.utils.Version;
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
// @JsonIgnoreProperties(ignoreUnknown=true)
|
// @JsonIgnoreProperties(ignoreUnknown=true)
|
||||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_PROPERTY })
|
||||||
@JsonDeserialize(as=PropertyImpl.class)
|
@JsonDeserialize(as=PropertyImpl.class)
|
||||||
@TypeMetadata(name = Property.NAME, description = "This is the base type for any Property", version = Version.MINIMAL_VERSION_STRING)
|
@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)
|
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||||
|
|
|
@ -35,7 +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.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY, Relation.PROPAGATION_CONSTRAINT_PROPERTY })
|
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, Element.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_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)
|
||||||
|
|
|
@ -57,6 +57,9 @@ public class ElementDeserializer<ISM extends Element> extends StdDeserializer<IS
|
||||||
List<TextNode> toBeKeepSuperClasses = new ArrayList<>();
|
List<TextNode> toBeKeepSuperClasses = new ArrayList<>();
|
||||||
|
|
||||||
ObjectNode objectNode = (ObjectNode) treeNode;
|
ObjectNode objectNode = (ObjectNode) treeNode;
|
||||||
|
if(!objectNode.has(Element.EXPECTED_TYPE_PROPERTY)) {
|
||||||
|
objectNode.set(Element.EXPECTED_TYPE_PROPERTY, objectNode.get(Element.TYPE_PROPERTY));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JsonNode superClassesTreeNode = objectNode
|
JsonNode superClassesTreeNode = objectNode
|
||||||
|
|
|
@ -204,22 +204,20 @@ public abstract class ElementMapper {
|
||||||
String unknownType = jsonNode.get(Element.TYPE_PROPERTY).asText();
|
String unknownType = jsonNode.get(Element.TYPE_PROPERTY).asText();
|
||||||
ArrayNode arrayNode = (ArrayNode) jsonNode.get(Element.SUPERTYPES_PROPERTY);
|
ArrayNode arrayNode = (ArrayNode) jsonNode.get(Element.SUPERTYPES_PROPERTY);
|
||||||
|
|
||||||
// TODO save original class and superclasses
|
String candidatedSupertype = null;
|
||||||
|
|
||||||
String candidatedSuperClass = null;
|
|
||||||
for(int i = 0; i < arrayNode.size(); i++) {
|
for(int i = 0; i < arrayNode.size(); i++) {
|
||||||
String superClass = arrayNode.get(i).asText();
|
String superType = arrayNode.get(i).asText();
|
||||||
if(knownTypes.containsKey(superClass)) {
|
if(knownTypes.containsKey(superType)) {
|
||||||
candidatedSuperClass = superClass;
|
candidatedSupertype = superType;
|
||||||
try {
|
try {
|
||||||
// Checking if it is one of the base type. In some cases we need to use dummy
|
// Checking if it is one of the base type. In some cases we need to use dummy
|
||||||
// implementation
|
// implementation
|
||||||
AccessType accessType = Enum.valueOf(AccessType.class, superClass.toUpperCase());
|
AccessType accessType = AccessType.getAccessType(superType);
|
||||||
// It is one of the BaseType.
|
// It is one of the BaseType.
|
||||||
// Looking if we need to set the dummy implementation class
|
// Looking if we need to set the dummy implementation class
|
||||||
if(accessType.getDummyImplementationClass()!=null) {
|
if(accessType.getDummyImplementationClass()!=null) {
|
||||||
// This should not happen because the type has been assigned already to the dummy class.
|
// This should not happen because the type has been assigned already to the dummy class.
|
||||||
candidatedSuperClass = accessType.getDummyImplementationClass().getSimpleName();
|
candidatedSupertype = accessType.getDummyImplementationClass().getSimpleName();
|
||||||
}
|
}
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
// can continue discovery
|
// can continue discovery
|
||||||
|
@ -228,8 +226,12 @@ public abstract class ElementMapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(candidatedSuperClass!=null) {
|
if(candidatedSupertype!=null) {
|
||||||
((ObjectNode) jsonNode).set(Element.TYPE_PROPERTY, new TextNode(candidatedSuperClass));
|
if(!jsonNode.has(Element.EXPECTED_TYPE_PROPERTY)) {
|
||||||
|
((ObjectNode) jsonNode).set(Element.EXPECTED_TYPE_PROPERTY, jsonNode.get(Element.TYPE_PROPERTY));
|
||||||
|
}
|
||||||
|
((ObjectNode) jsonNode).set(Element.TYPE_PROPERTY, new TextNode(candidatedSupertype));
|
||||||
|
((ObjectNode) jsonNode).remove(Element.SUPERTYPES_PROPERTY);
|
||||||
return jsonNode;
|
return jsonNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +316,7 @@ public abstract class ElementMapper {
|
||||||
JsonNode jsonNode = mapper.readTree(string);
|
JsonNode jsonNode = mapper.readTree(string);
|
||||||
jsonNode = analizeFullJson(jsonNode);
|
jsonNode = analizeFullJson(jsonNode);
|
||||||
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
|
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <El extends Element> List<El> unmarshalList(Class<El> clz, String string)
|
public static <El extends Element> List<El> unmarshalList(Class<El> clz, String string)
|
||||||
|
|
|
@ -62,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 List<String> supertypes;
|
||||||
|
protected String expectedtype;
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
protected String description;
|
protected String description;
|
||||||
|
@ -301,4 +302,10 @@ public class TypeImpl implements Type {
|
||||||
public List<String> getSupertypes() {
|
public List<String> getSupertypes() {
|
||||||
return this.supertypes;
|
return this.supertypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExpectedtype() {
|
||||||
|
return this.expectedtype;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +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;
|
protected List<String> supertypes;
|
||||||
|
protected String expectedtype;
|
||||||
|
|
||||||
private String name= "";
|
private String name= "";
|
||||||
private String description= "";
|
private String description= "";
|
||||||
|
@ -294,4 +295,10 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
|
||||||
public List<String> getSupertypes() {
|
public List<String> getSupertypes() {
|
||||||
return this.supertypes;
|
return this.supertypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExpectedtype() {
|
||||||
|
return this.expectedtype;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue