2016-12-27 11:27:01 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.er.entity;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
import java.util.Iterator;
|
2017-09-27 12:59:00 +02:00
|
|
|
import java.util.Map;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
import org.codehaus.jettison.json.JSONArray;
|
|
|
|
import org.codehaus.jettison.json.JSONObject;
|
2017-01-23 17:41:11 +01:00
|
|
|
import org.gcube.informationsystem.model.AccessType;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.Resource;
|
|
|
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
|
|
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2017-04-28 17:43:30 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
|
2017-11-17 11:42:37 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
|
2016-12-19 14:59:27 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
2017-11-17 11:42:37 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
2017-09-27 12:59:00 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
2017-11-28 17:34:43 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContext;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContext.PermissionMode;
|
2017-11-17 15:59:25 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
2016-12-27 11:27:01 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.er.relation.ConsistsOfManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
2016-12-22 17:27:26 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
2017-09-27 12:59:00 +02:00
|
|
|
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
2016-12-19 14:59:27 +01:00
|
|
|
import com.tinkerpop.blueprints.Direction;
|
|
|
|
import com.tinkerpop.blueprints.Edge;
|
2017-09-27 12:59:00 +02:00
|
|
|
import com.tinkerpop.blueprints.Element;
|
2016-12-19 14:59:27 +01:00
|
|
|
import com.tinkerpop.blueprints.Vertex;
|
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
2017-09-27 12:59:00 +02:00
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
2016-12-19 14:59:27 +01:00
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
2017-09-27 12:59:00 +02:00
|
|
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
|
|
|
public class ResourceManagement extends EntityManagement<Resource> {
|
|
|
|
|
|
|
|
public ResourceManagement() {
|
2017-03-29 16:53:37 +02:00
|
|
|
super(AccessType.RESOURCE);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 17:34:43 +01:00
|
|
|
public ResourceManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
|
|
|
super(AccessType.RESOURCE, workingContext, orientGraph);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-11-17 11:42:37 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected ResourceNotFoundException getSpecificElementNotFoundException(ERNotFoundException e) {
|
|
|
|
return new ResourceNotFoundException(e.getMessage(), e.getCause());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected ResourceAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
|
|
|
return new ResourceAvailableInAnotherContextException(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected ResourceAlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
|
|
|
return new ResourceAlreadyPresentException(message);
|
|
|
|
}
|
|
|
|
|
2017-01-13 12:21:35 +01:00
|
|
|
@Override
|
|
|
|
public String serialize() throws ResourceRegistryException {
|
|
|
|
return serializeAsJson().toString();
|
|
|
|
}
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2017-11-17 11:42:37 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2017-01-13 12:21:35 +01:00
|
|
|
@Override
|
|
|
|
public JSONObject serializeAsJson() throws ResourceRegistryException {
|
2017-01-17 16:53:24 +01:00
|
|
|
|
|
|
|
JSONObject sourceResource = serializeSelfOnly();
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
/*
|
2017-01-17 16:53:24 +01:00
|
|
|
* Cannot get ConsistsOf edge only because is not polymorphic for a
|
|
|
|
* com.tinkerpop.blueprints.Vertex
|
2016-12-19 15:56:16 +01:00
|
|
|
* vertex.getEdges(Direction.OUT, ConsistsOf.NAME);
|
2017-01-17 16:53:24 +01:00
|
|
|
* TODO Looks for a different query
|
2016-12-19 15:56:16 +01:00
|
|
|
*/
|
2017-04-14 14:37:57 +02:00
|
|
|
|
2017-01-17 16:53:24 +01:00
|
|
|
Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
|
|
|
|
for (Edge edge : edges) {
|
2017-11-17 18:10:35 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
@SuppressWarnings("rawtypes")
|
2017-11-17 18:10:35 +01:00
|
|
|
RelationManagement relationManagement = getRelationManagement(edge);
|
2017-11-21 18:18:11 +01:00
|
|
|
relationManagement.setReload(reload);
|
|
|
|
|
2017-11-17 18:41:02 +01:00
|
|
|
if(relationManagement.giveMeSourceEntityManagementAsIs()==null) {
|
2017-11-17 18:10:35 +01:00
|
|
|
relationManagement.setSourceEntityManagement(this);
|
2017-11-17 18:41:02 +01:00
|
|
|
}
|
|
|
|
|
2017-11-21 18:18:11 +01:00
|
|
|
|
2017-11-17 18:41:02 +01:00
|
|
|
if(relationManagement.giveMeSourceEntityManagementAsIs()!=this) {
|
2017-11-17 18:10:35 +01:00
|
|
|
StringBuilder errorMessage = new StringBuilder();
|
|
|
|
errorMessage.append("SourceEntityManagement for ");
|
|
|
|
errorMessage.append(relationManagement.getClass().getSimpleName());
|
|
|
|
errorMessage.append(" is not the one expected. ");
|
|
|
|
errorMessage.append(Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
|
|
|
throw new ResourceRegistryException(errorMessage.toString());
|
|
|
|
}
|
2017-11-17 11:42:37 +01:00
|
|
|
|
2017-01-17 16:53:24 +01:00
|
|
|
if (relationManagement instanceof ConsistsOfManagement) {
|
2017-03-28 16:02:23 +02:00
|
|
|
try {
|
2017-11-17 11:42:37 +01:00
|
|
|
JSONObject consistsOf = relationManagement.serializeAsJson(true, true);
|
2017-03-28 16:02:23 +02:00
|
|
|
sourceResource = addConsistsOf(sourceResource, consistsOf);
|
|
|
|
}catch (ResourceRegistryException e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
2017-04-14 14:37:57 +02:00
|
|
|
throw e;
|
|
|
|
}catch (Exception e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
2017-04-14 14:37:57 +02:00
|
|
|
throw new ResourceRegistryException(e);
|
2017-03-28 16:02:23 +02:00
|
|
|
}
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2016-12-19 15:37:15 +01:00
|
|
|
}
|
2016-12-19 14:59:27 +01:00
|
|
|
/*
|
2017-01-17 16:53:24 +01:00
|
|
|
* This comment is just to show that IsRelatedTo is not serialized
|
2017-04-14 14:37:57 +02:00
|
|
|
* by default as design choice and not because forget
|
2017-01-17 16:53:24 +01:00
|
|
|
*
|
2016-12-19 14:59:27 +01:00
|
|
|
* else if(orientEdgeType.isSubClassOf(IsRelatedTo.NAME)){
|
2017-11-17 18:10:35 +01:00
|
|
|
* JSONObject isRelatedTo = relationManagement.serializeAsJson(true, true);
|
2017-01-17 16:53:24 +01:00
|
|
|
* sourceResource = addIsRelatedTo(sourceResource, isRelatedTo);
|
|
|
|
* }
|
2016-12-19 14:59:27 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2017-01-17 16:53:24 +01:00
|
|
|
return sourceResource;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static JSONObject addConsistsOf(JSONObject sourceResource,
|
|
|
|
JSONObject consistsOf) throws ResourceRegistryException {
|
2017-11-15 19:31:49 +01:00
|
|
|
return addRelation(sourceResource, consistsOf, AccessType.CONSISTS_OF.lowerCaseFirstCharacter());
|
2017-01-17 16:53:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static JSONObject addIsRelatedTo(JSONObject sourceResource,
|
|
|
|
JSONObject isRelatedTo) throws ResourceRegistryException {
|
2017-11-15 19:31:49 +01:00
|
|
|
return addRelation(sourceResource, isRelatedTo, AccessType.IS_RELATED_TO.lowerCaseFirstCharacter());
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
@Override
|
2017-10-26 17:09:07 +02:00
|
|
|
protected Vertex reallyCreate() throws ResourceAlreadyPresentException,
|
2016-12-19 14:59:27 +01:00
|
|
|
ResourceRegistryException {
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
createVertex();
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
String property = AccessType.CONSISTS_OF.lowerCaseFirstCharacter();
|
2016-12-19 14:59:27 +01:00
|
|
|
if (jsonNode.has(property)) {
|
|
|
|
JsonNode jsonNodeArray = jsonNode.get(property);
|
|
|
|
for (JsonNode consistOfJsonNode : jsonNodeArray) {
|
2017-11-28 17:34:43 +01:00
|
|
|
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), orientGraph);
|
2016-12-19 14:59:27 +01:00
|
|
|
com.setJSON(consistOfJsonNode);
|
2017-11-17 11:42:37 +01:00
|
|
|
com.setSourceEntityManagement(this);
|
|
|
|
com.internalCreate();
|
2017-11-17 18:10:35 +01:00
|
|
|
addToRelationManagement(com);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
property = AccessType.IS_RELATED_TO.lowerCaseFirstCharacter();
|
2016-12-19 14:59:27 +01:00
|
|
|
if (jsonNode.has(property)) {
|
|
|
|
JsonNode jsonNodeArray = jsonNode.get(property);
|
|
|
|
for (JsonNode relationJsonNode : jsonNodeArray) {
|
2017-11-28 17:34:43 +01:00
|
|
|
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), orientGraph);
|
2016-12-19 14:59:27 +01:00
|
|
|
irtm.setJSON(relationJsonNode);
|
2017-11-17 11:42:37 +01:00
|
|
|
irtm.setSourceEntityManagement(this);
|
|
|
|
irtm.internalCreate();
|
2017-11-17 18:10:35 +01:00
|
|
|
addToRelationManagement(irtm);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
return element;
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-10-26 17:09:07 +02:00
|
|
|
protected Vertex reallyUpdate() throws ResourceNotFoundException, ResourceRegistryException {
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
getElement();
|
2016-12-19 14:59:27 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
String property = AccessType.CONSISTS_OF.lowerCaseFirstCharacter();
|
2016-12-19 14:59:27 +01:00
|
|
|
if (jsonNode.has(property)) {
|
|
|
|
JsonNode jsonNodeArray = jsonNode.get(property);
|
|
|
|
for (JsonNode relationJsonNode : jsonNodeArray) {
|
2017-11-28 17:34:43 +01:00
|
|
|
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), orientGraph);
|
2016-12-19 14:59:27 +01:00
|
|
|
com.setJSON(relationJsonNode);
|
2017-10-26 17:09:07 +02:00
|
|
|
com.internalCreateOrUdate();
|
2017-11-17 18:10:35 +01:00
|
|
|
addToRelationManagement(com);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
property = AccessType.IS_RELATED_TO.lowerCaseFirstCharacter();
|
2016-12-19 14:59:27 +01:00
|
|
|
if (jsonNode.has(property)) {
|
|
|
|
JsonNode jsonNodeArray = jsonNode.get(property);
|
|
|
|
for (JsonNode relationJsonNode : jsonNodeArray) {
|
2017-11-28 17:34:43 +01:00
|
|
|
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), orientGraph);
|
2016-12-19 14:59:27 +01:00
|
|
|
irtm.setJSON(relationJsonNode);
|
2017-10-26 17:09:07 +02:00
|
|
|
irtm.internalUpdate();
|
2017-11-17 18:10:35 +01:00
|
|
|
addToRelationManagement(irtm);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
return element;
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2016-12-19 14:59:27 +01:00
|
|
|
@Override
|
2017-10-26 17:09:07 +02:00
|
|
|
protected boolean reallyDelete() throws ResourceNotFoundException,
|
2016-12-19 14:59:27 +01:00
|
|
|
ResourceRegistryException {
|
2017-01-17 16:53:24 +01:00
|
|
|
// internalDeleteResource(orientGraph, uuid, null);
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
getElement();
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
Iterable<Edge> iterable = element.getEdges(Direction.OUT);
|
2016-12-19 14:59:27 +01:00
|
|
|
Iterator<Edge> iterator = iterable.iterator();
|
2017-01-17 16:53:24 +01:00
|
|
|
while (iterator.hasNext()) {
|
2017-11-17 11:42:37 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
Edge edge = iterator.next();
|
|
|
|
OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
RelationManagement relationManagement = null;
|
2017-01-17 16:53:24 +01:00
|
|
|
if (orientEdgeType.isSubClassOf(IsRelatedTo.NAME)) {
|
2017-11-28 17:34:43 +01:00
|
|
|
relationManagement = new IsRelatedToManagement(getWorkingContext(), orientGraph);
|
2017-01-17 16:53:24 +01:00
|
|
|
} else if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {
|
2017-11-28 17:34:43 +01:00
|
|
|
relationManagement = new ConsistsOfManagement(getWorkingContext(), orientGraph);
|
2017-01-17 16:53:24 +01:00
|
|
|
} else {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.warn("{} is not a {} nor a {}. {}",
|
2017-01-17 16:53:24 +01:00
|
|
|
Utility.toJsonString(edge, true), IsRelatedTo.NAME,
|
2017-11-23 09:39:21 +01:00
|
|
|
ConsistsOf.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-01-17 16:53:24 +01:00
|
|
|
if (relationManagement != null) {
|
2016-12-30 17:31:12 +01:00
|
|
|
relationManagement.setElement(edge);
|
2017-10-26 17:09:07 +02:00
|
|
|
relationManagement.internalDelete();
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
}
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
element.remove();
|
2017-01-17 16:53:24 +01:00
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
return true;
|
|
|
|
}
|
2017-09-27 12:59:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
public String all(boolean polymorphic, Map<String, String> constraint) throws ResourceRegistryException {
|
|
|
|
try {
|
2017-11-28 17:34:43 +01:00
|
|
|
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
2017-09-27 12:59:00 +02:00
|
|
|
|
|
|
|
return reallyGetAll(polymorphic, constraint);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
} finally {
|
|
|
|
if (orientGraph != null) {
|
|
|
|
orientGraph.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String reallyGetAll(boolean polymorphic, Map<String, String> constraint) throws ResourceRegistryException{
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
|
|
|
|
String relationType = constraint.get(AccessPath.RELATION_TYPE_PATH_PART);
|
|
|
|
constraint.remove(AccessPath.RELATION_TYPE_PATH_PART);
|
|
|
|
String facetType = constraint.get(AccessPath.FACET_TYPE_PATH_PART);
|
|
|
|
constraint.remove(AccessPath.FACET_TYPE_PATH_PART);
|
|
|
|
|
2017-11-13 12:50:11 +01:00
|
|
|
// TODO check types
|
|
|
|
|
2017-09-27 12:59:00 +02:00
|
|
|
/*
|
|
|
|
* SELECT FROM (TRAVERSE inE('isIdentifiedBy'), outV('EService')
|
|
|
|
* FROM (SELECT FROM SoftwareFacet WHERE group='VREManagement' AND name='SmartExecutor'))
|
|
|
|
*
|
|
|
|
* WHERE @class='EService' // Only is not polymorphic
|
|
|
|
*/
|
|
|
|
|
|
|
|
boolean first = true;
|
|
|
|
|
|
|
|
StringBuilder selectStringBuilder = new StringBuilder("SELECT FROM (TRAVERSE inE('");
|
|
|
|
selectStringBuilder.append(relationType);
|
|
|
|
selectStringBuilder.append("'), outV('");
|
|
|
|
selectStringBuilder.append(erType);
|
|
|
|
selectStringBuilder.append("') FROM (SELECT FROM ");
|
|
|
|
selectStringBuilder.append(facetType);
|
|
|
|
for(String key : constraint.keySet()){
|
|
|
|
if(first){
|
|
|
|
selectStringBuilder.append(" WHERE ");
|
|
|
|
first = false;
|
|
|
|
}else{
|
|
|
|
selectStringBuilder.append(" AND ");
|
|
|
|
}
|
|
|
|
selectStringBuilder.append(key);
|
|
|
|
selectStringBuilder.append("=");
|
|
|
|
String value = constraint.get(key).trim();
|
|
|
|
selectStringBuilder.append("'");
|
|
|
|
selectStringBuilder.append(value);
|
|
|
|
selectStringBuilder.append("'");
|
|
|
|
}
|
|
|
|
selectStringBuilder.append(" ))");
|
|
|
|
|
|
|
|
if(!polymorphic){
|
|
|
|
selectStringBuilder.append(" WHERE @class='");
|
|
|
|
selectStringBuilder.append(erType);
|
|
|
|
selectStringBuilder.append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
String select = selectStringBuilder.toString();
|
|
|
|
logger.trace(select);
|
|
|
|
|
|
|
|
|
|
|
|
OSQLSynchQuery<Element> osqlSynchQuery = new OSQLSynchQuery<Element>(
|
|
|
|
select);
|
|
|
|
Iterable<Element> elements = orientGraph.command(osqlSynchQuery)
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
for(Element element : elements){
|
|
|
|
|
|
|
|
if(polymorphic){
|
|
|
|
OrientVertexType orientVertexType = null;
|
|
|
|
try {
|
|
|
|
OrientElement orientElement = ((OrientElement) element);
|
|
|
|
if(orientElement instanceof OrientEdge){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
orientVertexType = ((OrientVertex) orientElement).getType();
|
|
|
|
}catch (Exception e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
String error = String.format("Unable to detect type of %s. %s",
|
|
|
|
element.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
2017-09-27 12:59:00 +02:00
|
|
|
logger.error(error, e);
|
|
|
|
throw new ResourceRegistryException(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(orientVertexType.getName().compareTo(erType)!=0){
|
|
|
|
if(!orientVertexType.isSubClassOf(erType) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Vertex vertex = (Vertex) element;
|
|
|
|
|
|
|
|
@SuppressWarnings("rawtypes")
|
2017-11-28 17:34:43 +01:00
|
|
|
EntityManagement entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(), orientGraph, vertex);
|
2017-09-27 12:59:00 +02:00
|
|
|
try {
|
|
|
|
JSONObject jsonObject = entityManagement.serializeAsJson();
|
|
|
|
jsonArray.put(jsonObject);
|
|
|
|
}catch (ResourceRegistryException e) {
|
2017-11-23 09:39:21 +01:00
|
|
|
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
|
|
|
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
2017-09-27 12:59:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return jsonArray.toString();
|
|
|
|
}
|
|
|
|
|
2016-12-19 14:59:27 +01:00
|
|
|
|
|
|
|
}
|