Fixing details
This commit is contained in:
parent
f4276a67a5
commit
a17e5f7b4b
|
@ -105,9 +105,9 @@ public class TypeDefinitionImpl extends ERImpl implements TypeDefinition {
|
|||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static TypeDefinition getInstance(Class<? extends ISManageable> clz) {
|
||||
if(BaseEntity.class.isAssignableFrom(clz)) {
|
||||
return new EntityTypeDefinitionImpl(clz);
|
||||
return new EntityTypeDefinitionImpl((Class<? extends BaseEntity>) clz);
|
||||
} else if(BaseRelation.class.isAssignableFrom(clz)){
|
||||
return new RelationTypeDefinitionImpl(clz);
|
||||
return new RelationTypeDefinitionImpl((Class<? extends BaseRelation<?,?>>) clz);
|
||||
} else if(BaseProperty.class.isAssignableFrom(clz)){
|
||||
return new PropertyTypeDefinitionImpl(clz);
|
||||
} else if(TypeDefinition.class.isAssignableFrom(clz)) {
|
||||
|
|
|
@ -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 implements EntityTypeDefinition<E> {
|
||||
public final class EntityTypeDefinitionImpl extends TypeDefinitionImpl implements EntityTypeDefinition {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
|
@ -28,20 +28,23 @@ public final class EntityTypeDefinitionImpl<E extends BaseEntity> extends TypeDe
|
|||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public EntityTypeDefinitionImpl(Class<E> clz) {
|
||||
public EntityTypeDefinitionImpl(Class<? extends BaseEntity> clz) {
|
||||
super(clz);
|
||||
|
||||
if(Resource.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Resource> c = (Class<? extends Resource>) clz;
|
||||
this.superClasses = retrieveSuperClasses(c, Resource.class, Entity.NAME);
|
||||
} else if(Facet.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Facet> c = (Class<? extends Facet>) clz;
|
||||
this.superClasses = retrieveSuperClasses(c, Facet.class, Entity.NAME);
|
||||
} else if(EntityTypeDefinition.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends EntityTypeDefinition> c = (Class<? extends EntityTypeDefinition>) clz;
|
||||
this.superClasses = retrieveSuperClasses(c, EntityTypeDefinition.class, BaseEntity.NAME);
|
||||
} else if(Context.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Context> c = (Class<? extends Context>) clz;
|
||||
this.superClasses = retrieveSuperClasses(c, Context.class, BaseEntity.NAME);
|
||||
} else if(BaseEntity.class.isAssignableFrom(clz)){
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.UUID;
|
|||
|
||||
import org.gcube.informationsystem.base.reference.ISManageable;
|
||||
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.OType;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
|
@ -86,7 +85,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
|
|||
this.type = OType.PROPERTY.getIntValue();
|
||||
|
||||
if(BaseProperty.class.isAssignableFrom(type)){
|
||||
if(type != Property.class){
|
||||
if(type != BaseProperty.class){
|
||||
this.linkedClass = TypeBinder.getType(type);
|
||||
}
|
||||
}else if (Type.getTypeByClass(type)!=null) {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
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;
|
||||
|
@ -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.IsRelatedTo;
|
||||
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.entities.EntityTypeDefinitionImpl;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
||||
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;
|
||||
|
||||
@JsonTypeName(value=RelationTypeDefinition.NAME)
|
||||
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> {
|
||||
public final class RelationTypeDefinitionImpl
|
||||
extends TypeDefinitionImpl implements RelationTypeDefinition {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
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() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RelationTypeDefinitionImpl(Class<? extends BaseRelation<S,T>> clz) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public RelationTypeDefinitionImpl(Class<? extends BaseRelation<?, ?>> clz) {
|
||||
super(clz);
|
||||
|
||||
if(IsRelatedTo.class.isAssignableFrom(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"})
|
||||
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;
|
||||
Class<RelationTypeDefinition> c = (Class<RelationTypeDefinition>) clz;
|
||||
this.superClasses = retrieveSuperClasses(c, RelationTypeDefinition.class, BaseRelation.NAME);
|
||||
} else if(IsParentOf.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings({"unchecked"})
|
||||
Class<? extends IsParentOf> c = (Class<? extends IsParentOf>) clz;
|
||||
this.superClasses = retrieveSuperClasses(c, IsParentOf.class, BaseRelation.NAME);
|
||||
} else if(BaseRelation.class.isAssignableFrom(clz)){
|
||||
|
@ -67,92 +53,50 @@ public final class RelationTypeDefinitionImpl<ES extends EntityTypeDefinition<S>
|
|||
}
|
||||
|
||||
java.lang.reflect.Type[] typeParameters = clz.getTypeParameters();
|
||||
Class<? extends BaseEntity> sourceClass;
|
||||
Class<? extends BaseEntity> targetClass;
|
||||
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);
|
||||
sourceClass = (Class<? extends BaseEntity>) typeParameters[0];
|
||||
targetClass = (Class<? extends BaseEntity>) typeParameters[1];
|
||||
}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);
|
||||
sourceClass = (Class<? extends BaseEntity>) getGenericClass(typeParameters[0]);
|
||||
targetClass = (Class<? extends BaseEntity>) getGenericClass(typeParameters[1]);
|
||||
}
|
||||
|
||||
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
|
||||
* We need to copy them.
|
||||
*/
|
||||
|
||||
protected Header header;
|
||||
protected EntityTypeDefinition source;
|
||||
protected EntityTypeDefinition target;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ES source;
|
||||
protected ET target;
|
||||
|
||||
@Override
|
||||
public ES getSource() {
|
||||
public EntityTypeDefinition getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setSource(ES source) {
|
||||
public void setSource(EntityTypeDefinition source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ET getTarget() {
|
||||
public EntityTypeDefinition getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setTarget(ET target) {
|
||||
public void setTarget(EntityTypeDefinition target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
|
|
@ -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, BaseEntity {
|
||||
public interface EntityTypeDefinition extends TypeDefinition, BaseEntity {
|
||||
|
||||
public static final String NAME = "EntityTypeDefinition"; //EntityTypeDefinition.class.getSimpleName();
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.gcube.informationsystem.types.reference.relations;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
||||
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
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.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<ES extends EntityTypeDefinition<S>, ET extends EntityTypeDefinition<T>, S extends BaseEntity, T extends BaseEntity>
|
||||
extends TypeDefinition, BaseRelation<ES,ET> {
|
||||
public interface RelationTypeDefinition extends TypeDefinition, BaseRelation<EntityTypeDefinition,EntityTypeDefinition> {
|
||||
|
||||
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)
|
||||
public Set<PropertyDefinition> getProperties();
|
||||
|
||||
/*
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Header getHeader();
|
||||
*/
|
||||
public EntityTypeDefinition getSource();
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public ES getSource();
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public ET getTarget();
|
||||
public EntityTypeDefinition getTarget();
|
||||
|
||||
/* 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 getTargetType();
|
||||
@JsonGetter(value=TARGET_PROPERTY)
|
||||
public String getTargetType();*/
|
||||
|
||||
}
|
||||
|
|
|
@ -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.relations.BaseRelation;
|
||||
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.LoggerFactory;
|
||||
|
||||
|
@ -49,8 +51,10 @@ public class ISMDiscovery<ISM extends ISManageable> {
|
|||
}
|
||||
|
||||
protected void add(Class<? extends ISM> clz) {
|
||||
if(!discovered.contains(clz)) {
|
||||
discovered.add(clz);
|
||||
logger.trace("+ Added {}.", clz);
|
||||
logger.info("+ Added {}.", 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()) {
|
||||
logger.trace("Going to manage : {}", entity);
|
||||
schemaAction.manageEntityClass(entity);
|
||||
if(entity.getName().compareTo(BaseEntity.class.getName())==0 ) {
|
||||
schemaAction.manageEntityClass(EntityTypeDefinition.class);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
@ -163,6 +170,9 @@ public class ISMDiscovery<ISM extends ISManageable> {
|
|||
Class<? extends BaseRelation> relation : relationDiscovery.getDiscovered()) {
|
||||
logger.trace("Going to manage : {}", relation);
|
||||
schemaAction.manageRelationClass(relation);
|
||||
if(relation.getName().compareTo(BaseRelation.class.getName())==0 ) {
|
||||
schemaAction.manageRelationClass(RelationTypeDefinition.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,15 +28,12 @@ public class SerializationTest {
|
|||
|
||||
@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));
|
||||
|
||||
|
|
Loading…
Reference in New Issue