Fixing model redefintion

This commit is contained in:
Luca Frosini 2019-10-24 19:50:43 +02:00
parent 7760440f6b
commit d77456ad98
20 changed files with 190 additions and 97 deletions

View File

@ -17,7 +17,6 @@ import org.gcube.informationsystem.model.impl.entities.ResourceImpl;
import org.gcube.informationsystem.model.impl.properties.DummyProperty;
import org.gcube.informationsystem.model.impl.properties.PropertyImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.impl.relations.DummyConsistsOf;
import org.gcube.informationsystem.model.impl.relations.DummyIsRelatedTo;
import org.gcube.informationsystem.model.impl.relations.IsRelatedToImpl;
import org.gcube.informationsystem.model.impl.relations.RelationImpl;
@ -28,6 +27,14 @@ import org.gcube.informationsystem.model.reference.properties.Property;
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.impl.entities.EntityTypeDefinitionImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyTypeDefinitionImpl;
import org.gcube.informationsystem.types.impl.relations.RelationTypeDefinitionImpl;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefiniton;
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,18 +45,23 @@ import org.slf4j.LoggerFactory;
*/
public enum AccessType {
PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null),
PROPERTY_TYPE_DEFINITION(PropertyTypeDefiniton.class, PropertyTypeDefiniton.NAME, PropertyTypeDefinitionImpl.class, null),
PROPERTY(Property.class, Property.NAME, PropertyImpl.class, DummyProperty.class),
CONTEXT(Context.class, Context.NAME, ContextImpl.class, null),
IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.class, null),
ENTITY_TYPE_DEFINITION(EntityTypeDefinition.class, EntityTypeDefinition.NAME, EntityTypeDefinitionImpl.class, null),
RELATION_TYPE_DEFINITION(RelationTypeDefinition.class, RelationTypeDefinition.NAME, RelationTypeDefinitionImpl.class, null),
ENTITY(Entity.class, Entity.NAME, EntityImpl.class, null),
RESOURCE(Resource.class, Resource.NAME, ResourceImpl.class, DummyResource.class),
FACET(Facet.class, Facet.NAME, FacetImpl.class, DummyFacet.class),
RELATION(Relation.class, Relation.NAME, RelationImpl.class, null),
IS_RELATED_TO(IsRelatedTo.class, IsRelatedTo.NAME, IsRelatedToImpl.class, DummyIsRelatedTo.class),
CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME, ConsistsOfImpl.class, DummyConsistsOf.class);
CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME, ConsistsOfImpl.class, null);
private static Logger logger = LoggerFactory.getLogger(AccessType.class);

View File

@ -1,7 +1,9 @@
package org.gcube.informationsystem.base.reference.entities;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -12,4 +14,9 @@ public interface BaseEntity extends ER {
public static final String NAME = "BaseEntity"; //Entity.class.getSimpleName();
/* Overriding getHeader method to create Header property in type */
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
@Override
public Header getHeader();
}

View File

@ -2,15 +2,12 @@ package org.gcube.informationsystem.base.reference.properties;
import org.gcube.informationsystem.base.reference.ISManageable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* @author Luca Frosini (ISTI - CNR)
* Root Class for Property types. It creates a base common type, which is useful
* for management purpose.
*/
// @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = ISManageable.CLASS_PROPERTY)
@JsonIgnoreProperties(ignoreUnknown=true)
// @JsonDeserialize(as=BasePropertympl.class) Do not uncomment to manage subclasses
public interface BaseProperty extends ISManageable {
public static final String NAME = "BaseProperty"; //BaseProperty.class.getSimpleName();

View File

@ -8,7 +8,6 @@ import java.util.List;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.impl.relations.IsRelatedToImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
@ -152,6 +151,7 @@ public abstract class ResourceImpl extends EntityImpl implements Resource {
*/
}
/*
@Override
public void attachResource(UUID uuid) {
Resource resource = new DummyResource(uuid);
@ -163,6 +163,7 @@ public abstract class ResourceImpl extends EntityImpl implements Resource {
IsRelatedTo<Resource, Resource> isRelatedTo = new IsRelatedToImpl<Resource, Resource>(this, resource, null);
attachResource(isRelatedTo);
}
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })

View File

@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedTo.NAME)
public class IsRelatedToImpl<Out extends Resource, In extends Resource> extends
public abstract class IsRelatedToImpl<Out extends Resource, In extends Resource> extends
RelationImpl<Out, In> implements IsRelatedTo<Out, In> {
/**

View File

@ -4,11 +4,7 @@
package org.gcube.informationsystem.model.reference.entities;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
@ -16,15 +12,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Basic_Concepts
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses
public interface Entity extends BaseEntity {
public static final String NAME = "Entity"; //Entity.class.getSimpleName();
/* Overriding getHeader method to create Header property in type */
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
@Override
public Header getHeader();
}

View File

@ -11,12 +11,14 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.annotations.Abstract;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Resources
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
// @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses
public interface Resource extends Entity {
@ -62,10 +64,11 @@ public interface Resource extends Entity {
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> void addFacet(C relation);
/*
public void attachResource(UUID uuid);
public <R extends Resource> void attachResource(R resource);
*/
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> void attachResource(I relation);

View File

@ -5,15 +5,13 @@ package org.gcube.informationsystem.model.reference.properties;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* @author Luca Frosini (ISTI - CNR)
* Root Class for Property types. It creates a base common type, which is useful
* for management purpose.
*/
// @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = ISManageable.CLASS_PROPERTY)
@JsonIgnoreProperties(ignoreUnknown=true)
// @JsonIgnoreProperties(ignoreUnknown=true)
// @JsonDeserialize(as=PropertyImpl.class) Do not uncomment to manage subclasses
public interface Property extends BaseProperty {
public static final String NAME = "Property"; //Property.class.getSimpleName();

View File

@ -4,12 +4,14 @@
package org.gcube.informationsystem.model.reference.relations;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.annotations.Abstract;
/**
* @author Luca Frosini (ISTI - CNR)
* This Relation is for internal use only
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isRelatedTo
*/
@Abstract
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
public interface IsRelatedTo<Out extends Resource, In extends Resource>
extends Relation<Out, In> {

View File

@ -5,7 +5,7 @@ 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.impl.ISManageableImpl;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
// @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
@JsonTypeName(value=TypeDefinition.NAME)
public abstract class TypeDefinitionImpl<ISM extends ISManageable> extends ERImpl implements TypeDefinition<ISM> {
public abstract class TypeDefinitionImpl<ISM extends ISManageable> extends ISManageableImpl implements TypeDefinition<ISM> {
/**
* Generated Serial Version UID
@ -37,7 +37,7 @@ public abstract class TypeDefinitionImpl<ISM extends ISManageable> extends ERImp
private static Logger logger = LoggerFactory.getLogger(TypeDefinitionImpl.class);
private final static String DESCRIPTION = "DESCRIPTION";
public final static String DESCRIPTION = "DESCRIPTION";
protected String name;
protected String description;

View File

@ -1,11 +1,15 @@
package org.gcube.informationsystem.types.impl.entities;
import java.io.StringWriter;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonTypeName;
@ -37,4 +41,39 @@ public class EntityTypeDefinitionImpl<E extends BaseEntity> extends TypeDefiniti
}
/*
* Java does not support 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;
@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

@ -7,6 +7,7 @@ import java.net.URL;
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;
@ -82,7 +83,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
Class<? extends ISManageable> type = (Class<? extends ISManageable>) method.getReturnType();
this.type = OType.PROPERTY.getIntValue();
if(Property.class.isAssignableFrom(type)){
if(BaseProperty.class.isAssignableFrom(type)){
if(type != Property.class){
this.linkedClass = TypeBinder.getType(type);
}

View File

@ -1,6 +1,9 @@
package org.gcube.informationsystem.types.impl.relations;
import java.io.StringWriter;
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.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
@ -9,6 +12,7 @@ import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
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;
@ -63,28 +67,65 @@ public class RelationTypeDefinitionImpl<Out extends BaseEntity, In extends BaseE
return targetType;
}
/*
* Java does not support 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;
@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 EntityTypeDefinition<Out> source;
protected EntityTypeDefinition<In> target;
@Override
public EntityTypeDefinition<Out> getSource() {
// TODO Auto-generated method stub
return null;
return source;
}
@Override
public void setSource(EntityTypeDefinition<Out> source) {
// TODO Auto-generated method stub
this.source = source;
}
@Override
public EntityTypeDefinition<In> getTarget() {
// TODO Auto-generated method stub
return null;
return target;
}
@Override
public void setTarget(EntityTypeDefinition<In> target) {
// TODO Auto-generated method stub
this.target = target;
}
}

View File

@ -2,7 +2,6 @@ package org.gcube.informationsystem.types.reference;
import java.util.Set;
import org.gcube.informationsystem.base.reference.ER;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
@ -12,7 +11,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 ER {
public interface TypeDefinition<ISM extends ISManageable> extends ISManageable {
public static final String NAME = "TypeDefinition"; //Entity.class.getSimpleName();

View File

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

View File

@ -3,9 +3,9 @@
*/
package org.gcube.informationsystem.utils;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
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.utils.discovery.SchemaAction;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -22,19 +22,19 @@ class ObjectMappingERAction implements SchemaAction {
}
@Override
public <E extends Property> void managePropertyClass(Class<E> e)
public <P extends BaseProperty> void managePropertyClass(Class<P> e)
throws Exception {
objectMapper.registerSubtypes(e);
}
@Override
public <E extends Entity> void manageEntityClass(Class<E> e)
public <E extends BaseEntity> void manageEntityClass(Class<E> e)
throws Exception {
objectMapper.registerSubtypes(e);
}
@Override
public <R extends Relation<? extends Entity, ? extends Entity>> void manageRelationClass(
public <R extends BaseRelation<? extends BaseEntity, ? extends BaseEntity>> void manageRelationClass(
Class<R> r) throws Exception {
objectMapper.registerSubtypes(r);
}

View File

@ -10,9 +10,10 @@ import java.util.List;
import java.util.Objects;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.model.reference.entities.Entity;
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.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -114,33 +115,33 @@ public class ISMDiscovery<ISM extends ISManageable> {
@SuppressWarnings("unchecked")
public static void manageISM(SchemaAction schemaAction, Package... packages) throws Exception {
ISMDiscovery<Property> propertyDiscovery = new ISMDiscovery<>(Property.class);
ISMDiscovery<BaseProperty> propertyDiscovery = new ISMDiscovery<>(BaseProperty.class);
if(Objects.nonNull(packages))
Arrays.stream(packages).forEach(p -> propertyDiscovery.addPackage(p));
propertyDiscovery.discover();
for (Class<Property> property : propertyDiscovery.getDiscovered()) {
for(Class<BaseProperty> property : propertyDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", property);
schemaAction.managePropertyClass(property);
}
ISMDiscovery<Entity> entityDiscovery = new ISMDiscovery<>(Entity.class);
ISMDiscovery<BaseEntity> entityDiscovery = new ISMDiscovery<>(BaseEntity.class);
if(Objects.nonNull(packages))
Arrays.stream(packages).forEach(p -> entityDiscovery.addPackage(p));
entityDiscovery.discover();
for (Class<Entity> entity : entityDiscovery.getDiscovered()) {
for(Class<BaseEntity> entity : entityDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", entity);
schemaAction.manageEntityClass(entity);
}
@SuppressWarnings("rawtypes")
ISMDiscovery<Relation> relationDiscovery = new ISMDiscovery<>(Relation.class);
ISMDiscovery<BaseRelation> relationDiscovery = new ISMDiscovery<BaseRelation>(BaseRelation.class);
if(Objects.nonNull(packages))
Arrays.stream(packages).forEach(p -> relationDiscovery.addPackage(p));
relationDiscovery.discover();
for(@SuppressWarnings("rawtypes")
Class<Relation> relation : relationDiscovery.getDiscovered()) {
Class<BaseRelation> relation : relationDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", relation);
schemaAction.manageRelationClass(relation);
}

View File

@ -139,6 +139,7 @@ public class ReflectionUtility {
* @throws ClassNotFoundException
* if something went wrong
*/
@SuppressWarnings("restriction")
public static List<Class<?>> getClassesForPackage(String pckgname)
throws ClassNotFoundException {
final List<Class<?>> classes = new ArrayList<Class<?>>();

View File

@ -3,9 +3,9 @@
*/
package org.gcube.informationsystem.utils.discovery;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
/**
* @author Luca Frosini (ISTI - CNR)
@ -13,10 +13,10 @@ import org.gcube.informationsystem.model.reference.relations.Relation;
*/
public interface SchemaAction {
public <E extends Property> void managePropertyClass(Class<E> e) throws Exception;
public <P extends BaseProperty> void managePropertyClass(Class<P> e) throws Exception;
public <E extends Entity> void manageEntityClass(Class<E> e) throws Exception;
public <E extends BaseEntity> void manageEntityClass(Class<E> e) throws Exception;
public <R extends Relation<? extends Entity, ? extends Entity>> void manageRelationClass(Class<R> r) throws Exception;
public <R extends BaseRelation<? extends BaseEntity, ? extends BaseEntity>> void manageRelationClass(Class<R> r) throws Exception;
}

View File

@ -55,4 +55,5 @@ public class SerializationTest {
String serialized = TypeBinder.serializeType(Header.class);
logger.info(serialized);
}
}