Fixing model redefintion
This commit is contained in:
parent
7760440f6b
commit
d77456ad98
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -11,5 +13,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|||
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();
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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" })
|
||||
|
|
|
@ -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> {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -21,17 +22,17 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ISMDiscovery<ISM extends ISManageable> {
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ISMDiscovery.class);
|
||||
|
||||
|
||||
protected final Class<ISM> root;
|
||||
protected final List<Package> packages;
|
||||
protected final List<Class<ISM>> discovered;
|
||||
|
||||
|
||||
public List<Class<ISM>> getDiscovered() {
|
||||
return discovered;
|
||||
}
|
||||
|
||||
|
||||
public ISMDiscovery(Class<ISM> root) {
|
||||
this.root = root;
|
||||
this.packages = new ArrayList<>();
|
||||
|
@ -39,111 +40,111 @@ public class ISMDiscovery<ISM extends ISManageable> {
|
|||
this.discovered = new ArrayList<>();
|
||||
add(root);
|
||||
}
|
||||
|
||||
|
||||
public void addPackage(Package p) {
|
||||
packages.add(p);
|
||||
}
|
||||
|
||||
|
||||
protected void add(Class<ISM> clz) {
|
||||
discovered.add(clz);
|
||||
logger.trace("+ Added {}.", clz);
|
||||
}
|
||||
|
||||
|
||||
protected void analizeISM(Class<ISM> clz) {
|
||||
logger.trace("Analizyng {}", clz);
|
||||
|
||||
if (!clz.isInterface()) {
|
||||
|
||||
if(!clz.isInterface()) {
|
||||
logger.trace("- Discarding {} that is not an interface", clz);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!root.isAssignableFrom(clz)) {
|
||||
|
||||
if(!root.isAssignableFrom(clz)) {
|
||||
logger.trace("- Discarding {} because is not a {}", clz, root.getSimpleName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (discovered.contains(clz)) {
|
||||
|
||||
if(discovered.contains(clz)) {
|
||||
logger.trace("- Discarding {} because was already managed", clz);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Class<?>[] interfaces = clz.getInterfaces();
|
||||
|
||||
for (Class<?> interfaceClass : interfaces) {
|
||||
|
||||
for(Class<?> interfaceClass : interfaces) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<ISM> parent = (Class<ISM>) interfaceClass;
|
||||
analizeISM(parent);
|
||||
}
|
||||
|
||||
if (root == Property.class) {
|
||||
|
||||
for (Method m : clz.getDeclaredMethods()) {
|
||||
|
||||
if(root == Property.class) {
|
||||
|
||||
for(Method m : clz.getDeclaredMethods()) {
|
||||
m.setAccessible(true);
|
||||
if (m.isAnnotationPresent(ISProperty.class)) {
|
||||
if (root.isAssignableFrom(m.getReturnType())) {
|
||||
if(m.isAnnotationPresent(ISProperty.class)) {
|
||||
if(root.isAssignableFrom(m.getReturnType())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<ISM> type = (Class<ISM>) m.getReturnType();
|
||||
analizeISM(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
add(clz);
|
||||
}
|
||||
|
||||
|
||||
public void discover() throws Exception {
|
||||
for (Package p : packages) {
|
||||
for(Package p : packages) {
|
||||
List<Class<?>> classes = ReflectionUtility.getClassesForPackage(p);
|
||||
for (Class<?> clz : classes) {
|
||||
for(Class<?> clz : classes) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<ISM> ism = (Class<ISM>) clz;
|
||||
analizeISM(ism);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void manageISM(SchemaAction schemaAction, List<Package> packages) throws Exception {
|
||||
if (Objects.nonNull(packages) && packages.size() > 0) {
|
||||
if(Objects.nonNull(packages) && packages.size() > 0) {
|
||||
manageISM(schemaAction, packages.stream().toArray(Package[]::new));
|
||||
} else {
|
||||
manageISM(schemaAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void manageISM(SchemaAction schemaAction, Package... packages) throws Exception {
|
||||
ISMDiscovery<Property> propertyDiscovery = new ISMDiscovery<>(Property.class);
|
||||
if (Objects.nonNull(packages))
|
||||
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);
|
||||
if (Objects.nonNull(packages))
|
||||
|
||||
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);
|
||||
if (Objects.nonNull(packages))
|
||||
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()) {
|
||||
|
||||
for(@SuppressWarnings("rawtypes")
|
||||
Class<BaseRelation> relation : relationDiscovery.getDiscovered()) {
|
||||
logger.trace("Going to manage : {}", relation);
|
||||
schemaAction.manageRelationClass(relation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<?>>();
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -55,4 +55,5 @@ public class SerializationTest {
|
|||
String serialized = TypeBinder.serializeType(Header.class);
|
||||
logger.info(serialized);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue