Added logs to better understanding what happen in case of failure
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134334 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6dff36cb0c
commit
cfa9c0ed32
|
@ -62,7 +62,7 @@ public class EntityManager {
|
|||
public String createFacet(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||
throws EntityException, ResourceRegistryException {
|
||||
logger.trace("requested facet creation for type {} defined by {} ",
|
||||
logger.info("requested facet creation for type {} defined by {} ",
|
||||
type, definition);
|
||||
return entityManager.createFacet(type, definition);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class EntityManager {
|
|||
public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid,
|
||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||
throws FacetNotFoundException, ResourceRegistryException {
|
||||
logger.trace("requested facet update for id {} with {}", uuid,
|
||||
logger.info("requested facet update for id {} with {}", uuid,
|
||||
definition);
|
||||
return entityManager.updateFacet(UUID.fromString(uuid), definition);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class EntityManager {
|
|||
@Path(EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
public boolean deleteFacet(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws FacetNotFoundException, ResourceRegistryException {
|
||||
logger.trace("Requested to delete Facet with id {}", uuid);
|
||||
logger.info("Requested to delete Facet with id {}", uuid);
|
||||
return entityManager.deleteFacet(UUID.fromString(uuid));
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class EntityManager {
|
|||
public String createResource(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||
throws FacetNotFoundException, ResourceRegistryException {
|
||||
logger.trace("requested resource creation for type {} with json {}",
|
||||
logger.info("requested resource creation for type {} with json {}",
|
||||
type, definition);
|
||||
return entityManager.createResource(type, definition);
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ public class EntityManager {
|
|||
@QueryParam(EntityPath.PROPERTIES_PARAM) String properties)
|
||||
throws FacetNotFoundException, ResourceNotFoundException,
|
||||
ResourceRegistryException {
|
||||
logger.trace(
|
||||
logger.info(
|
||||
"requested to attach resource {} to facet {} ({} Type {}) with properties {}",
|
||||
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
|
||||
type, properties);
|
||||
|
@ -195,7 +195,7 @@ public class EntityManager {
|
|||
@Path(EntityPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID)
|
||||
throws ResourceRegistryException {
|
||||
logger.trace("requested to detach {}", consistOfUUID);
|
||||
logger.info("requested to detach {}", consistOfUUID);
|
||||
return entityManager.detachFacet(UUID.fromString(consistOfUUID));
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ public class EntityManager {
|
|||
@QueryParam(EntityPath.TYPE_PARAM) String type,
|
||||
@QueryParam(EntityPath.PROPERTIES_PARAM) String properties)
|
||||
throws ResourceNotFoundException, ResourceRegistryException {
|
||||
logger.trace(
|
||||
logger.info(
|
||||
"requested to attach source {} {} and target {} {} ({} Type {}) with properties {}",
|
||||
Resource.NAME, sourceResourceUUID, Resource.NAME,
|
||||
targetResourceUUID, IsRelatedTo.class.getSimpleName(), type,
|
||||
|
@ -248,7 +248,7 @@ public class EntityManager {
|
|||
@Path(EntityPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID)
|
||||
throws ResourceRegistryException {
|
||||
logger.trace("requested to detach {}", relatedToUUID);
|
||||
logger.info("requested to detach {}", relatedToUUID);
|
||||
return entityManager.detachResource(UUID.fromString(relatedToUUID));
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ public class EntityManager {
|
|||
public boolean addResourceToContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
logger.trace("requested to add {} with UUID {} to current context {}",
|
||||
logger.info("requested to add {} with UUID {} to current context {}",
|
||||
Resource.NAME, uuid, ContextUtility.getCurrentContext());
|
||||
return entityManager.addResourceToContext(UUID.fromString(uuid));
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ public class EntityManager {
|
|||
public boolean addFacetToContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws FacetNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
logger.trace("requested to add {} with UUID {} to current context {}",
|
||||
logger.info("requested to add {} with UUID {} to current context {}",
|
||||
Facet.NAME, uuid, ContextUtility.getCurrentContext());
|
||||
return entityManager.addFacetToContext(UUID.fromString(uuid));
|
||||
}
|
||||
|
|
|
@ -134,8 +134,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
return null;
|
||||
}
|
||||
/*
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Header header = mapper.readValue(headerNode.toString(), Header.class);
|
||||
* ObjectMapper mapper = new ObjectMapper(); Header header =
|
||||
* mapper.readValue(headerNode.toString(), Header.class);
|
||||
*/
|
||||
HeaderOrient headerOrient = new HeaderOrient();
|
||||
headerOrient.fromJSON(headerNode.toString());
|
||||
|
@ -144,7 +144,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static void checkEmbeddedType(JsonNode jsonNode) throws ResourceRegistryException {
|
||||
private static void checkEmbeddedType(JsonNode jsonNode)
|
||||
throws ResourceRegistryException {
|
||||
if (jsonNode.has(Entities.CLASS_PROPERTY)) {
|
||||
// Complex type
|
||||
String type = getClassProperty(jsonNode);
|
||||
|
@ -162,18 +163,21 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
header = getHeader(jsonNode);
|
||||
} catch (Exception e) {
|
||||
logger.warn("An invalid Header has been provided. An embedded object cannot have an Header. It will be ignored.");
|
||||
throw new ResourceRegistryException("An embedded object cannot have an Header");
|
||||
throw new ResourceRegistryException(
|
||||
"An embedded object cannot have an Header");
|
||||
}
|
||||
|
||||
if (header != null) {
|
||||
logger.warn("An embedded object cannot have an Header. It will be ignored.");
|
||||
throw new ResourceRegistryException("An embedded object cannot have an Header");
|
||||
throw new ResourceRegistryException(
|
||||
"An embedded object cannot have an Header");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getObejctFromElement(JsonNode value) throws ResourceRegistryException {
|
||||
public static Object getObejctFromElement(JsonNode value)
|
||||
throws ResourceRegistryException {
|
||||
JsonNodeType jsonNodeType = value.getNodeType();
|
||||
switch (jsonNodeType) {
|
||||
case OBJECT:
|
||||
|
@ -261,16 +265,16 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
logger.warn("An invalidy property has been provided. It will be ignored.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private void createRelations(OrientGraph orientGraph, Vertex resource, JsonNode relationArray,
|
||||
@SuppressWarnings("rawtypes") Class<? extends Relation> relation) throws FacetNotFoundException,
|
||||
ResourceNotFoundException, ResourceRegistryException {
|
||||
private void createRelations(OrientGraph orientGraph, Vertex resource,
|
||||
JsonNode relationArray,
|
||||
@SuppressWarnings("rawtypes") Class<? extends Relation> relation)
|
||||
throws FacetNotFoundException, ResourceNotFoundException,
|
||||
ResourceRegistryException {
|
||||
|
||||
Iterator<JsonNode> iterator = relationArray.elements();
|
||||
while (iterator.hasNext()) {
|
||||
|
@ -286,17 +290,17 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
|
||||
|
||||
Vertex targetVertex = null;
|
||||
if (targetHeader == null) {
|
||||
if (ConsistsOf.class.isAssignableFrom(relation)) {
|
||||
targetVertex = createVertexEntity(
|
||||
orientGraph, getClassProperty(target),
|
||||
Facet.class, target.toString(), true);
|
||||
targetHeader = targetVertex.getProperty(Facet.HEADER_PROPERTY);
|
||||
targetVertex = createVertexEntity(orientGraph,
|
||||
getClassProperty(target), Facet.class,
|
||||
target.toString(), true);
|
||||
targetHeader = targetVertex
|
||||
.getProperty(Facet.HEADER_PROPERTY);
|
||||
} else {
|
||||
String error = String.format(
|
||||
"%s %s must already exist. The UUID must be provided in the %s of %s json respresentation",
|
||||
String error = String
|
||||
.format("%s %s must already exist. The UUID must be provided in the %s of %s json respresentation",
|
||||
Relation.TARGET_PROPERTY, Resource.NAME,
|
||||
Header.NAME, IsRelatedTo.NAME);
|
||||
logger.error(error);
|
||||
|
@ -312,9 +316,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
} else if (IsRelatedTo.class.isAssignableFrom(relation)) {
|
||||
targetClass = Resource.class;
|
||||
} else {
|
||||
String error = String.format(
|
||||
"%s Unsupported %s creation", relation.toString(),
|
||||
Relation.NAME);
|
||||
String error = String.format("%s Unsupported %s creation",
|
||||
relation.toString(), Relation.NAME);
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
@ -322,12 +325,12 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
UUID targetUUID = targetHeader.getUUID();
|
||||
String entityType = getClassProperty(target);
|
||||
|
||||
targetVertex = getEntity(orientGraph, targetUUID, entityType, targetClass);
|
||||
targetVertex = getEntity(orientGraph, targetUUID, entityType,
|
||||
targetClass);
|
||||
}
|
||||
|
||||
String relationType = getClassProperty(node);
|
||||
|
||||
|
||||
Set<String> ignoreKeys = new HashSet<>();
|
||||
ignoreKeys.add(Relation.TARGET_PROPERTY);
|
||||
ignoreKeys.add(Relation.SOURCE_PROPERTY);
|
||||
|
@ -352,13 +355,19 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
boolean deferredCommit) throws ResourceRegistryException {
|
||||
OrientGraph orientGraph = ContextUtility
|
||||
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
||||
return createVertexEntity(orientGraph, entityType, entity, jsonRepresentation,
|
||||
deferredCommit);
|
||||
return createVertexEntity(orientGraph, entityType, entity,
|
||||
jsonRepresentation, deferredCommit);
|
||||
}
|
||||
|
||||
public Vertex createVertexEntity(OrientGraph orientGraph, String entityType,
|
||||
Class<? extends Entity> entity, String jsonRepresentation,
|
||||
boolean deferredCommit) throws ResourceRegistryException {
|
||||
public Vertex createVertexEntity(OrientGraph orientGraph,
|
||||
String entityType, Class<? extends Entity> entity,
|
||||
String jsonRepresentation, boolean deferredCommit)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
logger.trace("Going to create {} for {} ({}) using {}",
|
||||
Vertex.class.getSimpleName(),
|
||||
entity.getClass().getSimpleName(), entityType,
|
||||
jsonRepresentation);
|
||||
|
||||
try {
|
||||
|
||||
|
@ -382,8 +391,7 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
OrientVertex vertex = orientGraph.addVertex("class:"
|
||||
+ entityType);
|
||||
OrientVertex vertex = orientGraph.addVertex("class:" + entityType);
|
||||
|
||||
Header entityHeader = getHeader(jsonNode);
|
||||
if (entityHeader != null) {
|
||||
|
@ -418,16 +426,20 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
|
||||
if (!deferredCommit) {
|
||||
orientGraph.commit();
|
||||
|
||||
logger.trace("Created {} is {} orientVertexToJsonString",
|
||||
Vertex.class.getSimpleName(), Utility
|
||||
.toJsonString((OrientVertex) vertex, true));
|
||||
}
|
||||
|
||||
logger.trace("Created {} is {}",
|
||||
Vertex.class.getSimpleName(),
|
||||
Utility.toJsonString((OrientVertex) vertex, true));
|
||||
|
||||
return vertex;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error Creating {} with {}", entityType, jsonRepresentation, e);
|
||||
logger.trace("Error while creating {} for {} ({}) using {}",
|
||||
Vertex.class.getSimpleName(),
|
||||
entity.getClass().getSimpleName(), entityType,
|
||||
jsonRepresentation, e);
|
||||
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -441,14 +453,17 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
}
|
||||
|
||||
public Edge createEdgeRelation(
|
||||
UUID sourceUUID, Class<? extends Entity> sourceClass,
|
||||
UUID targetUUID, Class<? extends Entity> targetClass,
|
||||
String relationType, @SuppressWarnings("rawtypes") Class<? extends Relation> relationBaseClass,
|
||||
String jsonProperties)
|
||||
throws FacetNotFoundException, ResourceNotFoundException,
|
||||
ResourceRegistryException {
|
||||
UUID sourceUUID,
|
||||
Class<? extends Entity> sourceClass,
|
||||
UUID targetUUID,
|
||||
Class<? extends Entity> targetClass,
|
||||
String relationType,
|
||||
@SuppressWarnings("rawtypes") Class<? extends Relation> relationBaseClass,
|
||||
String jsonProperties) throws FacetNotFoundException,
|
||||
ResourceNotFoundException, ResourceRegistryException {
|
||||
|
||||
logger.trace("Trying to create {} with {}", relationType, jsonProperties);
|
||||
logger.trace("Trying to create {} with {}", relationType,
|
||||
jsonProperties);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
|
@ -489,7 +504,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
relationType, relationBaseClass, edgeProperties, false);
|
||||
|
||||
} catch (ResourceNotFoundException rnfe) {
|
||||
logger.trace("Error Creating {} with {}", relationType, jsonProperties, rnfe);
|
||||
logger.trace("Error Creating {} with {}", relationType,
|
||||
jsonProperties, rnfe);
|
||||
throw rnfe;
|
||||
} catch (Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
|
@ -497,25 +513,31 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
|
||||
}
|
||||
|
||||
public Edge createEdgeRelation(OrientGraph orientGraph,
|
||||
Vertex source, Vertex target,
|
||||
String relationType, @SuppressWarnings("rawtypes") Class<? extends Relation> relationBaseClass,
|
||||
Map<String, Object> edgeProperties,
|
||||
boolean deferredCommit) throws ResourceRegistryException {
|
||||
public Edge createEdgeRelation(
|
||||
OrientGraph orientGraph,
|
||||
Vertex source,
|
||||
Vertex target,
|
||||
String relationType,
|
||||
@SuppressWarnings("rawtypes") Class<? extends Relation> relationBaseClass,
|
||||
Map<String, Object> edgeProperties, boolean deferredCommit)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
logger.info("Trying to create {} with {}", relationType, edgeProperties);
|
||||
logger.debug("Trying to create {} with {}", relationType,
|
||||
edgeProperties);
|
||||
|
||||
try {
|
||||
|
||||
SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
|
||||
try {
|
||||
schemaManagement.getTypeSchema(relationType, relationBaseClass.getSimpleName());
|
||||
schemaManagement.getTypeSchema(relationType,
|
||||
relationBaseClass.getSimpleName());
|
||||
} catch (SchemaNotFoundException e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (relationType == null || relationType.compareTo("") == 0) {
|
||||
throw new ResourceRegistryException(Relation.class.getSimpleName()
|
||||
throw new ResourceRegistryException(
|
||||
Relation.class.getSimpleName()
|
||||
+ " Type cannot be empty or null");
|
||||
}
|
||||
|
||||
|
@ -532,13 +554,14 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
try {
|
||||
edge.setProperty(key, edgeProperties.get(key));
|
||||
} catch (Exception e) {
|
||||
String error = String.format("Error while setting property %s : %s", key, edgeProperties.get(key).toString());
|
||||
String error = String.format(
|
||||
"Error while setting property %s : %s", key,
|
||||
edgeProperties.get(key).toString());
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HeaderUtility.addHeader(edge, null);
|
||||
ContextUtility.addToActualContext(orientGraph, edge);
|
||||
|
||||
|
@ -548,18 +571,21 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
orientGraph.commit();
|
||||
}
|
||||
|
||||
logger.info("{} with {} successfully created", relationType, edgeProperties);
|
||||
logger.info("{} with {} successfully created", relationType,
|
||||
edgeProperties);
|
||||
|
||||
return edge;
|
||||
|
||||
} catch (ResourceRegistryException rre) {
|
||||
logger.error("Error Creating {} with {}", relationType, edgeProperties, rre);
|
||||
logger.error("Error Creating {} with {}", relationType,
|
||||
edgeProperties, rre);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw rre;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error Creating {} with {}", relationType, edgeProperties, e);
|
||||
logger.error("Error Creating {} with {}", relationType,
|
||||
edgeProperties, e);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -574,7 +600,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
@Override
|
||||
public String createFacet(String facetType, String jsonRepresentation)
|
||||
throws ResourceRegistryException {
|
||||
Vertex vertex = createVertexEntity(facetType, Facet.class, jsonRepresentation, false);
|
||||
Vertex vertex = createVertexEntity(facetType, Facet.class,
|
||||
jsonRepresentation, false);
|
||||
return Utility.toJsonString((OrientVertex) vertex, false);
|
||||
}
|
||||
|
||||
|
@ -587,6 +614,10 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
@Override
|
||||
public String readFacet(UUID uuid, String facetType)
|
||||
throws FacetNotFoundException, ResourceRegistryException {
|
||||
|
||||
logger.debug("Going to read {} ({}) with UUID {}", Facet.NAME,
|
||||
facetType, uuid);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
|
@ -595,13 +626,18 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
|
||||
Vertex facet = getEntity(orientGraph, uuid, facetType, Facet.class);
|
||||
|
||||
logger.trace("{} of type {} with UUID {} is {}", Facet.NAME,
|
||||
facetType, uuid, Utility.toJsonString((OrientVertex) facet, true));
|
||||
logger.info("{} of type {} with UUID {} is {}", Facet.NAME,
|
||||
facetType, uuid,
|
||||
Utility.toJsonString((OrientVertex) facet, true));
|
||||
|
||||
return Utility.toJsonString((OrientVertex) facet, true);
|
||||
} catch (FacetNotFoundException fnfe) {
|
||||
logger.error("Unable to read {} ({}) with UUID {}", Facet.NAME,
|
||||
facetType, uuid, fnfe);
|
||||
throw fnfe;
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to read {} ({}) with UUID {}", Facet.NAME,
|
||||
facetType, uuid, e);
|
||||
throw new ResourceRegistryException(e.getMessage());
|
||||
} finally {
|
||||
if (orientGraph != null) {
|
||||
|
@ -613,6 +649,10 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
@Override
|
||||
public String updateFacet(UUID uuid, String jsonRepresentation)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
logger.debug("Trying to update {} with UUID {} usign {}", Facet.NAME,
|
||||
uuid, jsonRepresentation);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
|
@ -661,17 +701,21 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
((OrientVertex) facet).save();
|
||||
orientGraph.commit();
|
||||
|
||||
logger.trace("{} with UUID {} has been updated {}", Facet.NAME,
|
||||
logger.info("{} with UUID {} has been updated {}", Facet.NAME,
|
||||
uuid, Utility.toJsonString((OrientVertex) facet, true));
|
||||
|
||||
return Utility.toJsonString((OrientVertex) facet, false);
|
||||
|
||||
} catch (FacetNotFoundException fnfe) {
|
||||
logger.debug("Unable to update {} with UUID {} usign {}",
|
||||
Facet.NAME, uuid, jsonRepresentation, fnfe);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw fnfe;
|
||||
} catch (Exception e) {
|
||||
logger.debug("Unable to update {} with UUID {} usign {}",
|
||||
Facet.NAME, uuid, jsonRepresentation, e);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -687,6 +731,9 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
@Override
|
||||
public boolean deleteFacet(UUID uuid) throws FacetNotFoundException,
|
||||
ResourceRegistryException {
|
||||
|
||||
logger.debug("Going to delete {} with UUID {}", Facet.NAME, uuid);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
|
@ -697,12 +744,20 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
|
||||
facet.remove();
|
||||
orientGraph.commit();
|
||||
|
||||
logger.info("{} with UUID {} was successfully deleted.",
|
||||
Facet.NAME, uuid);
|
||||
|
||||
} catch (FacetNotFoundException fnfe) {
|
||||
logger.error("Unable to delete {} with UUID {}", Facet.NAME, uuid,
|
||||
fnfe);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw fnfe;
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to delete {} with UUID {}", Facet.NAME, uuid,
|
||||
e);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -721,33 +776,50 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
String consistOfType, String jsonProperties)
|
||||
throws FacetNotFoundException, ResourceNotFoundException,
|
||||
ResourceRegistryException {
|
||||
Edge edge = createEdgeRelation(resourceUUID, Resource.class,
|
||||
facetUUID, Facet.class,
|
||||
consistOfType, ConsistsOf.class,
|
||||
jsonProperties);
|
||||
Edge edge = createEdgeRelation(resourceUUID, Resource.class, facetUUID,
|
||||
Facet.class, consistOfType, ConsistsOf.class, jsonProperties);
|
||||
return Utility.toJsonString((OrientEdge) edge, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean detachFacet(UUID consistOfUUID)
|
||||
public boolean detachFacet(UUID consistsOfUUID)
|
||||
throws ResourceRegistryException {
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
logger.debug(
|
||||
"Going to remove {} {} with UUID {}. {} will be detached from its {}.",
|
||||
ConsistsOf.NAME, Relation.NAME, consistsOfUUID, Facet.NAME,
|
||||
Resource.NAME);
|
||||
|
||||
try {
|
||||
orientGraph = ContextUtility
|
||||
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
||||
|
||||
Edge edge = getRelation(orientGraph, consistOfUUID,
|
||||
Edge edge = getRelation(orientGraph, consistsOfUUID,
|
||||
ConsistsOf.NAME, ConsistsOf.class);
|
||||
|
||||
edge.remove();
|
||||
orientGraph.commit();
|
||||
|
||||
logger.info(
|
||||
"{} {} with UUID {} successfully removed. {} has been detached from its {}.",
|
||||
ConsistsOf.NAME, Relation.NAME, consistsOfUUID, Facet.NAME,
|
||||
Resource.NAME);
|
||||
|
||||
} catch (FacetNotFoundException fnfe) {
|
||||
logger.error(
|
||||
"Unable to remove {} {} with UUID {}. {} has not been detached from its {}.",
|
||||
ConsistsOf.NAME, Relation.NAME, consistsOfUUID, Facet.NAME,
|
||||
Resource.NAME);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw fnfe;
|
||||
} catch (Exception e) {
|
||||
logger.error(
|
||||
"Unable to remove {} {} with UUID {}. {} has not been detached from its {}.",
|
||||
ConsistsOf.NAME, Relation.NAME, consistsOfUUID, Facet.NAME,
|
||||
Resource.NAME);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -764,36 +836,53 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
|
||||
@Override
|
||||
public String attachResource(UUID sourceResourceUuid,
|
||||
UUID targetResourceUuid, String relatedToType,
|
||||
String jsonProperties) throws ResourceNotFoundException,
|
||||
ResourceRegistryException {
|
||||
UUID targetResourceUuid, String relatedToType, String jsonProperties)
|
||||
throws ResourceNotFoundException, ResourceRegistryException {
|
||||
Edge edge = createEdgeRelation(sourceResourceUuid, Resource.class,
|
||||
targetResourceUuid, Resource.class,
|
||||
relatedToType, IsRelatedTo.class,
|
||||
jsonProperties);
|
||||
targetResourceUuid, Resource.class, relatedToType,
|
||||
IsRelatedTo.class, jsonProperties);
|
||||
return Utility.toJsonString((OrientEdge) edge, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean detachResource(UUID relatedToUUID)
|
||||
public boolean detachResource(UUID isRelatedToUUID)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
logger.debug(
|
||||
"Going to remove {} {} with UUID {}. Related {}s will be detached.",
|
||||
IsRelatedTo.NAME, Relation.NAME, isRelatedToUUID, Resource.NAME);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
orientGraph = ContextUtility
|
||||
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
||||
|
||||
Edge edge = getRelation(orientGraph, relatedToUUID,
|
||||
Edge edge = getRelation(orientGraph, isRelatedToUUID,
|
||||
IsRelatedTo.NAME, IsRelatedTo.class);
|
||||
|
||||
edge.remove();
|
||||
orientGraph.commit();
|
||||
} catch (FacetNotFoundException fnfe) {
|
||||
|
||||
logger.info(
|
||||
"{} {} with UUID {} successfully removed. Related {}s were detached.",
|
||||
IsRelatedTo.NAME, Relation.NAME, isRelatedToUUID,
|
||||
Resource.NAME);
|
||||
|
||||
} catch (ResourceRegistryException rre) {
|
||||
logger.error(
|
||||
"Unable to remove {} {} with UUID. Related {}s will not be detached.",
|
||||
IsRelatedTo.NAME, Relation.NAME, isRelatedToUUID,
|
||||
Resource.NAME);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw fnfe;
|
||||
throw rre;
|
||||
} catch (Exception e) {
|
||||
logger.error(
|
||||
"Unable to remove {} {} with UUID {}. Related {}s will not be detached.",
|
||||
IsRelatedTo.NAME, Relation.NAME, isRelatedToUUID,
|
||||
Resource.NAME);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -808,7 +897,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
}
|
||||
|
||||
private static String marshallResource(Vertex vertex) throws JSONException {
|
||||
JSONObject jsonObject = Utility.toJsonObject((OrientVertex) vertex, true);
|
||||
JSONObject jsonObject = Utility.toJsonObject((OrientVertex) vertex,
|
||||
true);
|
||||
|
||||
JSONArray consistsOfArray = new JSONArray();
|
||||
|
||||
|
@ -822,9 +912,11 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
|
||||
schemaManagement.getTypeSchema(edgeType, ConsistsOf.NAME);
|
||||
|
||||
JSONObject jsonObjectEdge = Utility.toJsonObject((OrientEdge) edge, true);
|
||||
JSONObject jsonObjectEdge = Utility.toJsonObject(
|
||||
(OrientEdge) edge, true);
|
||||
Vertex facetVertex = edge.getVertex(Direction.IN);
|
||||
jsonObjectEdge.put(Relation.TARGET_PROPERTY, Utility.toJsonObject((OrientVertex) facetVertex, true));
|
||||
jsonObjectEdge.put(Relation.TARGET_PROPERTY,
|
||||
Utility.toJsonObject((OrientVertex) facetVertex, true));
|
||||
consistsOfArray.put(jsonObjectEdge);
|
||||
|
||||
} catch (SchemaNotFoundException e) {
|
||||
|
@ -833,7 +925,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
|
||||
}
|
||||
|
||||
jsonObject.put(lowerCaseFirstCharacter(ConsistsOf.NAME), consistsOfArray);
|
||||
jsonObject.put(lowerCaseFirstCharacter(ConsistsOf.NAME),
|
||||
consistsOfArray);
|
||||
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
@ -842,7 +935,7 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
public String createResource(String resourceType, String jsonRepresentation)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
logger.trace("Trying to create {} : {}", resourceType,
|
||||
logger.debug("Trying to create {} using {}", resourceType,
|
||||
jsonRepresentation);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
@ -850,7 +943,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
orientGraph = ContextUtility
|
||||
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
||||
|
||||
Vertex resource = createVertexEntity(orientGraph, resourceType, Resource.class, jsonRepresentation, true);
|
||||
Vertex resource = createVertexEntity(orientGraph, resourceType,
|
||||
Resource.class, jsonRepresentation, true);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode = mapper.readTree(jsonRepresentation);
|
||||
|
@ -858,25 +952,36 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
String property = lowerCaseFirstCharacter(ConsistsOf.NAME);
|
||||
if (jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
createRelations(orientGraph, resource, jsonNodeArray, ConsistsOf.class);
|
||||
createRelations(orientGraph, resource, jsonNodeArray,
|
||||
ConsistsOf.class);
|
||||
}
|
||||
|
||||
property = lowerCaseFirstCharacter(IsRelatedTo.NAME);
|
||||
if (jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
createRelations(orientGraph, resource, jsonNodeArray, IsRelatedTo.class);
|
||||
createRelations(orientGraph, resource, jsonNodeArray,
|
||||
IsRelatedTo.class);
|
||||
}
|
||||
|
||||
orientGraph.commit();
|
||||
|
||||
return marshallResource(resource);
|
||||
String resourceString = marshallResource(resource);
|
||||
|
||||
logger.info("{} ({}) successfully created {}", Resource.NAME,
|
||||
resourceType, resourceString);
|
||||
|
||||
return resourceString;
|
||||
|
||||
} catch (ResourceRegistryException rre) {
|
||||
logger.error("Unable to create {} ({}) using {}", Resource.NAME,
|
||||
resourceType, jsonRepresentation, rre);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw rre;
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to create {} ({}) using {}", Resource.NAME,
|
||||
resourceType, jsonRepresentation, e);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -897,6 +1002,10 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
@Override
|
||||
public String readResource(UUID uuid, String resourceType)
|
||||
throws ResourceNotFoundException {
|
||||
|
||||
logger.debug("Going to read {} ({}) with UUID {}", Resource.NAME,
|
||||
resourceType, uuid);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
|
@ -906,13 +1015,18 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
Vertex resource = getEntity(orientGraph, uuid, resourceType,
|
||||
Resource.class);
|
||||
|
||||
logger.trace("{} of type {} with UUID {} is {}", Resource.NAME,
|
||||
resourceType, uuid, Utility.toJsonString((OrientVertex) resource, true));
|
||||
logger.info("{} of type {} with UUID {} is {}", Resource.NAME,
|
||||
resourceType, uuid,
|
||||
Utility.toJsonString((OrientVertex) resource, true));
|
||||
|
||||
return marshallResource(resource);
|
||||
} catch (ResourceNotFoundException rnfe) {
|
||||
logger.error("Unable to read {} ({}) with UUID {}", Resource.NAME,
|
||||
resourceType, uuid, rnfe);
|
||||
throw rnfe;
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to read {} ({}) with UUID {}", Resource.NAME,
|
||||
resourceType, uuid, e);
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
} finally {
|
||||
if (orientGraph != null) {
|
||||
|
@ -922,8 +1036,11 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteResource(UUID uuid)
|
||||
throws ResourceNotFoundException, ResourceRegistryException {
|
||||
public boolean deleteResource(UUID uuid) throws ResourceNotFoundException,
|
||||
ResourceRegistryException {
|
||||
|
||||
logger.debug("Going to delete {} with UUID {}", Resource.NAME, uuid);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
|
@ -937,13 +1054,21 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
resource.remove();
|
||||
|
||||
orientGraph.commit();
|
||||
|
||||
logger.info("{} with UUID {} was successfully deleted.",
|
||||
Resource.NAME, uuid);
|
||||
|
||||
return true;
|
||||
} catch (ResourceNotFoundException fnfe) {
|
||||
} catch (ResourceNotFoundException rnfe) {
|
||||
logger.error("Unable to delete {} with UUID {}", Resource.NAME,
|
||||
uuid, rnfe);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw fnfe;
|
||||
throw rnfe;
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to delete {} with UUID {}", Resource.NAME,
|
||||
uuid, e);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -955,12 +1080,14 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected <E extends Entity> boolean addEntityToContext(Class<E> clz,
|
||||
UUID uuid) throws FacetNotFoundException,
|
||||
ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
|
||||
logger.debug("Going to add {} with UUID {} to actual Context",
|
||||
clz.getSimpleName(), uuid);
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
|
@ -970,7 +1097,8 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
|
||||
Vertex vertex = getEntity(orientGraph, uuid, null, clz);
|
||||
|
||||
UUID contextUUID = ContextUtility.addToActualContext(orientGraph, vertex);
|
||||
UUID contextUUID = ContextUtility.addToActualContext(orientGraph,
|
||||
vertex);
|
||||
|
||||
if (Resource.class.isAssignableFrom(clz)) {
|
||||
Iterable<Vertex> facets = vertex.getVertices(Direction.OUT,
|
||||
|
@ -981,10 +1109,14 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
}
|
||||
|
||||
orientGraph.commit();
|
||||
logger.info("{} with UUID {} successfully added to actual Context with UUID {}", clz.getSimpleName(),
|
||||
uuid, contextUUID);
|
||||
logger.info(
|
||||
"{} with UUID {} successfully added to actual Context with UUID {}",
|
||||
clz.getSimpleName(), uuid, contextUUID);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.error(
|
||||
"Unable to add {} with UUID {} successfully added to actual Context",
|
||||
clz.getSimpleName(), uuid, e);
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
|
@ -996,7 +1128,6 @@ public class EntityManagementImpl implements EntityManagement {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addResourceToContext(UUID uuid)
|
||||
throws ResourceNotFoundException, ContextNotFoundException,
|
||||
|
|
Loading…
Reference in New Issue