Fixed error on resource marshalling

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134709 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-11-24 16:56:05 +00:00
parent 92173467be
commit eb2c8022ba
1 changed files with 25 additions and 34 deletions

View File

@ -101,7 +101,7 @@ public class EntityManagementImpl implements EntityManagement {
String classProperty = getClassProperty(jsonNode);
try {
SchemaManagementImpl.getTypeSchema(classProperty, classProperty);
SchemaManagementImpl.getTypeSchema(orientGraph, classProperty, classProperty);
} catch (SchemaNotFoundException e) {
throw e;
}
@ -157,7 +157,7 @@ public class EntityManagementImpl implements EntityManagement {
String classProperty = getClassProperty(jsonNode);
if (relationType.compareTo(classProperty) != 0) {
try {
SchemaManagementImpl.getTypeSchema(relationType, classProperty);
SchemaManagementImpl.getTypeSchema(orientGraph, relationType, classProperty);
} catch (SchemaNotFoundException e) {
throw e;
}
@ -437,7 +437,7 @@ public class EntityManagementImpl implements EntityManagement {
try {
try {
SchemaManagementImpl.getTypeSchema(entityType,
SchemaManagementImpl.getTypeSchema(orientGraph, entityType,
entity.getSimpleName());
} catch (SchemaNotFoundException e) {
throw e;
@ -575,7 +575,7 @@ public class EntityManagementImpl implements EntityManagement {
}
try {
SchemaManagementImpl.getTypeSchema(relationType,
SchemaManagementImpl.getTypeSchema(orientGraph, relationType,
relationBaseClass.getSimpleName());
} catch (SchemaNotFoundException e) {
throw e;
@ -623,8 +623,7 @@ public class EntityManagementImpl implements EntityManagement {
private Edge updateRelation(
OrientGraph orientGraph,
JsonNode jsonNode,
@SuppressWarnings("rawtypes") Class<? extends Relation> relationClass,
boolean deferredCommit) throws ResourceRegistryException {
@SuppressWarnings("rawtypes") Class<? extends Relation> relationClass) throws ResourceRegistryException {
logger.debug("Trying to update {} : {}", relationClass.getSimpleName(),
jsonNode);
@ -640,7 +639,7 @@ public class EntityManagementImpl implements EntityManagement {
}
try {
SchemaManagementImpl.getTypeSchema(relationType,
SchemaManagementImpl.getTypeSchema(orientGraph, relationType,
relationClass.getSimpleName());
} catch (SchemaNotFoundException e) {
throw e;
@ -662,30 +661,16 @@ public class EntityManagementImpl implements EntityManagement {
updateFacet(orientGraph, targetUUID, target);
}
if (!deferredCommit) {
orientGraph.commit();
}
logger.info("{} {} successfully updated", relationType, jsonNode);
return edge;
} catch (ResourceRegistryException rre) {
logger.error("Error Updating {} {} ", relationClass, jsonNode, rre);
if (orientGraph != null) {
orientGraph.rollback();
}
throw rre;
} catch (Exception e) {
logger.error("Error Creating {} {}", relationClass, jsonNode, e);
if (orientGraph != null) {
orientGraph.rollback();
}
throw new ResourceRegistryException(e);
} finally {
if (orientGraph != null && !deferredCommit) {
orientGraph.shutdown();
}
}
}
@ -1066,7 +1051,7 @@ public class EntityManagementImpl implements EntityManagement {
return true;
}
private static String marshallResource(Vertex vertex) throws JSONException {
private static String marshallResource(OrientGraph orientGraph, Vertex vertex) throws JSONException {
JSONObject jsonObject = Utility.toJsonObject((OrientVertex) vertex,
true);
@ -1079,17 +1064,24 @@ public class EntityManagementImpl implements EntityManagement {
String edgeType = edge.getLabel();
try {
SchemaManagementImpl.getTypeSchema(edgeType, ConsistsOf.NAME);
SchemaManagementImpl.getTypeSchema(orientGraph, edgeType, ConsistsOf.NAME);
}catch (SchemaNotFoundException e) {
// This not an ConsistsOf Edge. it will be skipped
continue;
}
try{
JSONObject jsonObjectEdge = Utility.toJsonObject(
(OrientEdge) edge, true);
Vertex facetVertex = edge.getVertex(Direction.IN);
jsonObjectEdge.put(Relation.TARGET_PROPERTY,
Utility.toJsonObject((OrientVertex) facetVertex, true));
consistsOfArray.put(jsonObjectEdge);
} catch (SchemaNotFoundException e) {
// This not an ConsistsOf Edge. it will be skipped
} catch (Exception e) {
logger.error("Unable to add a Relation to serilization", e);
continue;
}
}
@ -1134,7 +1126,7 @@ public class EntityManagementImpl implements EntityManagement {
orientGraph.commit();
String resourceString = marshallResource(resource);
String resourceString = marshallResource(orientGraph, resource);
logger.info("{} ({}) successfully created {}", Resource.NAME,
resourceType, resourceString);
@ -1188,7 +1180,7 @@ public class EntityManagementImpl implements EntityManagement {
resourceType, uuid,
Utility.toJsonString((OrientVertex) resource, true));
return marshallResource(resource);
return marshallResource(orientGraph, resource);
} catch (ResourceNotFoundException rnfe) {
logger.error("Unable to read {} ({}) with UUID {}", Resource.NAME,
resourceType, uuid, rnfe);
@ -1225,8 +1217,7 @@ public class EntityManagementImpl implements EntityManagement {
if (jsonNode.has(property)) {
JsonNode jsonNodeArray = jsonNode.get(property);
for (JsonNode relationJsonNode : jsonNodeArray) {
updateRelation(orientGraph, relationJsonNode,
ConsistsOf.class, true);
updateRelation(orientGraph, relationJsonNode, ConsistsOf.class);
}
}
@ -1234,7 +1225,7 @@ public class EntityManagementImpl implements EntityManagement {
((OrientVertex) resource).save();
orientGraph.commit();
String resourceString = marshallResource(resource);
String resourceString = marshallResource(orientGraph, resource);
logger.info("{} with UUID {} has been updated {}", Resource.NAME,
resourceUUID,