Removed catch in resource marshalling

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134820 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-11-25 14:48:35 +00:00
parent e4cbaf19d4
commit 1c9f4cec10
1 changed files with 63 additions and 60 deletions

View File

@ -89,15 +89,18 @@ public class EntityManagementImpl implements EntityManagement {
RELATION_IGNORE_START_WITH_KEYS.add(AT); RELATION_IGNORE_START_WITH_KEYS.add(AT);
RELATION_IGNORE_START_WITH_KEYS.add(UNDERSCORE); RELATION_IGNORE_START_WITH_KEYS.add(UNDERSCORE);
ENTITY_IGNORE_KEYS = new HashSet<String>(); ENTITY_IGNORE_KEYS = new HashSet<String>();
ENTITY_IGNORE_KEYS.add(Entity.HEADER_PROPERTY); ENTITY_IGNORE_KEYS.add(Entity.HEADER_PROPERTY);
ENTITY_IGNORE_START_WITH_KEYS = new HashSet<String>(); ENTITY_IGNORE_START_WITH_KEYS = new HashSet<String>();
ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_IN_PREFIX.toLowerCase()); ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_IN_PREFIX
ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_OUT_PREFIX.toLowerCase()); .toLowerCase());
ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_IN_PREFIX.toUpperCase()); ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_OUT_PREFIX
ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_OUT_PREFIX.toUpperCase()); .toLowerCase());
ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_IN_PREFIX
.toUpperCase());
ENTITY_IGNORE_START_WITH_KEYS.add(OrientVertex.CONNECTION_OUT_PREFIX
.toUpperCase());
ENTITY_IGNORE_START_WITH_KEYS.add(AT); ENTITY_IGNORE_START_WITH_KEYS.add(AT);
ENTITY_IGNORE_START_WITH_KEYS.add(UNDERSCORE); ENTITY_IGNORE_START_WITH_KEYS.add(UNDERSCORE);
@ -148,7 +151,8 @@ public class EntityManagementImpl implements EntityManagement {
String classProperty = getClassProperty(jsonNode); String classProperty = getClassProperty(jsonNode);
try { try {
SchemaManagementImpl.getTypeSchema(orientGraph, classProperty, classProperty); SchemaManagementImpl.getTypeSchema(orientGraph, classProperty,
classProperty);
} catch (SchemaNotFoundException e) { } catch (SchemaNotFoundException e) {
throw e; throw e;
} }
@ -204,7 +208,8 @@ 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(orientGraph, relationType, classProperty); SchemaManagementImpl.getTypeSchema(orientGraph, relationType,
classProperty);
} catch (SchemaNotFoundException e) { } catch (SchemaNotFoundException e) {
throw e; throw e;
} }
@ -324,7 +329,8 @@ public class EntityManagementImpl implements EntityManagement {
} }
public static Map<String, Object> getPropertyMap(JsonNode jsonNode, public static Map<String, Object> getPropertyMap(JsonNode jsonNode,
Set<String> ignoreKeys, Set<String> ignoreStartWith) throws JsonProcessingException, IOException { Set<String> ignoreKeys, Set<String> ignoreStartWith)
throws JsonProcessingException, IOException {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
@ -338,8 +344,7 @@ public class EntityManagementImpl implements EntityManagement {
Iterator<Entry<String, JsonNode>> fields = jsonNode.fields(); Iterator<Entry<String, JsonNode>> fields = jsonNode.fields();
OUTER_WHILE: OUTER_WHILE: while (fields.hasNext()) {
while (fields.hasNext()) {
Entry<String, JsonNode> entry = fields.next(); Entry<String, JsonNode> entry = fields.next();
String key = entry.getKey(); String key = entry.getKey();
@ -348,8 +353,8 @@ public class EntityManagementImpl implements EntityManagement {
continue; continue;
} }
for(String prefix : ignoreStartWith){ for (String prefix : ignoreStartWith) {
if(key.startsWith(prefix)){ if (key.startsWith(prefix)) {
break OUTER_WHILE; break OUTER_WHILE;
} }
} }
@ -374,7 +379,8 @@ public class EntityManagementImpl implements EntityManagement {
throws ResourceRegistryException { throws ResourceRegistryException {
Map<String, Object> vertexProperties = null; Map<String, Object> vertexProperties = null;
try { try {
vertexProperties = getPropertyMap(node, ENTITY_IGNORE_KEYS, ENTITY_IGNORE_START_WITH_KEYS); vertexProperties = getPropertyMap(node, ENTITY_IGNORE_KEYS,
ENTITY_IGNORE_START_WITH_KEYS);
} catch (Exception e) { } catch (Exception e) {
String error = "Error while parsing json to get Relation properties"; String error = "Error while parsing json to get Relation properties";
logger.error(error, e); logger.error(error, e);
@ -387,7 +393,8 @@ public class EntityManagementImpl implements EntityManagement {
throws ResourceRegistryException { throws ResourceRegistryException {
Map<String, Object> edgeProperties = null; Map<String, Object> edgeProperties = null;
try { try {
edgeProperties = getPropertyMap(node, RELATION_IGNORE_KEYS, RELATION_IGNORE_START_WITH_KEYS); edgeProperties = getPropertyMap(node, RELATION_IGNORE_KEYS,
RELATION_IGNORE_START_WITH_KEYS);
} catch (Exception e) { } catch (Exception e) {
String error = "Error while parsing json to get Relation properties"; String error = "Error while parsing json to get Relation properties";
logger.error(error, e); logger.error(error, e);
@ -396,7 +403,6 @@ public class EntityManagementImpl implements EntityManagement {
return edgeProperties; return edgeProperties;
} }
private Element updateProperties(Element element, JsonNode jsonNode) private Element updateProperties(Element element, JsonNode jsonNode)
throws ResourceRegistryException { throws ResourceRegistryException {
Set<String> ignoreKeys = null; Set<String> ignoreKeys = null;
@ -433,15 +439,14 @@ public class EntityManagementImpl implements EntityManagement {
} }
} }
OUTER_FOR: OUTER_FOR: for (String key : oldKeys) {
for (String key : oldKeys) {
if (ignoreKeys.contains(key)) { if (ignoreKeys.contains(key)) {
continue; continue;
} }
for(String prefix : ignoreStartWithKeys){ for (String prefix : ignoreStartWithKeys) {
if(key.startsWith(prefix)){ if (key.startsWith(prefix)) {
break OUTER_FOR; break OUTER_FOR;
} }
} }
@ -727,7 +732,8 @@ 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) throws ResourceRegistryException { @SuppressWarnings("rawtypes") Class<? extends Relation> relationClass)
throws ResourceRegistryException {
logger.debug("Trying to update {} : {}", relationClass.getSimpleName(), logger.debug("Trying to update {} : {}", relationClass.getSimpleName(),
jsonNode); jsonNode);
@ -1113,7 +1119,8 @@ public class EntityManagementImpl implements EntityManagement {
return true; return true;
} }
private static String marshallResource(OrientGraph orientGraph, 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);
@ -1121,30 +1128,25 @@ public class EntityManagementImpl implements EntityManagement {
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(orientGraph, edgeType, ConsistsOf.NAME); SchemaManagementImpl.getTypeSchema(orientGraph, edgeType,
}catch (SchemaNotFoundException e) { ConsistsOf.NAME);
} catch (SchemaNotFoundException e) {
// This not an ConsistsOf Edge. it will be skipped // This not an ConsistsOf Edge. it will be skipped
continue; continue;
} }
try{ JSONObject jsonObjectEdge = Utility.toJsonObject((OrientEdge) edge,
JSONObject jsonObjectEdge = Utility.toJsonObject( 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 (Exception e) {
logger.error("Unable to add a Relation to serilization", e);
continue;
}
} }
@ -1279,7 +1281,8 @@ 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, ConsistsOf.class); updateRelation(orientGraph, relationJsonNode,
ConsistsOf.class);
} }
} }