Fixing model

This commit is contained in:
Luca Frosini 2019-11-04 18:06:46 +01:00
parent a58eec0cb3
commit 770155d5c5
27 changed files with 155 additions and 125 deletions

View File

@ -4,43 +4,43 @@ import org.gcube.informationsystem.base.impl.ERImpl;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
public abstract class BaseRelationImpl<Out extends BaseEntity, In extends BaseEntity> extends ERImpl implements BaseRelation<Out, In> {
public abstract class BaseRelationImpl<S extends BaseEntity, T extends BaseEntity> extends ERImpl implements BaseRelation<S, T> {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 28704968813390512L;
protected Out source;
protected In target;
protected S source;
protected T target;
protected BaseRelationImpl() {
super();
}
protected BaseRelationImpl(Out source, In target) {
protected BaseRelationImpl(S source, T target) {
this();
this.source = source;
this.target = target;
}
@Override
public Out getSource() {
public S getSource() {
return source;
}
@Override
public void setSource(Out source) {
public void setSource(S source) {
this.source = source;
}
@Override
public In getTarget() {
public T getTarget() {
return target;
}
@Override
public void setTarget(In target) {
public void setTarget(T target) {
this.target = target;
}

View File

@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
@Abstract
//@JsonDeserialize(as=BaseRelationImpl.class) Do not uncomment to manage subclasses
public interface BaseRelation<Out extends BaseEntity, In extends BaseEntity> extends ER {
public interface BaseRelation<S extends BaseEntity, T extends BaseEntity> extends ER {
public static final String NAME = "BaseRelation"; // BaseRelation.class.getSimpleName();
@ -24,15 +24,15 @@ public interface BaseRelation<Out extends BaseEntity, In extends BaseEntity> ext
public Header getHeader();
@JsonGetter(value=SOURCE_PROPERTY)
public Out getSource();
public S getSource();
@JsonIgnore
public void setSource(Out source);
public void setSource(S source);
@JsonGetter(value=TARGET_PROPERTY)
public In getTarget();
public T getTarget();
@JsonIgnore
public void setTarget(In target);
public void setTarget(T target);
}

View File

@ -31,8 +31,8 @@ public final class ContextImpl extends BaseEntityImpl implements Context {
protected String name;
protected IsParentOf<Context, Context> parent;
protected List<IsParentOf<Context, Context>> children;
protected IsParentOf parent;
protected List<IsParentOf> children;
protected ContextImpl() {
super();
@ -64,7 +64,7 @@ public final class ContextImpl extends BaseEntityImpl implements Context {
}
@Override
public IsParentOf<Context, Context> getParent() {
public IsParentOf getParent() {
return parent;
}
@ -81,15 +81,15 @@ public final class ContextImpl extends BaseEntityImpl implements Context {
@Override
public void setParent(Context context) {
IsParentOf<Context, Context> isParentOf = null;
IsParentOf isParentOf = null;
if(context!=null) {
isParentOf = new IsParentOfImpl<Context, Context>(context, this);
isParentOf = new IsParentOfImpl(context, this);
}
setParent(isParentOf);
}
@JsonSetter(value=PARENT_PROPERTY)
protected void setParentFromJson(IsParentOf<Context, Context> isParentOf) throws JsonProcessingException {
protected void setParentFromJson(IsParentOf isParentOf) throws JsonProcessingException {
if(isParentOf!=null) {
Context parent = isParentOf.getSource();
isParentOf.setTarget(this);
@ -99,23 +99,23 @@ public final class ContextImpl extends BaseEntityImpl implements Context {
}
@Override
public void setParent(IsParentOf<Context, Context> isParentOf) {
public void setParent(IsParentOf isParentOf) {
this.parent = isParentOf;
}
@Override
public List<IsParentOf<Context, Context>> getChildren() {
public List<IsParentOf> getChildren() {
return children;
}
@JsonSetter(value=CHILDREN_PROPERTY)
protected void setChildrenFromJson(List<IsParentOf<Context, Context>> children) throws JsonProcessingException {
for(IsParentOf<Context, Context> isParentOf : children){
protected void setChildrenFromJson(List<IsParentOf> children) throws JsonProcessingException {
for(IsParentOf isParentOf : children){
addChildFromJson(isParentOf);
}
}
protected void addChildFromJson(IsParentOf<Context, Context> isParentOf) throws JsonProcessingException {
protected void addChildFromJson(IsParentOf isParentOf) throws JsonProcessingException {
isParentOf.setSource(this);
addChild(isParentOf);
}
@ -129,12 +129,12 @@ public final class ContextImpl extends BaseEntityImpl implements Context {
@Override
public void addChild(Context child) {
IsParentOf<Context, Context> isParentOf = new IsParentOfImpl<Context, Context>(this, child);
IsParentOf isParentOf = new IsParentOfImpl(this, child);
this.addChild(isParentOf);
}
@Override
public void addChild(IsParentOf<Context, Context> isParentOf) {
public void addChild(IsParentOf isParentOf) {
((ContextImpl) isParentOf.getTarget()).setParent(this);
children.add(isParentOf);
}

View File

@ -13,8 +13,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsParentOf.NAME)
public final class IsParentOfImpl<Out extends Context, In extends Context> extends
BaseRelationImpl<Out, In> implements IsParentOf<Out, In> {
public final class IsParentOfImpl extends BaseRelationImpl<Context, Context> implements IsParentOf {
/**
*
@ -25,7 +24,7 @@ public final class IsParentOfImpl<Out extends Context, In extends Context> exten
super();
}
public IsParentOfImpl(Out source, In target) {
public IsParentOfImpl(Context source, Context target) {
super(source, target);
}

View File

@ -37,7 +37,7 @@ public interface Context extends BaseEntity {
@JsonGetter
@JsonIgnoreProperties({ Relation.TARGET_PROPERTY })
public IsParentOf<Context, Context> getParent();
public IsParentOf getParent();
@JsonIgnore
public void setParent(UUID uuid);
@ -46,16 +46,16 @@ public interface Context extends BaseEntity {
public void setParent(Context context);
@JsonIgnore
public void setParent(IsParentOf<Context, Context> isParentOf);
public void setParent(IsParentOf isParentOf);
@JsonGetter
@JsonIgnoreProperties({ Relation.SOURCE_PROPERTY })
public List<IsParentOf<Context, Context>> getChildren();
public List<IsParentOf> getChildren();
public void addChild(UUID uuid);
public void addChild(Context child);
public void addChild(IsParentOf<Context, Context> isParentOf);
public void addChild(IsParentOf isParentOf);
}

View File

@ -17,22 +17,22 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isParentOf
*/
@JsonDeserialize(as = IsParentOfImpl.class)
public interface IsParentOf<Out extends Context, In extends Context> extends BaseRelation<Out,In> {
public interface IsParentOf extends BaseRelation<Context,Context> {
public static final String NAME = "IsParentOf"; //IsParentOf.class.getSimpleName();
@JsonIgnoreProperties({Context.PARENT_PROPERTY, Context.CHILDREN_PROPERTY})
@JsonGetter(value = SOURCE_PROPERTY)
public Out getSource();
public Context getSource();
@JsonIgnore
public void setSource(Out source);
public void setSource(Context source);
@JsonIgnoreProperties({Context.PARENT_PROPERTY, Context.CHILDREN_PROPERTY})
@JsonGetter(value = TARGET_PROPERTY)
public In getTarget();
public Context getTarget();
@JsonIgnore
public void setTarget(In target);
public void setTarget(Context target);
}

View File

@ -14,8 +14,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ConsistsOf.NAME)
public class ConsistsOfImpl<Out extends Resource, In extends Facet> extends
RelationImpl<Out, In> implements ConsistsOf<Out, In> {
public class ConsistsOfImpl<S extends Resource, T extends Facet> extends
RelationImpl<S, T> implements ConsistsOf<S, T> {
/**
* Generated Serial Version UID
@ -26,7 +26,7 @@ public class ConsistsOfImpl<Out extends Resource, In extends Facet> extends
super();
}
public ConsistsOfImpl(Out source, In target,
public ConsistsOfImpl(S source, T target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}

View File

@ -14,8 +14,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ConsistsOf.NAME)
public class DummyConsistsOf<Out extends Resource, In extends Facet> extends
ConsistsOfImpl<Out, In> implements ConsistsOf<Out, In> {
public class DummyConsistsOf<S extends Resource, T extends Facet> extends
ConsistsOfImpl<S, T> implements ConsistsOf<S, T> {
/**
* Generated Serial Version UID
@ -26,7 +26,7 @@ public class DummyConsistsOf<Out extends Resource, In extends Facet> extends
super();
}
public DummyConsistsOf(Out source, In target,
public DummyConsistsOf(S source, T target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}

View File

@ -13,8 +13,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedTo.NAME)
public class DummyIsRelatedTo<Out extends Resource, In extends Resource>
extends IsRelatedToImpl<Out, In> implements IsRelatedTo<Out, In>{
public class DummyIsRelatedTo<S extends Resource, T extends Resource>
extends IsRelatedToImpl<S, T> implements IsRelatedTo<S, T>{
/**
* Generated Serial Version UID
@ -25,7 +25,7 @@ public class DummyIsRelatedTo<Out extends Resource, In extends Resource>
super();
}
public DummyIsRelatedTo(Out source, In target,
public DummyIsRelatedTo(S source, T target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}

View File

@ -14,8 +14,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsIdentifiedBy.NAME)
public class IsIdentifiedByImpl<Out extends Resource, In extends Facet> extends
ConsistsOfImpl<Out, In> implements IsIdentifiedBy<Out, In> {
public class IsIdentifiedByImpl<S extends Resource, T extends Facet> extends
ConsistsOfImpl<S, T> implements IsIdentifiedBy<S, T> {
/**
* Generated Serial Version UID
@ -26,7 +26,7 @@ public class IsIdentifiedByImpl<Out extends Resource, In extends Facet> extends
super();
}
public IsIdentifiedByImpl(Out source, In target,
public IsIdentifiedByImpl(S source, T target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}

View File

@ -13,8 +13,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedTo.NAME)
public abstract class IsRelatedToImpl<Out extends Resource, In extends Resource> extends
RelationImpl<Out, In> implements IsRelatedTo<Out, In> {
public abstract class IsRelatedToImpl<S extends Resource, T extends Resource> extends
RelationImpl<S, T> implements IsRelatedTo<S, T> {
/**
* Generated Serial Version UID
@ -25,7 +25,7 @@ public abstract class IsRelatedToImpl<Out extends Resource, In extends Resource>
super();
}
public IsRelatedToImpl(Out source, In target,
public IsRelatedToImpl(S source, T target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}

View File

@ -11,6 +11,7 @@ import java.util.Set;
import org.gcube.informationsystem.base.impl.relations.BaseRelationImpl;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.model.reference.entities.Entity;
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;
@ -23,8 +24,8 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = Relation.NAME)
public abstract class RelationImpl<Out extends Entity, In extends Entity>
extends BaseRelationImpl<Out,In> implements Relation<Out, In> {
public abstract class RelationImpl<S extends Resource, T extends Entity>
extends BaseRelationImpl<S,T> implements Relation<S, T> {
/**
*
@ -48,7 +49,7 @@ public abstract class RelationImpl<Out extends Entity, In extends Entity>
this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY);
}
protected RelationImpl(Out source, In target,
protected RelationImpl(S source, T target,
PropagationConstraint propagationConstraint) {
this();
this.source = source;

View File

@ -11,8 +11,8 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#consistsOf
*/
// @JsonDeserialize(as=ConsistsOfImpl.class) Do not uncomment to manage subclasses
public interface ConsistsOf<Out extends Resource, In extends Facet>
extends Relation<Out, In> {
public interface ConsistsOf<S extends Resource, T extends Facet>
extends Relation<S, T> {
public static final String NAME = "ConsistsOf"; //ConsistsOf.class.getSimpleName();

View File

@ -14,8 +14,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isIdentifiedBy
*/
@JsonDeserialize(as=IsIdentifiedByImpl.class)
public interface IsIdentifiedBy<Out extends Resource, In extends Facet>
extends ConsistsOf<Out, In> {
public interface IsIdentifiedBy<S extends Resource, T extends Facet>
extends ConsistsOf<S, T> {
public static final String NAME = "IsIdentifiedBy"; //IsIdentifiedBy.class.getSimpleName();

View File

@ -13,8 +13,8 @@ import org.gcube.informationsystem.types.annotations.Abstract;
*/
@Abstract
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
public interface IsRelatedTo<Out extends Resource, In extends Resource>
extends Relation<Out, In> {
public interface IsRelatedTo<S extends Resource, T extends Resource>
extends Relation<S, T> {
public static final String NAME = "IsRelatedTo"; //IsRelatedTo.class.getSimpleName();

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
*/
@Abstract
// @JsonDeserialize(as=RelationImpl.class) Do not uncomment to manage subclasses
public interface Relation<Out extends Entity, In extends Entity> extends BaseRelation<Out,In> {
public interface Relation<S extends Resource, T extends Entity> extends BaseRelation<S,T> {
public static final String NAME = "Relation"; //Relation.class.getSimpleName();
@ -34,16 +34,16 @@ public interface Relation<Out extends Entity, In extends Entity> extends BaseRel
@JsonIgnoreProperties({Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY})
@JsonGetter(value = SOURCE_PROPERTY)
public Out getSource();
public S getSource();
@JsonIgnore
public void setSource(Out source);
public void setSource(S source);
@JsonGetter(value = TARGET_PROPERTY)
public In getTarget();
public T getTarget();
@JsonIgnore
public void setTarget(In target);
public void setTarget(T target);
@ISProperty(name = PROPAGATION_CONSTRAINT)
public PropagationConstraint getPropagationConstraint();

View File

@ -15,56 +15,34 @@ public class TypeBinder {
private final static String NAME = "NAME";
@SuppressWarnings("rawtypes")
public static String serializeTypeDefinition(TypeDefinition typeDefinition) throws Exception{
/*
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(typeDefinition);
*/
String json = ISMapper.marshal(typeDefinition);
return json;
}
public static <ISM extends ISManageable> String serializeType(Class<ISM> type) throws Exception{
TypeDefinition<ISM> typeDefinition = createTypeDefinition(type);
TypeDefinition typeDefinition = createTypeDefinition(type);
return ISMapper.marshal(typeDefinition);
}
@SuppressWarnings("rawtypes")
public static TypeDefinition deserializeTypeDefinition(String json) throws Exception{
/*
ObjectMapper mapper = new ObjectMapper();
@SuppressWarnings("unchecked")
TypeDefinition<ISM> readValue = mapper.readValue(json, TypeDefinition.class);
*/
TypeDefinition readValue = ISMapper.unmarshal(TypeDefinition.class, json);
return readValue;
}
public static <ISM extends ISManageable> String serializeTypeDefinitions(List<TypeDefinition<ISM>> typeDefinitions) throws Exception{
/*
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(typeDefinitions);
return json;
*/
public static <ISM extends ISManageable> String serializeTypeDefinitions(List<TypeDefinition> typeDefinitions) throws Exception{
String json = ISMapper.marshal(typeDefinitions);
return json;
}
@SuppressWarnings("rawtypes")
public static List<TypeDefinition> deserializeTypeDefinitions(String json) throws Exception{
/*
ObjectMapper mapper = new ObjectMapper();
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, TypeDefinition.class) ;
return mapper.readValue(json, type);
*/
List<TypeDefinition> list = ISMapper.unmarshalList(TypeDefinition.class, json);
return list;
}
public static <ISM extends ISManageable> TypeDefinition<ISM> createTypeDefinition(Class<ISM> clz) {
TypeDefinition<ISM> typeDefinition = TypeDefinitionImpl.getInstance(clz);
public static <ISM extends ISManageable> TypeDefinition createTypeDefinition(Class<ISM> clz) {
TypeDefinition typeDefinition = TypeDefinitionImpl.getInstance(clz);
return typeDefinition;
}

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.types.impl;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.util.HashSet;
import java.util.Set;
@ -28,7 +29,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
// @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
@JsonTypeName(value=TypeDefinition.NAME)
public class TypeDefinitionImpl<ISM extends ISManageable> extends ISManageableImpl implements TypeDefinition<ISM> {
public class TypeDefinitionImpl extends ISManageableImpl implements TypeDefinition {
/**
* Generated Serial Version UID
@ -94,11 +95,15 @@ public class TypeDefinitionImpl<ISM extends ISManageable> extends ISManageableIm
TypeVariable<?> typeVariable = (TypeVariable<?>) type;
java.lang.reflect.Type[] bounds = typeVariable.getBounds();
java.lang.reflect.Type t = bounds[0];
if(t instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) t;
return (Class<?>) parameterizedType.getRawType();
}
return (Class<?>) t;
}
@SuppressWarnings({"rawtypes", "unchecked"})
public static <ISM extends ISManageable> TypeDefinition<ISM> getInstance(Class<ISM> clz) {
public static TypeDefinition getInstance(Class<? extends ISManageable> clz) {
if(BaseEntity.class.isAssignableFrom(clz)) {
return new EntityTypeDefinitionImpl(clz);
} else if(BaseRelation.class.isAssignableFrom(clz)){
@ -114,7 +119,7 @@ public class TypeDefinitionImpl<ISM extends ISManageable> extends ISManageableIm
protected TypeDefinitionImpl() {}
protected TypeDefinitionImpl(Class<ISM> clz) {
protected TypeDefinitionImpl(Class<? extends ISManageable> clz) {
this.name = TypeBinder.getType(clz);
this.description = TypeBinder.getStaticStringFieldByName(clz, DESCRIPTION, "");
this.abstractType = false;

View File

@ -15,7 +15,7 @@ import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value=EntityTypeDefinition.NAME)
public final class EntityTypeDefinitionImpl<E extends BaseEntity> extends TypeDefinitionImpl<E> implements EntityTypeDefinition<E> {
public final class EntityTypeDefinitionImpl<E extends BaseEntity> extends TypeDefinitionImpl implements EntityTypeDefinition<E> {
/**
* Generated Serial Version UID

View File

@ -7,7 +7,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefini
import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value=PropertyTypeDefinition.NAME)
public final class PropertyTypeDefinitionImpl<P extends BaseProperty> extends TypeDefinitionImpl<P> implements PropertyTypeDefinition<P> {
public final class PropertyTypeDefinitionImpl<P extends BaseProperty> extends TypeDefinitionImpl implements PropertyTypeDefinition<P> {
/**
* Generated Serial Version UID

View File

@ -1,11 +1,14 @@
package org.gcube.informationsystem.types.impl.relations;
import java.io.StringWriter;
import java.lang.reflect.ParameterizedType;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
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.model.reference.relations.Relation;
@ -19,8 +22,8 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value=RelationTypeDefinition.NAME)
public final class RelationTypeDefinitionImpl<Out extends BaseEntity, In extends BaseEntity, Rel extends BaseRelation<Out,In>>
extends TypeDefinitionImpl<Rel> implements RelationTypeDefinition<Out,In,Rel> {
public final class RelationTypeDefinitionImpl<ES extends EntityTypeDefinition<S>, ET extends EntityTypeDefinition<T>, S extends BaseEntity, T extends BaseEntity>
extends TypeDefinitionImpl implements RelationTypeDefinition<ES, ET, S,T> {
/**
* Generated Serial Version UID
@ -38,23 +41,23 @@ public final class RelationTypeDefinitionImpl<Out extends BaseEntity, In extends
super();
}
public RelationTypeDefinitionImpl(Class<Rel> clz) {
public RelationTypeDefinitionImpl(Class<? extends BaseRelation<S,T>> clz) {
super(clz);
if(IsRelatedTo.class.isAssignableFrom(clz)){
@SuppressWarnings({"unchecked", "rawtypes"})
Class<? extends IsRelatedTo> c = (Class<? extends IsRelatedTo>) clz;
@SuppressWarnings({"unchecked"})
Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>> c = (Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>>) clz;
this.superClasses = retrieveSuperClasses(c, IsRelatedTo.class, Relation.NAME);
} else if(ConsistsOf.class.isAssignableFrom(clz)) {
@SuppressWarnings({"unchecked", "rawtypes"})
Class<? extends ConsistsOf> c = (Class<? extends ConsistsOf>) clz;
@SuppressWarnings({"unchecked"})
Class<? extends ConsistsOf<? extends Resource, ? extends Facet>> c = (Class<? extends ConsistsOf<? extends Resource, ? extends Facet>>) clz;
this.superClasses = retrieveSuperClasses(c, ConsistsOf.class, Relation.NAME);
} else if(RelationTypeDefinition.class.isAssignableFrom(clz)){
@SuppressWarnings({"unchecked", "rawtypes"})
Class<? extends RelationTypeDefinition> c = (Class<? extends RelationTypeDefinition>) clz;
this.superClasses = retrieveSuperClasses(c, RelationTypeDefinition.class, BaseRelation.NAME);
} else if(IsParentOf.class.isAssignableFrom(clz)){
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings({"unchecked"})
Class<? extends IsParentOf> c = (Class<? extends IsParentOf>) clz;
this.superClasses = retrieveSuperClasses(c, IsParentOf.class, BaseRelation.NAME);
} else if(BaseRelation.class.isAssignableFrom(clz)){
@ -64,13 +67,23 @@ public final class RelationTypeDefinitionImpl<Out extends BaseEntity, In extends
}
java.lang.reflect.Type[] typeParameters = clz.getTypeParameters();
@SuppressWarnings("unchecked")
Class<Out> sourceClass = (Class<Out>) getGenericClass(typeParameters[0]);
@SuppressWarnings("unchecked")
Class<In> targetClass = (Class<In>) getGenericClass(typeParameters[1]);
if(typeParameters.length==0) {
typeParameters = ((ParameterizedType) clz.getGenericInterfaces()[0]).getActualTypeArguments();
@SuppressWarnings("unchecked")
Class<S> sourceClass = (Class<S>) typeParameters[0];
@SuppressWarnings("unchecked")
Class<T> targetClass = (Class<T>) typeParameters[1];
this.sourceType = TypeBinder.getType(sourceClass);
this.targetType = TypeBinder.getType(targetClass);
}else {
@SuppressWarnings("unchecked")
Class<S> sourceClass = (Class<S>) getGenericClass(typeParameters[0]);
@SuppressWarnings("unchecked")
Class<T> targetClass = (Class<T>) getGenericClass(typeParameters[1]);
this.sourceType = TypeBinder.getType(sourceClass);
this.targetType = TypeBinder.getType(targetClass);
}
this.sourceType = TypeBinder.getType(sourceClass);
this.targetType = TypeBinder.getType(targetClass);
}
@ -117,29 +130,29 @@ public final class RelationTypeDefinitionImpl<Out extends BaseEntity, In extends
}
}
protected EntityTypeDefinition<Out> source;
protected EntityTypeDefinition<In> target;
protected ES source;
protected ET target;
@Override
public EntityTypeDefinition<Out> getSource() {
public ES getSource() {
return source;
}
@Override
public void setSource(EntityTypeDefinition<Out> source) {
public void setSource(ES source) {
this.source = source;
}
@Override
public EntityTypeDefinition<In> getTarget() {
public ET getTarget() {
return target;
}
@Override
public void setTarget(EntityTypeDefinition<In> target) {
public void setTarget(ET target) {
this.target = target;
}

View File

@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonDeserialize(as=TypeDefinitionImpl.class) Do not uncomment to manage subclasses
public interface TypeDefinition<ISM extends ISManageable> extends ISManageable {
public interface TypeDefinition extends ISManageable {
public static final String NAME = "TypeDefinition"; //TypeDefinition.class.getSimpleName();

View File

@ -13,7 +13,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = EntityTypeDefinitionImpl.class)
public interface EntityTypeDefinition<E extends BaseEntity> extends TypeDefinition<E>, BaseEntity {
public interface EntityTypeDefinition<E extends BaseEntity> extends TypeDefinition, BaseEntity {
public static final String NAME = "EntityTypeDefinition"; //EntityTypeDefinition.class.getSimpleName();

View File

@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = PropertyTypeDefinitionImpl.class)
public interface PropertyTypeDefinition<P extends BaseProperty> extends TypeDefinition<P>, BaseProperty {
public interface PropertyTypeDefinition<P extends BaseProperty> extends TypeDefinition, BaseProperty {
public static final String NAME = "PropertyTypeDefinition"; // PropertyTypeDefinition.class.getSimpleName();

View File

@ -10,13 +10,14 @@ import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = RelationTypeDefinitionImpl.class)
public interface RelationTypeDefinition<Out extends BaseEntity, In extends BaseEntity, Rel extends BaseRelation<Out,In>>
extends TypeDefinition<Rel>, BaseRelation<EntityTypeDefinition<Out>,EntityTypeDefinition<In>> {
public interface RelationTypeDefinition<ES extends EntityTypeDefinition<S>, ET extends EntityTypeDefinition<T>, S extends BaseEntity, T extends BaseEntity>
extends TypeDefinition, BaseRelation<ES,ET> {
public static final String NAME = "RelationTypeDefinition"; // PropertyTypeDefiniton.class.getSimpleName();
@ -42,6 +43,20 @@ public interface RelationTypeDefinition<Out extends BaseEntity, In extends BaseE
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
/*
@Override
@JsonIgnore
public Header getHeader();
*/
@Override
@JsonIgnore
public ES getSource();
@Override
@JsonIgnore
public ET getTarget();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
public String getSourceType();

View File

@ -50,7 +50,6 @@ public abstract class ISMapper {
List<Package> packages = new ArrayList<Package>();
@SuppressWarnings("rawtypes")
Class<TypeDefinition> tdClz = TypeDefinition.class;
ISMapper.registerSubtypes(tdClz);
packages.add(tdClz.getPackage());

View File

@ -1,11 +1,14 @@
package org.gcube.informationsystem.types;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
import org.gcube.informationsystem.utils.ISMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -21,6 +24,23 @@ public class SerializationTest {
TypeBinder.serializeType(EntityTest.class);
}
@Test
public void getISParentOfSchema() throws Exception{
@SuppressWarnings("rawtypes")
RelationTypeDefinition relationTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedTo.class);
logger.info(ISMapper.marshal(relationTypeDefinition));
@SuppressWarnings("rawtypes")
RelationTypeDefinition rtd = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsParentOf.class);
logger.info(ISMapper.marshal(rtd));
@SuppressWarnings("rawtypes")
RelationTypeDefinition rtdSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(RelationTypeDefinition.class);
logger.info(ISMapper.marshal(rtdSelf));
}
@Test
public void testGetEnumcostants(){
Class<?> clz = PropagationConstraint.RemoveConstraint.class;