Fixing details

This commit is contained in:
Luca Frosini 2019-11-08 12:29:05 +01:00
parent f4276a67a5
commit a17e5f7b4b
8 changed files with 50 additions and 107 deletions

View File

@ -105,9 +105,9 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public static TypeDefinition getInstance(Class<? extends ISManageable> clz) { public static TypeDefinition getInstance(Class<? extends ISManageable> clz) {
if(BaseEntity.class.isAssignableFrom(clz)) { if(BaseEntity.class.isAssignableFrom(clz)) {
return new EntityTypeDefinitionImpl(clz); return new EntityTypeDefinitionImpl((Class<? extends BaseEntity>) clz);
} else if(BaseRelation.class.isAssignableFrom(clz)){ } else if(BaseRelation.class.isAssignableFrom(clz)){
return new RelationTypeDefinitionImpl(clz); return new RelationTypeDefinitionImpl((Class<? extends BaseRelation<?,?>>) clz);
} else if(BaseProperty.class.isAssignableFrom(clz)){ } else if(BaseProperty.class.isAssignableFrom(clz)){
return new PropertyTypeDefinitionImpl(clz); return new PropertyTypeDefinitionImpl(clz);
} else if(TypeDefinition.class.isAssignableFrom(clz)) { } else if(TypeDefinition.class.isAssignableFrom(clz)) {

View File

@ -15,7 +15,7 @@ import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value=EntityTypeDefinition.NAME) @JsonTypeName(value=EntityTypeDefinition.NAME)
public final class EntityTypeDefinitionImpl<E extends BaseEntity> extends TypeDefinitionImpl implements EntityTypeDefinition<E> { public final class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements EntityTypeDefinition {
/** /**
* Generated Serial Version UID * Generated Serial Version UID
@ -28,20 +28,23 @@ public final class EntityTypeDefinitionImpl<E extends BaseEntity> extends TypeDe
super(); super();
} }
@SuppressWarnings({"rawtypes", "unchecked"}) public EntityTypeDefinitionImpl(Class<? extends BaseEntity> clz) {
public EntityTypeDefinitionImpl(Class<E> clz) {
super(clz); super(clz);
if(Resource.class.isAssignableFrom(clz)){ if(Resource.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends Resource> c = (Class<? extends Resource>) clz; Class<? extends Resource> c = (Class<? extends Resource>) clz;
this.superClasses = retrieveSuperClasses(c, Resource.class, Entity.NAME); this.superClasses = retrieveSuperClasses(c, Resource.class, Entity.NAME);
} else if(Facet.class.isAssignableFrom(clz)){ } else if(Facet.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends Facet> c = (Class<? extends Facet>) clz; Class<? extends Facet> c = (Class<? extends Facet>) clz;
this.superClasses = retrieveSuperClasses(c, Facet.class, Entity.NAME); this.superClasses = retrieveSuperClasses(c, Facet.class, Entity.NAME);
} else if(EntityTypeDefinition.class.isAssignableFrom(clz)){ } else if(EntityTypeDefinition.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends EntityTypeDefinition> c = (Class<? extends EntityTypeDefinition>) clz; Class<? extends EntityTypeDefinition> c = (Class<? extends EntityTypeDefinition>) clz;
this.superClasses = retrieveSuperClasses(c, EntityTypeDefinition.class, BaseEntity.NAME); this.superClasses = retrieveSuperClasses(c, EntityTypeDefinition.class, BaseEntity.NAME);
} else if(Context.class.isAssignableFrom(clz)){ } else if(Context.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends Context> c = (Class<? extends Context>) clz; Class<? extends Context> c = (Class<? extends Context>) clz;
this.superClasses = retrieveSuperClasses(c, Context.class, BaseEntity.NAME); this.superClasses = retrieveSuperClasses(c, Context.class, BaseEntity.NAME);
} else if(BaseEntity.class.isAssignableFrom(clz)){ } else if(BaseEntity.class.isAssignableFrom(clz)){

View File

@ -8,7 +8,6 @@ import java.util.UUID;
import org.gcube.informationsystem.base.reference.ISManageable; import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.types.Type; import org.gcube.informationsystem.types.Type;
import org.gcube.informationsystem.types.Type.OType; import org.gcube.informationsystem.types.Type.OType;
import org.gcube.informationsystem.types.TypeBinder; import org.gcube.informationsystem.types.TypeBinder;
@ -86,7 +85,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
this.type = OType.PROPERTY.getIntValue(); this.type = OType.PROPERTY.getIntValue();
if(BaseProperty.class.isAssignableFrom(type)){ if(BaseProperty.class.isAssignableFrom(type)){
if(type != Property.class){ if(type != BaseProperty.class){
this.linkedClass = TypeBinder.getType(type); this.linkedClass = TypeBinder.getType(type);
} }
}else if (Type.getTypeByClass(type)!=null) { }else if (Type.getTypeByClass(type)!=null) {

View File

@ -1,10 +1,8 @@
package org.gcube.informationsystem.types.impl.relations; package org.gcube.informationsystem.types.impl.relations;
import java.io.StringWriter;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import org.gcube.informationsystem.base.reference.entities.BaseEntity; 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.base.reference.relations.BaseRelation;
import org.gcube.informationsystem.context.reference.relations.IsParentOf; import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
@ -12,52 +10,40 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl; import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.impl.entities.EntityTypeDefinitionImpl;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition; import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
@JsonTypeName(value=RelationTypeDefinition.NAME) @JsonTypeName(value=RelationTypeDefinition.NAME)
public final class RelationTypeDefinitionImpl<ES extends EntityTypeDefinition<S>, ET extends EntityTypeDefinition<T>, S extends BaseEntity, T extends BaseEntity> public final class RelationTypeDefinitionImpl
extends TypeDefinitionImpl implements RelationTypeDefinition<ES, ET, S,T> { extends TypeDefinitionImpl implements RelationTypeDefinition {
/** /**
* Generated Serial Version UID * Generated Serial Version UID
*/ */
private static final long serialVersionUID = 2221831081869571296L; private static final long serialVersionUID = 2221831081869571296L;
// private static final String EDGE_CLASS_NAME = "E";
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String sourceType;
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String targetType;
protected RelationTypeDefinitionImpl() { protected RelationTypeDefinitionImpl() {
super(); super();
} }
public RelationTypeDefinitionImpl(Class<? extends BaseRelation<S,T>> clz) { @SuppressWarnings("unchecked")
public RelationTypeDefinitionImpl(Class<? extends BaseRelation<?, ?>> clz) {
super(clz); super(clz);
if(IsRelatedTo.class.isAssignableFrom(clz)){ if(IsRelatedTo.class.isAssignableFrom(clz)){
@SuppressWarnings({"unchecked"})
Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>> c = (Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>>) clz; Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>> c = (Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>>) clz;
this.superClasses = retrieveSuperClasses(c, IsRelatedTo.class, Relation.NAME); this.superClasses = retrieveSuperClasses(c, IsRelatedTo.class, Relation.NAME);
} else if(ConsistsOf.class.isAssignableFrom(clz)) { } else if(ConsistsOf.class.isAssignableFrom(clz)) {
@SuppressWarnings({"unchecked"})
Class<? extends ConsistsOf<? extends Resource, ? extends Facet>> c = (Class<? extends ConsistsOf<? extends Resource, ? extends Facet>>) clz; Class<? extends ConsistsOf<? extends Resource, ? extends Facet>> c = (Class<? extends ConsistsOf<? extends Resource, ? extends Facet>>) clz;
this.superClasses = retrieveSuperClasses(c, ConsistsOf.class, Relation.NAME); this.superClasses = retrieveSuperClasses(c, ConsistsOf.class, Relation.NAME);
} else if(RelationTypeDefinition.class.isAssignableFrom(clz)){ } else if(RelationTypeDefinition.class.isAssignableFrom(clz)){
@SuppressWarnings({"unchecked", "rawtypes"}) Class<RelationTypeDefinition> c = (Class<RelationTypeDefinition>) clz;
Class<? extends RelationTypeDefinition> c = (Class<? extends RelationTypeDefinition>) clz;
this.superClasses = retrieveSuperClasses(c, RelationTypeDefinition.class, BaseRelation.NAME); this.superClasses = retrieveSuperClasses(c, RelationTypeDefinition.class, BaseRelation.NAME);
} else if(IsParentOf.class.isAssignableFrom(clz)){ } else if(IsParentOf.class.isAssignableFrom(clz)){
@SuppressWarnings({"unchecked"})
Class<? extends IsParentOf> c = (Class<? extends IsParentOf>) clz; Class<? extends IsParentOf> c = (Class<? extends IsParentOf>) clz;
this.superClasses = retrieveSuperClasses(c, IsParentOf.class, BaseRelation.NAME); this.superClasses = retrieveSuperClasses(c, IsParentOf.class, BaseRelation.NAME);
} else if(BaseRelation.class.isAssignableFrom(clz)){ } else if(BaseRelation.class.isAssignableFrom(clz)){
@ -67,93 +53,51 @@ public final class RelationTypeDefinitionImpl<ES extends EntityTypeDefinition<S>
} }
java.lang.reflect.Type[] typeParameters = clz.getTypeParameters(); java.lang.reflect.Type[] typeParameters = clz.getTypeParameters();
Class<? extends BaseEntity> sourceClass;
Class<? extends BaseEntity> targetClass;
if(typeParameters.length==0) { if(typeParameters.length==0) {
typeParameters = ((ParameterizedType) clz.getGenericInterfaces()[0]).getActualTypeArguments(); typeParameters = ((ParameterizedType) clz.getGenericInterfaces()[0]).getActualTypeArguments();
@SuppressWarnings("unchecked") sourceClass = (Class<? extends BaseEntity>) typeParameters[0];
Class<S> sourceClass = (Class<S>) typeParameters[0]; targetClass = (Class<? extends BaseEntity>) typeParameters[1];
@SuppressWarnings("unchecked")
Class<T> targetClass = (Class<T>) typeParameters[1];
this.sourceType = TypeBinder.getType(sourceClass);
this.targetType = TypeBinder.getType(targetClass);
}else { }else {
@SuppressWarnings("unchecked") sourceClass = (Class<? extends BaseEntity>) getGenericClass(typeParameters[0]);
Class<S> sourceClass = (Class<S>) getGenericClass(typeParameters[0]); targetClass = (Class<? extends BaseEntity>) getGenericClass(typeParameters[1]);
@SuppressWarnings("unchecked")
Class<T> targetClass = (Class<T>) getGenericClass(typeParameters[1]);
this.sourceType = TypeBinder.getType(sourceClass);
this.targetType = TypeBinder.getType(targetClass);
} }
this.source = new EntityTypeDefinitionImpl(sourceClass);
this.target = new EntityTypeDefinitionImpl(targetClass);
} }
public String getSourceType() {
return sourceType;
}
public String getTargetType() {
return targetType;
}
/* /*
* Java does not support multiple inheritance. * Java does not support class multiple inheritance.
* TypeDefinitionImpl is the superclass so that this class does not inherits the methods and field of BaseRelationImpl * TypeDefinitionImpl is the superclass so that this class does not inherits the methods and field of BaseRelationImpl
* We need to copy them. * We need to copy them.
*/ */
protected Header header; protected EntityTypeDefinition source;
protected EntityTypeDefinition target;
@Override @Override
public Header getHeader() { public EntityTypeDefinition getSource() {
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();
}
}
}
protected ES source;
protected ET target;
@Override
public ES getSource() {
return source; return source;
} }
@Override @Override
public void setSource(ES source) { public void setSource(EntityTypeDefinition source) {
this.source = source; this.source = source;
} }
@Override @Override
public ET getTarget() { public EntityTypeDefinition getTarget() {
return target; return target;
} }
@Override @Override
public void setTarget(ET target) { public void setTarget(EntityTypeDefinition target) {
this.target = target; this.target = target;
} }
} }

View File

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

View File

@ -2,7 +2,6 @@ package org.gcube.informationsystem.types.reference.relations;
import java.util.Set; import java.util.Set;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.relations.BaseRelation; import org.gcube.informationsystem.base.reference.relations.BaseRelation;
import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.relations.RelationTypeDefinitionImpl; import org.gcube.informationsystem.types.impl.relations.RelationTypeDefinitionImpl;
@ -10,14 +9,12 @@ import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition; import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition; import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = RelationTypeDefinitionImpl.class) @JsonDeserialize(as = RelationTypeDefinitionImpl.class)
public interface RelationTypeDefinition<ES extends EntityTypeDefinition<S>, ET extends EntityTypeDefinition<T>, S extends BaseEntity, T extends BaseEntity> public interface RelationTypeDefinition extends TypeDefinition, BaseRelation<EntityTypeDefinition,EntityTypeDefinition> {
extends TypeDefinition, BaseRelation<ES,ET> {
public static final String NAME = "RelationTypeDefinition"; // PropertyTypeDefiniton.class.getSimpleName(); public static final String NAME = "RelationTypeDefinition"; // PropertyTypeDefiniton.class.getSimpleName();
@ -43,24 +40,17 @@ public interface RelationTypeDefinition<ES extends EntityTypeDefinition<S>, ET e
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false) @ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties(); public Set<PropertyDefinition> getProperties();
/*
@Override @Override
@JsonIgnore public EntityTypeDefinition getSource();
public Header getHeader();
*/
@Override @Override
@JsonIgnore public EntityTypeDefinition getTarget();
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 */ /* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
/*@JsonGetter(value=SOURCE_PROPERTY)
public String getSourceType(); public String getSourceType();
public String getTargetType(); @JsonGetter(value=TARGET_PROPERTY)
public String getTargetType();*/
} }

