Changer elements serialization
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@131463 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
624ba10dc2
commit
a0181b68bb
|
@ -4,6 +4,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.resources.impl;
|
package org.gcube.informationsystem.resourceregistry.resources.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -16,6 +17,8 @@ import java.util.Set;
|
||||||
import org.codehaus.jettison.json.JSONArray;
|
import org.codehaus.jettison.json.JSONArray;
|
||||||
import org.codehaus.jettison.json.JSONException;
|
import org.codehaus.jettison.json.JSONException;
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
|
import org.codehaus.jettison.json.JSONStringer;
|
||||||
|
import org.codehaus.jettison.json.JSONWriter;
|
||||||
import org.gcube.informationsystem.impl.utils.Entities;
|
import org.gcube.informationsystem.impl.utils.Entities;
|
||||||
import org.gcube.informationsystem.model.embedded.Embedded;
|
import org.gcube.informationsystem.model.embedded.Embedded;
|
||||||
import org.gcube.informationsystem.model.embedded.Header;
|
import org.gcube.informationsystem.model.embedded.Header;
|
||||||
|
@ -412,8 +415,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
|
|
||||||
logger.trace("Created {} is {} orientVertexToJsonString",
|
logger.trace("Created {} is {} orientVertexToJsonString",
|
||||||
Vertex.class.getSimpleName(), Utility
|
Vertex.class.getSimpleName(), Utility
|
||||||
.orientVertexToJsonString(
|
.toJsonString((OrientVertex) vertex, true));
|
||||||
(OrientVertex) vertex, true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vertex;
|
return vertex;
|
||||||
|
@ -556,7 +558,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
public String createFacet(String facetType, String jsonRepresentation)
|
public String createFacet(String facetType, String jsonRepresentation)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
Vertex vertex = createVertexEntity(facetType, Facet.class, jsonRepresentation, false);
|
Vertex vertex = createVertexEntity(facetType, Facet.class, jsonRepresentation, false);
|
||||||
return Utility.orientVertexToJsonString((OrientVertex) vertex, false);
|
return Utility.toJsonString((OrientVertex) vertex, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -577,10 +579,9 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
Vertex facet = getEntity(orientGraph, uuid, facetType, Facet.class);
|
Vertex facet = getEntity(orientGraph, uuid, facetType, Facet.class);
|
||||||
|
|
||||||
logger.trace("{} of type {} with UUID {} is {}", Facet.NAME,
|
logger.trace("{} of type {} with UUID {} is {}", Facet.NAME,
|
||||||
facetType, uuid, Utility.orientVertexToJsonString(
|
facetType, uuid, Utility.toJsonString((OrientVertex) facet, true));
|
||||||
(OrientVertex) facet, true));
|
|
||||||
|
|
||||||
return Utility.orientVertexToJsonString((OrientVertex) facet, true);
|
return Utility.toJsonString((OrientVertex) facet, true);
|
||||||
} catch (FacetNotFoundException fnfe) {
|
} catch (FacetNotFoundException fnfe) {
|
||||||
throw fnfe;
|
throw fnfe;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -644,11 +645,9 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
|
|
||||||
logger.trace("{} with UUID {} has been updated {}", Facet.NAME,
|
logger.trace("{} with UUID {} has been updated {}", Facet.NAME,
|
||||||
uuid, Utility.orientVertexToJsonString(
|
uuid, Utility.toJsonString((OrientVertex) facet, true));
|
||||||
(OrientVertex) facet, true));
|
|
||||||
|
|
||||||
return Utility
|
return Utility.toJsonString((OrientVertex) facet, false);
|
||||||
.orientVertexToJsonString((OrientVertex) facet, false);
|
|
||||||
|
|
||||||
} catch (FacetNotFoundException fnfe) {
|
} catch (FacetNotFoundException fnfe) {
|
||||||
if (orientGraph != null) {
|
if (orientGraph != null) {
|
||||||
|
@ -709,7 +708,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
facetUUID, Facet.class,
|
facetUUID, Facet.class,
|
||||||
consistOfType, ConsistsOf.class,
|
consistOfType, ConsistsOf.class,
|
||||||
jsonProperties);
|
jsonProperties);
|
||||||
return Utility.orientEdgeToJsonString((OrientEdge) edge, false);
|
return Utility.toJsonString((OrientEdge) edge, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -755,7 +754,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
targetResourceUuid, Resource.class,
|
targetResourceUuid, Resource.class,
|
||||||
relatedToType, IsRelatedTo.class,
|
relatedToType, IsRelatedTo.class,
|
||||||
jsonProperties);
|
jsonProperties);
|
||||||
return Utility.orientEdgeToJsonString((OrientEdge) edge, false);
|
return Utility.toJsonString((OrientEdge) edge, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -792,23 +791,34 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String marshallResource(Vertex vertex) throws JSONException{
|
private static String marshallResource(Vertex vertex) throws JSONException{
|
||||||
JSONObject jsonObject = Utility.toJsonObject(vertex, false);
|
JSONObject jsonObject = Utility.toJsonObject((OrientVertex) vertex, true);
|
||||||
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray consistsOfArray = new JSONArray();
|
||||||
|
|
||||||
|
Iterable<Edge> edges = vertex.getEdges(Direction.OUT);
|
||||||
|
|
||||||
Iterable<Edge> edges = vertex.getEdges(Direction.OUT, ConsistsOf.NAME);
|
|
||||||
for(Edge edge : edges){
|
for(Edge edge : edges){
|
||||||
JSONObject jsonObjectEdge = Utility.toJsonObject(edge, false);
|
|
||||||
|
|
||||||
Vertex facetVertex = edge.getVertex(Direction.OUT);
|
String edgeType = edge.getLabel();
|
||||||
jsonObjectEdge.put(Relation.TARGET_PROPERTY, Utility.toJsonObject(facetVertex, false));
|
|
||||||
|
try {
|
||||||
|
SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
|
||||||
|
schemaManagement.getTypeSchema(edgeType, ConsistsOf.NAME);
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
jsonArray.put(jsonObjectEdge);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonObject.append(lowerCaseFirstCharacter(ConsistsOf.NAME), jsonArray);
|
jsonObject.put(lowerCaseFirstCharacter(ConsistsOf.NAME), consistsOfArray);
|
||||||
|
|
||||||
return jsonObject.toString();
|
return jsonObject.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -881,8 +891,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
Resource.class);
|
Resource.class);
|
||||||
|
|
||||||
logger.trace("{} of type {} with UUID {} is {}", Resource.NAME,
|
logger.trace("{} of type {} with UUID {} is {}", Resource.NAME,
|
||||||
resourceType, uuid, Utility.orientVertexToJsonString(
|
resourceType, uuid, Utility.toJsonString((OrientVertex) resource, true));
|
||||||
(OrientVertex) resource, true));
|
|
||||||
|
|
||||||
return marshallResource(resource);
|
return marshallResource(resource);
|
||||||
} catch (ResourceNotFoundException rnfe) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
|
|
|
@ -23,9 +23,8 @@ import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||||
import com.tinkerpop.blueprints.Edge;
|
import com.tinkerpop.blueprints.Edge;
|
||||||
import com.tinkerpop.blueprints.Element;
|
import com.tinkerpop.blueprints.Element;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
|
||||||
import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode;
|
import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode;
|
||||||
import com.tinkerpop.blueprints.util.io.graphson.GraphSONUtility;
|
import com.tinkerpop.blueprints.util.io.graphson.GraphSONUtility;
|
||||||
|
|
||||||
|
@ -37,16 +36,12 @@ public class Utility {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Utility.class);
|
private static final Logger logger = LoggerFactory.getLogger(Utility.class);
|
||||||
|
|
||||||
public static String orientVertexToJsonString(OrientVertex orientVertex, boolean raw) {
|
public static JSONObject toJsonObject(OrientElement element, boolean raw) throws JSONException {
|
||||||
ORecord oRecord = orientVertex.getRecord();
|
return new JSONObject(toJsonString(element, raw));
|
||||||
if (raw) {
|
|
||||||
return oRecord.toJSON();
|
|
||||||
}
|
|
||||||
return oRecord.toJSON("class");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String orientEdgeToJsonString(OrientEdge orientEdge, boolean raw) {
|
public static String toJsonString(OrientElement element, boolean raw) {
|
||||||
ORecord oRecord = orientEdge.getRecord();
|
ORecord oRecord = element.getRecord();
|
||||||
if (raw) {
|
if (raw) {
|
||||||
return oRecord.toJSON();
|
return oRecord.toJSON();
|
||||||
}
|
}
|
||||||
|
@ -68,8 +63,6 @@ public class Utility {
|
||||||
GraphSONMode.EXTENDED);
|
GraphSONMode.EXTENDED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String toJsonString(Element element) {
|
public static String toJsonString(Element element) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue