Improving code
This commit is contained in:
parent
de12ce5a6d
commit
799aa5a770
|
@ -184,7 +184,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
oClass = ElementManagementUtility.getOClass(element);
|
oClass = ElementManagementUtility.getOClass(element);
|
||||||
} else {
|
} else {
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
CachedType cachedType = typesCache.getType(typeName);
|
CachedType cachedType = typesCache.getCachedType(typeName);
|
||||||
oClass = cachedType.getOClass();
|
oClass = cachedType.getOClass();
|
||||||
AccessType gotAccessType = cachedType.getAccessType();
|
AccessType gotAccessType = cachedType.getAccessType();
|
||||||
if(accessType!=gotAccessType) {
|
if(accessType!=gotAccessType) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class ElementManagementUtility {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public static ElementManagement getERManagement(String type) throws ResourceRegistryException {
|
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;
|
ElementManagement erManagement = null;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class PropertyElementManagement {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
CachedType cachedType = typesCache.getType(type);
|
CachedType cachedType = typesCache.getCachedType(type);
|
||||||
oClass = cachedType.getOClass();
|
oClass = cachedType.getOClass();
|
||||||
AccessType gotAccessType = cachedType.getAccessType();
|
AccessType gotAccessType = cachedType.getAccessType();
|
||||||
if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) {
|
if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) {
|
||||||
|
@ -131,7 +131,7 @@ public class PropertyElementManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
CachedType cachedType = typesCache.getType(type);
|
CachedType cachedType = typesCache.getCachedType(type);
|
||||||
OClass oClass = cachedType.getOClass();
|
OClass oClass = cachedType.getOClass();
|
||||||
AccessType gotAccessType = cachedType.getAccessType();
|
AccessType gotAccessType = cachedType.getAccessType();
|
||||||
if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) {
|
if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) {
|
||||||
|
|
|
@ -781,13 +781,13 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
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) {
|
if(relationAccessType != AccessType.IS_RELATED_TO && relationAccessType != AccessType.CONSISTS_OF) {
|
||||||
String error = String.format("%s must be a relation type", relationType);
|
String error = String.format("%s must be a relation type", relationType);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessType referenceAccessType = typesCache.getType(referenceType).getAccessType();
|
AccessType referenceAccessType = typesCache.getCachedType(referenceType).getAccessType();
|
||||||
if(referenceAccessType != AccessType.RESOURCE && referenceAccessType != AccessType.FACET) {
|
if(referenceAccessType != AccessType.RESOURCE && referenceAccessType != AccessType.FACET) {
|
||||||
String error = String.format("%s must be a en entity type", referenceType);
|
String error = String.format("%s must be a en entity type", referenceType);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
|
|
|
@ -334,7 +334,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
Set<LinkedEntity> constraints = new HashSet<>();
|
Set<LinkedEntity> constraints = new HashSet<>();
|
||||||
|
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
CachedType cachedType = typesCache.getType(typeName);
|
CachedType cachedType = typesCache.getCachedType(typeName);
|
||||||
ResourceType resourceType = (ResourceType) cachedType.getType();
|
ResourceType resourceType = (ResourceType) cachedType.getType();
|
||||||
|
|
||||||
List<LinkedEntity> linkedEntities = resourceType.getFacets();
|
List<LinkedEntity> linkedEntities = resourceType.getFacets();
|
||||||
|
@ -347,7 +347,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
Set<CachedType> cachedSuperTypes = new HashSet<>();
|
Set<CachedType> cachedSuperTypes = new HashSet<>();
|
||||||
List<String> superTypes = cachedType.getSuperTypes();
|
List<String> superTypes = cachedType.getSuperTypes();
|
||||||
for(String superType : superTypes) {
|
for(String superType : superTypes) {
|
||||||
CachedType cachedSuperType = typesCache.getType(superType);
|
CachedType cachedSuperType = typesCache.getCachedType(superType);
|
||||||
cachedSuperTypes.add(cachedSuperType);
|
cachedSuperTypes.add(cachedSuperType);
|
||||||
|
|
||||||
ResourceType resourceSuperType = (ResourceType) cachedSuperType.getType();
|
ResourceType resourceSuperType = (ResourceType) cachedSuperType.getType();
|
||||||
|
@ -380,20 +380,20 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
return stringBuffer.toString();
|
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) {
|
if(requiredType.compareTo(effectiveType)==0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CachedType cachedType = typesCache.getType(requiredType);
|
CachedType cachedType = typesCache.getCachedType(requiredType);
|
||||||
if(cachedType.getSpecilisationTypes().contains(effectiveType)) {
|
if(cachedType.getSubTypes().contains(effectiveType)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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();
|
String requiredSourceResourceType = constraint.getSource();
|
||||||
if(!typeSatified(typesCache, requiredSourceResourceType, typeName)) {
|
if(!typeSatified(typesCache, requiredSourceResourceType, typeName)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.rest;
|
package org.gcube.informationsystem.resourceregistry.rest;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
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.Query;
|
||||||
import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
|
import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
|
||||||
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement;
|
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.orientechnologies.orient.core.record.ODirection;
|
||||||
import com.tinkerpop.blueprints.Direction;
|
import com.tinkerpop.blueprints.Direction;
|
||||||
|
@ -158,7 +161,12 @@ public class Access extends BaseRest {
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(type);
|
schemaManagement.setTypeName(type);
|
||||||
return schemaManagement.read(polymorphic);
|
List<Type> types = schemaManagement.read(polymorphic);
|
||||||
|
try {
|
||||||
|
return TypeMapper.serializeTypeDefinitions(types);
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.rest;
|
package org.gcube.informationsystem.resourceregistry.rest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
import javax.ws.rs.GET;
|
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.AccessPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||||
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -92,7 +96,12 @@ public class SchemaManager {
|
||||||
CalledMethodProvider.instance.set("readType");
|
CalledMethodProvider.instance.set("readType");
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(type);
|
schemaManagement.setTypeName(type);
|
||||||
return schemaManagement.read(polymorphic);
|
List<Type> types = schemaManagement.read(polymorphic);
|
||||||
|
try {
|
||||||
|
return TypeMapper.serializeTypeDefinitions(types);
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.AdminSecurityContext;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
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.Type;
|
||||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||||
import org.slf4j.Logger;
|
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.OMetadata;
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
||||||
|
import com.orientechnologies.orient.core.record.OElement;
|
||||||
import com.tinkerpop.blueprints.util.StringFactory;
|
import com.tinkerpop.blueprints.util.StringFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +53,7 @@ public class CachedType {
|
||||||
|
|
||||||
protected Type type;
|
protected Type type;
|
||||||
protected List<String> superTypes;
|
protected List<String> superTypes;
|
||||||
protected Set<String> specilisationTypes;
|
protected List<String> subTypes;
|
||||||
|
|
||||||
/* Valid only for resource types */
|
/* Valid only for resource types */
|
||||||
protected Set<LinkedEntity> constraints;
|
protected Set<LinkedEntity> constraints;
|
||||||
|
@ -64,7 +67,7 @@ public class CachedType {
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
ODatabaseDocument oDatabaseDocument = null;
|
ODatabaseDocument oDatabaseDocument = null;
|
||||||
try {
|
try {
|
||||||
logger.debug("GettingType {} schema", type);
|
logger.debug("GettingType {} schema", typeName);
|
||||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||||
OMetadata oMetadata = oDatabaseDocument.getMetadata();
|
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 {
|
private synchronized void setOClass(OClass oClass) throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
|
||||||
if(this.oClass==null) {
|
if(this.oClass==null) {
|
||||||
this.oClass = oClass;
|
this.oClass = oClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized OClass getOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
|
|
||||||
return internalGetOClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
private AccessType getAccessTypeFromOClass(OClass oClass) throws ResourceRegistryException {
|
private AccessType getAccessTypeFromOClass(OClass oClass) throws ResourceRegistryException {
|
||||||
AccessType[] accessTypes = AccessType.values();
|
AccessType[] accessTypes = AccessType.values();
|
||||||
for(int i=accessTypes.length-1; i>=0; i--) {
|
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");
|
throw new ResourceRegistryException(typeName + " is not a base type");
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccessType internalGetAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
|
private List<String> getAllSuperclasses(Collection<String> superClassesToBeExcluded) throws SchemaException, ResourceRegistryException {
|
||||||
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
|
|
||||||
|
List<String> 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<OClass> superClasses = internalGetOClass().getSuperClasses();
|
||||||
|
while(superClasses.size()>0) {
|
||||||
|
List<OClass> 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<String> getAllSubclasses() throws SchemaException, ResourceRegistryException {
|
||||||
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
|
|
||||||
|
List<String> allSubClasses = new ArrayList<>();
|
||||||
|
Collection<OClass> subclasses = internalGetOClass().getSubclasses();
|
||||||
|
while(subclasses.size()>0) {
|
||||||
|
List<OClass> 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<? extends OElement> 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(accessType==null) {
|
||||||
if(type!=null) {
|
if(type!=null) {
|
||||||
accessType = type.getAccessType();
|
accessType = type.getAccessType();
|
||||||
|
@ -136,56 +197,39 @@ public class CachedType {
|
||||||
return accessType;
|
return accessType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> internaGetSuperTypes() throws SchemaException, ResourceRegistryException {
|
||||||
|
if(superTypes==null) {
|
||||||
|
superTypes = getAllSuperclasses(superClassesToBeExcluded);
|
||||||
|
}
|
||||||
|
return superTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> 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 {
|
public synchronized AccessType getAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
|
||||||
return internalGetAccessType();
|
return internalGetAccessType();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> getSuperclasses(Collection<String> superClassesToBeExcluded) throws SchemaException, ResourceRegistryException {
|
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
|
||||||
|
|
||||||
List<String> superClasses = new ArrayList<>();
|
|
||||||
List<OClass> allSuperClasses = internalGetOClass().getSuperClasses();
|
|
||||||
while(allSuperClasses.size()>0) {
|
|
||||||
List<OClass> 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<String> getSuperTypes() throws SchemaException, ResourceRegistryException {
|
public synchronized List<String> getSuperTypes() throws SchemaException, ResourceRegistryException {
|
||||||
if(superTypes==null) {
|
return internaGetSuperTypes();
|
||||||
superTypes = getSuperclasses(superClassesToBeExcluded);
|
|
||||||
}
|
|
||||||
return superTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Set<String> getSpecilisationTypes() {
|
public synchronized List<String> getSubTypes() throws SchemaException, ResourceRegistryException {
|
||||||
if(specilisationTypes==null) {
|
return internalGetSubTypes();
|
||||||
|
|
||||||
}
|
|
||||||
return specilisationTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -219,8 +219,7 @@ public class SchemaManagement {
|
||||||
private String getTypeAsString(ElementManagement<? extends OElement> erManagement) throws SchemaException {
|
private String getTypeAsString(ElementManagement<? extends OElement> erManagement) throws SchemaException {
|
||||||
try {
|
try {
|
||||||
if(erManagement!=null) {
|
if(erManagement!=null) {
|
||||||
String ret = erManagement.read().toString();
|
return erManagement.read();
|
||||||
return ret;
|
|
||||||
}else {
|
}else {
|
||||||
throw new SchemaException("You can only request schema of IS Model types and their specilization");
|
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<Type> getSchema(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
||||||
ODatabaseDocument oDatabaseDocument = null;
|
ODatabaseDocument oDatabaseDocument = null;
|
||||||
try {
|
try {
|
||||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||||
|
@ -723,7 +722,7 @@ public class SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TypeMapper.serializeTypeDefinitions(typeDefinitions);
|
return typeDefinitions;
|
||||||
} catch(SchemaException e) {
|
} catch(SchemaException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(SchemaNotFoundException e) {
|
} catch(SchemaNotFoundException e) {
|
||||||
|
@ -782,7 +781,7 @@ public class SchemaManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String read(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
public List<Type> read(boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
||||||
return getSchema(includeSubtypes);
|
return getSchema(includeSubtypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class TypesCache {
|
||||||
cachedTypes = new HashMap<>();
|
cachedTypes = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedType getType(String typeName) {
|
public CachedType getCachedType(String typeName) {
|
||||||
CachedType cachedType = cachedTypes.get(typeName);
|
CachedType cachedType = cachedTypes.get(typeName);
|
||||||
if(cachedType == null ) {
|
if(cachedType == null ) {
|
||||||
logger.trace("{} not in cache. Going to create {} instance", typeName, CachedType.class.getSimpleName());
|
logger.trace("{} not in cache. Going to create {} instance", typeName, CachedType.class.getSimpleName());
|
||||||
|
|
|
@ -62,7 +62,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
public void getPropertyTypeSchema() throws Exception {
|
public void getPropertyTypeSchema() throws Exception {
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(Property.NAME);
|
schemaManagement.setTypeName(Property.NAME);
|
||||||
String json = schemaManagement.read(false);
|
List<Type> types = schemaManagement.read(false);
|
||||||
|
String json = TypeMapper.serializeTypeDefinitions(types);
|
||||||
logger.debug(json);
|
logger.debug(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +88,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
public void getFacetSchema() throws Exception {
|
public void getFacetSchema() throws Exception {
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(ContactFacet.NAME);
|
schemaManagement.setTypeName(ContactFacet.NAME);
|
||||||
String json = schemaManagement.read(false);
|
List<Type> types = schemaManagement.read(false);
|
||||||
|
String json = TypeMapper.serializeTypeDefinitions(types);
|
||||||
logger.info(json);
|
logger.info(json);
|
||||||
List<Type> typeDefinitions = TypeMapper.deserializeTypeDefinitions(json);
|
List<Type> typeDefinitions = TypeMapper.deserializeTypeDefinitions(json);
|
||||||
logger.info("{}", typeDefinitions);
|
logger.info("{}", typeDefinitions);
|
||||||
|
@ -114,7 +116,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
public void getResourceSchema() throws Exception {
|
public void getResourceSchema() throws Exception {
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(Actor.NAME);
|
schemaManagement.setTypeName(Actor.NAME);
|
||||||
String json = schemaManagement.read(false);
|
List<Type> types = schemaManagement.read(false);
|
||||||
|
String json = TypeMapper.serializeTypeDefinitions(types);
|
||||||
logger.trace(json);
|
logger.trace(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +137,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(Resource.NAME);
|
schemaManagement.setTypeName(Resource.NAME);
|
||||||
String list = schemaManagement.read(includeSubTypes);
|
List<Type> types = schemaManagement.read(includeSubTypes);
|
||||||
|
String list = TypeMapper.serializeTypeDefinitions(types);
|
||||||
logger.info("{} list : {}", Resource.NAME, list);
|
logger.info("{} list : {}", Resource.NAME, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +150,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(Facet.NAME);
|
schemaManagement.setTypeName(Facet.NAME);
|
||||||
String list = schemaManagement.read(includeSubTypes);
|
List<Type> types = schemaManagement.read(includeSubTypes);
|
||||||
|
String list = TypeMapper.serializeTypeDefinitions(types);
|
||||||
logger.info("{} list : {}", Facet.NAME, list);
|
logger.info("{} list : {}", Facet.NAME, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +163,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(ConsistsOf.NAME);
|
schemaManagement.setTypeName(ConsistsOf.NAME);
|
||||||
String list = schemaManagement.read(includeSubTypes);
|
List<Type> types = schemaManagement.read(includeSubTypes);
|
||||||
|
String list = TypeMapper.serializeTypeDefinitions(types);
|
||||||
logger.info("{} list : {}", ConsistsOf.NAME, list);
|
logger.info("{} list : {}", ConsistsOf.NAME, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +176,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
|
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
schemaManagement.setTypeName(IsRelatedTo.NAME);
|
schemaManagement.setTypeName(IsRelatedTo.NAME);
|
||||||
String list = schemaManagement.read(includeSubTypes);
|
List<Type> types = schemaManagement.read(includeSubTypes);
|
||||||
|
String list = TypeMapper.serializeTypeDefinitions(types);
|
||||||
logger.info("{} list : {}", IsRelatedTo.NAME, list);
|
logger.info("{} list : {}", IsRelatedTo.NAME, list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<String> superTypes = cachedType.getSuperTypes();
|
||||||
|
logger.debug("{} superTypes are {}", typeName, superTypes);
|
||||||
|
for(String superType : superTypes) {
|
||||||
|
getCachedType(typesCache, superType);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -13,7 +13,7 @@
|
||||||
<logger name="org.gcube.informationsystem" level="TRACE" />
|
<logger name="org.gcube.informationsystem" level="TRACE" />
|
||||||
<logger name="org.gcube.informationsystem.types" level="INFO" />
|
<logger name="org.gcube.informationsystem.types" level="INFO" />
|
||||||
<logger name="org.gcube.informationsystem.resourceregistry.dbinitialization" level="INFO" />
|
<logger name="org.gcube.informationsystem.resourceregistry.dbinitialization" level="INFO" />
|
||||||
<logger name=" org.gcube.informationsystem.impl.utils.discovery" level="INFO" />
|
<logger name="org.gcube.informationsystem.utils.discovery" level="ERROR" />
|
||||||
|
|
||||||
<root level="WARN">
|
<root level="WARN">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
|
|
Loading…
Reference in New Issue