Adding type cache. Refatoring code
This commit is contained in:
parent
c21fa2aa1a
commit
421dce843f
|
@ -177,6 +177,10 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
}
|
||||
}
|
||||
|
||||
public void setoDatabaseDocument(ODatabaseDocument oDatabaseDocument) {
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
}
|
||||
|
||||
public void setOClass(OClass oClass) {
|
||||
this.oClass = oClass;
|
||||
}
|
||||
|
@ -186,8 +190,12 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
if(element != null) {
|
||||
oClass = getOClass(element);
|
||||
} else {
|
||||
oClass = TypesCache.getTypeSchema(elementType);
|
||||
TypesCache.checkAccessType(oClass, elementType, accessType);
|
||||
TypesCache typesCache = TypesCache.getInstance();
|
||||
oClass = TypesCache.getInstance().getTypeOClass(elementType);
|
||||
AccessType gotAccessType = typesCache.getBaseAccessType(elementType);
|
||||
if(accessType!=gotAccessType) {
|
||||
throw new SchemaException(elementType + " is not a " + accessType.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return oClass;
|
||||
|
@ -454,7 +462,6 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
boolean update = false;
|
||||
try {
|
||||
getElement();
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.gcube.informationsystem.base.reference.AccessType;
|
|||
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.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;
|
||||
|
@ -37,71 +36,34 @@ public class ElementManagementUtility {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(ElementManagementUtility.class);
|
||||
|
||||
public static AccessType getBaseAccessType(String type) throws ResourceRegistryException {
|
||||
|
||||
OClass oClass = TypesCache.getTypeSchema(type);
|
||||
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
return AccessType.RESOURCE;
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
return AccessType.FACET;
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
return AccessType.CONSISTS_OF;
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
return AccessType.IS_RELATED_TO;
|
||||
} else if(oClass.isSubClassOf(Property.NAME)) {
|
||||
return AccessType.PROPERTY;
|
||||
}
|
||||
|
||||
throw new ResourceRegistryException(type + "is not a base type");
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ElementManagement getERManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument, String type) throws ResourceRegistryException {
|
||||
|
||||
OClass oClass = TypesCache.getTypeSchema(oDatabaseDocument, type);
|
||||
ElementManagement erManagement = null;
|
||||
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
erManagement = new ResourceManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
erManagement = new FacetManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
erManagement = new ConsistsOfManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
erManagement = new IsRelatedToManagement(workingContext, oDatabaseDocument);
|
||||
}
|
||||
|
||||
if(erManagement == null) {
|
||||
throw new ResourceRegistryException(String.format("%s is not querable", type.toString()));
|
||||
}
|
||||
|
||||
erManagement.setElementType(type);
|
||||
return erManagement;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ElementManagement getERManagement(String type) throws ResourceRegistryException {
|
||||
|
||||
OClass oClass = TypesCache.getTypeSchema(type);
|
||||
AccessType accessType = TypesCache.getInstance().getBaseAccessType(type);
|
||||
|
||||
ElementManagement erManagement = null;
|
||||
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
switch (accessType) {
|
||||
case RESOURCE:
|
||||
erManagement = new ResourceManagement();
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
erManagement = new FacetManagement();
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
erManagement = new ConsistsOfManagement();
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
erManagement = new IsRelatedToManagement();
|
||||
}
|
||||
break;
|
||||
|
||||
if(erManagement == null) {
|
||||
case FACET:
|
||||
erManagement = new FacetManagement();
|
||||
break;
|
||||
|
||||
case IS_RELATED_TO:
|
||||
erManagement = new IsRelatedToManagement();
|
||||
break;
|
||||
|
||||
case CONSISTS_OF:
|
||||
erManagement = new ConsistsOfManagement();
|
||||
|
||||
default:
|
||||
throw new ResourceRegistryException(String.format("%s is not querable", type.toString()));
|
||||
}
|
||||
|
||||
erManagement.setElementType(type);
|
||||
|
||||
return erManagement;
|
||||
}
|
||||
|
||||
|
@ -180,14 +142,16 @@ public class ElementManagementUtility {
|
|||
|
||||
EntityManagement entityManagement = null;
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
entityManagement = new ResourceManagement(workingContext, oDatabaseDocument);
|
||||
entityManagement = new ResourceManagement();
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
entityManagement = new FacetManagement(workingContext, oDatabaseDocument);
|
||||
entityManagement = new FacetManagement();
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. %s", vertex, Resource.NAME, Facet.NAME,
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
entityManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
entityManagement.setWorkingContext(workingContext);
|
||||
entityManagement.setElement(vertex);
|
||||
return entityManagement;
|
||||
}
|
||||
|
@ -210,14 +174,19 @@ public class ElementManagementUtility {
|
|||
|
||||
RelationManagement relationManagement = null;
|
||||
if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(workingContext, oDatabaseDocument);
|
||||
relationManagement = new ConsistsOfManagement();
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(workingContext, oDatabaseDocument);
|
||||
relationManagement = new IsRelatedToManagement();
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. %s", edge, ConsistsOf.NAME, IsRelatedTo.NAME,
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
|
||||
relationManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
relationManagement.setWorkingContext(workingContext);
|
||||
|
||||
relationManagement.setElement(edge);
|
||||
return relationManagement;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
|||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
|
@ -53,8 +54,12 @@ public class PropertyElementManagement {
|
|||
OClass oClass = null;
|
||||
|
||||
try {
|
||||
oClass = TypesCache.getTypeSchema(type);
|
||||
TypesCache.checkAccessType(oClass, type, AccessType.PROPERTY_ELEMENT);
|
||||
TypesCache typesCache = TypesCache.getInstance();
|
||||
oClass = typesCache.getTypeOClass(type);
|
||||
AccessType gotAccessType = typesCache.getBaseAccessType(type);
|
||||
if(AccessType.PROPERTY_ELEMENT!=gotAccessType) {
|
||||
throw new SchemaException(type + " is not a " + AccessType.PROPERTY_ELEMENT.getName());
|
||||
}
|
||||
} catch(SchemaNotFoundException e) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -122,9 +127,12 @@ public class PropertyElementManagement {
|
|||
if(type==null) {
|
||||
return jsonNode;
|
||||
}
|
||||
|
||||
OClass oClass = TypesCache.getTypeSchema(type);
|
||||
TypesCache.checkAccessType(oClass, type, AccessType.PROPERTY_ELEMENT);
|
||||
TypesCache typesCache = TypesCache.getInstance();
|
||||
OClass oClass = typesCache.getTypeOClass(type);
|
||||
AccessType gotAccessType = typesCache.getBaseAccessType(type);
|
||||
if(AccessType.PROPERTY_ELEMENT!=gotAccessType) {
|
||||
throw new SchemaException(type + " is not a " + AccessType.PROPERTY_ELEMENT.getName());
|
||||
}
|
||||
/*
|
||||
* In case it is an Encrypted type the value is encrypted with the DB Key
|
||||
* Resource Registry must decrypt the value with the DB Key and Encrypt it with Context key.
|
||||
|
|
|
@ -187,7 +187,9 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
|
|||
if(accessType.compareTo(AccessType.CONSISTS_OF) == 0) {
|
||||
JsonNode target = jsonNode.get(Relation.TARGET_PROPERTY);
|
||||
if(target != null) {
|
||||
FacetManagement fm = new FacetManagement(getWorkingContext(), oDatabaseDocument);
|
||||
FacetManagement fm = new FacetManagement();
|
||||
fm.setWorkingContext(getWorkingContext());
|
||||
fm.setoDatabaseDocument(oDatabaseDocument);
|
||||
fm.setJsonNode(target);
|
||||
fm.internalUpdate();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,9 @@ public class ERManagementUtility {
|
|||
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(adminSecurityContext, oDatabaseDocument, type);
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||
elementManagement.setWorkingContext(adminSecurityContext);
|
||||
elementManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
elementManagement.setUUID(uuid);
|
||||
elementManagement.setElementType(type);
|
||||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
|
@ -109,7 +111,9 @@ public class ERManagementUtility {
|
|||
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(adminSecurityContext, oDatabaseDocument, type);
|
||||
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||
elementManagement.setWorkingContext(adminSecurityContext);
|
||||
elementManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
elementManagement.setUUID(uuid);
|
||||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage
|
|||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
|
@ -153,12 +154,6 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
|||
this.honourPropagationConstraintsInContextSharing = true;
|
||||
}
|
||||
|
||||
protected EntityManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
this(accessType);
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OVertex getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
|
@ -784,13 +779,13 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
|||
try {
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
||||
AccessType relationAccessType = ElementManagementUtility.getBaseAccessType(relationType);
|
||||
AccessType relationAccessType = TypesCache.getInstance().getBaseAccessType(relationType);
|
||||
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 = ElementManagementUtility.getBaseAccessType(referenceType);
|
||||
AccessType referenceAccessType = TypesCache.getInstance().getBaseAccessType(referenceType);
|
||||
if(referenceAccessType != AccessType.RESOURCE && referenceAccessType != AccessType.FACET) {
|
||||
String error = String.format("%s must be a en entity type", referenceType);
|
||||
throw new ResourceRegistryException(error);
|
||||
|
|
|
@ -11,9 +11,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
|
@ -25,10 +23,6 @@ public class FacetManagement extends EntityManagement<Facet> {
|
|||
super(AccessType.FACET);
|
||||
}
|
||||
|
||||
public FacetManagement(SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
super(AccessType.FACET, workingContext, orientGraph);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FacetNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new FacetNotFoundException(e.getMessage(), e.getCause());
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.gcube.informationsystem.types.TypeMapper;
|
|||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
|
@ -51,10 +50,6 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
super(AccessType.RESOURCE);
|
||||
}
|
||||
|
||||
public ResourceManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument) {
|
||||
super(AccessType.RESOURCE, workingContext, oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new ResourceNotFoundException(e.getMessage(), e.getCause());
|
||||
|
@ -147,7 +142,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode consistOfJsonNode : jsonNodeArray) {
|
||||
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), oDatabaseDocument);
|
||||
ConsistsOfManagement com = new ConsistsOfManagement();
|
||||
com.setWorkingContext(getWorkingContext());
|
||||
com.setoDatabaseDocument(oDatabaseDocument);
|
||||
com.setJsonNode(consistOfJsonNode);
|
||||
com.setSourceEntityManagement(this);
|
||||
com.internalCreate();
|
||||
|
@ -159,7 +156,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), oDatabaseDocument);
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement();
|
||||
irtm.setWorkingContext(getWorkingContext());
|
||||
irtm.setoDatabaseDocument(oDatabaseDocument);
|
||||
irtm.setJsonNode(relationJsonNode);
|
||||
irtm.setSourceEntityManagement(this);
|
||||
irtm.internalCreate();
|
||||
|
@ -179,7 +178,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), oDatabaseDocument);
|
||||
ConsistsOfManagement com = new ConsistsOfManagement();
|
||||
com.setWorkingContext(getWorkingContext());
|
||||
com.setoDatabaseDocument(oDatabaseDocument);
|
||||
com.setJsonNode(relationJsonNode);
|
||||
com.internalCreateOrUdate();
|
||||
addToRelationManagement(com);
|
||||
|
@ -190,7 +191,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), oDatabaseDocument);
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement();
|
||||
irtm.setWorkingContext(getWorkingContext());
|
||||
irtm.setoDatabaseDocument(oDatabaseDocument);
|
||||
irtm.setJsonNode(relationJsonNode);
|
||||
irtm.internalUpdate();
|
||||
addToRelationManagement(irtm);
|
||||
|
@ -217,14 +220,16 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
@SuppressWarnings("rawtypes")
|
||||
RelationManagement relationManagement = null;
|
||||
if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(getWorkingContext(), oDatabaseDocument);
|
||||
relationManagement = new IsRelatedToManagement();
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(getWorkingContext(), oDatabaseDocument);
|
||||
relationManagement = new ConsistsOfManagement();
|
||||
} else {
|
||||
logger.warn("{} is not a {} nor a {}. {}", Utility.toJsonString(edge, true), IsRelatedTo.NAME,
|
||||
ConsistsOf.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
if(relationManagement != null) {
|
||||
relationManagement.setWorkingContext(getWorkingContext());
|
||||
relationManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
relationManagement.setElement(edge);
|
||||
relationManagement.internalDelete();
|
||||
}
|
||||
|
|
|
@ -15,11 +15,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
|
@ -37,10 +34,6 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement> {
|
|||
super(AccessType.CONSISTS_OF, Facet.class, DEFAULT_CONSISTS_OF_PC);
|
||||
}
|
||||
|
||||
public ConsistsOfManagement(SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
super(AccessType.CONSISTS_OF, Facet.class, workingContext, orientGraph, DEFAULT_CONSISTS_OF_PC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConsistsOfNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new ConsistsOfNotFoundException(e.getMessage(), e.getCause());
|
||||
|
@ -59,7 +52,10 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement> {
|
|||
|
||||
@Override
|
||||
protected FacetManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new FacetManagement(getWorkingContext(), oDatabaseDocument);
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setWorkingContext(getWorkingContext());
|
||||
return facetManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,11 +15,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
|
@ -37,10 +34,6 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
|||
super(AccessType.IS_RELATED_TO, Resource.class, DEFAULT_IS_RELATED_TO_PC);
|
||||
}
|
||||
|
||||
public IsRelatedToManagement(SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
super(AccessType.IS_RELATED_TO, Resource.class, workingContext, orientGraph, DEFAULT_IS_RELATED_TO_PC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IsRelatedToNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new IsRelatedToNotFoundException(e.getMessage(), e.getCause());
|
||||
|
@ -59,7 +52,10 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
|||
|
||||
@Override
|
||||
protected ResourceManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), oDatabaseDocument);
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setWorkingContext(getWorkingContext());
|
||||
resourceManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
return resourceManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -136,13 +136,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
this.honourPropagationConstraintsInContextSharing = true;
|
||||
}
|
||||
|
||||
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph,
|
||||
PropagationConstraint defaultPropagationConstraint) {
|
||||
this(accessType, targetEntityClass, defaultPropagationConstraint);
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
protected PropagationConstraint propagationConstraint;
|
||||
|
||||
@Override
|
||||
|
@ -335,7 +328,10 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
|
||||
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), oDatabaseDocument);
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setWorkingContext(getWorkingContext());
|
||||
resourceManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
return resourceManagement;
|
||||
}
|
||||
|
||||
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
|
||||
|
@ -351,9 +347,11 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
if(accessType.compareTo(AccessType.CONSISTS_OF) == 0) {
|
||||
JsonNode target = jsonNode.get(Relation.TARGET_PROPERTY);
|
||||
if(target != null) {
|
||||
FacetManagement fm = new FacetManagement(getWorkingContext(), oDatabaseDocument);
|
||||
fm.setJsonNode(target);
|
||||
fm.internalUpdate();
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setWorkingContext(getWorkingContext());
|
||||
facetManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setJsonNode(target);
|
||||
facetManagement.internalUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.types.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -81,7 +81,7 @@ public class SchemaManager {
|
|||
throw new ResourceRegistryException("No superclasses defined");
|
||||
}
|
||||
for(String superClass : superClasses) {
|
||||
accessType = ElementManagementUtility.getBaseAccessType(superClass);
|
||||
accessType = TypesCache.getInstance().getBaseAccessType(superClass);
|
||||
break;
|
||||
}
|
||||
} catch (ResourceRegistryException e) {
|
||||
|
|
|
@ -29,55 +29,69 @@ public class TypesCache {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(TypesCache.class);
|
||||
|
||||
protected static final Map<String, OClass> oClasses;
|
||||
protected static final Map<String, Type> types;
|
||||
protected static final Map<String, List<String>> superTypes;
|
||||
protected static final Map<String, List<String>> specilisationTypes;
|
||||
private static TypesCache typesCache;
|
||||
|
||||
public synchronized static TypesCache getInstance() {
|
||||
if(typesCache == null) {
|
||||
typesCache = new TypesCache();
|
||||
}
|
||||
return typesCache;
|
||||
}
|
||||
|
||||
protected final Map<String, OClass> oClasses;
|
||||
protected final Map<String, AccessType> accessTypes;
|
||||
protected final Map<String, Type> types;
|
||||
protected final Map<String, List<String>> superTypes;
|
||||
protected final Map<String, List<String>> specilisationTypes;
|
||||
|
||||
|
||||
static {
|
||||
private TypesCache() {
|
||||
oClasses = new HashMap<>();
|
||||
accessTypes = new HashMap<>();
|
||||
types = new HashMap<>();
|
||||
superTypes = new HashMap<>();
|
||||
specilisationTypes = new HashMap<>();
|
||||
}
|
||||
|
||||
public synchronized AccessType getBaseAccessType(String type) throws ResourceRegistryException {
|
||||
AccessType accessType = accessTypes.get(type);
|
||||
if(accessType==null) {
|
||||
|
||||
|
||||
public static AccessType getBaseAccessType(String type) throws ResourceRegistryException {
|
||||
|
||||
OClass oClass = getTypeSchema(type);
|
||||
OClass oClass = getTypeOClass(type);
|
||||
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
return AccessType.RESOURCE;
|
||||
accessType = AccessType.RESOURCE;
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
return AccessType.FACET;
|
||||
accessType = AccessType.FACET;
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
return AccessType.CONSISTS_OF;
|
||||
accessType = AccessType.CONSISTS_OF;
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
return AccessType.IS_RELATED_TO;
|
||||
accessType = AccessType.IS_RELATED_TO;
|
||||
} else if(oClass.isSubClassOf(Property.NAME)) {
|
||||
return AccessType.PROPERTY;
|
||||
}
|
||||
|
||||
accessType = AccessType.PROPERTY;
|
||||
}else {
|
||||
throw new ResourceRegistryException(type + "is not a base type");
|
||||
|
||||
}
|
||||
|
||||
public static void checkAccessType(OClass oClass, String type, AccessType accessType) throws SchemaException {
|
||||
accessTypes.put(type, accessType);
|
||||
}
|
||||
return accessType;
|
||||
}
|
||||
|
||||
/*
|
||||
public void checkAccessType(OClass oClass, String type, AccessType accessType) throws SchemaException {
|
||||
if(accessType != null && type.compareTo(accessType.getName()) != 0) {
|
||||
if(!oClass.isSubClassOf(accessType.getName())) {
|
||||
throw new SchemaException(type + " is not a " + accessType.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private static OClass getTypeSchema(OSchema oSchema, String type)
|
||||
private OClass getTypeOClass(OSchema oSchema, String type)
|
||||
throws SchemaException, SchemaNotFoundException {
|
||||
try {
|
||||
OClass oClass;
|
||||
synchronized (oClasses) {
|
||||
oClass = oClasses.get(type);
|
||||
OClass oClass= oClasses.get(type);
|
||||
if(oClass==null) {
|
||||
oClass = oSchema.getClass(type);
|
||||
if(oClass == null) {
|
||||
|
@ -85,7 +99,6 @@ public class TypesCache {
|
|||
}
|
||||
oClasses.put(type, oClass);
|
||||
}
|
||||
}
|
||||
return oClass;
|
||||
} catch(SchemaNotFoundException snfe) {
|
||||
throw snfe;
|
||||
|
@ -94,7 +107,7 @@ public class TypesCache {
|
|||
}
|
||||
}
|
||||
|
||||
public static OClass getTypeSchema(ODatabaseDocument oDatabaseDocument, String type)
|
||||
public synchronized OClass getTypeOClass(ODatabaseDocument oDatabaseDocument, String type)
|
||||
throws SchemaException, SchemaNotFoundException {
|
||||
|
||||
synchronized (oClasses) {
|
||||
|
@ -106,18 +119,16 @@ public class TypesCache {
|
|||
|
||||
OMetadata oMetadata = oDatabaseDocument.getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
return getTypeSchema(oSchema, type);
|
||||
return getTypeOClass(oSchema, type);
|
||||
}
|
||||
|
||||
public static OClass getTypeSchema(String type)
|
||||
public synchronized OClass getTypeOClass(String type)
|
||||
throws SchemaException, ResourceRegistryException {
|
||||
|
||||
synchronized (oClasses) {
|
||||
OClass oClass = oClasses.get(type);
|
||||
if(oClass!=null) {
|
||||
return oClass;
|
||||
}
|
||||
}
|
||||
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
|
@ -125,7 +136,7 @@ public class TypesCache {
|
|||
logger.debug("GettingType {} schema", type);
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
return getTypeSchema(oDatabaseDocument, type);
|
||||
return getTypeOClass(oDatabaseDocument, type);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
|
Loading…
Reference in New Issue