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