View File

@ -18,6 +18,8 @@ import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.properties.BaseProperty; import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.base.reference.relations.BaseRelation; import org.gcube.informationsystem.base.reference.relations.BaseRelation;
import org.gcube.informationsystem.types.annotations.ISProperty; import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -49,8 +51,10 @@ public class ISMDiscovery<ISM extends ISManageable> {
} }
protected void add(Class<? extends ISM> clz) { protected void add(Class<? extends ISM> clz) {
discovered.add(clz); if(!discovered.contains(clz)) {
logger.trace("+ Added {}.", clz); discovered.add(clz);
logger.info("+ Added {}.", clz);
}
} }
protected void analizeISM(Class<? extends ISM> clz) { protected void analizeISM(Class<? extends ISM> clz) {
@ -151,6 +155,9 @@ public class ISMDiscovery<ISM extends ISManageable> {
for(Class<? extends BaseEntity> entity : entityDiscovery.getDiscovered()) { for(Class<? extends BaseEntity> entity : entityDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", entity); logger.trace("Going to manage : {}", entity);
schemaAction.manageEntityClass(entity); schemaAction.manageEntityClass(entity);
if(entity.getName().compareTo(BaseEntity.class.getName())==0 ) {
schemaAction.manageEntityClass(EntityTypeDefinition.class);
}
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@ -163,6 +170,9 @@ public class ISMDiscovery<ISM extends ISManageable> {
Class<? extends BaseRelation> relation : relationDiscovery.getDiscovered()) { Class<? extends BaseRelation> relation : relationDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", relation); logger.trace("Going to manage : {}", relation);
schemaAction.manageRelationClass(relation); schemaAction.manageRelationClass(relation);
if(relation.getName().compareTo(BaseRelation.class.getName())==0 ) {
schemaAction.manageRelationClass(RelationTypeDefinition.class);
}
} }
} }

View File

@ -28,15 +28,12 @@ public class SerializationTest {
@Test @Test
public void getISParentOfSchema() throws Exception{ public void getISParentOfSchema() throws Exception{
@SuppressWarnings("rawtypes")
RelationTypeDefinition relationTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedTo.class); RelationTypeDefinition relationTypeDefinition = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsRelatedTo.class);
logger.info(ISMapper.marshal(relationTypeDefinition)); logger.info(ISMapper.marshal(relationTypeDefinition));
@SuppressWarnings("rawtypes")
RelationTypeDefinition rtd = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsParentOf.class); RelationTypeDefinition rtd = (RelationTypeDefinition) TypeBinder.createTypeDefinition(IsParentOf.class);
logger.info(ISMapper.marshal(rtd)); logger.info(ISMapper.marshal(rtd));
@SuppressWarnings("rawtypes")
RelationTypeDefinition rtdSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(RelationTypeDefinition.class); RelationTypeDefinition rtdSelf = (RelationTypeDefinition) TypeBinder.createTypeDefinition(RelationTypeDefinition.class);
logger.info(ISMapper.marshal(rtdSelf)); logger.info(ISMapper.marshal(rtdSelf));