Fixing model redesign

This commit is contained in:
Luca Frosini 2019-10-30 09:57:14 +01:00
parent fe15bea3de
commit 6f15a1d7dc
15 changed files with 225 additions and 85 deletions

View File

@ -5,8 +5,12 @@ package org.gcube.informationsystem.base.reference;
import java.util.Arrays;
import org.gcube.informationsystem.base.impl.entities.BaseEntityImpl;
import org.gcube.informationsystem.base.impl.properties.BasePropertyImpl;
import org.gcube.informationsystem.base.impl.relations.BaseRelationImpl;
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.context.impl.entities.ContextImpl;
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
@ -29,12 +33,10 @@ 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.TypeDefinitionImpl;
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.TypeDefinition;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition;
@ -57,15 +59,17 @@ public enum AccessType {
PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null),
TYPE_DEFINITION(TypeDefinition.class, TypeDefinition.NAME, TypeDefinitionImpl.class, null),
// TYPE_DEFINITION(TypeDefinition.class, TypeDefinition.NAME, TypeDefinitionImpl.class, null),
PROPERTY_TYPE_DEFINITION(PropertyTypeDefinition.class, PropertyTypeDefinition.NAME, PropertyTypeDefinitionImpl.class, null),
ENTITY_TYPE_DEFINITION(EntityTypeDefinition.class, EntityTypeDefinition.NAME, EntityTypeDefinitionImpl.class, null),
RELATION_TYPE_DEFINITION(RelationTypeDefinition.class, RelationTypeDefinition.NAME, RelationTypeDefinitionImpl.class, null),
BASE_ENTITY(BaseEntity.class, BaseEntity.NAME, BaseEntityImpl.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),
BASE_RELATION(BaseRelation.class, BaseRelation.NAME, BaseRelationImpl.class, null),
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, null);

View File

@ -3,11 +3,9 @@
*/
package org.gcube.informationsystem.context.reference.relations;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.types.annotations.ISProperty;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
@ -23,11 +21,6 @@ public interface IsParentOf<Out extends Context, In extends Context> extends Bas
public static final String NAME = "IsParentOf"; //IsParentOf.class.getSimpleName();
/* Overriding getHeader method to create Header property in type */
@ISProperty(name = HEADER_PROPERTY, mandatory = true, nullable = false)
@Override
public Header getHeader();
@JsonIgnoreProperties({Context.PARENT_PROPERTY, Context.CHILDREN_PROPERTY})
@JsonGetter(value = SOURCE_PROPERTY)
public Out getSource();

View File

@ -9,7 +9,6 @@ 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.TypeDefinition;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.utils.ISMapper;
@ -23,30 +22,32 @@ public final class EntityTypeDefinitionImpl<E extends BaseEntity> extends TypeDe
*/
private static final long serialVersionUID = 2614315845213942880L;
private static final String VERTEX_CLASS_NAME = "V";
// private static final String VERTEX_CLASS_NAME = "V";
protected EntityTypeDefinitionImpl() {
super();
}
@SuppressWarnings({"rawtypes", "unchecked"})
public EntityTypeDefinitionImpl(Class<E> 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)){
this.superClasses = retrieveSuperClasses(clz, BaseEntity.class, VERTEX_CLASS_NAME);
this.superClasses.add(TypeDefinition.class.getSimpleName());
Class<? extends EntityTypeDefinition> c = (Class<? extends EntityTypeDefinition>) clz;
this.superClasses = retrieveSuperClasses(c, EntityTypeDefinition.class, BaseEntity.NAME);
} else if(Context.class.isAssignableFrom(clz)){
this.superClasses = retrieveSuperClasses(clz, BaseEntity.class, VERTEX_CLASS_NAME);
Class<? extends Context> c = (Class<? extends Context>) clz;
this.superClasses = retrieveSuperClasses(c, Context.class, BaseEntity.NAME);
} else if(BaseEntity.class.isAssignableFrom(clz)){
this.superClasses = retrieveSuperClasses(clz, BaseEntity.class, null);
} else {
throw new RuntimeException("Type Hierachy Error");
throw new RuntimeException("Type Hierachy Error for class " + clz.getSimpleName());
}

View File

@ -147,47 +147,57 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
}
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean isMandatory() {
return mandatory;
}
@Override
public boolean isReadonly() {
return readonly;
}
@Override
public boolean isNotnull() {
return notnull;
}
@Override
public Integer getMax() {
return max;
}
@Override
public Integer getMin() {
return min;
}
@Override
public String getRegexp() {
return regexp;
}
@Override
public Integer getLinkedType() {
return linkedType;
}
@Override
public String getLinkedClass() {
return linkedClass;
}
@Override
public Integer getType() {
return type;
}

