2016-12-19 14:59:27 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-12-27 11:27:01 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.er.entity;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
|
|
import org.gcube.informationsystem.model.embedded.Header;
|
|
|
|
import org.gcube.informationsystem.model.entity.Entity;
|
|
|
|
import org.gcube.informationsystem.model.entity.Facet;
|
|
|
|
import org.gcube.informationsystem.model.entity.Resource;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
2016-12-22 17:33:10 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
2016-12-27 11:27:01 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
2016-12-22 17:27:26 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.tinkerpop.blueprints.Direction;
|
|
|
|
import com.tinkerpop.blueprints.Edge;
|
|
|
|
import com.tinkerpop.blueprints.Vertex;
|
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
|
|
|
public abstract class EntityManagement<E extends Entity> {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory
|
|
|
|
.getLogger(EntityManagement.class);
|
|
|
|
|
|
|
|
public final String AT = "@";
|
|
|
|
public final String UNDERSCORE = "_";
|
|
|
|
|
|
|
|
protected final Set<String> ignoreKeys;
|
|
|
|
protected final Set<String> ignoreStartWithKeys;
|
|
|
|
|
|
|
|
protected final Class<E> entityClass;
|
|
|
|
protected final String baseType;
|
|
|
|
|
|
|
|
protected OrientGraph orientGraph;
|
|
|
|
|
|
|
|
protected UUID uuid;
|
|
|
|
protected JsonNode jsonNode;
|
|
|
|
protected String entityType;
|
|
|
|
protected Vertex vertex;
|
|
|
|
|
|
|
|
protected EntityManagement(Class<E> entityClass) {
|
|
|
|
this.ignoreKeys = new HashSet<String>();
|
|
|
|
this.ignoreKeys.add(Entity.HEADER_PROPERTY);
|
|
|
|
|
|
|
|
this.ignoreStartWithKeys = new HashSet<String>();
|
|
|
|
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX
|
|
|
|
.toLowerCase());
|
|
|
|
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX
|
|
|
|
.toLowerCase());
|
|
|
|
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX
|
|
|
|
.toUpperCase());
|
|
|
|
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX
|
|
|
|
.toUpperCase());
|
|
|
|
this.ignoreStartWithKeys.add(AT);
|
|
|
|
this.ignoreStartWithKeys.add(UNDERSCORE);
|
|
|
|
|
|
|
|
this.entityClass = entityClass;
|
|
|
|
if (Facet.class.isAssignableFrom(entityClass)) {
|
|
|
|
this.baseType = Facet.NAME;
|
|
|
|
} else if (Resource.class.isAssignableFrom(entityClass)) {
|
|
|
|
this.baseType = Resource.NAME;
|
|
|
|
} else {
|
|
|
|
this.baseType = Entity.NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected EntityManagement(Class<E> entityClass, OrientGraph orientGraph) {
|
|
|
|
this(entityClass);
|
|
|
|
this.orientGraph = orientGraph;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVertex(Vertex vertex) throws ResourceRegistryException {
|
2016-12-19 16:25:29 +01:00
|
|
|
if (vertex == null) {
|
|
|
|
throw new ResourceRegistryException("Trying to set null Vertex in "
|
|
|
|
+ this);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
this.vertex = vertex;
|
|
|
|
this.uuid = HeaderUtility.getHeader(vertex).getUUID();
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
public void setUUID(UUID uuid) throws ResourceRegistryException {
|
|
|
|
this.uuid = uuid;
|
|
|
|
if (jsonNode != null) {
|
|
|
|
checkUUIDMatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setJSON(JsonNode jsonNode) throws ResourceRegistryException {
|
|
|
|
this.jsonNode = jsonNode;
|
|
|
|
|
|
|
|
checkJSON();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setJSON(String jsonRepresentation)
|
|
|
|
throws ResourceRegistryException {
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
try {
|
|
|
|
this.jsonNode = mapper.readTree(jsonRepresentation);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
checkJSON();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void checkJSON() throws ResourceRegistryException {
|
|
|
|
if (uuid == null) {
|
|
|
|
try {
|
|
|
|
uuid = org.gcube.informationsystem.impl.utils.Utility
|
|
|
|
.getUUIDFromJsonNode(jsonNode);
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
checkUUIDMatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.entityType == null) {
|
|
|
|
this.entityType = ERManagement.getClassProperty(jsonNode);
|
|
|
|
} else {
|
|
|
|
checkEntityMatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEntityType(String entityType)
|
|
|
|
throws ResourceRegistryException {
|
|
|
|
this.entityType = entityType;
|
|
|
|
if (entityType == null || entityType.compareTo("") == 0) {
|
|
|
|
if (Facet.class.isAssignableFrom(entityClass)) {
|
|
|
|
entityType = Facet.NAME;
|
|
|
|
}
|
|
|
|
if (Resource.class.isAssignableFrom(entityClass)) {
|
|
|
|
entityType = Resource.NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (jsonNode != null) {
|
|
|
|
checkEntityMatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void checkEntityMatch() throws ResourceRegistryException {
|
|
|
|
String type = ERManagement.getClassProperty(jsonNode);
|
|
|
|
if (type != null && type.compareTo(entityType) != 0) {
|
|
|
|
String error = String
|
|
|
|
.format("Declared resourceType does not match with json representation %s!=%s",
|
|
|
|
entityType, type);
|
|
|
|
logger.trace(error);
|
|
|
|
throw new ResourceRegistryException(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
SchemaManagementImpl.getTypeSchema(entityType, baseType);
|
|
|
|
} catch (SchemaNotFoundException e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void checkUUIDMatch() throws ResourceRegistryException {
|
|
|
|
Header header = null;
|
|
|
|
try {
|
|
|
|
header = HeaderUtility.getHeader(jsonNode, false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header != null) {
|
|
|
|
UUID resourceUUID = header.getUUID();
|
|
|
|
if (resourceUUID.compareTo(uuid) != 0) {
|
|
|
|
String error = String
|
|
|
|
.format("UUID provided in header (%s) differs from the one (%s) used to identify the %s instance",
|
|
|
|
resourceUUID.toString(), uuid.toString(),
|
|
|
|
entityType);
|
|
|
|
throw new ResourceRegistryException(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 16:25:29 +01:00
|
|
|
public Vertex getVertex() throws EntityNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2016-12-19 14:59:27 +01:00
|
|
|
try {
|
2016-12-19 16:25:29 +01:00
|
|
|
if (vertex == null) {
|
2016-12-19 14:59:27 +01:00
|
|
|
vertex = Utility.getElementByUUID(orientGraph,
|
2016-12-19 16:25:29 +01:00
|
|
|
entityType == null ? baseType : entityType, uuid,
|
|
|
|
Vertex.class);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
return vertex;
|
|
|
|
} catch (ResourceRegistryException e) {
|
2016-12-19 16:25:29 +01:00
|
|
|
if (Resource.class.isAssignableFrom(entityClass)) {
|
2016-12-19 14:59:27 +01:00
|
|
|
throw new ResourceNotFoundException(e);
|
2016-12-19 16:25:29 +01:00
|
|
|
} else if (Facet.class.isAssignableFrom(entityClass)) {
|
2016-12-19 14:59:27 +01:00
|
|
|
throw new FacetNotFoundException(e);
|
2016-12-19 16:25:29 +01:00
|
|
|
} else {
|
2016-12-19 14:59:27 +01:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Vertex createVertex() throws EntityAlreadyPresentException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
|
|
|
|
logger.trace("Going to create {} for {} ({}) using {}",
|
|
|
|
Vertex.class.getSimpleName(), baseType, entityType, jsonNode);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2016-12-19 15:37:15 +01:00
|
|
|
Vertex vertexEntity = orientGraph.addVertex("class:" + entityType);
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Vertex v = getVertex();
|
|
|
|
if (v != null) {
|
|
|
|
String error = String.format(
|
|
|
|
"A %s with UUID %s already exist", entityType,
|
|
|
|
uuid.toString());
|
|
|
|
throw new EntityAlreadyPresentException(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (EntityAlreadyPresentException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
// no header or no header with uuid is provided and it is fine
|
|
|
|
}
|
|
|
|
|
2016-12-19 15:37:15 +01:00
|
|
|
this.vertex = vertexEntity;
|
2016-12-19 16:25:29 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
|
|
|
if (entityHeader != null) {
|
|
|
|
vertex.setProperty(Entity.HEADER_PROPERTY, entityHeader);
|
|
|
|
} else {
|
|
|
|
entityHeader = HeaderUtility.addHeader(vertex, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Resource.class.isAssignableFrom(entityClass)) {
|
|
|
|
// Facet and relation are created in calling method
|
|
|
|
} else {
|
|
|
|
ERManagement.updateProperties(vertex, jsonNode, ignoreKeys,
|
|
|
|
ignoreStartWithKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContextUtility.addToActualContext(orientGraph, vertex);
|
|
|
|
|
|
|
|
((OrientVertex) vertex).save();
|
|
|
|
|
|
|
|
logger.info("Created {} is {}", Vertex.class.getSimpleName(),
|
|
|
|
Utility.toJsonString((OrientVertex) vertex, true));
|
|
|
|
|
|
|
|
return vertex;
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.trace("Error while creating {} for {} ({}) using {}",
|
|
|
|
Vertex.class.getSimpleName(), baseType, entityType,
|
|
|
|
jsonNode, e);
|
|
|
|
throw new ResourceRegistryException("Error Creating " + entityType
|
|
|
|
+ " with " + jsonNode, e.getCause());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract String serialize() throws ResourceRegistryException;
|
2016-12-19 16:25:29 +01:00
|
|
|
|
|
|
|
public abstract JSONObject serializeAsJson()
|
|
|
|
throws ResourceRegistryException;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
public abstract Vertex reallyCreate() throws EntityAlreadyPresentException,
|
|
|
|
ResourceRegistryException;
|
|
|
|
|
|
|
|
public abstract Vertex reallyUpdate() throws EntityNotFoundException,
|
|
|
|
ResourceRegistryException;
|
|
|
|
|
|
|
|
public abstract boolean reallyDelete() throws EntityNotFoundException,
|
|
|
|
ResourceRegistryException;
|
|
|
|
|
2016-12-19 16:25:29 +01:00
|
|
|
public boolean reallyAddToContext() throws ContextException,
|
|
|
|
ResourceRegistryException {
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2016-12-20 18:36:17 +01:00
|
|
|
ContextUtility.addToActualContext(orientGraph, getVertex());
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2016-12-20 18:36:17 +01:00
|
|
|
Iterable<Edge> edges = vertex.getEdges(Direction.OUT);
|
2016-12-19 16:25:29 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
for (Edge edge : edges) {
|
|
|
|
@SuppressWarnings("rawtypes")
|
2016-12-19 16:25:29 +01:00
|
|
|
RelationManagement relationManagement = RelationManagement
|
|
|
|
.getRelationManagement(orientGraph, edge);
|
2016-12-19 14:59:27 +01:00
|
|
|
relationManagement.reallyAddToContext();
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-19 16:25:29 +01:00
|
|
|
public boolean reallyRemoveFromContext() throws ContextException,
|
|
|
|
ResourceRegistryException {
|
2016-12-20 18:36:17 +01:00
|
|
|
|
|
|
|
ContextUtility.removeFromActualContext(orientGraph, getVertex());
|
|
|
|
|
|
|
|
Iterable<Edge> edges = vertex.getEdges(Direction.OUT);
|
|
|
|
|
|
|
|
for (Edge edge : edges) {
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
RelationManagement relationManagement = RelationManagement
|
|
|
|
.getRelationManagement(orientGraph, edge);
|
|
|
|
relationManagement.reallyRemoveFromContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
@SuppressWarnings("rawtypes")
|
2016-12-19 16:25:29 +01:00
|
|
|
public static EntityManagement getEntityManagement(OrientGraph orientGraph,
|
|
|
|
Vertex vertex) throws ResourceRegistryException {
|
2016-12-19 14:59:27 +01:00
|
|
|
OrientVertexType orientVertexType = ((OrientVertex) vertex).getType();
|
|
|
|
EntityManagement entityManagement = null;
|
|
|
|
if (orientVertexType.isSubClassOf(Resource.NAME)) {
|
|
|
|
entityManagement = new ResourceManagement(orientGraph);
|
|
|
|
} else if (orientVertexType.isSubClassOf(Facet.NAME)) {
|
|
|
|
entityManagement = new FacetManagement(orientGraph);
|
|
|
|
} else {
|
|
|
|
String error = String.format("{%s is not a %s nor a %s. "
|
2016-12-20 18:36:17 +01:00
|
|
|
+ "This is really strange and should not occur. "
|
2016-12-19 16:25:29 +01:00
|
|
|
+ "Please Investigate it.", vertex, Resource.NAME,
|
|
|
|
Facet.NAME);
|
2016-12-19 14:59:27 +01:00
|
|
|
throw new ResourceRegistryException(error);
|
|
|
|
}
|
|
|
|
entityManagement.setVertex(vertex);
|
|
|
|
return entityManagement;
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
public String create() throws EntityAlreadyPresentException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
|
|
|
|
try {
|
2016-12-19 16:25:29 +01:00
|
|
|
orientGraph = ContextUtility
|
|
|
|
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
reallyCreate();
|
|
|
|
|
|
|
|
orientGraph.commit();
|
|
|
|
|
|
|
|
return serialize();
|
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String read() throws EntityNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
try {
|
2016-12-19 16:25:29 +01:00
|
|
|
orientGraph = ContextUtility
|
|
|
|
.getActualSecurityContextGraph(PermissionMode.READER);
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
getVertex();
|
|
|
|
|
|
|
|
return serialize();
|
2016-12-19 16:25:29 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
throw e;
|
2016-12-19 14:59:27 +01:00
|
|
|
} catch (Exception e) {
|
2016-12-19 16:25:29 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
2016-12-19 14:59:27 +01:00
|
|
|
} finally {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String update() throws EntityNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
try {
|
2016-12-19 16:25:29 +01:00
|
|
|
orientGraph = ContextUtility
|
|
|
|
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
reallyUpdate();
|
|
|
|
|
|
|
|
orientGraph.commit();
|
|
|
|
|
|
|
|
return serialize();
|
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.debug("Unable to update {} with UUID {} usign {}", baseType,
|
|
|
|
uuid, jsonNode, e);
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
throw new ResourceRegistryException(e);
|
2016-12-19 14:59:27 +01:00
|
|
|
} finally {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean delete() throws FacetNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
logger.debug("Going to delete {} with UUID {}", baseType, uuid);
|
|
|
|
|
|
|
|
try {
|
2016-12-19 16:25:29 +01:00
|
|
|
orientGraph = ContextUtility
|
|
|
|
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
boolean deleted = reallyDelete();
|
|
|
|
|
|
|
|
orientGraph.commit();
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} was successfully deleted.", baseType,
|
|
|
|
uuid);
|
|
|
|
|
|
|
|
return deleted;
|
|
|
|
|
2016-12-19 16:25:29 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
logger.error("Unable to delete {} with UUID {}", baseType, uuid, e);
|
2016-12-19 14:59:27 +01:00
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
throw e;
|
2016-12-19 14:59:27 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Unable to delete {} with UUID {}", baseType, uuid, e);
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean addToContext() throws ContextException {
|
|
|
|
logger.debug("Going to add {} with UUID {} to actual Context",
|
|
|
|
baseType, uuid);
|
|
|
|
|
|
|
|
try {
|
2016-12-19 16:25:29 +01:00
|
|
|
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
|
|
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
|
|
|
PermissionMode.WRITER).getTx();
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
boolean added = reallyAddToContext();
|
|
|
|
|
|
|
|
orientGraph.commit();
|
|
|
|
logger.info("{} with UUID {} successfully added to actual Context",
|
|
|
|
baseType, uuid);
|
|
|
|
|
|
|
|
return added;
|
|
|
|
} catch (Exception e) {
|
2016-12-19 16:25:29 +01:00
|
|
|
logger.error("Unable to add {} with UUID {} to actual Context",
|
2016-12-19 14:59:27 +01:00
|
|
|
baseType, uuid, e);
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
throw new ContextException(e);
|
2016-12-19 14:59:27 +01:00
|
|
|
} finally {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean removeFromContext() throws ContextException {
|
|
|
|
logger.debug("Going to remove {} with UUID {} from actual Context",
|
|
|
|
baseType, uuid);
|
|
|
|
|
|
|
|
try {
|
2016-12-19 16:25:29 +01:00
|
|
|
orientGraph = SecurityContextMapper.getSecurityContextFactory(
|
|
|
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
|
|
|
PermissionMode.WRITER).getTx();
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
boolean removed = reallyRemoveFromContext();
|
|
|
|
|
|
|
|
orientGraph.commit();
|
2016-12-19 16:25:29 +01:00
|
|
|
logger.info(
|
|
|
|
"{} with UUID {} successfully removed from actual Context",
|
2016-12-19 14:59:27 +01:00
|
|
|
baseType, uuid);
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error(
|
|
|
|
"Unable to remove {} with UUID {} from actual Context",
|
|
|
|
baseType, uuid, e);
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.rollback();
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
throw new ContextException(e);
|
2016-12-19 14:59:27 +01:00
|
|
|
} finally {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-19 16:25:29 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|