diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java index 863a767..bec8e5d 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java @@ -184,7 +184,7 @@ public abstract class ElementManagement { oClass = ElementManagementUtility.getOClass(element); } else { TypesCache typesCache = TypesCache.getInstance(); - CachedType cachedType = typesCache.getType(typeName); + CachedType cachedType = typesCache.getCachedType(typeName); oClass = cachedType.getOClass(); AccessType gotAccessType = cachedType.getAccessType(); if(accessType!=gotAccessType) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java index a9f378b..56d8810 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java @@ -40,7 +40,7 @@ public class ElementManagementUtility { @SuppressWarnings("rawtypes") public static ElementManagement getERManagement(String type) throws ResourceRegistryException { - AccessType accessType = TypesCache.getInstance().getType(type).getAccessType(); + AccessType accessType = TypesCache.getInstance().getCachedType(type).getAccessType(); ElementManagement erManagement = null; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java index 2cc13e9..1f7ce8c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/properties/PropertyElementManagement.java @@ -56,7 +56,7 @@ public class PropertyElementManagement { try { TypesCache typesCache = TypesCache.getInstance(); - CachedType cachedType = typesCache.getType(type); + CachedType cachedType = typesCache.getCachedType(type); oClass = cachedType.getOClass(); AccessType gotAccessType = cachedType.getAccessType(); if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) { @@ -131,7 +131,7 @@ public class PropertyElementManagement { } TypesCache typesCache = TypesCache.getInstance(); - CachedType cachedType = typesCache.getType(type); + CachedType cachedType = typesCache.getCachedType(type); OClass oClass = cachedType.getOClass(); AccessType gotAccessType = cachedType.getAccessType(); if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index bc4c9ca..8b29942 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -781,13 +781,13 @@ public abstract class EntityManagement extends EntityElementMa oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER); TypesCache typesCache = TypesCache.getInstance(); - AccessType relationAccessType = typesCache.getType(relationType).getAccessType(); + AccessType relationAccessType = typesCache.getCachedType(relationType).getAccessType(); if(relationAccessType != AccessType.IS_RELATED_TO && relationAccessType != AccessType.CONSISTS_OF) { String error = String.format("%s must be a relation type", relationType); throw new ResourceRegistryException(error); } - AccessType referenceAccessType = typesCache.getType(referenceType).getAccessType(); + AccessType referenceAccessType = typesCache.getCachedType(referenceType).getAccessType(); if(referenceAccessType != AccessType.RESOURCE && referenceAccessType != AccessType.FACET) { String error = String.format("%s must be a en entity type", referenceType); throw new ResourceRegistryException(error); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java index 3c36a7e..f174f10 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java @@ -334,7 +334,7 @@ public class ResourceManagement extends EntityManagement { Set constraints = new HashSet<>(); TypesCache typesCache = TypesCache.getInstance(); - CachedType cachedType = typesCache.getType(typeName); + CachedType cachedType = typesCache.getCachedType(typeName); ResourceType resourceType = (ResourceType) cachedType.getType(); List linkedEntities = resourceType.getFacets(); @@ -347,7 +347,7 @@ public class ResourceManagement extends EntityManagement { Set cachedSuperTypes = new HashSet<>(); List superTypes = cachedType.getSuperTypes(); for(String superType : superTypes) { - CachedType cachedSuperType = typesCache.getType(superType); + CachedType cachedSuperType = typesCache.getCachedType(superType); cachedSuperTypes.add(cachedSuperType); ResourceType resourceSuperType = (ResourceType) cachedSuperType.getType(); @@ -380,20 +380,20 @@ public class ResourceManagement extends EntityManagement { return stringBuffer.toString(); } - protected boolean typeSatified(TypesCache typesCache, String requiredType, String effectiveType) { + protected boolean typeSatified(TypesCache typesCache, String requiredType, String effectiveType) throws SchemaException, ResourceRegistryException { if(requiredType.compareTo(effectiveType)==0) { return true; } - CachedType cachedType = typesCache.getType(requiredType); - if(cachedType.getSpecilisationTypes().contains(effectiveType)) { + CachedType cachedType = typesCache.getCachedType(requiredType); + if(cachedType.getSubTypes().contains(effectiveType)) { return true; } return false; } - protected boolean constraintSatisfied(TypesCache typesCache, LinkedEntity constraint, String consistsOfType, String facetType) { + protected boolean constraintSatisfied(TypesCache typesCache, LinkedEntity constraint, String consistsOfType, String facetType) throws SchemaException, ResourceRegistryException { String requiredSourceResourceType = constraint.getSource(); if(!typeSatified(typesCache, requiredSourceResourceType, typeName)) { return false; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java index 197c6e9..2c3fe65 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java @@ -1,6 +1,7 @@ package org.gcube.informationsystem.resourceregistry.rest; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -35,6 +36,8 @@ import org.gcube.informationsystem.resourceregistry.instances.model.entities.Res import org.gcube.informationsystem.resourceregistry.query.Query; import org.gcube.informationsystem.resourceregistry.query.QueryImpl; import org.gcube.informationsystem.resourceregistry.types.SchemaManagement; +import org.gcube.informationsystem.types.TypeMapper; +import org.gcube.informationsystem.types.reference.Type; import com.orientechnologies.orient.core.record.ODirection; import com.tinkerpop.blueprints.Direction; @@ -158,7 +161,12 @@ public class Access extends BaseRest { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(type); - return schemaManagement.read(polymorphic); + List types = schemaManagement.read(polymorphic); + try { + return TypeMapper.serializeTypeDefinitions(types); + }catch (Exception e) { + throw new ResourceRegistryException(e); + } } /* diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java index 724ed49..138102b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java @@ -1,5 +1,7 @@ package org.gcube.informationsystem.resourceregistry.rest; +import java.util.List; + import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -20,6 +22,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.TypePath; import org.gcube.informationsystem.resourceregistry.types.SchemaManagement; +import org.gcube.informationsystem.types.TypeMapper; +import org.gcube.informationsystem.types.reference.Type; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,7 +96,12 @@ public class SchemaManager { CalledMethodProvider.instance.set("readType"); SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(type); - return schemaManagement.read(polymorphic); + List types = schemaManagement.read(polymorphic); + try { + return TypeMapper.serializeTypeDefinitions(types); + }catch (Exception e) { + throw new ResourceRegistryException(e); + } } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java index 9ad3dcc..4603d11 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java @@ -14,6 +14,8 @@ import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment; +import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; +import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.types.reference.properties.LinkedEntity; import org.slf4j.Logger; @@ -23,6 +25,7 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.metadata.OMetadata; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OSchema; +import com.orientechnologies.orient.core.record.OElement; import com.tinkerpop.blueprints.util.StringFactory; /** @@ -50,7 +53,7 @@ public class CachedType { protected Type type; protected List superTypes; - protected Set specilisationTypes; + protected List subTypes; /* Valid only for resource types */ protected Set constraints; @@ -64,7 +67,7 @@ public class CachedType { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument oDatabaseDocument = null; try { - logger.debug("GettingType {} schema", type); + logger.debug("GettingType {} schema", typeName); AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER); OMetadata oMetadata = oDatabaseDocument.getMetadata(); @@ -97,23 +100,12 @@ public class CachedType { } - private OClass internalGetOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { - if(oClass==null) { - oClass = retrieveOClass(); - } - return oClass; - } - private synchronized void setOClass(OClass oClass) throws SchemaNotFoundException, SchemaException, ResourceRegistryException { if(this.oClass==null) { this.oClass = oClass; } } - public synchronized OClass getOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { - return internalGetOClass(); - } - private AccessType getAccessTypeFromOClass(OClass oClass) throws ResourceRegistryException { AccessType[] accessTypes = AccessType.values(); for(int i=accessTypes.length-1; i>=0; i--) { @@ -125,7 +117,76 @@ public class CachedType { throw new ResourceRegistryException(typeName + " is not a base type"); } - public AccessType internalGetAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + private List getAllSuperclasses(Collection superClassesToBeExcluded) throws SchemaException, ResourceRegistryException { + TypesCache typesCache = TypesCache.getInstance(); + + List allSuperClasses = new ArrayList<>(); + + // Instead of using getAllSuperClasses() we get just the first level superclasses and so on. + // This allow to have an order list where the first superclass is a a first level superclass. + List superClasses = internalGetOClass().getSuperClasses(); + while(superClasses.size()>0) { + List toBeAnalysed = new ArrayList<>(superClasses); + superClasses = new ArrayList<>(); + for(OClass oSuperClass : toBeAnalysed) { + String name = oSuperClass.getName(); + CachedType cachedType = typesCache.getCachedType(name); + cachedType.setOClass(oSuperClass); + if(name.compareTo(StringFactory.V.toUpperCase()) == 0 || name.compareTo(StringFactory.E.toUpperCase()) == 0 + || name.compareTo(DatabaseEnvironment.O_RESTRICTED_CLASS) == 0) { + continue; + } + + if(superClassesToBeExcluded.contains(name)) { + continue; + } + allSuperClasses.add(allSuperClasses.size(), name); + superClasses.addAll(oSuperClass.getSuperClasses()); + } + } + return allSuperClasses; + } + + protected List getAllSubclasses() throws SchemaException, ResourceRegistryException { + TypesCache typesCache = TypesCache.getInstance(); + + List allSubClasses = new ArrayList<>(); + Collection subclasses = internalGetOClass().getSubclasses(); + while(subclasses.size()>0) { + List toBeAnalysed = new ArrayList<>(subclasses); + subclasses = new ArrayList<>(); + for(OClass oSubClass : toBeAnalysed) { + String name = oSubClass.getName(); + CachedType cachedType = typesCache.getCachedType(name); + cachedType.setOClass(oSubClass); + allSubClasses.add(allSubClasses.size(), name); + subclasses.addAll(oSubClass.getSubclasses()); + } + } + return allSubClasses; + } + + private OClass internalGetOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + if(oClass==null) { + oClass = retrieveOClass(); + } + return oClass; + } + + private Type internalGetType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + if(type==null) { + ElementManagement erManagement = SchemaManagement.getTypeManagement(internalGetOClass()); + String typeString = erManagement.read(); + try { + type = TypeMapper.deserializeTypeDefinition(typeString); + } catch (Exception e) { + throw new ResourceRegistryException(e); + } + } + return type; + } + + private AccessType internalGetAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { if(accessType==null) { if(type!=null) { accessType = type.getAccessType(); @@ -136,56 +197,39 @@ public class CachedType { return accessType; } + private List internaGetSuperTypes() throws SchemaException, ResourceRegistryException { + if(superTypes==null) { + superTypes = getAllSuperclasses(superClassesToBeExcluded); + } + return superTypes; + } + + private List internalGetSubTypes() throws SchemaException, ResourceRegistryException { + if(subTypes==null) { + subTypes = getAllSubclasses(); + } + return subTypes; + } + + + public synchronized OClass getOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + return internalGetOClass(); + } + + public synchronized Type getType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + return internalGetType(); + } + public synchronized AccessType getAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { return internalGetAccessType(); } - protected List getSuperclasses(Collection superClassesToBeExcluded) throws SchemaException, ResourceRegistryException { - TypesCache typesCache = TypesCache.getInstance(); - - List superClasses = new ArrayList<>(); - List allSuperClasses = internalGetOClass().getSuperClasses(); - while(allSuperClasses.size()>0) { - List toBeAnalysed = new ArrayList<>(allSuperClasses); - allSuperClasses = new ArrayList<>(); - for(OClass oSuperClass : toBeAnalysed) { - String name = oSuperClass.getName(); - CachedType cachedType = typesCache.getType(name); - cachedType.setOClass(oSuperClass); - if(name.compareTo(StringFactory.V.toUpperCase()) == 0 || name.compareTo(StringFactory.E.toUpperCase()) == 0 - || name.compareTo(DatabaseEnvironment.O_RESTRICTED_CLASS) == 0) { - continue; - } - - if(superClassesToBeExcluded.contains(name)) { - continue; - } - superClasses.add(superClasses.size(), name); - allSuperClasses.addAll(oSuperClass.getSuperClasses()); - } - } - return superClasses; - } - - public synchronized Type getType() { - if(type==null) { - - } - return type; - } - public synchronized List getSuperTypes() throws SchemaException, ResourceRegistryException { - if(superTypes==null) { - superTypes = getSuperclasses(superClassesToBeExcluded); - } - return superTypes; + return internaGetSuperTypes(); } - public synchronized Set getSpecilisationTypes() { - if(specilisationTypes==null) { - - } - return specilisationTypes; + public synchronized List getSubTypes() throws SchemaException, ResourceRegistryException { + return internalGetSubTypes(); } @Override diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java index ed93596..44bafed 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagement.java @@ -219,8 +219,7 @@ public class SchemaManagement { private String getTypeAsString(ElementManagement erManagement) throws SchemaException { try { if(erManagement!=null) { - String ret = erManagement.read().toString(); - return ret; + return erManagement.read(); }else { throw new SchemaException("You can only request schema of IS Model types and their specilization"); } @@ -700,7 +699,7 @@ public class SchemaManagement { } } - protected String getSchema(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException { + protected List getSchema(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException { ODatabaseDocument oDatabaseDocument = null; try { AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext(); @@ -723,7 +722,7 @@ public class SchemaManagement { } } - return TypeMapper.serializeTypeDefinitions(typeDefinitions); + return typeDefinitions; } catch(SchemaException e) { throw e; } catch(SchemaNotFoundException e) { @@ -782,7 +781,7 @@ public class SchemaManagement { } } - public String read(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException { + public List read(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException { return getSchema(includeSubtypes); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypesCache.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypesCache.java index 5c718c1..5fac835 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypesCache.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/TypesCache.java @@ -28,7 +28,7 @@ public class TypesCache { cachedTypes = new HashMap<>(); } - public CachedType getType(String typeName) { + public CachedType getCachedType(String typeName) { CachedType cachedType = cachedTypes.get(typeName); if(cachedType == null ) { logger.trace("{} not in cache. Going to create {} instance", typeName, CachedType.class.getSimpleName()); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagementImplTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagementImplTest.java index 02fea39..31b4044 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagementImplTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/types/SchemaManagementImplTest.java @@ -62,7 +62,8 @@ public class SchemaManagementImplTest extends ContextTest { public void getPropertyTypeSchema() throws Exception { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(Property.NAME); - String json = schemaManagement.read(false); + List types = schemaManagement.read(false); + String json = TypeMapper.serializeTypeDefinitions(types); logger.debug(json); } @@ -87,7 +88,8 @@ public class SchemaManagementImplTest extends ContextTest { public void getFacetSchema() throws Exception { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(ContactFacet.NAME); - String json = schemaManagement.read(false); + List types = schemaManagement.read(false); + String json = TypeMapper.serializeTypeDefinitions(types); logger.info(json); List typeDefinitions = TypeMapper.deserializeTypeDefinitions(json); logger.info("{}", typeDefinitions); @@ -114,7 +116,8 @@ public class SchemaManagementImplTest extends ContextTest { public void getResourceSchema() throws Exception { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(Actor.NAME); - String json = schemaManagement.read(false); + List types = schemaManagement.read(false); + String json = TypeMapper.serializeTypeDefinitions(types); logger.trace(json); } @@ -134,7 +137,8 @@ public class SchemaManagementImplTest extends ContextTest { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(Resource.NAME); - String list = schemaManagement.read(includeSubTypes); + List types = schemaManagement.read(includeSubTypes); + String list = TypeMapper.serializeTypeDefinitions(types); logger.info("{} list : {}", Resource.NAME, list); } @@ -146,7 +150,8 @@ public class SchemaManagementImplTest extends ContextTest { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(Facet.NAME); - String list = schemaManagement.read(includeSubTypes); + List types = schemaManagement.read(includeSubTypes); + String list = TypeMapper.serializeTypeDefinitions(types); logger.info("{} list : {}", Facet.NAME, list); } @@ -158,7 +163,8 @@ public class SchemaManagementImplTest extends ContextTest { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(ConsistsOf.NAME); - String list = schemaManagement.read(includeSubTypes); + List types = schemaManagement.read(includeSubTypes); + String list = TypeMapper.serializeTypeDefinitions(types); logger.info("{} list : {}", ConsistsOf.NAME, list); } @@ -170,7 +176,8 @@ public class SchemaManagementImplTest extends ContextTest { SchemaManagement schemaManagement = new SchemaManagement(); schemaManagement.setTypeName(IsRelatedTo.NAME); - String list = schemaManagement.read(includeSubTypes); + List types = schemaManagement.read(includeSubTypes); + String list = TypeMapper.serializeTypeDefinitions(types); logger.info("{} list : {}", IsRelatedTo.NAME, list); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/types/TypesCacheTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/types/TypesCacheTest.java new file mode 100644 index 0000000..d887a83 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/types/TypesCacheTest.java @@ -0,0 +1,62 @@ +package org.gcube.informationsystem.resourceregistry.types; + +import java.util.List; + +import org.gcube.informationsystem.base.reference.AccessType; +import org.gcube.informationsystem.types.TypeMapper; +import org.gcube.informationsystem.types.reference.Type; +import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin; +import org.gcube.resourcemanagement.model.reference.entities.resources.Service; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.orientechnologies.orient.core.metadata.schema.OClass; + +public class TypesCacheTest { + + private static Logger logger = LoggerFactory.getLogger(TypesCacheTest.class); + + protected CachedType getCachedType(TypesCache typesCache, String typeName) throws Exception { + CachedType cachedType = typesCache.getCachedType(typeName); + OClass oClass = cachedType.getOClass(); + AccessType accessType = cachedType.getAccessType(); + Type type = cachedType.getType(); + logger.debug("{} ({}) : {}", oClass.toString(), accessType.toString(), TypeMapper.serializeTypeDefinition(type)); + return cachedType; + } + + public void testCacheType(String typeName) throws Exception { + + TypesCache typesCache = TypesCache.getInstance(); + CachedType cachedType = getCachedType(typesCache, typeName); + + List superTypes = cachedType.getSuperTypes(); + logger.debug("{} superTypes are {}", typeName, superTypes); + for(String superType : superTypes) { + getCachedType(typesCache, superType); + } + + List subTypes = cachedType.getSubTypes(); + logger.debug("{} subTypes are {}", typeName, subTypes); + for(String subType : subTypes) { + getCachedType(typesCache, subType); + } + + } + + @Test + public void test() throws Exception { + testCacheType(Service.NAME); + testCacheType(RunningPlugin.NAME); + } + + @Test + public void test2() throws Exception { + logger.debug("------------------------------------------"); + testCacheType(Service.NAME); + testCacheType(RunningPlugin.NAME); + } + + +} diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index b00fc6b..fd988d8 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -13,7 +13,7 @@ - +