Fixing model

This commit is contained in:
Luca Frosini 2020-02-03 10:51:29 +01:00
parent 05d6f6796d
commit 0709706ddc
33 changed files with 359 additions and 343 deletions

View File

@ -1,56 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.base.impl;
import java.io.StringWriter;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ER.NAME)
public abstract class ERImpl extends ElementImpl implements ER {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -494123926950181618L;
protected Header header;
public ERImpl(){
super();
}
@Override
public Header getHeader() {
return header;
}
@Override
public void setHeader(Header header){
this.header = header;
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ISMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ISMapper.marshal(this.header, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
}

View File

@ -6,7 +6,7 @@ package org.gcube.informationsystem.base.impl;
import java.io.StringWriter;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -18,16 +18,12 @@ public class ElementImpl implements Element {
*
*/
private static final long serialVersionUID = 7338083489551084860L;
public ElementImpl(){
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ISMapper.marshal(this, stringWriter);
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
return super.toString();

View File

@ -2,25 +2,25 @@ package org.gcube.informationsystem.base.impl.entities;
import java.io.StringWriter;
import org.gcube.informationsystem.base.impl.ERImpl;
import org.gcube.informationsystem.base.impl.ElementImpl;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value=EntityElement.NAME)
public abstract class EntityElementImpl extends ERImpl implements Entity {
public abstract class EntityElementImpl extends ElementImpl implements EntityElement {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -4488771434017342703L;
protected Header header;
protected EntityElementImpl(){
super();
this.header = null;
}
@Override
@ -37,11 +37,11 @@ public abstract class EntityElementImpl extends ERImpl implements Entity {
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ISMapper.marshal(this, stringWriter);
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ISMapper.marshal(this.header, stringWriter);
ElementMapper.marshal(this.header, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();

View File

@ -1,24 +1,27 @@
package org.gcube.informationsystem.base.impl.relations;
import org.gcube.informationsystem.base.impl.ERImpl;
import org.gcube.informationsystem.base.impl.ElementImpl;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value=RelationElement.NAME)
public abstract class RelationElementImpl<S extends EntityElement, T extends EntityElement> extends ERImpl implements RelationElement<S, T> {
public abstract class RelationElementImpl<S extends EntityElement, T extends EntityElement> extends ElementImpl implements RelationElement<S, T> {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 28704968813390512L;
protected Header header;
protected S source;
protected T target;
protected RelationElementImpl() {
super();
super();
}
protected RelationElementImpl(S source, T target) {
@ -27,6 +30,16 @@ public abstract class RelationElementImpl<S extends EntityElement, T extends Ent
this.target = target;
}
@Override
public Header getHeader() {
return header;
}
@Override
public void setHeader(Header header){
this.header = header;
}
@Override
public S getSource() {
return source;

View File

@ -1,23 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.base.reference;
import org.gcube.informationsystem.model.reference.properties.Header;
/**
* @author Luca Frosini (ISTI - CNR)
* Basic Interface for all Entity and Relations
*/
// @JsonDeserialize(as=ERImpl.class) Do not uncomment to manage subclasses
// @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = ER.HEADER_PROPERTY)
public interface ER extends Element {
public static final String NAME = "ER"; //ER.class.getSimpleName();
public static final String HEADER_PROPERTY = "header";
public Header getHeader();
public void setHeader(Header header);
}

View File

@ -0,0 +1,16 @@
package org.gcube.informationsystem.base.reference;
import org.gcube.informationsystem.model.reference.properties.Header;
/**
* @author Luca Frosini (ISTI - CNR)
* this is just a useful interface
*/
public interface IdentifiableElement extends Element {
public static final String HEADER_PROPERTY = "header";
public Header getHeader();
public void setHeader(Header header);
}

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.base.reference.entities;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
@ -10,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonDeserialize(as=EntityElementImpl.class) Do not uncomment to manage subclasses
public interface EntityElement extends ER {
public interface EntityElement extends Element, IdentifiableElement {
public static final String NAME = "EntityElement"; //Entity.class.getSimpleName();

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.base.reference.relations;
import org.gcube.informationsystem.base.reference.ER;
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.properties.Header;
import org.gcube.informationsystem.types.annotations.Abstract;
@ -11,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Abstract
//@JsonDeserialize(as=RelationElementImpl.class) Do not uncomment to manage subclasses
public interface RelationElement<S extends EntityElement, T extends EntityElement> extends ER {
public interface RelationElement<S extends EntityElement, T extends EntityElement> extends Element, IdentifiableElement {
public static final String NAME = "RelationElement"; // RelationElement.class.getSimpleName();

View File

@ -11,7 +11,7 @@ import java.util.Set;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName;
@ -79,8 +79,8 @@ public abstract class FacetImpl extends EntityImpl implements Facet {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) value;
if(map.containsKey(Element.CLASS_PROPERTY)) {
String reserialized = ISMapper.getObjectMapper().writeValueAsString(map);
Property property = ISMapper.unmarshal(Property.class, reserialized);
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
Property property = ElementMapper.unmarshal(Property.class, reserialized);
value = property;
}
}

View File

@ -15,7 +15,7 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName;
@ -107,8 +107,8 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) value;
if(map.containsKey(Element.CLASS_PROPERTY)) {
String reserialized = ISMapper.getObjectMapper().writeValueAsString(map);
Property property = ISMapper.unmarshal(Property.class, reserialized);
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
Property property = ElementMapper.unmarshal(Property.class, reserialized);
value = property;
}
}

View File

@ -1,12 +1,25 @@
package org.gcube.informationsystem.types;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
import org.gcube.informationsystem.types.reference.relations.RelationType;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -15,45 +28,74 @@ public class TypeBinder {
private final static String NAME = "NAME";
public static String serializeTypeDefinition(TypeDefinition typeDefinition) throws Exception{
String json = ISMapper.marshal(typeDefinition);
return json;
protected static final ObjectMapper mapper;
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerSubtypes(Type.class);
mapper.registerSubtypes(EntityType.class);
mapper.registerSubtypes(ResourceType.class);
mapper.registerSubtypes(FacetType.class);
mapper.registerSubtypes(RelationType.class);
mapper.registerSubtypes(IsRelatedToType.class);
mapper.registerSubtypes(ConsistsOfType.class);
mapper.registerSubtypes(PropertyType.class);
mapper.registerSubtypes(PropertyDefinition.class);
mapper.registerSubtypes(LinkedEntity.class);
// TODO
// mapper.registerSubtypes(LinkedResource.class);
// mapper.registerSubtypes(LinkedFacet.class);
}
public static <ISM extends Element> String serializeType(Class<ISM> type) throws Exception{
TypeDefinition typeDefinition = createTypeDefinition(type);
return ISMapper.marshal(typeDefinition);
public static String serializeTypeDefinition(Type type) throws Exception{
String json = mapper.writeValueAsString(type);
return json;
}
public static TypeDefinition deserializeTypeDefinition(String json) throws Exception{
TypeDefinition readValue = ISMapper.unmarshal(TypeDefinition.class, json);
return readValue;
public static Type deserializeTypeDefinition(String json) throws Exception{
Type type = mapper.readValue(json, Type.class);
return type;
}
public static <ISM extends Element> String serializeTypeDefinitions(List<TypeDefinition> typeDefinitions) throws Exception{
String json = ISMapper.marshal(typeDefinitions);
return json;
public static String serializeTypeDefinitions(List<Type> typeDefinitions) throws Exception{
JavaType javaType = mapper.getTypeFactory().constructCollectionType(List.class, Type.class);
return mapper.writerFor(javaType).writeValueAsString(typeDefinitions);
}
public static List<TypeDefinition> deserializeTypeDefinitions(String json) throws Exception{
List<TypeDefinition> list = ISMapper.unmarshalList(TypeDefinition.class, json);
return list;
public static List<Type> deserializeTypeDefinitions(String json) throws Exception{
JavaType javaType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Type.class);
return mapper.readValue(json, javaType);
}
public static <ISM extends Element> TypeDefinition createTypeDefinition(Class<ISM> clz) {
TypeDefinition typeDefinition = TypeDefinitionImpl.getInstance(clz);
return typeDefinition;
// TODO move somewhere else, probably in Element
public static <E extends Element> Type createTypeDefinition(Class<E> clz) {
Type type = TypeImpl.getInstance(clz);
return type;
}
public static <E extends Element> String serializeType(Class<E> clz) throws Exception{
Type type = createTypeDefinition(clz);
return serializeTypeDefinition(type);
}
public static String getType(Class<? extends Element> clz){
return getStaticStringFieldByName(clz, NAME, clz.getSimpleName());
}
public static String getStaticStringFieldByName(Class<? extends Element> type, String fieldName, String defaultValue){
public static String getStaticStringFieldByName(Class<? extends Element> clz, String fieldName, String defaultValue){
Field field;
try {
field = type.getDeclaredField(fieldName);
field = clz.getDeclaredField(fieldName);
field.setAccessible(true);
return (String) field.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {

View File

@ -1,21 +0,0 @@
package org.gcube.informationsystem.types.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.informationsystem.model.reference.entities.Facet;
/**
* @author Luca Frosini (ISTI - CNR)
* Provide a way to identify a Key for a
* {@link Facet}
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Key {
String[] fields() default {};
}

View File

@ -6,12 +6,11 @@ import java.lang.reflect.TypeVariable;
import java.util.HashSet;
import java.util.Set;
import org.gcube.informationsystem.base.impl.ERImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
@ -19,27 +18,28 @@ import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
import org.gcube.informationsystem.types.impl.relations.RelationTypeImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
// @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
@JsonTypeName(value=TypeDefinition.NAME)
public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
public class TypeImpl implements Type {
private static Logger logger = LoggerFactory.getLogger(TypeImpl.class);
/**
* Generated Serial Version UID
* Generated Serial version UID
*/
private static final long serialVersionUID = 2698204820689338513L;
private static Logger logger = LoggerFactory.getLogger(TypeDefinitionImpl.class);
private static final long serialVersionUID = -4333954207969059451L;
public final static String DESCRIPTION = "DESCRIPTION";
protected Header header;
protected String name;
protected String description;
@JsonProperty(value="abstract")
@ -48,7 +48,7 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
protected Set<PropertyDefinition> properties;
protected <ISM extends Element> Set<String> retrieveSuperClasses(Class<? extends ISM> type, Class<ISM> baseClass, String topSuperClass){
protected <E extends Element> Set<String> retrieveSuperClasses(Class<? extends E> type, Class<E> baseClass, String topSuperClass){
Set<String> interfaceList = new HashSet<>();
if(type==baseClass){
@ -104,8 +104,8 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
}
@SuppressWarnings({"rawtypes", "unchecked"})
public static TypeDefinition getInstance(Class<? extends Element> clz) {
TypeDefinition typeDefinition = null;
public static Type getInstance(Class<? extends Element> clz) {
Type typeDefinition = null;
try {
if(EntityElement.class.isAssignableFrom(clz)) {
typeDefinition = EntityTypeImpl.getEntityTypeDefinitionInstance((Class<? extends EntityElement>) clz);
@ -116,8 +116,8 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
} else if(PropertyElement.class.isAssignableFrom(clz)){
typeDefinition = new PropertyTypeImpl(clz);
return typeDefinition;
} else if(TypeDefinition.class.isAssignableFrom(clz)) {
typeDefinition = new TypeDefinitionImpl(clz);
} else if(Type.class.isAssignableFrom(clz)) {
typeDefinition = new TypeImpl(clz);
return typeDefinition;
} else {
throw new RuntimeException("Serialization required");
@ -129,9 +129,9 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
}
}
protected TypeDefinitionImpl() {}
protected TypeImpl() {}
protected TypeDefinitionImpl(Class<? extends Element> clz) {
protected TypeImpl(Class<? extends Element> clz) {
this.name = TypeBinder.getType(clz);
this.description = TypeBinder.getStaticStringFieldByName(clz, DESCRIPTION, "");
this.abstractType = false;
@ -140,12 +140,19 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
this.abstractType = true;
}
if(!Resource.class.isAssignableFrom(clz)) {
this.properties = retrieveListOfProperties(clz);
}
}
@Override
public Header getHeader() {
return header;
}
@Override
public void setHeader(Header header){
this.header = header;
}
@Override
public String getName() {
return name;
@ -166,9 +173,8 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
return superClasses;
}
@Override
@JsonInclude(Include.NON_EMPTY)
public Set<PropertyDefinition> getProperties() {
return properties;
}
}

View File

@ -7,9 +7,9 @@ import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import com.fasterxml.jackson.annotation.JsonTypeName;
@ -17,7 +17,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=EntityType.NAME)
public class EntityTypeImpl extends TypeDefinitionImpl implements EntityType {
public class EntityTypeImpl extends TypeImpl implements EntityType {
/**
* Generated Serial Version UID
@ -60,9 +60,11 @@ public class EntityTypeImpl extends TypeDefinitionImpl implements EntityType {
} else {
throw new RuntimeException("Type Hierachy Error for class " + clz.getSimpleName());
}
this.properties = retrieveListOfProperties(clz);
}
/*
* Java does not support multiple inheritance.
* TypeDefinitionImpl is the superclass so that this class does not inherits the methods and field of BaseRelationImpl
@ -85,11 +87,11 @@ public class EntityTypeImpl extends TypeDefinitionImpl implements EntityType {
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ISMapper.marshal(this, stringWriter);
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ISMapper.marshal(this.header, stringWriter);
ElementMapper.marshal(this.header, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();

View File

@ -1,8 +1,11 @@
package org.gcube.informationsystem.types.impl.entities;
import java.util.Set;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import com.fasterxml.jackson.annotation.JsonTypeName;
@ -17,15 +20,21 @@ public class FacetTypeImpl extends EntityTypeImpl implements FacetType {
*/
private static final long serialVersionUID = 6268161046955738969L;
protected Set<PropertyDefinition> properties;
protected FacetTypeImpl() {
super();
}
public FacetTypeImpl(Class<? extends Facet> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, Facet.class, Entity.NAME);
this.properties = retrieveListOfProperties(clz);
}
@Override
public Set<PropertyDefinition> getProperties() {
return properties;
}
}

View File

@ -12,7 +12,7 @@ import org.gcube.informationsystem.types.OrientDBType;
import org.gcube.informationsystem.types.OrientDBType.OType;
import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -29,7 +29,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
*/
private static final long serialVersionUID = -5925314595659292025L;
private static Logger logger = LoggerFactory.getLogger(TypeDefinitionImpl.class);
private static Logger logger = LoggerFactory.getLogger(TypeImpl.class);
public final static String UUID_PATTERN = "^([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}$";
public final static String URI_PATTERN = null;

View File

@ -1,13 +1,16 @@
package org.gcube.informationsystem.types.impl.properties;
import java.util.Set;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value = PropertyType.NAME)
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeDefinitionImpl
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
implements PropertyType<P> {
/**
@ -15,6 +18,8 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeDefin
*/
private static final long serialVersionUID = 7532701373450638829L;
protected Set<PropertyDefinition> properties;
protected PropertyTypeImpl() {
super();
}
@ -25,4 +30,9 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeDefin
clz == PropertyElement.class ? null : PropertyElement.NAME);
}
@Override
public Set<PropertyDefinition> getProperties() {
return properties;
}
}

View File

@ -10,7 +10,7 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.relations.RelationType;
@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value = RelationType.NAME)
public class RelationTypeImpl<S extends EntityType, T extends EntityType>
extends TypeDefinitionImpl implements RelationType<S,T> {
extends TypeImpl implements RelationType<S,T> {
/**
* Generated Serial Version UID
@ -61,6 +61,8 @@ public class RelationTypeImpl<S extends EntityType, T extends EntityType>
throw new RuntimeException("Type Hierachy Error");
}
this.properties = retrieveListOfProperties(clz);
discoverSourceAndTarget(clz);
}

View File

@ -0,0 +1,30 @@
package org.gcube.informationsystem.types.reference;
import java.util.Set;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.types.annotations.Abstract;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonDeserialize(as=TypeImpl.class) Do not uncomment to manage subclasses
public interface Type extends IdentifiableElement, TypeWithProperties {
public static final String NAME = "Type"; //Type.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
public static final String DESCRIPTION_PROPERTY = "description";
public static final String ABSTRACT_PROPERTY = "abstract";
public static final String TYPE_SUPERCLASSES_PROPERTY = "superClasses";
public String getName();
public String getDescription();
public boolean isAbstract();
public Set<String> getSuperClasses();
}

View File

@ -1,40 +0,0 @@
package org.gcube.informationsystem.types.reference;
import java.util.Set;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonDeserialize(as=TypeDefinitionImpl.class) Do not uncomment to manage subclasses
public interface TypeDefinition extends ER {
public static final String NAME = "TypeDefinition"; //TypeDefinition.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
public static final String DESCRIPTION_PROPERTY = "description";
public static final String ABSTRACT_PROPERTY = "abstract";
public static final String TYPE_SUPERCLASSES_PROPERTY = "superClasses";
public static final String PROPERTIES_PROPERTY = "properties";
@ISProperty(name = NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@ISProperty(name = DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@ISProperty(name = ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@ISProperty(name = TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@ISProperty(name = PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
}

View File

@ -0,0 +1,12 @@
package org.gcube.informationsystem.types.reference;
import java.util.Set;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
public interface TypeWithProperties {
public static final String PROPERTIES_PROPERTY = "properties";
public Set<PropertyDefinition> getProperties();
}

View File

@ -5,39 +5,35 @@ import java.util.Set;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.Type;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = EntityTypeImpl.class)
public interface EntityType extends TypeDefinition, EntityElement {
public interface EntityType extends Type, EntityElement {
public static final String NAME = "EntityType"; //EntityType.class.getSimpleName();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = TypeDefinition.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@Override
@ISProperty(name = TypeDefinition.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = Type.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@Override
@ISProperty(name = TypeDefinition.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@Override
@ISProperty(name = TypeDefinition.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@Override
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */

View File

@ -1,15 +1,23 @@
package org.gcube.informationsystem.types.reference.entities;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import java.util.Set;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.entities.FacetTypeImpl;
import org.gcube.informationsystem.types.reference.TypeWithProperties;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = FacetTypeImpl.class)
public interface FacetType extends EntityType, EntityElement {
public interface FacetType extends EntityType {
public static final String NAME = "FacetType"; //FacetTypeDefinition.class.getSimpleName();
public static final String NAME = "FacetType"; //FacetType.class.getSimpleName();
@ISProperty(name = TypeWithProperties.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
}

View File

@ -2,23 +2,24 @@ package org.gcube.informationsystem.types.reference.properties;
import java.util.Set;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.TypeWithProperties;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = PropertyTypeImpl.class)
public interface PropertyType<P extends PropertyElement> extends TypeDefinition, PropertyElement {
public interface PropertyType<P extends PropertyElement> extends PropertyElement, Type {
public static final String NAME = "PropertyType"; // PropertyTypeDefinition.class.getSimpleName();
@ISProperty(name=ER.HEADER_PROPERTY, mandatory=true, nullable=false)
@ISProperty(name=IdentifiableElement.HEADER_PROPERTY, mandatory=true, nullable=false)
public Header getHeader();
public void setHeader(Header header);
@ -26,23 +27,22 @@ public interface PropertyType<P extends PropertyElement> extends TypeDefinition,
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = TypeDefinition.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@Override
@ISProperty(name = TypeDefinition.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = Type.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@Override
@ISProperty(name = TypeDefinition.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@Override
@ISProperty(name = TypeDefinition.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@Override
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = TypeWithProperties.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */

View File

@ -5,7 +5,8 @@ import java.util.Set;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.relations.RelationTypeImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.TypeWithProperties;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
@ -15,30 +16,30 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = RelationTypeImpl.class)
public interface RelationType<S extends EntityType, T extends EntityType>
extends TypeDefinition, RelationElement<S,T> {
extends Type, RelationElement<S,T> {
public static final String NAME = "RelationType"; // RelationType.class.getSimpleName();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = TypeDefinition.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@Override
@ISProperty(name = TypeDefinition.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = Type.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@Override
@ISProperty(name = TypeDefinition.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@Override
@ISProperty(name = TypeDefinition.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = Type.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@Override
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = TypeWithProperties.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
@Override

View File

@ -11,8 +11,8 @@ import java.util.ServiceLoader;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.utils.discovery.ElementSpecilizationDiscovery;
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
import org.gcube.informationsystem.utils.discovery.SchemaAction;
import org.slf4j.Logger;
@ -31,9 +31,9 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
* @author Luca Frosini (ISTI - CNR)
*/
@SuppressWarnings("unchecked")
public abstract class ISMapper {
public abstract class ElementMapper {
private static Logger logger = LoggerFactory.getLogger(ISMapper.class);
private static Logger logger = LoggerFactory.getLogger(ElementMapper.class);
protected static final ObjectMapper mapper;
@ -50,22 +50,26 @@ public abstract class ISMapper {
List<Package> packages = new ArrayList<Package>();
Class<TypeDefinition> tdClz = TypeDefinition.class;
ISMapper.registerSubtypes(tdClz);
/*
Class<Type> tdClz = Type.class;
ElementMapper.registerSubtypes(tdClz);
packages.add(tdClz.getPackage());
*/
AccessType[] accessTypes = AccessType.values();
for(AccessType accessType : accessTypes) {
@SuppressWarnings("rawtypes")
Class clz = accessType.getTypeClass();
Class<Element> dummyClz = accessType.getDummyImplementationClass();
if(dummyClz != null) {
SimpleModule isModule = new SimpleModule(accessType.getName());
isModule.addDeserializer(clz, new ElementDeserializer<>(clz, mapper));
mapper.registerModule(isModule);
ISMapper.registerSubtypes(dummyClz);
if(!Type.class.isAssignableFrom(clz)) {
Class<Element> dummyClz = accessType.getDummyImplementationClass();
if(dummyClz != null) {
SimpleModule isModule = new SimpleModule(accessType.getName());
isModule.addDeserializer(clz, new ElementDeserializer<>(clz, mapper));
mapper.registerModule(isModule);
ElementMapper.registerSubtypes(dummyClz);
}
packages.add(clz.getPackage());
}
packages.add(clz.getPackage());
}
registerPackages(packages);
@ -80,7 +84,7 @@ public abstract class ISMapper {
public static void registerPackages(List<Package> packages) {
SchemaAction schemaAction = new ISMappingAction();
try {
ISMDiscovery.manageISM(schemaAction, packages);
ElementSpecilizationDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {
logger.error("Error registering types", e);
}
@ -90,14 +94,14 @@ public abstract class ISMapper {
public static void registerPackages(Package... packages) {
SchemaAction schemaAction = new ISMappingAction();
try {
ISMDiscovery.manageISM(schemaAction, packages);
ElementSpecilizationDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {
logger.error("Error registering types", e);
}
}
public static <ISM extends Element> void registerSubtypes(Class<ISM>... classes) {
public static <El extends Element> void registerSubtypes(Class<El>... classes) {
mapper.registerSubtypes(classes);
}
@ -137,7 +141,7 @@ public abstract class ISMapper {
* @return the String serialization of a given resource
* @throws JsonProcessingException
*/
public static <ISM extends Element> String marshal(ISM object) throws JsonProcessingException {
public static <El extends Element> String marshal(El object) throws JsonProcessingException {
return mapper.writeValueAsString(object);
}
@ -147,7 +151,7 @@ public abstract class ISMapper {
* @return the String serialization of a given list
* @throws JsonProcessingException
*/
public static <ISM extends Element> String marshal(List<ISM> list) throws JsonProcessingException {
public static <El extends Element> String marshal(List<El> list) throws JsonProcessingException {
JavaType type = mapper.getTypeFactory().constructCollectionType(List.class, Element.class);
return mapper.writerFor(type).writeValueAsString(list);
}
@ -158,7 +162,7 @@ public abstract class ISMapper {
* @return the String serialization of a given array
* @throws JsonProcessingException
*/
public static <ISM extends Element> String marshal(ISM[] array) throws JsonProcessingException {
public static <El extends Element> String marshal(El[] array) throws JsonProcessingException {
return mapper.writeValueAsString(array);
}
@ -172,7 +176,7 @@ public abstract class ISMapper {
* @throws JsonMappingException
* @throws IOException
*/
public static <ISM extends Element> ISM unmarshal(Class<ISM> clz, Reader reader)
public static <El extends Element> El unmarshal(Class<El> clz, Reader reader)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(reader, clz);
}
@ -187,7 +191,7 @@ public abstract class ISMapper {
* @throws JsonMappingException
* @throws JsonParseException
*/
public static <ISM extends Element> ISM unmarshal(Class<ISM> clz, InputStream stream)
public static <El extends Element> El unmarshal(Class<El> clz, InputStream stream)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(stream, clz);
}

View File

@ -21,21 +21,21 @@ class ISMappingAction implements SchemaAction {
@Override
public <P extends PropertyElement> void managePropertyClass(Class<P> e)
throws Exception {
ISMapper.registerSubtypes(e);
ElementMapper.registerSubtypes(e);
}
@SuppressWarnings("unchecked")
@Override
public <E extends EntityElement> void manageEntityClass(Class<E> e)
throws Exception {
ISMapper.registerSubtypes(e);
ElementMapper.registerSubtypes(e);
}
@SuppressWarnings("unchecked")
@Override
public <R extends RelationElement<? extends EntityElement, ? extends EntityElement>> void manageRelationClass(
Class<R> r) throws Exception {
ISMapper.registerSubtypes(r);
ElementMapper.registerSubtypes(r);
}
}

View File

@ -24,19 +24,19 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ISMDiscovery<ISM extends Element> {
public class ElementSpecilizationDiscovery<E extends Element> {
private static Logger logger = LoggerFactory.getLogger(ISMDiscovery.class);
private static Logger logger = LoggerFactory.getLogger(ElementSpecilizationDiscovery.class);
protected final Class<ISM> root;
protected final Class<E> root;
protected final List<Package> packages;
protected final List<Class<? extends ISM>> discovered;
protected final List<Class<? extends E>> discovered;
public List<Class<? extends ISM>> getDiscovered() {
public List<Class<? extends E>> getDiscovered() {
return discovered;
}
public ISMDiscovery(Class<ISM> root) {
public ElementSpecilizationDiscovery(Class<E> root) {
this.root = root;
this.packages = new ArrayList<>();
addPackage(root.getPackage());
@ -48,14 +48,14 @@ public class ISMDiscovery<ISM extends Element> {
packages.add(p);
}
protected void add(Class<? extends ISM> clz) {
protected void add(Class<? extends E> clz) {
if(!discovered.contains(clz)) {
discovered.add(clz);
logger.info("+ Added {}.", clz);
}
}
protected void analizeISM(Class<? extends ISM> clz) {
protected void analizeISM(Class<? extends E> clz) {
logger.trace("Analizyng {}", clz);
if(!clz.isInterface()) {
@ -77,7 +77,7 @@ public class ISMDiscovery<ISM extends Element> {
for(Class<?> interfaceClass : interfaces) {
@SuppressWarnings("unchecked")
Class<ISM> parent = (Class<ISM>) interfaceClass;
Class<E> parent = (Class<E>) interfaceClass;
analizeISM(parent);
}
@ -95,14 +95,14 @@ public class ISMDiscovery<ISM extends Element> {
Class<? extends PropertyElement> tClass = (Class<? extends PropertyElement>) t;
if(root.isAssignableFrom(tClass)) {
@SuppressWarnings("unchecked")
Class<ISM> type = (Class<ISM>) tClass;
Class<E> type = (Class<E>) tClass;
analizeISM(type);
}
}
} else if(root.isAssignableFrom(m.getReturnType())) {
@SuppressWarnings("unchecked")
Class<ISM> type = (Class<ISM>) m.getReturnType();
Class<E> type = (Class<E>) m.getReturnType();
analizeISM(type);
}
}
@ -117,7 +117,7 @@ public class ISMDiscovery<ISM extends Element> {
List<Class<?>> classes = ReflectionUtility.getClassesForPackage(p);
for(Class<?> clz : classes) {
@SuppressWarnings("unchecked")
Class<ISM> ism = (Class<ISM>) clz;
Class<E> ism = (Class<E>) clz;
analizeISM(ism);
}
}
@ -134,7 +134,7 @@ public class ISMDiscovery<ISM extends Element> {
@SuppressWarnings("unchecked")
public static void manageISM(SchemaAction schemaAction, Package... packages) throws Exception {
ISMDiscovery<PropertyElement> propertyDiscovery = new ISMDiscovery<>(PropertyElement.class);
ElementSpecilizationDiscovery<PropertyElement> propertyDiscovery = new ElementSpecilizationDiscovery<>(PropertyElement.class);
if(Objects.nonNull(packages)) {
Arrays.stream(packages).forEach(p -> propertyDiscovery.addPackage(p));
}
@ -144,7 +144,7 @@ public class ISMDiscovery<ISM extends Element> {
schemaAction.managePropertyClass(property);
}
ISMDiscovery<EntityElement> entityDiscovery = new ISMDiscovery<>(EntityElement.class);
ElementSpecilizationDiscovery<EntityElement> entityDiscovery = new ElementSpecilizationDiscovery<>(EntityElement.class);
if(Objects.nonNull(packages)) {
Arrays.stream(packages).forEach(p -> entityDiscovery.addPackage(p));
}
@ -161,7 +161,7 @@ public class ISMDiscovery<ISM extends Element> {
}
@SuppressWarnings("rawtypes")
ISMDiscovery<RelationElement> relationDiscovery = new ISMDiscovery<RelationElement>(RelationElement.class);
ElementSpecilizationDiscovery<RelationElement> relationDiscovery = new ElementSpecilizationDiscovery<RelationElement>(RelationElement.class);
if(Objects.nonNull(packages))
Arrays.stream(packages).forEach(p -> relationDiscovery.addPackage(p));
relationDiscovery.discover();

View File

@ -10,7 +10,7 @@ import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@ -63,10 +63,10 @@ public class EncryptedTest extends ContextTest {
Encrypted encrypted = new EncryptedImpl();
encrypted.setEncryptedValue(EncryptedImpl.encrypt(value));
String json = ISMapper.marshal(encrypted);
String json = ElementMapper.marshal(encrypted);
logger.debug(json);
Encrypted unmarshalled = ISMapper.unmarshal(Encrypted.class, json);
Encrypted unmarshalled = ElementMapper.unmarshal(Encrypted.class, json);
String decrypted = EncryptedImpl.decrypt(unmarshalled.getEncryptedValue());
Assert.assertTrue(decrypted.compareTo(value)==0);
@ -82,8 +82,8 @@ public class EncryptedTest extends ContextTest {
@Test
public void testEncryptedSpecilization() throws Exception {
String marshalled = "{\"@class\":\"MyEncrypted\",\"@superClasses\":[\"Encrypted\", \"Property\"],\"value\":\"Encrypted\"}";
Property property = ISMapper.unmarshal(Property.class, marshalled);
logger.debug(ISMapper.marshal(property));
Property property = ElementMapper.unmarshal(Property.class, marshalled);
logger.debug(ElementMapper.marshal(property));
}
@Test

View File

@ -2,7 +2,7 @@ package org.gcube.informationsystem.model.impl.entities;
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,30 +14,30 @@ public class ISContextTest {
@Test
public void testMarshalling() throws Exception {
Context gcube = new ContextImpl("gcube");
logger.debug("gcube : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(gcube))));
logger.debug("gcube : {}", ElementMapper.marshal(ElementMapper.unmarshal(Context.class, ElementMapper.marshal(gcube))));
Context devsec = new ContextImpl("devsec");
gcube.addChild(devsec);
logger.debug("devsec : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(devsec))));
logger.debug("devsec : {}", ElementMapper.marshal(ElementMapper.unmarshal(Context.class, ElementMapper.marshal(devsec))));
Context devVRE = new ContextImpl("devVRE");
devsec.addChild(devVRE);
logger.debug("devVRE : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(devVRE))));
logger.debug("devVRE : {}", ElementMapper.marshal(ElementMapper.unmarshal(Context.class, ElementMapper.marshal(devVRE))));
Context devNext = new ContextImpl("devNext");
gcube.addChild(devNext);
logger.debug("devNext : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(devNext))));
logger.debug("devNext : {}", ElementMapper.marshal(ElementMapper.unmarshal(Context.class, ElementMapper.marshal(devNext))));
Context NextNext = new ContextImpl("NextNext");
devNext.addChild(NextNext);
logger.debug("NextNext : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(NextNext))));
logger.debug("NextNext : {}", ElementMapper.marshal(ElementMapper.unmarshal(Context.class, ElementMapper.marshal(NextNext))));
logger.debug("------------------------------------");
logger.debug("gcube : {}", ISMapper.marshal(gcube));
logger.debug("devsec : {}", ISMapper.marshal(devsec));
logger.debug("devVRE : {}", ISMapper.marshal(devVRE));
logger.debug("devNext : {}", ISMapper.marshal(devNext));
logger.debug("NextNext : {}", ISMapper.marshal(NextNext));
logger.debug("gcube : {}", ElementMapper.marshal(gcube));
logger.debug("devsec : {}", ElementMapper.marshal(devsec));
logger.debug("devVRE : {}", ElementMapper.marshal(devVRE));
logger.debug("devNext : {}", ElementMapper.marshal(devNext));
logger.debug("NextNext : {}", ElementMapper.marshal(NextNext));
}
}

View File

@ -6,7 +6,7 @@ import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@ -24,10 +24,10 @@ public class HeaderTest {
header.lastUpdateTime = date;
header.creator = Header.UNKNOWN_USER;
String json = ISMapper.marshal(header);
String json = ElementMapper.marshal(header);
logger.debug(json);
Header h = ISMapper.unmarshal(Header.class, json);
Header h = ElementMapper.unmarshal(Header.class, json);
Assert.assertTrue(h.getCreationTime().compareTo(date)==0);
Assert.assertTrue(h.getLastUpdateTime().compareTo(date)==0);

View File

@ -26,7 +26,7 @@ import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
import org.gcube.informationsystem.types.reference.relations.RelationType;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -43,99 +43,106 @@ public class SerializationTest {
}
@Test
public void makeTypeDefinition() throws Exception{
public void makeFacetTypeDefinition() throws Exception{
EntityType facetTypeDefinitionSelf = (EntityType) TypeBinder.createTypeDefinition(FacetType.class);
logger.info(ElementMapper.marshal(facetTypeDefinitionSelf));
}
@Test
public void makeResourceTypeDefinition() throws Exception{
EntityType resourceTypeDefinitionSelf = (EntityType) TypeBinder.createTypeDefinition(ResourceType.class);
logger.info(ISMapper.marshal(resourceTypeDefinitionSelf));
logger.info(ElementMapper.marshal(resourceTypeDefinitionSelf));
}
@Test
public void testPropertyTypeDefinition() throws Exception{
@SuppressWarnings("unchecked")
PropertyType<PropertyElement> basePropertyTypeDefinition = (PropertyType<PropertyElement>) TypeBinder.createTypeDefinition(PropertyElement.class);
logger.info(ISMapper.marshal(basePropertyTypeDefinition));
logger.info(ElementMapper.marshal(basePropertyTypeDefinition));
@SuppressWarnings("unchecked")
PropertyType<Property> propertyTypeDefinition = (PropertyType<Property>) TypeBinder.createTypeDefinition(Property.class);
logger.info(ISMapper.marshal(propertyTypeDefinition));
logger.info(ElementMapper.marshal(propertyTypeDefinition));
@SuppressWarnings("unchecked")
PropertyType<Header> headerTypeDefinition = (PropertyType<Header>) TypeBinder.createTypeDefinition(Header.class);
logger.info(ISMapper.marshal(headerTypeDefinition));
logger.info(ElementMapper.marshal(headerTypeDefinition));
@SuppressWarnings("unchecked")
PropertyType<PropagationConstraint> propagationConstraintDefinition = (PropertyType<PropagationConstraint>) TypeBinder.createTypeDefinition(PropagationConstraint.class);
logger.info(ISMapper.marshal(propagationConstraintDefinition));
logger.info(ElementMapper.marshal(propagationConstraintDefinition));
@SuppressWarnings("unchecked")
PropertyType<Encrypted> encryptedTypeDefinition = (PropertyType<Encrypted>) TypeBinder.createTypeDefinition(Encrypted.class);
logger.info(ISMapper.marshal(encryptedTypeDefinition));
logger.info(ElementMapper.marshal(encryptedTypeDefinition));
@SuppressWarnings("unchecked")
PropertyType<PropertyDefinition> propertyDefinition = (PropertyType<PropertyDefinition>) TypeBinder.createTypeDefinition(PropertyDefinition.class);
logger.info(ISMapper.marshal(propertyDefinition));
logger.info(ElementMapper.marshal(propertyDefinition));
@SuppressWarnings("unchecked")
PropertyType<LinkedEntity> resourceEntryDefinition = (PropertyType<LinkedEntity>) TypeBinder.createTypeDefinition(LinkedEntity.class);
logger.info(ISMapper.marshal(resourceEntryDefinition));
logger.info(ElementMapper.marshal(resourceEntryDefinition));
}
@Test
public void testEntityTypeDefinition() throws Exception{
EntityType baseEntityTypeDefinition = (EntityType) TypeBinder.createTypeDefinition(EntityElement.class);
logger.info(ISMapper.marshal(baseEntityTypeDefinition));
logger.info(ElementMapper.marshal(baseEntityTypeDefinition));
EntityType entityTypeDefinition = (EntityType) TypeBinder.createTypeDefinition(Entity.class);
logger.info(ISMapper.marshal(entityTypeDefinition));
logger.info(ElementMapper.marshal(entityTypeDefinition));
ResourceType resourceTypeDefinition = (ResourceType) TypeBinder.createTypeDefinition(Resource.class);
logger.info(ISMapper.marshal(resourceTypeDefinition));
logger.info(ElementMapper.marshal(resourceTypeDefinition));
FacetType facetTypeDefinition = (FacetType) TypeBinder.createTypeDefinition(Facet.class);
logger.info(ISMapper.marshal(facetTypeDefinition));
logger.info(ElementMapper.marshal(facetTypeDefinition));
EntityType contextTypeDefinition = (EntityType) TypeBinder.createTypeDefinition(Context.class);
logger.info(ISMapper.marshal(contextTypeDefinition));
logger.info(ElementMapper.marshal(contextTypeDefinition));
EntityType entityTypeDefinitionSelf = (EntityType) TypeBinder.createTypeDefinition(EntityType.class);
logger.info(ISMapper.marshal(entityTypeDefinitionSelf));
logger.info(ElementMapper.marshal(entityTypeDefinitionSelf));
EntityType resourceTypeDefinitionSelf = (EntityType) TypeBinder.createTypeDefinition(ResourceType.class);
logger.info(ISMapper.marshal(resourceTypeDefinitionSelf));
logger.info(ElementMapper.marshal(resourceTypeDefinitionSelf));
EntityType facetTypeDefinitionSelf = (EntityType) TypeBinder.createTypeDefinition(FacetType.class);
logger.info(ISMapper.marshal(facetTypeDefinitionSelf));
logger.info(ElementMapper.marshal(facetTypeDefinitionSelf));
}
@Test
public void testRelationTypeDefinition() throws Exception{
@SuppressWarnings("unchecked")
RelationType<EntityType,EntityType> relationTypeDefinition = (RelationType<EntityType,EntityType>) TypeBinder.createTypeDefinition(Relation.class);
logger.info(ISMapper.marshal(relationTypeDefinition));
logger.info(ElementMapper.marshal(relationTypeDefinition));
IsRelatedToType isRelatedToTypeDefinition = (IsRelatedToType) TypeBinder.createTypeDefinition(IsRelatedTo.class);
logger.info(ISMapper.marshal(isRelatedToTypeDefinition));
logger.info(ElementMapper.marshal(isRelatedToTypeDefinition));
ConsistsOfType consistsOfTypeDefinition = (ConsistsOfType) TypeBinder.createTypeDefinition(ConsistsOf.class);
logger.info(ISMapper.marshal(consistsOfTypeDefinition));
logger.info(ElementMapper.marshal(consistsOfTypeDefinition));
@SuppressWarnings("unchecked")
RelationType<EntityType,EntityType> isParentOfTypeDefinition = (RelationType<EntityType,EntityType>) TypeBinder.createTypeDefinition(IsParentOf.class);
logger.info(ISMapper.marshal(isParentOfTypeDefinition));
logger.info(ElementMapper.marshal(isParentOfTypeDefinition));
@SuppressWarnings("unchecked")
RelationType<EntityType,EntityType> rtdSelf = (RelationType<EntityType,EntityType>) TypeBinder.createTypeDefinition(RelationType.class);
logger.info(ISMapper.marshal(rtdSelf));
logger.info(ElementMapper.marshal(rtdSelf));
@SuppressWarnings("unchecked")
RelationType<EntityType,EntityType> isRelatedToTypeDefinitionSelf = (RelationType<EntityType,EntityType>) TypeBinder.createTypeDefinition(IsRelatedToType.class);
logger.info(ISMapper.marshal(isRelatedToTypeDefinitionSelf));
logger.info(ElementMapper.marshal(isRelatedToTypeDefinitionSelf));
@SuppressWarnings("unchecked")
RelationType<EntityType,EntityType> consistsOfTypeDefinitionSelf = (RelationType<EntityType,EntityType>) TypeBinder.createTypeDefinition(ConsistsOfType.class);
logger.info(ISMapper.marshal(consistsOfTypeDefinitionSelf));
logger.info(ElementMapper.marshal(consistsOfTypeDefinitionSelf));
}
@Test

View File

@ -8,7 +8,7 @@ public class ISMDiscoveryTest {
@Test
public void testISMDIscovery() {
ISMDiscovery<PropertyElement> propertyDiscovery = new ISMDiscovery<>(PropertyElement.class);
ElementSpecilizationDiscovery<PropertyElement> propertyDiscovery = new ElementSpecilizationDiscovery<>(PropertyElement.class);
propertyDiscovery.analizeISM(PropertyType.class);
}
}