View File

@ -2,7 +2,6 @@ package org.gcube.informationsystem.types.impl.properties;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.types.impl.TypeDefinitionImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition;
import com.fasterxml.jackson.annotation.JsonTypeName;
@ -22,9 +21,6 @@ public final class PropertyTypeDefinitionImpl<P extends BaseProperty> extends Ty
public PropertyTypeDefinitionImpl(Class<P> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, BaseProperty.class, clz == BaseProperty.class ? null : BaseProperty.NAME);
if(PropertyTypeDefinition.class.isAssignableFrom(clz)) {
this.superClasses.add(TypeDefinition.class.getSimpleName());
}
}
}

View File

@ -11,7 +11,6 @@ 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.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
import org.gcube.informationsystem.utils.ISMapper;
@ -28,7 +27,7 @@ public final class RelationTypeDefinitionImpl<Out extends BaseEntity, In extends
*/
private static final long serialVersionUID = 2221831081869571296L;
private static final String EDGE_CLASS_NAME = "E";
// private static final String EDGE_CLASS_NAME = "E";
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String sourceType;
@ -51,10 +50,15 @@ public final class RelationTypeDefinitionImpl<Out extends BaseEntity, In extends
Class<? extends ConsistsOf> c = (Class<? extends ConsistsOf>) clz;
this.superClasses = retrieveSuperClasses(c, ConsistsOf.class, Relation.NAME);
} else if(RelationTypeDefinition.class.isAssignableFrom(clz)){
this.superClasses = retrieveSuperClasses(clz, BaseRelation.class, EDGE_CLASS_NAME);
this.superClasses.add(TypeDefinition.class.getSimpleName());
@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)){
this.superClasses = retrieveSuperClasses(clz, BaseRelation.class, EDGE_CLASS_NAME);
@SuppressWarnings({"unchecked", "rawtypes"})
Class<? extends IsParentOf> c = (Class<? extends IsParentOf>) clz;
this.superClasses = retrieveSuperClasses(c, IsParentOf.class, BaseRelation.NAME);
} else if(BaseRelation.class.isAssignableFrom(clz)){
this.superClasses = retrieveSuperClasses(clz, BaseRelation.class, null);
} else {
throw new RuntimeException("Type Hierachy Error");
}

View File

@ -19,7 +19,7 @@ public interface TypeDefinition<ISM extends ISManageable> extends ISManageable {
public static final String NAME_PROPERTY = "name";
public static final String DESCRIPTION_PROPERTY = "description";
public static final String ABSTRACT_PROPERTY = "abstract";
public static final String SUPERCLASSES_PROPERTY = "superClasses";
public static final String TYPE_SUPERCLASSES_PROPERTY = "superClasses";
public static final String PROPERTIES_PROPERTY = "properties";
@ISProperty(name = NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ -31,7 +31,7 @@ public interface TypeDefinition<ISM extends ISManageable> extends ISManageable {
@ISProperty(name = ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@ISProperty(name = SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ISProperty(name = TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@ISProperty(name = PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)

View File

@ -1,8 +1,12 @@
package org.gcube.informationsystem.types.reference.entities;
import java.util.Set;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.entities.EntityTypeDefinitionImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@ -13,4 +17,29 @@ public interface EntityTypeDefinition<E extends BaseEntity> extends TypeDefiniti
public static final String NAME = "EntityTypeDefinition"; //EntityTypeDefinition.class.getSimpleName();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = TypeDefinition.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@Override
@ISProperty(name = TypeDefinition.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@Override
@ISProperty(name = TypeDefinition.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@Override
@ISProperty(name = TypeDefinition.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@Override
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
}

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.types.reference.properties;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -16,29 +17,49 @@ public interface PropertyDefinition extends BaseProperty {
public static final String NAME = "PropertyDefinition"; // PropertyDefinition.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
public static final String DESCRIPTION_PROPERTY = "description";
public static final String MANDATORY_PROPERTY = "mandatory";
public static final String READ_ONLY_PROPERTY = "readonly";
public static final String NOT_NULL_PROPERTY = "notnull";
public static final String MAX_PROPERTY = "max";
public static final String MIN_PROPERTY = "min";
public static final String REGEX_PROPERTY = "regexp";
public static final String LINKED_TYPE_PROPERTY = "linkedType";
public static final String LINKED_CLASS_PROPERTY = "linkedClass";
public static final String TYPE_PROPERTY = "type";
@ISProperty(name = NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@ISProperty(name = DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@ISProperty(name = MANDATORY_PROPERTY, readonly = false, mandatory = true, nullable = false)
public boolean isMandatory();
@ISProperty(name = READ_ONLY_PROPERTY, readonly = false, mandatory = true, nullable = false)
public boolean isReadonly();
@ISProperty(name = NOT_NULL_PROPERTY, readonly = false, mandatory = true, nullable = false)
public boolean isNotnull();
@ISProperty(name = MAX_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getMax();
@ISProperty(name = MIN_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getMin();
@ISProperty(name = REGEX_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getRegexp();
@ISProperty(name = LINKED_TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getLinkedType();
@ISProperty(name = LINKED_CLASS_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getLinkedClass();
@ISProperty(name = TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getType();
}

View File

@ -1,6 +1,9 @@
package org.gcube.informationsystem.types.reference.properties;
import java.util.Set;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.properties.PropertyTypeDefinitionImpl;
import org.gcube.informationsystem.types.reference.TypeDefinition;
@ -13,4 +16,28 @@ public interface PropertyTypeDefinition<P extends BaseProperty> extends TypeDefi
public static final String NAME = "PropertyTypeDefinition"; // PropertyTypeDefinition.class.getSimpleName();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = TypeDefinition.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@Override
@ISProperty(name = TypeDefinition.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@Override
@ISProperty(name = TypeDefinition.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@Override
@ISProperty(name = TypeDefinition.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@Override
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
}

View File

@ -1,10 +1,14 @@
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;
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.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@ -16,6 +20,30 @@ public interface RelationTypeDefinition<Out extends BaseEntity, In extends BaseE
public static final String NAME = "RelationTypeDefinition"; // PropertyTypeDefiniton.class.getSimpleName();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = TypeDefinition.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@Override
@ISProperty(name = TypeDefinition.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@Override
@ISProperty(name = TypeDefinition.ABSTRACT_PROPERTY, readonly = true, mandatory = true, nullable = false)
public boolean isAbstract();
@Override
@ISProperty(name = TypeDefinition.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@Override
@ISProperty(name = TypeDefinition.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
public String getSourceType();
public String getTargetType();

View File

@ -11,6 +11,7 @@ import java.util.ServiceLoader;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.types.reference.TypeDefinition;
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
import org.gcube.informationsystem.utils.discovery.SchemaAction;
@ -44,36 +45,31 @@ public abstract class ISMapper {
}
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<Package> packages = new ArrayList<Package>();
@SuppressWarnings("rawtypes")
Class<TypeDefinition> tdClz = TypeDefinition.class;
ISMapper.registerSubtypes(tdClz);
packages.add(tdClz.getPackage());
AccessType[] accessTypes = AccessType.values();
for(AccessType accessType : accessTypes) {
@SuppressWarnings("rawtypes")
Class clz = accessType.getTypeClass();
Class<?> dummyClz = accessType.getDummyImplementationClass();
Class<ISManageable> dummyClz = accessType.getDummyImplementationClass();
if(dummyClz != null) {
SimpleModule isModule = new SimpleModule(accessType.getName());
isModule.addDeserializer(clz, new ERDeserializer<>(clz, mapper));
mapper.registerModule(isModule);
mapper.registerSubtypes(dummyClz);
ISMapper.registerSubtypes(dummyClz);
}
}
SchemaAction schemaAction = new ObjectMappingERAction(mapper);
try {
List<Package> packages = new ArrayList<Package>();
for(AccessType accessType : accessTypes) {
Class<ISManageable> clz = accessType.getTypeClass();
packages.add(clz.getPackage());
}
ISMDiscovery.manageISM(schemaAction, packages.toArray(new Package[]{}));
} catch(Exception e) {
logger.error("Error registering types", e);
}
registerPackages(packages);
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader.load(RegistrationProvider.class);
for (RegistrationProvider registrationProvider : regsitrationProviders) {
@ -83,7 +79,7 @@ public abstract class ISMapper {
}
public static void registerPackages(List<Package> packages) {
SchemaAction schemaAction = new ObjectMappingERAction(mapper);
SchemaAction schemaAction = new ISMappingAction();
try {
ISMDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {
@ -93,7 +89,7 @@ public abstract class ISMapper {
public static void registerPackages(Package... packages) {
SchemaAction schemaAction = new ObjectMappingERAction(mapper);
SchemaAction schemaAction = new ISMappingAction();
try {
ISMDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {

View File

@ -8,35 +8,34 @@ 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;
/**
* @author Luca Frosini (ISTI - CNR)
*/
class ObjectMappingERAction implements SchemaAction {
class ISMappingAction implements SchemaAction {
protected ObjectMapper objectMapper;
public ISMappingAction(){
public ObjectMappingERAction(ObjectMapper objectMapper){
this.objectMapper = objectMapper;
}
@SuppressWarnings("unchecked")
@Override
public <P extends BaseProperty> void managePropertyClass(Class<P> e)
throws Exception {
objectMapper.registerSubtypes(e);
ISMapper.registerSubtypes(e);
}
@SuppressWarnings("unchecked")
@Override
public <E extends BaseEntity> void manageEntityClass(Class<E> e)
throws Exception {
objectMapper.registerSubtypes(e);
ISMapper.registerSubtypes(e);
}
@SuppressWarnings("unchecked")
@Override
public <R extends BaseRelation<? extends BaseEntity, ? extends BaseEntity>> void manageRelationClass(
Class<R> r) throws Exception {
objectMapper.registerSubtypes(r);
ISMapper.registerSubtypes(r);
}
}

View File

@ -4,10 +4,14 @@
package org.gcube.informationsystem.utils.discovery;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.gcube.informationsystem.base.reference.ISManageable;
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
@ -26,9 +30,9 @@ public class ISMDiscovery<ISM extends ISManageable> {
protected final Class<ISM> root;
protected final List<Package> packages;
protected final List<Class<ISM>> discovered;
protected final List<Class<? extends ISM>> discovered;
public List<Class<ISM>> getDiscovered() {
public List<Class<? extends ISM>> getDiscovered() {
return discovered;
}
@ -44,12 +48,12 @@ public class ISMDiscovery<ISM extends ISManageable> {
packages.add(p);
}
protected void add(Class<ISM> clz) {
protected void add(Class<? extends ISM> clz) {
discovered.add(clz);
logger.trace("+ Added {}.", clz);
}
protected void analizeISM(Class<ISM> clz) {
protected void analizeISM(Class<? extends ISM> clz) {
logger.trace("Analizyng {}", clz);
if(!clz.isInterface()) {
@ -80,7 +84,21 @@ public class ISMDiscovery<ISM extends ISManageable> {
for(Method m : clz.getDeclaredMethods()) {
m.setAccessible(true);
if(m.isAnnotationPresent(ISProperty.class)) {
if(root.isAssignableFrom(m.getReturnType())) {
if(Map.class.isAssignableFrom(m.getReturnType()) || Set.class.isAssignableFrom(m.getReturnType())
|| List.class.isAssignableFrom(m.getReturnType())) {
Type[] typeArguments = ((ParameterizedType) m.getGenericReturnType()).getActualTypeArguments();
for(Type t : typeArguments) {
@SuppressWarnings("unchecked")
Class<? extends BaseProperty> tClass = (Class<? extends BaseProperty>) t;
if(root.isAssignableFrom(tClass)) {
@SuppressWarnings("unchecked")
Class<ISM> type = (Class<ISM>) tClass;
analizeISM(type);
}
}
} else if(root.isAssignableFrom(m.getReturnType())) {
@SuppressWarnings("unchecked")
Class<ISM> type = (Class<ISM>) m.getReturnType();
analizeISM(type);
@ -119,7 +137,7 @@ public class ISMDiscovery<ISM extends ISManageable> {
Arrays.stream(packages).forEach(p -> propertyDiscovery.addPackage(p));
}
propertyDiscovery.discover();
for(Class<BaseProperty> property : propertyDiscovery.getDiscovered()) {
for(Class<? extends BaseProperty> property : propertyDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", property);
schemaAction.managePropertyClass(property);
}
@ -130,7 +148,7 @@ public class ISMDiscovery<ISM extends ISManageable> {
}
entityDiscovery.discover();
for(Class<BaseEntity> entity : entityDiscovery.getDiscovered()) {
for(Class<? extends BaseEntity> entity : entityDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", entity);
schemaAction.manageEntityClass(entity);
}
@ -142,7 +160,7 @@ public class ISMDiscovery<ISM extends ISManageable> {
relationDiscovery.discover();
for(@SuppressWarnings("rawtypes")
Class<BaseRelation> relation : relationDiscovery.getDiscovered()) {
Class<? extends BaseRelation> relation : relationDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", relation);
schemaAction.manageRelationClass(relation);
}

View File

@ -0,0 +1,14 @@
package org.gcube.informationsystem.utils.discovery;
import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.types.reference.properties.PropertyTypeDefinition;
import org.junit.Test;
public class ISMDiscoveryTest {
@Test
public void testISMDIscovery() {
ISMDiscovery<BaseProperty> propertyDiscovery = new ISMDiscovery<>(BaseProperty.class);
propertyDiscovery.analizeISM(PropertyTypeDefinition.class);
}
}