Switched from OrientGraph to oDatabaseDocument to have one interface for
managing vertexes, edges and properties. Moreover, switched from Element to OElement, Vertex to OVertex, Edge to OEdge to have the same APIs to manage instances, and to be able to directly use oDatabaseDocument instead of frequent casts to OrientElement to perform operations not supported by thinkerpop standard interface.
This commit is contained in:
parent
f14061774d
commit
f683681a8a
|
@ -36,14 +36,13 @@ import com.orientechnologies.orient.core.db.ODatabaseSession;
|
|||
import com.orientechnologies.orient.core.db.ODatabaseType;
|
||||
import com.orientechnologies.orient.core.db.OrientDB;
|
||||
import com.orientechnologies.orient.core.db.OrientDBConfig;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
||||
import com.orientechnologies.orient.core.metadata.security.ORole;
|
||||
import com.orientechnologies.orient.core.metadata.security.OSecurity;
|
||||
import com.orientechnologies.orient.core.metadata.security.OUser;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -197,13 +196,12 @@ public class DatabaseEnvironment {
|
|||
contextUtility.addSecurityContext(schemaSecurityContext.getUUID().toString(), schemaSecurityContext);
|
||||
|
||||
if(created) {
|
||||
OrientGraphFactory factory = new OrientGraphFactory(DB_URI, CHANGED_ADMIN_USERNAME,
|
||||
CHANGED_ADMIN_PASSWORD).setupPool(1, 10);
|
||||
OrientGraph orientGraph = factory.getTx();
|
||||
adminSecurityContext.create(orientGraph);
|
||||
orientGraph.commit();
|
||||
orientGraph.shutdown();
|
||||
factory.close();
|
||||
ODatabasePool pool = new ODatabasePool(DatabaseEnvironment.DB_URI, CHANGED_ADMIN_USERNAME, CHANGED_ADMIN_PASSWORD);
|
||||
ODatabaseDocument oDatabaseDocument = pool.acquire();
|
||||
adminSecurityContext.create(oDatabaseDocument);
|
||||
oDatabaseDocument.commit();
|
||||
oDatabaseDocument.close();
|
||||
pool.close();
|
||||
|
||||
contextSecurityContext.create();
|
||||
|
||||
|
@ -261,8 +259,8 @@ public class DatabaseEnvironment {
|
|||
}
|
||||
}
|
||||
|
||||
protected static void setDateTimeFormat(ODatabaseSession oDatabaseSession) {
|
||||
oDatabaseSession.set(ATTRIBUTES.DATETIMEFORMAT, ISConstants.DATETIME_PATTERN);
|
||||
protected static void setDateTimeFormat(ODatabaseDocument oDatabaseDocument) {
|
||||
oDatabaseDocument.set(ATTRIBUTES.DATETIMEFORMAT, ISConstants.DATETIME_PATTERN);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -46,24 +47,21 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
|||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.TextNode;
|
||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OProperty;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.orientechnologies.orient.core.util.ODateHelper;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.util.StringFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class ERManagement<El extends Element> {
|
||||
public abstract class ERManagement<El extends OElement> {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
@ -80,7 +78,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
protected Class<El> elementClass;
|
||||
protected final AccessType accessType;
|
||||
|
||||
protected OrientGraph orientGraph;
|
||||
protected ODatabaseDocument oDatabaseDocument;
|
||||
|
||||
protected UUID uuid;
|
||||
protected JsonNode jsonNode;
|
||||
|
@ -155,14 +153,19 @@ public abstract class ERManagement<El extends Element> {
|
|||
checkJsonNode();
|
||||
}
|
||||
|
||||
public static OClass getOClass(OElement oElement) throws SchemaException, ResourceRegistryException {
|
||||
Optional<OClass> optional = oElement.getSchemaType();
|
||||
if(optional.isPresent()) {
|
||||
return optional.get();
|
||||
}else {
|
||||
throw new ResourceRegistryException("An element not belonging to any defined type should not exists. Please contact the administrator.");
|
||||
}
|
||||
}
|
||||
|
||||
protected OClass getOClass() throws SchemaException, ResourceRegistryException {
|
||||
if(oClass == null) {
|
||||
if(element != null) {
|
||||
OrientElement orientElement = (OrientElement) element;
|
||||
OMetadata oMetadata = orientElement.getRecord().getDatabase().getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
String type = orientElement.getRecord().getClassName();
|
||||
oClass = oSchema.getClass(type);
|
||||
oClass = getOClass(element);
|
||||
} else {
|
||||
oClass = SchemaManagementImpl.getTypeSchema(elementType, accessType);
|
||||
}
|
||||
|
@ -268,9 +271,9 @@ public abstract class ERManagement<El extends Element> {
|
|||
entityHeader = HeaderUtility.addHeader(element, null);
|
||||
}
|
||||
|
||||
getWorkingContext().addElement(element, orientGraph);
|
||||
getWorkingContext().addElement(element, oDatabaseDocument);
|
||||
|
||||
((OrientElement) element).save();
|
||||
element.save();
|
||||
|
||||
return element;
|
||||
} catch(ResourceRegistryException e) {
|
||||
|
@ -288,7 +291,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
reallyUpdate();
|
||||
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
((OrientElement) element).save();
|
||||
element.save();
|
||||
|
||||
return element;
|
||||
} catch(ResourceRegistryException e) {
|
||||
|
@ -321,7 +324,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
try {
|
||||
boolean ret = reallyAddToContext(targetSecurityContext);
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
((OrientElement) element).save();
|
||||
element.save();
|
||||
return ret && true;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
@ -339,7 +342,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
try {
|
||||
boolean ret = reallyRemoveFromContext(targetSecurityContext);
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
((OrientElement) element).save();
|
||||
element.save();
|
||||
return ret && true;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
@ -355,7 +358,8 @@ public abstract class ERManagement<El extends Element> {
|
|||
}
|
||||
this.element = element;
|
||||
this.uuid = HeaderUtility.getHeader(element).getUUID();
|
||||
this.elementType = ((OrientElement) element).getLabel();
|
||||
OClass oClass = getOClass();
|
||||
this.elementType = oClass.getName();
|
||||
}
|
||||
|
||||
protected abstract NotFoundException getSpecificElementNotFoundException(NotFoundException e);
|
||||
|
@ -388,7 +392,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
|
||||
} else {
|
||||
if(reload) {
|
||||
((OrientElement) element).reload();
|
||||
element.reload();
|
||||
}
|
||||
}
|
||||
return element;
|
||||
|
@ -399,7 +403,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
if(uuid == null) {
|
||||
throw new NotFoundException("null UUID does not allow to retrieve the Element");
|
||||
}
|
||||
return Utility.getElementByUUID(orientGraph, elementType == null ? accessType.getName() : elementType, uuid,
|
||||
return Utility.getElementByUUID(oDatabaseDocument, elementType == null ? accessType.getName() : elementType, uuid,
|
||||
elementClass);
|
||||
} catch(NotFoundException e) {
|
||||
throw getSpecificElementNotFoundException(e);
|
||||
|
@ -428,7 +432,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
public String all(boolean polymorphic) throws ResourceRegistryException {
|
||||
try {
|
||||
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
||||
return reallyGetAll(polymorphic);
|
||||
} catch(ResourceRegistryException e) {
|
||||
|
@ -436,15 +440,15 @@ public abstract class ERManagement<El extends Element> {
|
|||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
||||
getElement();
|
||||
|
||||
|
@ -456,8 +460,8 @@ public abstract class ERManagement<El extends Element> {
|
|||
logger.error("Unable to find {} with UUID {}", accessType.getName(), uuid, e);
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -465,9 +469,8 @@ public abstract class ERManagement<El extends Element> {
|
|||
public String createOrUpdate()
|
||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
boolean update = false;
|
||||
try {
|
||||
|
@ -478,7 +481,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
element = internalCreate();
|
||||
}
|
||||
|
||||
orientGraph.commit();
|
||||
oDatabaseDocument.commit();
|
||||
|
||||
if(update) {
|
||||
setReload(true);
|
||||
|
@ -490,19 +493,19 @@ public abstract class ERManagement<El extends Element> {
|
|||
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid, e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -510,13 +513,12 @@ public abstract class ERManagement<El extends Element> {
|
|||
public String create() throws AlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
element = internalCreate();
|
||||
|
||||
orientGraph.commit();
|
||||
oDatabaseDocument.commit();
|
||||
|
||||
// TODO Notify to subscriptionNotification
|
||||
|
||||
|
@ -524,26 +526,26 @@ public abstract class ERManagement<El extends Element> {
|
|||
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to create {}", accessType.getName());
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to create {}", accessType.getName(), e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
||||
getElement();
|
||||
|
||||
|
@ -555,21 +557,20 @@ public abstract class ERManagement<El extends Element> {
|
|||
logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid, e);
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
element = internalUpdate();
|
||||
|
||||
orientGraph.commit();
|
||||
oDatabaseDocument.commit();
|
||||
|
||||
setReload(true);
|
||||
|
||||
|
@ -579,19 +580,19 @@ public abstract class ERManagement<El extends Element> {
|
|||
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid, e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -600,15 +601,13 @@ public abstract class ERManagement<El extends Element> {
|
|||
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
|
||||
|
||||
try {
|
||||
|
||||
orientGraph = ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
boolean deleted = reallyDelete();
|
||||
|
||||
if(deleted) {
|
||||
orientGraph.commit();
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} was successfully deleted.", accessType.getName(), uuid);
|
||||
} else {
|
||||
throw new ResourceRegistryException("Error while deleting " + accessType.getName() + " with UUID " + uuid);
|
||||
|
@ -619,19 +618,19 @@ public abstract class ERManagement<El extends Element> {
|
|||
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid, e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -641,33 +640,32 @@ public abstract class ERManagement<El extends Element> {
|
|||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
|
||||
try {
|
||||
orientGraph = ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
boolean added = internalAddToContext(targetSecurityContext);
|
||||
|
||||
orientGraph.commit();
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
return added;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID, e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -677,36 +675,34 @@ public abstract class ERManagement<El extends Element> {
|
|||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
|
||||
try {
|
||||
|
||||
orientGraph = ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph.begin();
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
boolean removed = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
orientGraph.commit();
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid,
|
||||
contextUUID);
|
||||
|
||||
return removed;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID,
|
||||
e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -837,13 +833,13 @@ public abstract class ERManagement<El extends Element> {
|
|||
* @return
|
||||
* @throws ResourceRegistryException
|
||||
*/
|
||||
public static Element updateProperties(OClass oClass, Element element, JsonNode jsonNode, Set<String> ignoreKeys,
|
||||
public static OElement updateProperties(OClass oClass, OElement element, JsonNode jsonNode, Set<String> ignoreKeys,
|
||||
Set<String> ignoreStartWithKeys) throws ResourceRegistryException {
|
||||
|
||||
Set<String> oldKeys = element.getPropertyKeys();
|
||||
Set<String> oldKeys = element.getPropertyNames();
|
||||
|
||||
Map<String,Object> properties;
|
||||
if(element instanceof Vertex || element instanceof Edge) {
|
||||
if(element instanceof OVertex || element instanceof OEdge) {
|
||||
try {
|
||||
properties = getPropertyMap(jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
} catch(IOException e) {
|
||||
|
@ -865,7 +861,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
|
||||
if(object instanceof ODocument) {
|
||||
ODocument oDocument = (ODocument) object;
|
||||
((OrientElement) element).setProperty(key, oDocument, OType.EMBEDDED);
|
||||
element.setProperty(key, oDocument, OType.EMBEDDED);
|
||||
set = true;
|
||||
}
|
||||
|
||||
|
@ -873,11 +869,11 @@ public abstract class ERManagement<El extends Element> {
|
|||
* List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354
|
||||
*/
|
||||
if(object instanceof Set) {
|
||||
((OrientElement) element).setProperty(key, object, OType.EMBEDDEDSET);
|
||||
element.setProperty(key, object, OType.EMBEDDEDSET);
|
||||
set = true;
|
||||
}
|
||||
if(object instanceof List) {
|
||||
((OrientElement) element).setProperty(key, object, OType.EMBEDDEDLIST);
|
||||
element.setProperty(key, object, OType.EMBEDDEDLIST);
|
||||
set = true;
|
||||
}
|
||||
|
||||
|
@ -908,7 +904,7 @@ public abstract class ERManagement<El extends Element> {
|
|||
element.removeProperty(key);
|
||||
}
|
||||
|
||||
((OrientElement) element).save();
|
||||
element.save();
|
||||
|
||||
return element;
|
||||
}
|
||||
|
@ -1001,20 +997,21 @@ public abstract class ERManagement<El extends Element> {
|
|||
|
||||
public JsonNode toJsonNode() throws ResourceRegistryException {
|
||||
try {
|
||||
OrientElement orientElement = (OrientElement) getElement();
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
|
||||
Map<String,Object> properties = orientElement.getProperties();
|
||||
for(String key : orientElement.getPropertyKeys()) {
|
||||
Object object = properties.get(key);
|
||||
OElement element = getElement();
|
||||
Set<String> keys = element.getPropertyNames();
|
||||
for(String key : keys) {
|
||||
Object object = element.getProperty(key);
|
||||
JsonNode jsonNode = getPropertyForJson(key, object);
|
||||
if(jsonNode != null) {
|
||||
objectNode.replace(key, jsonNode);
|
||||
}
|
||||
}
|
||||
|
||||
String type = orientElement.getRecord().getClassName();
|
||||
OClass oClass = getOClass();
|
||||
String type = oClass.getName();
|
||||
objectNode.put(ISManageable.CLASS_PROPERTY, type);
|
||||
|
||||
Collection<String> superClasses = getSuperclasses();
|
||||
|
|
|
@ -24,15 +24,11 @@ import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -86,23 +82,22 @@ public class ERManagementUtility {
|
|||
return erManagement;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ERManagement getERManagement(SecurityContext workingContext, OrientGraph orientGraph,
|
||||
Element element) throws ResourceRegistryException {
|
||||
if(element instanceof Vertex) {
|
||||
return getEntityManagement(workingContext, orientGraph, (Vertex) element);
|
||||
} else if(element instanceof Edge) {
|
||||
return getRelationManagement(workingContext, orientGraph, (Edge) element);
|
||||
public static ERManagement<?> getERManagement(SecurityContext workingContext, ODatabaseDocument orientGraph,
|
||||
OElement element) throws ResourceRegistryException {
|
||||
if(element instanceof OVertex) {
|
||||
return getEntityManagement(workingContext, orientGraph, (OVertex) element);
|
||||
} else if(element instanceof OEdge) {
|
||||
return getRelationManagement(workingContext, orientGraph, (OEdge) element);
|
||||
}
|
||||
throw new ResourceRegistryException(String.format("%s is not a %s nor a %s", element.getClass().getSimpleName(),
|
||||
Entity.NAME, Relation.NAME));
|
||||
}
|
||||
|
||||
public static Element getAnyElementByUUID(UUID uuid) throws NotFoundException, ResourceRegistryException {
|
||||
public static OElement getAnyElementByUUID(UUID uuid) throws NotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
return Utility.getElementByUUIDAsAdmin(null, uuid, Vertex.class);
|
||||
return Utility.getElementByUUIDAsAdmin(null, uuid, OVertex.class);
|
||||
} catch(NotFoundException e) {
|
||||
return Utility.getElementByUUIDAsAdmin(null, uuid, Edge.class);
|
||||
return Utility.getElementByUUIDAsAdmin(null, uuid, OEdge.class);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -110,12 +105,12 @@ public class ERManagementUtility {
|
|||
}
|
||||
}
|
||||
|
||||
private static Element getAnyElementByUUID(OrientGraph orientGraph, UUID uuid)
|
||||
private static OElement getAnyElementByUUID(ODatabaseDocument orientGraph, UUID uuid)
|
||||
throws NotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
return Utility.getElementByUUID(orientGraph, null, uuid, Vertex.class);
|
||||
return Utility.getElementByUUID(orientGraph, null, uuid, OVertex.class);
|
||||
} catch(NotFoundException e) {
|
||||
return Utility.getElementByUUID(orientGraph, null, uuid, Edge.class);
|
||||
return Utility.getElementByUUID(orientGraph, null, uuid, OEdge.class);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -124,9 +119,9 @@ public class ERManagementUtility {
|
|||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ERManagement getERManagementFromUUID(SecurityContext workingContext, OrientGraph orientGraph,
|
||||
public static ERManagement getERManagementFromUUID(SecurityContext workingContext, ODatabaseDocument orientGraph,
|
||||
UUID uuid) throws ResourceRegistryException {
|
||||
Element element;
|
||||
OElement element;
|
||||
try {
|
||||
element = getAnyElementByUUID(orientGraph, uuid);
|
||||
return getERManagement(workingContext, orientGraph, element);
|
||||
|
@ -137,22 +132,22 @@ public class ERManagementUtility {
|
|||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static EntityManagement getEntityManagement(SecurityContext workingContext, OrientGraph orientGraph,
|
||||
Vertex vertex) throws ResourceRegistryException {
|
||||
public static EntityManagement getEntityManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument,
|
||||
OVertex vertex) throws ResourceRegistryException {
|
||||
|
||||
if(orientGraph == null) {
|
||||
if(oDatabaseDocument == null) {
|
||||
throw new ResourceRegistryException(
|
||||
OrientGraph.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
ODatabaseDocument.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
if(vertex == null) {
|
||||
throw new ResourceRegistryException(
|
||||
Vertex.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
OVertex.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
OrientVertexType orientVertexType = null;
|
||||
OClass oClass = null;
|
||||
try {
|
||||
orientVertexType = ((OrientVertex) vertex).getType();
|
||||
oClass = ERManagement.getOClass(vertex);
|
||||
} catch(Exception e) {
|
||||
String error = String.format("Unable to detect type of %s. %s", vertex.toString(),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
|
@ -161,10 +156,10 @@ public class ERManagementUtility {
|
|||
}
|
||||
|
||||
EntityManagement entityManagement = null;
|
||||
if(orientVertexType.isSubClassOf(Resource.NAME)) {
|
||||
entityManagement = new ResourceManagement(workingContext, orientGraph);
|
||||
} else if(orientVertexType.isSubClassOf(Facet.NAME)) {
|
||||
entityManagement = new FacetManagement(workingContext, orientGraph);
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
||||
entityManagement = new ResourceManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(Facet.NAME)) {
|
||||
entityManagement = new FacetManagement(workingContext, oDatabaseDocument);
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. %s", vertex, Resource.NAME, Facet.NAME,
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
|
@ -175,25 +170,26 @@ public class ERManagementUtility {
|
|||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static RelationManagement getRelationManagement(SecurityContext workingContext, OrientGraph orientGraph,
|
||||
Edge edge) throws ResourceRegistryException {
|
||||
public static RelationManagement getRelationManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument,
|
||||
OEdge edge) throws ResourceRegistryException {
|
||||
|
||||
if(orientGraph == null) {
|
||||
if(oDatabaseDocument == null) {
|
||||
throw new ResourceRegistryException(
|
||||
OrientGraph.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
ODatabaseDocument.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
if(edge == null) {
|
||||
throw new ResourceRegistryException(
|
||||
Edge.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
OEdge.class.getSimpleName() + "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
|
||||
OClass oClass = ERManagement.getOClass(edge);
|
||||
|
||||
RelationManagement relationManagement = null;
|
||||
if(orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(workingContext, orientGraph);
|
||||
} else if(orientEdgeType.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(workingContext, orientGraph);
|
||||
if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(workingContext, oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(workingContext, oDatabaseDocument);
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. %s", edge, ConsistsOf.NAME, IsRelatedTo.NAME,
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
|
|
|
@ -19,16 +19,15 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManagement<Vertex> {
|
||||
public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManagement<OVertex> {
|
||||
|
||||
/**
|
||||
* Provide a cache edge-internal-id -> RelationManagement
|
||||
|
@ -42,18 +41,18 @@ public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManag
|
|||
|
||||
this.ignoreKeys.add(BaseEntity.HEADER_PROPERTY);
|
||||
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX.toUpperCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX.toUpperCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_IN_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_OUT_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_IN_PREFIX.toUpperCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_OUT_PREFIX.toUpperCase());
|
||||
|
||||
this.relationManagements = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
protected BaseEntityManagement(AccessType accessType, SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
protected BaseEntityManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
this(accessType);
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
|
@ -64,11 +63,11 @@ public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManag
|
|||
* fake id starting with - (minus) sign. This not imply any collateral effect
|
||||
* but a better solution is a desiderata.
|
||||
*/
|
||||
protected BaseRelationManagement getBaseRelationManagement(Edge edge) throws ResourceRegistryException {
|
||||
String id = edge.getId().toString();
|
||||
protected BaseRelationManagement getBaseRelationManagement(OEdge edge) throws ResourceRegistryException {
|
||||
String id = edge.getIdentity().toString();
|
||||
BaseRelationManagement relationManagement = relationManagements.get(id);
|
||||
if(relationManagement == null) {
|
||||
relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(), orientGraph, edge);
|
||||
relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge);
|
||||
relationManagements.put(id, relationManagement);
|
||||
}
|
||||
return relationManagement;
|
||||
|
@ -76,8 +75,8 @@ public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManag
|
|||
|
||||
protected void addToRelationManagement(@SuppressWarnings("rawtypes") BaseRelationManagement baseRelationManagement)
|
||||
throws ResourceRegistryException {
|
||||
Element elem = baseRelationManagement.getElement();
|
||||
String id = elem.getId().toString();
|
||||
OElement elem = baseRelationManagement.getElement();
|
||||
String id = elem.getIdentity().toString();
|
||||
if(relationManagements.get(id) != null && relationManagements.get(id) != baseRelationManagement) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
errorMessage.append("Two different instance of ");
|
||||
|
@ -108,9 +107,9 @@ public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManag
|
|||
return sourceResource;
|
||||
}
|
||||
|
||||
protected Vertex createVertex() throws EntityAlreadyPresentException, ResourceRegistryException {
|
||||
protected OVertex createVertex() throws EntityAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
logger.trace("Going to create {} for {} ({}) using {}", Vertex.class.getSimpleName(), accessType.getName(),
|
||||
logger.trace("Going to create {} for {} ({}) using {}", OVertex.class.getSimpleName(), accessType.getName(),
|
||||
elementType, jsonNode);
|
||||
|
||||
try {
|
||||
|
@ -122,11 +121,11 @@ public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManag
|
|||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
Vertex vertexEntity = orientGraph.addVertex("class:" + elementType);
|
||||
OVertex vertexEntity = oDatabaseDocument.newVertex(elementType);
|
||||
|
||||
try {
|
||||
if(uuid != null) {
|
||||
Vertex v = getElement();
|
||||
OVertex v = getElement();
|
||||
if(v != null) {
|
||||
String error = String.format("A %s with UUID %s already exist", elementType, uuid.toString());
|
||||
throw getSpecificERAlreadyPresentException(error);
|
||||
|
@ -135,10 +134,10 @@ public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManag
|
|||
|
||||
} catch(NotFoundException e) {
|
||||
try {
|
||||
Element el = ERManagementUtility.getAnyElementByUUID(uuid);
|
||||
OElement el = ERManagementUtility.getAnyElementByUUID(uuid);
|
||||
String error = String.format("UUID %s is already used by another %s. This is not allowed.",
|
||||
uuid.toString(),
|
||||
(el instanceof Vertex) ? org.gcube.informationsystem.model.reference.entities.Entity.NAME :
|
||||
(el instanceof OVertex) ? org.gcube.informationsystem.model.reference.entities.Entity.NAME :
|
||||
org.gcube.informationsystem.model.reference.relations.Relation.NAME);
|
||||
throw getSpecificERAvailableInAnotherContextException(error);
|
||||
|
||||
|
@ -157,14 +156,14 @@ public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManag
|
|||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
}
|
||||
|
||||
logger.info("Created {} is {}", Vertex.class.getSimpleName(),
|
||||
Utility.toJsonString((OrientVertex) element, true));
|
||||
logger.info("Created {} is {}", OVertex.class.getSimpleName(),
|
||||
Utility.toJsonString(element, true));
|
||||
|
||||
return element;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.trace("Error while creating {} for {} ({}) using {}", Vertex.class.getSimpleName(),
|
||||
logger.trace("Error while creating {} for {} ({}) using {}", OVertex.class.getSimpleName(),
|
||||
accessType.getName(), elementType, jsonNode, e);
|
||||
throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e.getCause());
|
||||
}
|
||||
|
|
|
@ -17,17 +17,16 @@ import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM extends BaseEntityManagement<S>, TEM extends BaseEntityManagement<T>, S extends BaseEntity, T extends BaseEntity>
|
||||
extends ERManagement<Edge> {
|
||||
extends ERManagement<OEdge> {
|
||||
|
||||
protected final Class<S> sourceEntityClass;
|
||||
protected final Class<T> targetEntityClass;
|
||||
|
@ -41,10 +40,10 @@ public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM e
|
|||
this.ignoreKeys.add(Relation.HEADER_PROPERTY);
|
||||
this.ignoreKeys.add(Relation.SOURCE_PROPERTY);
|
||||
this.ignoreKeys.add(Relation.TARGET_PROPERTY);
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_OUT.toLowerCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_IN.toLowerCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_OUT.toUpperCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_IN.toUpperCase());
|
||||
this.ignoreKeys.add(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.CONNECTION_OUT.toLowerCase());
|
||||
this.ignoreKeys.add(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.CONNECTION_IN.toLowerCase());
|
||||
this.ignoreKeys.add(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.CONNECTION_OUT.toUpperCase());
|
||||
this.ignoreKeys.add(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.CONNECTION_IN.toUpperCase());
|
||||
|
||||
this.sourceEntityClass = sourceEntityClass;
|
||||
this.targetEntityClass = targetEntityClass;
|
||||
|
@ -53,15 +52,15 @@ public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM e
|
|||
this.targetEntityManagement = null;
|
||||
}
|
||||
|
||||
protected BaseRelationManagement(AccessType accessType, Class<S> sourceEntityClass, Class<T> targetEntityClass, SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
protected BaseRelationManagement(AccessType accessType, Class<S> sourceEntityClass, Class<T> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
this(accessType, sourceEntityClass, targetEntityClass);
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
public SEM getSourceEntityManagement() throws ResourceRegistryException {
|
||||
if(sourceEntityManagement == null) {
|
||||
Vertex source = getElement().getVertex(Direction.OUT);
|
||||
OVertex source = getElement().getVertex(ODirection.OUT);
|
||||
sourceEntityManagement = newSourceEntityManagement();
|
||||
sourceEntityManagement.setElement(source);
|
||||
}
|
||||
|
@ -71,7 +70,7 @@ public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM e
|
|||
|
||||
public TEM getTargetEntityManagement() throws ResourceRegistryException {
|
||||
if(targetEntityManagement == null) {
|
||||
Vertex target = getElement().getVertex(Direction.IN);
|
||||
OVertex target = getElement().getVertex(ODirection.IN);
|
||||
targetEntityManagement = newTargetEntityManagement();
|
||||
targetEntityManagement.setElement(target);
|
||||
}
|
||||
|
@ -123,7 +122,7 @@ public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM e
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Edge reallyCreate() throws ResourceRegistryException {
|
||||
protected OEdge reallyCreate() throws ResourceRegistryException {
|
||||
|
||||
if(sourceEntityManagement == null) {
|
||||
|
||||
|
@ -169,10 +168,10 @@ public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM e
|
|||
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serialize(),
|
||||
getTargetEntityManagement().serialize());
|
||||
|
||||
Vertex source = (Vertex) getSourceEntityManagement().getElement();
|
||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||
OVertex source = (OVertex) getSourceEntityManagement().getElement();
|
||||
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
||||
|
||||
element = orientGraph.addEdge(null, source, target, elementType);
|
||||
element = oDatabaseDocument.newEdge(source, target, elementType);
|
||||
|
||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
|
@ -184,17 +183,17 @@ public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM e
|
|||
protected abstract TEM newTargetEntityManagement() throws ResourceRegistryException;
|
||||
|
||||
@Override
|
||||
protected Edge reallyUpdate() throws ResourceRegistryException {
|
||||
protected OEdge reallyUpdate() throws ResourceRegistryException {
|
||||
|
||||
logger.debug("Trying to update {} : {}", elementType, jsonNode);
|
||||
|
||||
Edge edge = getElement();
|
||||
OEdge edge = getElement();
|
||||
ERManagement.updateProperties(oClass, edge, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
if(accessType.compareTo(AccessType.CONSISTS_OF) == 0) {
|
||||
JsonNode target = jsonNode.get(Relation.TARGET_PROPERTY);
|
||||
if(target != null) {
|
||||
FacetManagement fm = new FacetManagement(getWorkingContext(), orientGraph);
|
||||
FacetManagement fm = new FacetManagement(getWorkingContext(), oDatabaseDocument);
|
||||
fm.setJsonNode(target);
|
||||
fm.internalUpdate();
|
||||
}
|
||||
|
@ -211,7 +210,7 @@ public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM e
|
|||
logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
|
||||
targetEntityClass.getSimpleName());
|
||||
|
||||
getElement().remove();
|
||||
getElement().delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,11 @@ import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -123,7 +125,7 @@ public class ContextUtility {
|
|||
logger.trace("{} for {} is not in cache. Going to get it", SecurityContext.class.getSimpleName(),
|
||||
fullName);
|
||||
|
||||
Vertex contextVertex = getContextVertexByFullName(fullName);
|
||||
OVertex contextVertex = getContextVertexByFullName(fullName);
|
||||
|
||||
uuid = Utility.getUUID(contextVertex);
|
||||
|
||||
|
@ -147,12 +149,27 @@ public class ContextUtility {
|
|||
return getSecurityContextByUUID(uuid, null);
|
||||
}
|
||||
|
||||
private Vertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException {
|
||||
return Utility.getElementByUUID(getAdminSecurityContext().getGraph(PermissionMode.READER), Context.NAME, uuid,
|
||||
Vertex.class);
|
||||
public static ODatabaseDocument getCurrentODatabaseDocumentFromThreadLocal() {
|
||||
ODatabaseDocument current = null;
|
||||
try {
|
||||
current = (ODatabaseDocument) ODatabaseRecordThreadLocal.instance().get();
|
||||
}catch (Exception e) {
|
||||
// It is possible that there is non current ODatabaseDocument
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
private SecurityContext getSecurityContextByUUID(UUID uuid, Vertex contextVertex) throws ResourceRegistryException {
|
||||
private OVertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException {
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
OVertex oVertex = Utility.getElementByUUID(getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER), Context.NAME, uuid,
|
||||
OVertex.class);
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
return oVertex;
|
||||
}
|
||||
|
||||
private SecurityContext getSecurityContextByUUID(UUID uuid, OVertex contextVertex) throws ResourceRegistryException {
|
||||
SecurityContext securityContext = contexts.get(uuid);
|
||||
if(securityContext == null) {
|
||||
|
||||
|
@ -162,7 +179,7 @@ public class ContextUtility {
|
|||
if(contextVertex == null) {
|
||||
contextVertex = getContextVertexByUUID(uuid);
|
||||
}
|
||||
Vertex parentVertex = contextVertex.getVertices(Direction.IN, IsParentOf.NAME).iterator().next();
|
||||
OVertex parentVertex = contextVertex.getVertices(ODirection.IN, IsParentOf.NAME).iterator().next();
|
||||
|
||||
if(parentVertex != null) {
|
||||
UUID parentUUID = Utility.getUUID(parentVertex);
|
||||
|
@ -180,14 +197,14 @@ public class ContextUtility {
|
|||
}
|
||||
|
||||
protected UUID getContextUUIDFromFullName(String fullName) throws ResourceRegistryException {
|
||||
Vertex contextVertex = getContextVertexByFullName(fullName);
|
||||
OVertex contextVertex = getContextVertexByFullName(fullName);
|
||||
return Utility.getUUID(contextVertex);
|
||||
}
|
||||
|
||||
|
||||
private Vertex getContextVertexByFullName(String fullName) throws ResourceRegistryException {
|
||||
private OVertex getContextVertexByFullName(String fullName) throws ResourceRegistryException {
|
||||
|
||||
logger.trace("Going to get {} {} with full name '{}'", Context.NAME, Vertex.class.getSimpleName(), fullName);
|
||||
logger.trace("Going to get {} {} with full name '{}'", Context.NAME, OVertex.class.getSimpleName(), fullName);
|
||||
|
||||
ScopeBean scopeBean = new ScopeBean(fullName);
|
||||
String name = scopeBean.name();
|
||||
|
@ -198,17 +215,20 @@ public class ContextUtility {
|
|||
String select = "SELECT FROM " + Context.class.getSimpleName() + " WHERE " + Context.NAME_PROPERTY + " = \""
|
||||
+ name + "\"";
|
||||
;
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(select);
|
||||
OSQLSynchQuery<OVertex> osqlSynchQuery = new OSQLSynchQuery<OVertex>(select);
|
||||
|
||||
Iterable<Vertex> vertexes = getAdminSecurityContext().getGraph(PermissionMode.READER).command(osqlSynchQuery)
|
||||
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
|
||||
Iterable<OVertex> vertexes = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER).command(osqlSynchQuery)
|
||||
.execute();
|
||||
|
||||
if(vertexes == null || !vertexes.iterator().hasNext()) {
|
||||
throw new ContextNotFoundException("Error retrieving context with name " + fullName);
|
||||
}
|
||||
|
||||
Iterator<Vertex> iterator = vertexes.iterator();
|
||||
Vertex context = iterator.next();
|
||||
Iterator<OVertex> iterator = vertexes.iterator();
|
||||
OVertex context = iterator.next();
|
||||
|
||||
logger.trace("Context Representing Vertex : {}", Utility.toJsonString(context, true));
|
||||
|
||||
|
@ -217,6 +237,10 @@ public class ContextUtility {
|
|||
+ "but required the one with path" + fullName + ". Please Reimplement the query");
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,11 +31,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.NullNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -57,9 +58,9 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
init();
|
||||
}
|
||||
|
||||
public ContextManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
public ContextManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
getWorkingContext();
|
||||
}
|
||||
|
||||
|
@ -104,7 +105,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
throws ContextNotFoundException, ContextAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
if(parentContext != null) {
|
||||
String parentId = parentContext.getElement().getId().toString();
|
||||
String parentId = parentContext.getElement().getIdentity().toString();
|
||||
|
||||
// TODO Rewrite using Gremlin
|
||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME + ") FROM " + parentId
|
||||
|
@ -121,8 +122,8 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
|
||||
logger.trace("Checking if {} -> {}", message, select);
|
||||
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(select);
|
||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery).execute();
|
||||
OSQLSynchQuery<OVertex> osqlSynchQuery = new OSQLSynchQuery<OVertex>(select);
|
||||
Iterable<OVertex> vertexes = oDatabaseDocument.command(osqlSynchQuery).execute();
|
||||
|
||||
if(vertexes != null && vertexes.iterator().hasNext()) {
|
||||
throw new ContextAlreadyPresentException(message.toString());
|
||||
|
@ -134,8 +135,8 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
+ Context.NAME_PROPERTY + " = \"" + getName() + "\"" + " AND in(\"" + IsParentOf.NAME
|
||||
+ "\").size() = 0";
|
||||
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(select);
|
||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery).execute();
|
||||
OSQLSynchQuery<OVertex> osqlSynchQuery = new OSQLSynchQuery<OVertex>(select);
|
||||
Iterable<OVertex> vertexes = oDatabaseDocument.command(osqlSynchQuery).execute();
|
||||
|
||||
if(vertexes != null && vertexes.iterator().hasNext()) {
|
||||
throw new ContextAlreadyPresentException(
|
||||
|
@ -157,13 +158,13 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
JsonNode context = serializeSelfOnly();
|
||||
|
||||
int count = 0;
|
||||
Iterable<Edge> parents = getElement().getEdges(Direction.IN);
|
||||
for(Edge edge : parents) {
|
||||
Iterable<OEdge> parents = getElement().getEdges(ODirection.IN);
|
||||
for(OEdge edge : parents) {
|
||||
if(++count > 1) {
|
||||
throw new ContextException("A " + Context.NAME + " can not have more than one parent");
|
||||
}
|
||||
try {
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||
isParentOfManagement.setElement(edge);
|
||||
JsonNode isParentOf = isParentOfManagement.serializeAsJson(true, false);
|
||||
if(isParentOf!=null) {
|
||||
|
@ -175,10 +176,10 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
}
|
||||
}
|
||||
|
||||
Iterable<Edge> childrenEdges = getElement().getEdges(Direction.OUT);
|
||||
for(Edge edge : childrenEdges) {
|
||||
Iterable<OEdge> childrenEdges = getElement().getEdges(ODirection.OUT);
|
||||
for(OEdge edge : childrenEdges) {
|
||||
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||
isParentOfManagement.setElement(edge);
|
||||
try {
|
||||
JsonNode isParentOf = isParentOfManagement.serializeAsJson();
|
||||
|
@ -196,7 +197,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
SecurityContext securityContext = null;
|
||||
SecurityContext parentSecurityContext = null;
|
||||
|
||||
|
@ -206,7 +207,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
if(isParentOfJsonNode != null && !(isParentOfJsonNode instanceof NullNode)) {
|
||||
|
||||
JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
||||
ContextManagement parentContextManagement = new ContextManagement(orientGraph);
|
||||
ContextManagement parentContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
parentContextManagement.setJsonNode(parentJsonNode);
|
||||
UUID parentUUID = parentContextManagement.uuid;
|
||||
parentSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(parentUUID);
|
||||
|
@ -219,7 +220,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
|
||||
createVertex();
|
||||
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||
isParentOfManagement.setJsonNode(isParentOfJsonNode);
|
||||
isParentOfManagement.setSourceEntityManagement(parentContextManagement);
|
||||
isParentOfManagement.setTargetEntityManagement(this);
|
||||
|
@ -233,15 +234,15 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
|
||||
securityContext = new SecurityContext(uuid);
|
||||
securityContext.setParentSecurityContext(parentSecurityContext);
|
||||
securityContext.create(orientGraph);
|
||||
securityContext.create(oDatabaseDocument);
|
||||
|
||||
ContextUtility.getInstance().addSecurityContext(securityContext);
|
||||
|
||||
return getElement();
|
||||
} catch(Exception e) {
|
||||
orientGraph.rollback();
|
||||
oDatabaseDocument.rollback();
|
||||
if(securityContext != null) {
|
||||
securityContext.delete(orientGraph);
|
||||
securityContext.delete(oDatabaseDocument);
|
||||
if(parentSecurityContext!=null && securityContext!=null) {
|
||||
parentSecurityContext.getChildren().remove(securityContext);
|
||||
}
|
||||
|
@ -252,16 +253,16 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
|
||||
boolean parentChanged = false;
|
||||
boolean nameChanged = false;
|
||||
|
||||
Vertex parent = null;
|
||||
OVertex parent = null;
|
||||
boolean found = false;
|
||||
|
||||
Iterable<Vertex> iterable = getElement().getVertices(Direction.IN, IsParentOf.NAME);
|
||||
for(Vertex p : iterable) {
|
||||
Iterable<OVertex> iterable = getElement().getVertices(ODirection.IN, IsParentOf.NAME);
|
||||
for(OVertex p : iterable) {
|
||||
if(found) {
|
||||
String message = String.format("{} has more than one parent. {}", Context.NAME,
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
|
@ -273,7 +274,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
|
||||
ContextManagement actualParentContextManagement = null;
|
||||
if(parent != null) {
|
||||
actualParentContextManagement = new ContextManagement(orientGraph);
|
||||
actualParentContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
actualParentContextManagement.setElement(parent);
|
||||
}
|
||||
|
||||
|
@ -296,7 +297,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
}
|
||||
|
||||
if(parentChanged) {
|
||||
newParentContextManagement = new ContextManagement(orientGraph);
|
||||
newParentContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
newParentContextManagement.setJsonNode(parentContextJsonNode);
|
||||
}
|
||||
} else {
|
||||
|
@ -322,7 +323,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
move(newParentContextManagement, false);
|
||||
}
|
||||
|
||||
element = (Vertex) ERManagement.updateProperties(oClass, getElement(), jsonNode, ignoreKeys,
|
||||
element = (OVertex) ERManagement.updateProperties(oClass, getElement(), jsonNode, ignoreKeys,
|
||||
ignoreStartWithKeys);
|
||||
|
||||
ContextUtility.getInstance().removeFromCache(uuid, (nameChanged && !parentChanged));
|
||||
|
@ -339,10 +340,10 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
SecurityContext newParentSecurityContext = null;
|
||||
|
||||
// Removing the old parent relationship if any
|
||||
Iterable<Edge> edges = getElement().getEdges(Direction.IN, IsParentOf.NAME);
|
||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.IN, IsParentOf.NAME);
|
||||
if(edges != null && edges.iterator().hasNext()) {
|
||||
Iterator<Edge> edgeIterator = edges.iterator();
|
||||
Edge edge = edgeIterator.next();
|
||||
Iterator<OEdge> edgeIterator = edges.iterator();
|
||||
OEdge edge = edgeIterator.next();
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement();
|
||||
isParentOfManagement.setElement(edge);
|
||||
isParentOfManagement.internalDelete();
|
||||
|
@ -355,7 +356,7 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
|
||||
if(newParentContextManagement != null) {
|
||||
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||
isParentOfManagement.setJsonNode(isParentOfJsonNode);
|
||||
isParentOfManagement.setSourceEntityManagement(newParentContextManagement);
|
||||
isParentOfManagement.setTargetEntityManagement(this);
|
||||
|
@ -364,22 +365,22 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
}
|
||||
|
||||
SecurityContext thisSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
|
||||
thisSecurityContext.changeParentSecurityContext(newParentSecurityContext, orientGraph);
|
||||
thisSecurityContext.changeParentSecurityContext(newParentSecurityContext, oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||
Iterable<Edge> iterable = getElement().getEdges(Direction.OUT);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
Iterable<OEdge> iterable = getElement().getEdges(ODirection.OUT);
|
||||
Iterator<OEdge> iterator = iterable.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
throw new ContextException("Cannot remove a " + Context.NAME + " having children");
|
||||
}
|
||||
|
||||
element.remove();
|
||||
element.delete();
|
||||
|
||||
ContextUtility contextUtility = ContextUtility.getInstance();
|
||||
SecurityContext securityContext = contextUtility.getSecurityContextByUUID(uuid);
|
||||
securityContext.delete(orientGraph);
|
||||
securityContext.delete(oDatabaseDocument);
|
||||
|
||||
contextUtility.removeFromCache(uuid, false);
|
||||
|
||||
|
@ -391,10 +392,10 @@ public class ContextManagement extends BaseEntityManagement<Context> {
|
|||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||
Iterable<Vertex> iterable = orientGraph.getVerticesOfClass(elementType, polymorphic);
|
||||
for(Vertex vertex : iterable) {
|
||||
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(elementType, polymorphic);
|
||||
for(ODocument vertex : iterable) {
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setElement(vertex);
|
||||
contextManagement.setElement((OVertex) vertex);
|
||||
try {
|
||||
JsonNode jsonObject = contextManagement.serializeAsJson();
|
||||
arrayNode.add(jsonObject);
|
||||
|
|
|
@ -19,9 +19,9 @@ import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -32,9 +32,9 @@ public class IsParentOfManagement extends BaseRelationManagement<IsParentOf,Cont
|
|||
super(AccessType.IS_PARENT_OF, Context.class, Context.class);
|
||||
}
|
||||
|
||||
public IsParentOfManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
public IsParentOfManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
getWorkingContext();
|
||||
}
|
||||
|
||||
|
@ -66,15 +66,15 @@ public class IsParentOfManagement extends BaseRelationManagement<IsParentOf,Cont
|
|||
JsonNode relation = serializeSelfOnly();
|
||||
|
||||
try {
|
||||
Vertex source = element.getVertex(Direction.OUT);
|
||||
ContextManagement sourceContextManagement = new ContextManagement(orientGraph);
|
||||
OVertex source = element.getVertex(ODirection.OUT);
|
||||
ContextManagement sourceContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
sourceContextManagement.setElement(source);
|
||||
if(includeSource) {
|
||||
((ObjectNode)relation).replace(Relation.SOURCE_PROPERTY, sourceContextManagement.serializeSelfOnly());
|
||||
}
|
||||
|
||||
Vertex target = element.getVertex(Direction.IN);
|
||||
ContextManagement targetContextManagement = new ContextManagement(orientGraph);
|
||||
OVertex target = element.getVertex(ODirection.IN);
|
||||
ContextManagement targetContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
targetContextManagement.setElement(target);
|
||||
if(includeTarget) {
|
||||
((ObjectNode)relation).replace(Relation.TARGET_PROPERTY, targetContextManagement.serializeSelfOnly());
|
||||
|
@ -93,12 +93,12 @@ public class IsParentOfManagement extends BaseRelationManagement<IsParentOf,Cont
|
|||
|
||||
@Override
|
||||
protected ContextManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ContextManagement(orientGraph);
|
||||
return new ContextManagement(oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContextManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new ContextManagement(orientGraph);
|
||||
return new ContextManagement(oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,16 +33,14 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
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.OrientVertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -61,18 +59,18 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
|
||||
this.ignoreKeys.add(Entity.HEADER_PROPERTY);
|
||||
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX.toUpperCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX.toUpperCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_IN_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_OUT_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_IN_PREFIX.toUpperCase());
|
||||
this.ignoreStartWithKeys.add(com.tinkerpop.blueprints.impls.orient.OrientVertex.CONNECTION_OUT_PREFIX.toUpperCase());
|
||||
|
||||
this.relationManagements = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
protected EntityManagement(AccessType accessType, SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
protected EntityManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
this(accessType);
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
|
@ -83,11 +81,11 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
* fake id starting with - (minus) sign. This not imply any collateral effect
|
||||
* but a better solution is a desiderata.
|
||||
*/
|
||||
protected RelationManagement getRelationManagement(Edge edge) throws ResourceRegistryException {
|
||||
String id = edge.getId().toString();
|
||||
protected RelationManagement getRelationManagement(OEdge edge) throws ResourceRegistryException {
|
||||
String id = edge.getIdentity().toString();
|
||||
RelationManagement relationManagement = relationManagements.get(id);
|
||||
if(relationManagement == null) {
|
||||
relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(), orientGraph, edge);
|
||||
relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge);
|
||||
relationManagements.put(id, relationManagement);
|
||||
}
|
||||
return relationManagement;
|
||||
|
@ -95,8 +93,8 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
|
||||
protected void addToRelationManagement(@SuppressWarnings("rawtypes") RelationManagement relationManagement)
|
||||
throws ResourceRegistryException {
|
||||
Element elem = relationManagement.getElement();
|
||||
String id = elem.getId().toString();
|
||||
OElement elem = relationManagement.getElement();
|
||||
String id = elem.getIdentity().toString();
|
||||
if(relationManagements.get(id) != null && relationManagements.get(id) != relationManagement) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
errorMessage.append("Two different instance of ");
|
||||
|
@ -127,9 +125,9 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
return sourceResource;
|
||||
}
|
||||
|
||||
protected Vertex createVertex() throws EntityAlreadyPresentException, ResourceRegistryException {
|
||||
protected OVertex createVertex() throws EntityAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
logger.trace("Going to create {} for {} ({}) using {}", Vertex.class.getSimpleName(), accessType.getName(),
|
||||
logger.trace("Going to create {} for {} ({}) using {}", OVertex.class.getSimpleName(), accessType.getName(),
|
||||
elementType, jsonNode);
|
||||
|
||||
try {
|
||||
|
@ -141,11 +139,11 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
Vertex vertexEntity = orientGraph.addVertex("class:" + elementType);
|
||||
OVertex vertexEntity = oDatabaseDocument.newVertex(elementType);
|
||||
|
||||
try {
|
||||
if(uuid != null) {
|
||||
Vertex v = getElement();
|
||||
OVertex v = getElement();
|
||||
if(v != null) {
|
||||
String error = String.format("A %s with UUID %s already exist", elementType, uuid.toString());
|
||||
throw getSpecificERAlreadyPresentException(error);
|
||||
|
@ -154,9 +152,9 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
|
||||
} catch(NotFoundException e) {
|
||||
try {
|
||||
Element el = ERManagementUtility.getAnyElementByUUID(uuid);
|
||||
OElement el = ERManagementUtility.getAnyElementByUUID(uuid);
|
||||
String error = String.format("UUID %s is already used by another %s. This is not allowed.",
|
||||
uuid.toString(), (el instanceof Vertex) ? Entity.NAME : Relation.NAME);
|
||||
uuid.toString(), (el instanceof OVertex) ? Entity.NAME : Relation.NAME);
|
||||
throw getSpecificERAvailableInAnotherContextException(error);
|
||||
|
||||
} catch(NotFoundException e1) {
|
||||
|
@ -174,14 +172,14 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
}
|
||||
|
||||
logger.info("Created {} is {}", Vertex.class.getSimpleName(),
|
||||
Utility.toJsonString((OrientVertex) element, true));
|
||||
logger.info("Created {} is {}", OVertex.class.getSimpleName(),
|
||||
Utility.toJsonString((OVertex) element, true));
|
||||
|
||||
return element;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.trace("Error while creating {} for {} ({}) using {}", Vertex.class.getSimpleName(),
|
||||
logger.trace("Error while creating {} for {} ({}) using {}", OVertex.class.getSimpleName(),
|
||||
accessType.getName(), elementType, jsonNode, e);
|
||||
throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e.getCause());
|
||||
}
|
||||
|
@ -191,11 +189,11 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
targetSecurityContext.addElement(getElement(), orientGraph);
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
||||
Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
|
||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||
|
||||
for(Edge edge : edges) {
|
||||
for(OEdge edge : edges) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
RelationManagement relationManagement = getRelationManagement(edge);
|
||||
relationManagement.internalAddToContext(targetSecurityContext);
|
||||
|
@ -208,15 +206,15 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
|
||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||
|
||||
for(Edge edge : edges) {
|
||||
for(OEdge edge : edges) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
RelationManagement relationManagement = getRelationManagement(edge);
|
||||
relationManagement.internalRemoveFromContext(targetSecurityContext);
|
||||
}
|
||||
|
||||
targetSecurityContext.removeElement(getElement(), orientGraph);
|
||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -226,11 +224,10 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||
|
||||
Iterable<Vertex> iterable = orientGraph.getVerticesOfClass(elementType, polymorphic);
|
||||
for(Vertex vertex : iterable) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
EntityManagement entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, vertex);
|
||||
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(elementType, polymorphic);
|
||||
for(ODocument vertex : iterable) {
|
||||
EntityManagement<?> entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
oDatabaseDocument, (OVertex) vertex);
|
||||
try {
|
||||
JsonNode jsonNode = entityManagement.serializeAsJson();
|
||||
arrayNode.add(jsonNode);
|
||||
|
@ -246,25 +243,23 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
}
|
||||
}
|
||||
|
||||
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, Direction direction,
|
||||
public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||
boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||
|
||||
Iterable<Vertex> references = null;
|
||||
Iterable<?> references = null;
|
||||
|
||||
if(referenceUUID != null) {
|
||||
Element element = ERManagementUtility.getAnyElementByUUID(referenceUUID);
|
||||
if(element instanceof Vertex) {
|
||||
OElement element = ERManagementUtility.getAnyElementByUUID(referenceUUID);
|
||||
if(element instanceof OVertex) {
|
||||
@SuppressWarnings("unchecked")
|
||||
EntityManagement<Entity> entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, (Vertex) element);
|
||||
|
||||
OrientVertexType orientVertexType = ((OrientVertex) element).getType();
|
||||
oDatabaseDocument, (OVertex) element);
|
||||
|
||||
String elementType = entityManagement.getElementType();
|
||||
if(elementType.compareTo(referenceType) != 0) {
|
||||
if(polymorphic && orientVertexType.isSubClassOf(referenceType)) {
|
||||
if(polymorphic && getOClass().isSubClassOf(referenceType)) {
|
||||
// OK
|
||||
} else {
|
||||
String error = String.format("Referenced instace with UUID %s is not a %s", referenceUUID,
|
||||
|
@ -273,8 +268,8 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
}
|
||||
}
|
||||
|
||||
List<Vertex> vertexes = new ArrayList<>();
|
||||
vertexes.add((Vertex) element);
|
||||
List<OVertex> vertexes = new ArrayList<>();
|
||||
vertexes.add((OVertex) element);
|
||||
references = vertexes;
|
||||
|
||||
} else {
|
||||
|
@ -283,45 +278,42 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
}
|
||||
|
||||
} else {
|
||||
references = orientGraph.getVerticesOfClass(referenceType, polymorphic);
|
||||
references = oDatabaseDocument.browseClass(referenceType, polymorphic);
|
||||
}
|
||||
|
||||
for(Vertex v : references) {
|
||||
List<Direction> directions = new ArrayList<>();
|
||||
if(direction==Direction.BOTH) {
|
||||
directions.add(Direction.IN);
|
||||
directions.add(Direction.OUT);
|
||||
for(Object r : references) {
|
||||
OVertex v = (OVertex) r;
|
||||
List<ODirection> directions = new ArrayList<>();
|
||||
if(direction==ODirection.BOTH) {
|
||||
directions.add(ODirection.IN);
|
||||
directions.add(ODirection.OUT);
|
||||
}else {
|
||||
directions.add(direction);
|
||||
}
|
||||
|
||||
for(Direction d : directions) {
|
||||
for(ODirection d : directions) {
|
||||
|
||||
Iterable<Edge> edges = v.getEdges(d.opposite(), relationType);
|
||||
for(Edge edge : edges) {
|
||||
Vertex vertex = ((OrientEdge) edge).getVertex(d);
|
||||
OrientVertex orientVertex = (OrientVertex) vertex;
|
||||
Iterable<OEdge> edges = v.getEdges(d.opposite(), relationType);
|
||||
for(OEdge edge : edges) {
|
||||
OVertex vertex = edge.getVertex(d);
|
||||
|
||||
if(((OrientVertex) v).getIdentity().compareTo(orientVertex.getIdentity()) == 0) {
|
||||
if(v.getIdentity().compareTo(vertex.getIdentity()) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(elementType.compareTo(orientVertex.getLabel()) != 0) {
|
||||
OrientVertexType orientVertexType = orientVertex.getType();
|
||||
|
||||
if(polymorphic && orientVertexType.isSubClassOf(elementType)) {
|
||||
// OK
|
||||
} else {
|
||||
// excluding from results
|
||||
continue;
|
||||
}
|
||||
OClass oClass = ERManagement.getOClass(vertex);
|
||||
if(polymorphic && oClass.isSubClassOf(elementType)) {
|
||||
// OK
|
||||
} else {
|
||||
// excluding from results
|
||||
continue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
EntityManagement entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, vertex);
|
||||
oDatabaseDocument, vertex);
|
||||
try {
|
||||
if(entityManagement.getUUID().compareTo(referenceUUID) == 0) {
|
||||
if(referenceUUID!=null && entityManagement.getUUID().compareTo(referenceUUID) == 0) {
|
||||
continue;
|
||||
}
|
||||
JsonNode jsonNode = entityManagement.serializeAsJson();
|
||||
|
@ -342,7 +334,7 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
}
|
||||
|
||||
public String reallyQueryTraversal(String relationType, String referenceType, UUID referenceUUID,
|
||||
Direction direction, boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
ODirection direction, boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||
|
||||
|
@ -395,19 +387,18 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
String select = selectStringBuilder.toString();
|
||||
logger.trace(select);
|
||||
|
||||
OSQLSynchQuery<Element> osqlSynchQuery = new OSQLSynchQuery<Element>(select);
|
||||
Iterable<Element> elements = orientGraph.command(osqlSynchQuery).execute();
|
||||
OSQLSynchQuery<OElement> osqlSynchQuery = new OSQLSynchQuery<OElement>(select);
|
||||
Iterable<OElement> elements = oDatabaseDocument.command(osqlSynchQuery).execute();
|
||||
|
||||
for(Element element : elements) {
|
||||
for(OElement element : elements) {
|
||||
|
||||
if(polymorphic) {
|
||||
OrientVertexType orientVertexType = null;
|
||||
OClass oClass = null;
|
||||
try {
|
||||
OrientElement orientElement = ((OrientElement) element);
|
||||
if(orientElement instanceof OrientEdge) {
|
||||
if(element instanceof OEdge) {
|
||||
continue;
|
||||
}
|
||||
orientVertexType = ((OrientVertex) orientElement).getType();
|
||||
oClass = ERManagement.getOClass(element);
|
||||
} catch(Exception e) {
|
||||
String error = String.format("Unable to detect type of %s. %s", element.toString(),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
|
@ -415,19 +406,17 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
if(orientVertexType.getName().compareTo(elementType) != 0) {
|
||||
if(!orientVertexType.isSubClassOf(elementType)) {
|
||||
continue;
|
||||
}
|
||||
if(oClass.isSubClassOf(elementType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vertex vertex = (Vertex) element;
|
||||
OVertex vertex = (OVertex) element;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
EntityManagement entityManagement = ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, vertex);
|
||||
oDatabaseDocument, vertex);
|
||||
try {
|
||||
if(constraint.containsKey(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY)) {
|
||||
String uuid = constraint.get(Entity.HEADER_PROPERTY + "." + Header.UUID_PROPERTY);
|
||||
|
@ -450,10 +439,10 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
}
|
||||
}
|
||||
|
||||
public String query(String relationType, String referenceType, UUID referenceUUID, Direction direction,
|
||||
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||
boolean polymorphic, Map<String,String> constraint) throws ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
||||
AccessType relationAccessType = ERManagementUtility.getBaseAccessType(relationType);
|
||||
if(relationAccessType != AccessType.IS_RELATED_TO && relationAccessType != AccessType.CONSISTS_OF) {
|
||||
|
@ -476,9 +465,9 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
|
||||
if(relationAccessType == AccessType.CONSISTS_OF) {
|
||||
|
||||
if(direction != Direction.OUT) {
|
||||
if(direction != ODirection.OUT) {
|
||||
String error = String.format("%s can only goes %s from %s.", relationType,
|
||||
Direction.OUT.name(), elementType);
|
||||
ODirection.OUT.name(), elementType);
|
||||
throw new InvalidQueryException(error);
|
||||
} else {
|
||||
if(referenceAccessType != AccessType.FACET) {
|
||||
|
@ -492,10 +481,10 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
break;
|
||||
|
||||
case FACET:
|
||||
if(relationAccessType != AccessType.CONSISTS_OF || direction != Direction.IN
|
||||
if(relationAccessType != AccessType.CONSISTS_OF || direction != ODirection.IN
|
||||
|| referenceAccessType != AccessType.RESOURCE) {
|
||||
String error = String.format("%s can only has %s %s from a %s.", elementType,
|
||||
Direction.IN.name(), ConsistsOf.NAME, Resource.NAME);
|
||||
ODirection.IN.name(), ConsistsOf.NAME, Resource.NAME);
|
||||
throw new InvalidQueryException(error);
|
||||
}
|
||||
|
||||
|
@ -512,8 +501,8 @@ public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityM
|
|||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
|||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -23,7 +23,7 @@ public class FacetManagement extends EntityManagement<Facet> {
|
|||
super(AccessType.FACET);
|
||||
}
|
||||
|
||||
public FacetManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
public FacetManagement(SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
super(AccessType.FACET, workingContext, orientGraph);
|
||||
}
|
||||
|
||||
|
@ -53,20 +53,20 @@ public class FacetManagement extends EntityManagement<Facet> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyCreate() throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||
protected OVertex reallyCreate() throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||
return createVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyUpdate() throws FacetNotFoundException, ResourceRegistryException {
|
||||
Vertex facet = getElement();
|
||||
facet = (Vertex) ERManagement.updateProperties(oClass, facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
protected OVertex reallyUpdate() throws FacetNotFoundException, ResourceRegistryException {
|
||||
OVertex facet = getElement();
|
||||
facet = (OVertex) ERManagement.updateProperties(oClass, facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
return facet;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws FacetNotFoundException, ResourceRegistryException {
|
||||
getElement().remove();
|
||||
getElement().delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,11 @@ import org.gcube.informationsystem.resourceregistry.security.SecurityContext.Per
|
|||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -35,8 +34,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
super(AccessType.RESOURCE);
|
||||
}
|
||||
|
||||
public ResourceManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
super(AccessType.RESOURCE, workingContext, orientGraph);
|
||||
public ResourceManagement(SecurityContext workingContext, ODatabaseDocument oDatabaseDocument) {
|
||||
super(AccessType.RESOURCE, workingContext, oDatabaseDocument);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,8 +70,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
* ConsistsOf.NAME); TODO Looks for a different query
|
||||
*/
|
||||
|
||||
Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
|
||||
for(Edge edge : edges) {
|
||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||
for(OEdge edge : edges) {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
RelationManagement relationManagement = getRelationManagement(edge);
|
||||
|
@ -128,7 +127,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyCreate() throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
protected OVertex reallyCreate() throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
createVertex();
|
||||
|
||||
|
@ -136,7 +135,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode consistOfJsonNode : jsonNodeArray) {
|
||||
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), orientGraph);
|
||||
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), oDatabaseDocument);
|
||||
com.setJsonNode(consistOfJsonNode);
|
||||
com.setSourceEntityManagement(this);
|
||||
com.internalCreate();
|
||||
|
@ -148,7 +147,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), orientGraph);
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), oDatabaseDocument);
|
||||
irtm.setJsonNode(relationJsonNode);
|
||||
irtm.setSourceEntityManagement(this);
|
||||
irtm.internalCreate();
|
||||
|
@ -160,7 +159,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyUpdate() throws ResourceNotFoundException, ResourceRegistryException {
|
||||
protected OVertex reallyUpdate() throws ResourceNotFoundException, ResourceRegistryException {
|
||||
|
||||
getElement();
|
||||
|
||||
|
@ -168,7 +167,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), orientGraph);
|
||||
ConsistsOfManagement com = new ConsistsOfManagement(getWorkingContext(), oDatabaseDocument);
|
||||
com.setJsonNode(relationJsonNode);
|
||||
com.internalCreateOrUdate();
|
||||
addToRelationManagement(com);
|
||||
|
@ -179,7 +178,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
if(jsonNode.has(property)) {
|
||||
JsonNode jsonNodeArray = jsonNode.get(property);
|
||||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), orientGraph);
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement(getWorkingContext(), oDatabaseDocument);
|
||||
irtm.setJsonNode(relationJsonNode);
|
||||
irtm.internalUpdate();
|
||||
addToRelationManagement(irtm);
|
||||
|
@ -196,18 +195,19 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
|
||||
getElement();
|
||||
|
||||
Iterable<Edge> iterable = element.getEdges(Direction.OUT);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
Iterable<OEdge> iterable = element.getEdges(ODirection.OUT);
|
||||
Iterator<OEdge> iterator = iterable.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
|
||||
Edge edge = iterator.next();
|
||||
OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
|
||||
OEdge edge = iterator.next();
|
||||
OClass oClass = getOClass(edge);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
RelationManagement relationManagement = null;
|
||||
if(orientEdgeType.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(getWorkingContext(), orientGraph);
|
||||
} else if(orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(getWorkingContext(), orientGraph);
|
||||
if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(getWorkingContext(), oDatabaseDocument);
|
||||
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(getWorkingContext(), oDatabaseDocument);
|
||||
} else {
|
||||
logger.warn("{} is not a {} nor a {}. {}", Utility.toJsonString(edge, true), IsRelatedTo.NAME,
|
||||
ConsistsOf.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
|
@ -219,14 +219,14 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
|
||||
}
|
||||
|
||||
element.remove();
|
||||
element.delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String all(boolean polymorphic) throws ResourceRegistryException {
|
||||
try {
|
||||
orientGraph = getWorkingContext().getGraph(PermissionMode.READER);
|
||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||
|
||||
return reallyGetAll(polymorphic);
|
||||
} catch(ResourceRegistryException e) {
|
||||
|
@ -234,8 +234,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.cons
|
|||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -35,7 +35,7 @@ public class ConsistsOfManagement extends RelationManagement<ConsistsOf<Resource
|
|||
super(AccessType.CONSISTS_OF, Facet.class, DEFAULT_CONSISTS_OF_PC);
|
||||
}
|
||||
|
||||
public ConsistsOfManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
public ConsistsOfManagement(SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
super(AccessType.CONSISTS_OF, Facet.class, workingContext, orientGraph, DEFAULT_CONSISTS_OF_PC);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class ConsistsOfManagement extends RelationManagement<ConsistsOf<Resource
|
|||
|
||||
@Override
|
||||
protected FacetManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new FacetManagement(getWorkingContext(), orientGraph);
|
||||
return new FacetManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isre
|
|||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -34,7 +34,7 @@ public class IsRelatedToManagement extends RelationManagement<IsRelatedTo<Resour
|
|||
super(AccessType.IS_RELATED_TO, Resource.class, DEFAULT_IS_RELATED_TO_PC);
|
||||
}
|
||||
|
||||
public IsRelatedToManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
public IsRelatedToManagement(SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
super(AccessType.IS_RELATED_TO, Resource.class, workingContext, orientGraph, DEFAULT_IS_RELATED_TO_PC);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class IsRelatedToManagement extends RelationManagement<IsRelatedTo<Resour
|
|||
|
||||
@Override
|
||||
protected ResourceManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), orientGraph);
|
||||
return new ResourceManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,14 +34,13 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -56,10 +55,10 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
this.defaultPropagationConstraint = defaultPropagationConstraint;
|
||||
}
|
||||
|
||||
protected RelationManagement(AccessType accessType, Class<TE> targetEntityClass, SecurityContext workingContext, OrientGraph orientGraph,
|
||||
protected RelationManagement(AccessType accessType, Class<TE> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph,
|
||||
PropagationConstraint defaultPropagationConstraint) {
|
||||
this(accessType, targetEntityClass, defaultPropagationConstraint);
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
|
@ -74,7 +73,7 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
|
||||
public ResourceManagement getSourceEntityManagement() throws ResourceRegistryException {
|
||||
if(sourceEntityManagement == null) {
|
||||
Vertex source = getElement().getVertex(Direction.OUT);
|
||||
OVertex source = getElement().getVertex(ODirection.OUT);
|
||||
sourceEntityManagement = newSourceEntityManagement();
|
||||
sourceEntityManagement.setElement(source);
|
||||
}
|
||||
|
@ -84,7 +83,7 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
|
||||
public T getTargetEntityManagement() throws ResourceRegistryException {
|
||||
if(targetEntityManagement == null) {
|
||||
Vertex target = getElement().getVertex(Direction.IN);
|
||||
OVertex target = getElement().getVertex(ODirection.IN);
|
||||
targetEntityManagement = newTargetEntityManagement();
|
||||
targetEntityManagement.setElement(target);
|
||||
}
|
||||
|
@ -138,16 +137,16 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
protected Map<String,JsonNode> fullSerialize(Map<String,JsonNode> visitedSourceResources)
|
||||
throws ResourceRegistryException {
|
||||
|
||||
Vertex source = getElement().getVertex(Direction.OUT);
|
||||
OVertex source = getElement().getVertex(ODirection.OUT);
|
||||
|
||||
String id = source.getId().toString();
|
||||
String id = source.getIdentity().toString();
|
||||
|
||||
JsonNode sourceResource = visitedSourceResources.get(id);
|
||||
ResourceManagement resourceManagement = null;
|
||||
|
||||
if(sourceResource == null) {
|
||||
resourceManagement = (ResourceManagement) ERManagementUtility.getEntityManagement(getWorkingContext(),
|
||||
orientGraph, source);
|
||||
oDatabaseDocument, source);
|
||||
if(this instanceof IsRelatedToManagement) {
|
||||
sourceResource = resourceManagement.serializeAsJson();
|
||||
} else if(this instanceof ConsistsOfManagement) {
|
||||
|
@ -216,14 +215,13 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
}
|
||||
|
||||
protected void checkPropagationConstraint() throws ResourceRegistryException {
|
||||
OrientElement orientElement = (OrientElement) element;
|
||||
Object object = orientElement.getProperty(Relation.PROPAGATION_CONSTRAINT);
|
||||
Object object = getElement().getProperty(Relation.PROPAGATION_CONSTRAINT);
|
||||
PropagationConstraintOrient pc = getPropagationConstraint((ODocument) object);
|
||||
orientElement.setProperty(Relation.PROPAGATION_CONSTRAINT, pc, OType.EMBEDDED);
|
||||
getElement().setProperty(Relation.PROPAGATION_CONSTRAINT, pc, OType.EMBEDDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Edge reallyCreate() throws ResourceRegistryException {
|
||||
protected OEdge reallyCreate() throws ResourceRegistryException {
|
||||
element = super.reallyCreate();
|
||||
|
||||
checkPropagationConstraint();
|
||||
|
@ -234,23 +232,23 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
}
|
||||
|
||||
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), orientGraph);
|
||||
return new ResourceManagement(getWorkingContext(), oDatabaseDocument);
|
||||
}
|
||||
|
||||
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
|
||||
|
||||
@Override
|
||||
protected Edge reallyUpdate() throws ResourceRegistryException {
|
||||
protected OEdge reallyUpdate() throws ResourceRegistryException {
|
||||
|
||||
logger.debug("Trying to update {} : {}", elementType, jsonNode);
|
||||
|
||||
Edge edge = getElement();
|
||||
OEdge edge = getElement();
|
||||
ERManagement.updateProperties(oClass, edge, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
if(accessType.compareTo(AccessType.CONSISTS_OF) == 0) {
|
||||
JsonNode target = jsonNode.get(Relation.TARGET_PROPERTY);
|
||||
if(target != null) {
|
||||
FacetManagement fm = new FacetManagement(getWorkingContext(), orientGraph);
|
||||
FacetManagement fm = new FacetManagement(getWorkingContext(), oDatabaseDocument);
|
||||
fm.setJsonNode(target);
|
||||
fm.internalUpdate();
|
||||
}
|
||||
|
@ -297,7 +295,7 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
*/
|
||||
getTargetEntityManagement().internalAddToContext(targetSecurityContext);
|
||||
|
||||
targetSecurityContext.addElement(getElement(), orientGraph);
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
||||
break;
|
||||
|
||||
|
@ -322,7 +320,7 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
/* Adding target to Context */
|
||||
getTargetEntityManagement().internalAddToContext(targetSecurityContext);
|
||||
|
||||
targetSecurityContext.addElement(getElement(), orientGraph);
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -359,7 +357,7 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
* In any removeConstraint value the relation MUST be removed from context to
|
||||
* avoid to have edge having a source outside of the context.
|
||||
*/
|
||||
targetSecurityContext.removeElement(getElement(), orientGraph);
|
||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||
|
||||
switch(removeConstraint) {
|
||||
case cascade:
|
||||
|
@ -367,17 +365,17 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
break;
|
||||
|
||||
case cascadeWhenOrphan:
|
||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
||||
|
||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
Iterable<OEdge> iterable = target.getEdges(ODirection.IN);
|
||||
Iterator<OEdge> iterator = iterable.iterator();
|
||||
int count = 0;
|
||||
OrientEdge edge = null;
|
||||
OEdge edge = null;
|
||||
while(iterator.hasNext()) {
|
||||
edge = (OrientEdge) iterator.next();
|
||||
OrientEdge thisOrientEdge = (OrientEdge) getElement();
|
||||
if(edge.compareTo(thisOrientEdge) != 0) {
|
||||
if(thisOrientEdge.getOutVertex().compareTo(edge.getOutVertex()) != 0) {
|
||||
edge = (OEdge) iterator.next();
|
||||
OEdge thisOEdge = (OEdge) getElement();
|
||||
if(edge.compareTo(thisOEdge) != 0) {
|
||||
if(thisOEdge.getVertex(ODirection.OUT).compareTo(edge.getVertex(ODirection.OUT)) != 0) {
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
|
@ -432,8 +430,8 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
Utility.toJsonString(element, true), removeConstraint, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||
element.remove();
|
||||
OVertex target = getTargetEntityManagement().getElement();
|
||||
element.delete();
|
||||
|
||||
switch(removeConstraint) {
|
||||
case cascade:
|
||||
|
@ -441,8 +439,8 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
break;
|
||||
|
||||
case cascadeWhenOrphan:
|
||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
Iterable<OEdge> iterable = target.getEdges(ODirection.IN);
|
||||
Iterator<OEdge> iterator = iterable.iterator();
|
||||
if(iterator.hasNext()) {
|
||||
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
|
||||
target, removeConstraint);
|
||||
|
@ -462,16 +460,19 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Collection<JsonNode> serializeEdges(Iterable<Edge> edges, boolean postFilterPolymorphic)
|
||||
protected Collection<JsonNode> serializeEdges(Iterable<ODocument> edges, boolean postFilterPolymorphic)
|
||||
throws ResourceRegistryException {
|
||||
Map<String,JsonNode> visitedSourceResources = new HashMap<>();
|
||||
for(Edge edge : edges) {
|
||||
if(postFilterPolymorphic && edge.getLabel().compareTo(elementType) != 0) {
|
||||
for(ODocument d : edges) {
|
||||
OEdge edge = (OEdge) d;
|
||||
|
||||
// TODO check because it was using compare
|
||||
if(postFilterPolymorphic && getOClass().isSubClassOf(elementType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RelationManagement<R, T, TE> relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(),
|
||||
orientGraph, edge);
|
||||
oDatabaseDocument, edge);
|
||||
visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);
|
||||
}
|
||||
return visitedSourceResources.values();
|
||||
|
@ -489,7 +490,7 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
Iterable<Edge> edges = orientGraph.getEdgesOfClass(elementType, polymorphic);
|
||||
Iterable<ODocument> edges = oDatabaseDocument.browseClass(elementType, polymorphic);
|
||||
Collection<JsonNode> collection = serializeEdges(edges, false);
|
||||
return serializeJsonNodeCollectionAsString(collection);
|
||||
}
|
||||
|
@ -499,13 +500,13 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
|
||||
try {
|
||||
orientGraph = ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
boolean added = forcedAddToContext(targetSecurityContext);
|
||||
|
||||
orientGraph.commit();
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID);
|
||||
|
||||
|
@ -513,13 +514,13 @@ public abstract class RelationManagement<R extends Relation<Resource, TE>, T ext
|
|||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID, e);
|
||||
if(orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.rollback();
|
||||
}
|
||||
throw new ContextException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,10 @@ import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinit
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
||||
|
||||
public class SchemaContextManagementOld implements SchemaManagement {
|
||||
|
||||
|
@ -29,13 +28,13 @@ public class SchemaContextManagementOld implements SchemaManagement {
|
|||
|
||||
public static final String SCHEMA = "__SCHEMA";
|
||||
|
||||
protected Vertex getVertex(OrientGraph orientGraph, String vertexType) throws Exception {
|
||||
Iterable<Vertex> iterable = orientGraph.getVerticesOfClass(vertexType, false);
|
||||
Iterator<Vertex> iterator = iterable.iterator();
|
||||
protected OVertex getVertex(ODatabaseDocument oDatabaseDocument, String vertexType) throws Exception {
|
||||
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(vertexType, false);
|
||||
Iterator<ODocument> iterator = iterable.iterator();
|
||||
|
||||
Vertex vertex = null;
|
||||
OVertex vertex = null;
|
||||
if(iterator.hasNext()) {
|
||||
vertex = iterator.next();
|
||||
vertex = (OVertex) iterator.next();
|
||||
} else {
|
||||
String error = String.format("%s is not a registered type", vertexType);
|
||||
logger.trace(error);
|
||||
|
@ -56,30 +55,30 @@ public class SchemaContextManagementOld implements SchemaManagement {
|
|||
@Override
|
||||
public String create(String json, AccessType baseType) throws SchemaException {
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
ODatabaseDocument orientGraph = null;
|
||||
|
||||
try {
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
orientGraph = adminSecurityContext.getGraph(PermissionMode.WRITER);
|
||||
orientGraph = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
TypeDefinition typeDefinition = TypeBinder.deserializeTypeDefinition(json);
|
||||
|
||||
if(BaseEntity.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||
OrientVertex orientVertex = orientGraph.addVertex("class:" + typeDefinition.getName());
|
||||
orientVertex.setProperty(SCHEMA, json);
|
||||
orientVertex.save();
|
||||
OVertex oVertex = orientGraph.newVertex(typeDefinition.getName());
|
||||
oVertex.setProperty(SCHEMA, json);
|
||||
oVertex.save();
|
||||
} else if(BaseRelation.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
String sourceClass = ((RelationTypeDefinition) typeDefinition).getSourceType();
|
||||
Vertex source = getVertex(orientGraph, sourceClass);
|
||||
OVertex source = getVertex(orientGraph, sourceClass);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
String targetClass = ((RelationTypeDefinition) typeDefinition).getTargetType();
|
||||
Vertex target = getVertex(orientGraph, targetClass);
|
||||
OVertex target = getVertex(orientGraph, targetClass);
|
||||
|
||||
OrientEdge orientEdge = orientGraph.addEdge(null, source, target, typeDefinition.getName());
|
||||
orientEdge.setProperty(SCHEMA, json);
|
||||
orientEdge.save();
|
||||
OEdge oEdge = orientGraph.newEdge(source, target, typeDefinition.getName());
|
||||
oEdge.setProperty(SCHEMA, json);
|
||||
oEdge.save();
|
||||
|
||||
} else if(BaseProperty.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||
ODocument doc = new ODocument(typeDefinition.getName());
|
||||
|
@ -97,7 +96,7 @@ public class SchemaContextManagementOld implements SchemaManagement {
|
|||
throw new SchemaException(e);
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
orientGraph.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.orientechnologies.orient.core.db.ODatabaseSession;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.exception.OSchemaException;
|
||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
|
@ -78,9 +78,9 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public static OClass getTypeSchema(ODatabaseSession oDatabaseSession, String type, AccessType accessType)
|
||||
public static OClass getTypeSchema(ODatabaseDocument oDatabaseDocument, String type, AccessType accessType)
|
||||
throws SchemaException, SchemaNotFoundException {
|
||||
OMetadata oMetadata = oDatabaseSession.getMetadata();
|
||||
OMetadata oMetadata = oDatabaseDocument.getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
return getTypeSchema(oSchema, type, accessType);
|
||||
}
|
||||
|
@ -114,21 +114,21 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
ExecutorService es = Executors.newSingleThreadExecutor();
|
||||
Future<OClass> result = es.submit(new Callable<OClass>() {
|
||||
public OClass call() throws Exception {
|
||||
ODatabaseSession oDatabaseSession = null;
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
logger.debug("Getting {} Type {} schema", accessType != null ? accessType.getName() : "", type);
|
||||
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseSession = adminSecurityContext.getDatabaseSession(PermissionMode.READER);
|
||||
|
||||
return getTypeSchema(oDatabaseSession, type, accessType);
|
||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
oDatabaseDocument.activateOnCurrentThread();
|
||||
return getTypeSchema(oDatabaseDocument, type, accessType);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
}catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if(oDatabaseSession != null) {
|
||||
oDatabaseSession.close();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
}
|
||||
|
||||
protected List<OClass> getSuperclassesAndCheckCompliancy(ODatabaseSession oDatabaseSession,
|
||||
protected List<OClass> getSuperclassesAndCheckCompliancy(ODatabaseDocument oDatabaseDocument,
|
||||
TypeDefinition typeDefinition, String baseType) throws SchemaException, SchemaNotFoundException {
|
||||
|
||||
Set<String> superClasses = typeDefinition.getSuperClasses();
|
||||
|
@ -191,7 +191,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
}
|
||||
|
||||
OMetadata oMetadata = oDatabaseSession.getMetadata();
|
||||
OMetadata oMetadata = oDatabaseDocument.getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
|
||||
List<OClass> oSuperclasses = new ArrayList<>();
|
||||
|
@ -231,7 +231,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
|
||||
protected String registerTypeSchema(String jsonSchema, AccessType baseType) throws SchemaException {
|
||||
|
||||
ODatabaseSession oDatabaseSession = null;
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
TypeDefinition typeDefinition = null;
|
||||
try {
|
||||
|
@ -250,17 +250,17 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
|
||||
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseSession = adminSecurityContext.getDatabaseSession(PermissionMode.WRITER);
|
||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
OMetadata oMetadata = oDatabaseSession.getMetadata();
|
||||
OMetadata oMetadata = oDatabaseDocument.getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
|
||||
OClass oClass = null;
|
||||
|
||||
if(BaseEntity.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||
oClass = oDatabaseSession.createVertexClass(typeDefinition.getName());
|
||||
oClass = oDatabaseDocument.createVertexClass(typeDefinition.getName());
|
||||
} else if(BaseRelation.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||
oClass = oDatabaseSession.createEdgeClass(typeDefinition.getName());
|
||||
oClass = oDatabaseDocument.createEdgeClass(typeDefinition.getName());
|
||||
|
||||
/*
|
||||
* This information are persisted in Management Context String outBaseType =
|
||||
|
@ -299,7 +299,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
|
||||
if(! baseTypes.contains(typeDefinition.getName())) {
|
||||
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(oDatabaseSession, typeDefinition,
|
||||
List<OClass> oSuperclasses = getSuperclassesAndCheckCompliancy(oDatabaseDocument, typeDefinition,
|
||||
baseType.getName());
|
||||
oClass.setSuperClasses(oSuperclasses);
|
||||
}
|
||||
|
@ -396,19 +396,19 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
} catch(Exception ex) {
|
||||
throw new SchemaCreationException(ex);
|
||||
} finally {
|
||||
if(oDatabaseSession != null) {
|
||||
oDatabaseSession.close();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getSchema(String type, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
||||
ODatabaseSession oDatabaseSession = null;
|
||||
ODatabaseDocument oDatabaseDocument = null;
|
||||
try {
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseSession = adminSecurityContext.getDatabaseSession(PermissionMode.WRITER);
|
||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
OMetadata oMetadata = oDatabaseSession.getMetadata();
|
||||
OMetadata oMetadata = oDatabaseDocument.getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
OClass baseOClass = getTypeSchema(oSchema, type, null);
|
||||
|
||||
|
@ -428,8 +428,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
} catch(Exception e) {
|
||||
throw new SchemaException(e);
|
||||
} finally {
|
||||
if(oDatabaseSession != null) {
|
||||
oDatabaseSession.close();
|
||||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
public class EntityTypeDefinitionManagement<ETD extends EntityTypeDefinition<? extends BaseEntity>> extends BaseEntityManagement<ETD> {
|
||||
|
||||
|
@ -39,9 +39,9 @@ public class EntityTypeDefinitionManagement<ETD extends EntityTypeDefinition<? e
|
|||
init();
|
||||
}
|
||||
|
||||
public EntityTypeDefinitionManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
public EntityTypeDefinitionManagement(ODatabaseDocument orientGraph) throws ResourceRegistryException {
|
||||
this();
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = orientGraph;
|
||||
getWorkingContext();
|
||||
}
|
||||
|
||||
|
@ -94,23 +94,23 @@ public class EntityTypeDefinitionManagement<ETD extends EntityTypeDefinition<? e
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
logger.debug("Going to create {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
return createVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to update {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
Vertex entityTypeDefinition = getElement();
|
||||
entityTypeDefinition = (Vertex) ERManagement.updateProperties(oClass, entityTypeDefinition, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
OVertex entityTypeDefinition = getElement();
|
||||
entityTypeDefinition = (OVertex) ERManagement.updateProperties(oClass, entityTypeDefinition, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
return entityTypeDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
getElement().remove();
|
||||
getElement().delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinit
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
public class RelationTypeDefinitionManagement<R extends RelationTypeDefinition<SETD, TETD, S, T>,
|
||||
SEM extends EntityTypeDefinitionManagement<SETD>, TEM extends EntityTypeDefinitionManagement<TETD>,
|
||||
|
@ -37,9 +37,9 @@ public class RelationTypeDefinitionManagement<R extends RelationTypeDefinition<S
|
|||
super(AccessType.RELATION_TYPE_DEFINITION, (Class<SETD>) EntityTypeDefinition.class, (Class<TETD>) EntityTypeDefinition.class);
|
||||
}
|
||||
|
||||
public RelationTypeDefinitionManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
public RelationTypeDefinitionManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.orientGraph = orientGraph;
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
getWorkingContext();
|
||||
}
|
||||
|
||||
|
@ -71,15 +71,15 @@ public class RelationTypeDefinitionManagement<R extends RelationTypeDefinition<S
|
|||
JsonNode relation = serializeSelfOnly();
|
||||
|
||||
try {
|
||||
Vertex source = element.getVertex(Direction.OUT);
|
||||
ContextManagement sourceContextManagement = new ContextManagement(orientGraph);
|
||||
OVertex source = element.getVertex(ODirection.OUT);
|
||||
ContextManagement sourceContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
sourceContextManagement.setElement(source);
|
||||
if(includeSource) {
|
||||
((ObjectNode)relation).replace(Relation.SOURCE_PROPERTY, sourceContextManagement.serializeSelfOnly());
|
||||
}
|
||||
|
||||
Vertex target = element.getVertex(Direction.IN);
|
||||
ContextManagement targetContextManagement = new ContextManagement(orientGraph);
|
||||
OVertex target = element.getVertex(ODirection.IN);
|
||||
ContextManagement targetContextManagement = new ContextManagement(oDatabaseDocument);
|
||||
targetContextManagement.setElement(target);
|
||||
if(includeTarget) {
|
||||
((ObjectNode)relation).replace(Relation.TARGET_PROPERTY, targetContextManagement.serializeSelfOnly());
|
||||
|
@ -99,14 +99,14 @@ public class RelationTypeDefinitionManagement<R extends RelationTypeDefinition<S
|
|||
@Override
|
||||
protected SEM newSourceEntityManagement() throws ResourceRegistryException {
|
||||
@SuppressWarnings("unchecked")
|
||||
SEM sem = (SEM) new EntityTypeDefinitionManagement<SETD>(orientGraph);
|
||||
SEM sem = (SEM) new EntityTypeDefinitionManagement<SETD>(oDatabaseDocument);
|
||||
return sem;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TEM newTargetEntityManagement() throws ResourceRegistryException {
|
||||
@SuppressWarnings("unchecked")
|
||||
TEM tem = (TEM) new EntityTypeDefinitionManagement<TETD>(orientGraph);
|
||||
TEM tem = (TEM) new EntityTypeDefinitionManagement<TETD>(oDatabaseDocument);
|
||||
return tem;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ import org.slf4j.LoggerFactory;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -34,13 +34,12 @@ public class QueryImpl implements Query {
|
|||
}
|
||||
limit = (limit <= 0) ? AccessPath.UNBOUNDED : limit;
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
ODatabaseDocument orientGraph = null;
|
||||
|
||||
try {
|
||||
SecurityContext securityContext = ContextUtility.getCurrentSecurityContext();
|
||||
|
||||
orientGraph = securityContext.getGraph(PermissionMode.READER);
|
||||
orientGraph.setAutoStartTx(false);
|
||||
orientGraph = securityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
orientGraph.begin();
|
||||
|
||||
OSQLSynchQuery<ODocument> osqlSynchQuery = new OSQLSynchQuery<>(query, limit);
|
||||
|
@ -50,13 +49,13 @@ public class QueryImpl implements Query {
|
|||
logger.debug("Going to execute query : \"{}\", fetchPlan : \"{}\", limit : {}", osqlSynchQuery.getText(),
|
||||
osqlSynchQuery.getFetchPlan(), osqlSynchQuery.getLimit());
|
||||
|
||||
Iterable<Element> elements = orientGraph.command(osqlSynchQuery).execute();
|
||||
Iterable<OElement> elements = orientGraph.command(osqlSynchQuery).execute();
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||
|
||||
|
||||
for(Element element : elements) {
|
||||
for(OElement element : elements) {
|
||||
try {
|
||||
JsonNode jsonNode = null;
|
||||
if(raw) {
|
||||
|
@ -81,7 +80,7 @@ public class QueryImpl implements Query {
|
|||
throw new InvalidQueryException(e.getMessage());
|
||||
} finally {
|
||||
if(orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
orientGraph.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
|
||||
/**
|
||||
|
@ -341,7 +342,7 @@ public class Access {
|
|||
|
||||
if(erManagement instanceof ResourceManagement) {
|
||||
UUID refereceUUID = null;
|
||||
Direction directionEnum = Direction.OUT;
|
||||
ODirection directionEnum = ODirection.OUT;
|
||||
|
||||
Map<String,String> constraint = new HashMap<>();
|
||||
|
||||
|
@ -368,7 +369,7 @@ public class Access {
|
|||
}
|
||||
}
|
||||
try {
|
||||
directionEnum = Direction.valueOf(direction.toUpperCase());
|
||||
directionEnum = ODirection.valueOf(direction.toUpperCase());
|
||||
} catch(Exception e) {
|
||||
String error = String.format("%s is not a valid. Allowed values are %s", direction, Direction.values());
|
||||
throw new InvalidQueryException(error);
|
||||
|
|
|
@ -25,17 +25,15 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.orientechnologies.orient.core.db.ODatabasePool;
|
||||
import com.orientechnologies.orient.core.db.ODatabaseSession;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.security.ORestrictedOperation;
|
||||
import com.orientechnologies.orient.core.metadata.security.ORole;
|
||||
import com.orientechnologies.orient.core.metadata.security.OSecurity;
|
||||
import com.orientechnologies.orient.core.metadata.security.OSecurityRole.ALLOW_MODES;
|
||||
import com.orientechnologies.orient.core.metadata.security.OUser;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.ORecord;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -81,7 +79,6 @@ public class SecurityContext {
|
|||
|
||||
protected final UUID context;
|
||||
|
||||
protected final Map<Boolean,Map<PermissionMode,OrientGraphFactory>> factoryMap;
|
||||
protected final Map<Boolean,Map<PermissionMode,ODatabasePool>> poolMap;
|
||||
|
||||
protected SecurityContext parentSecurityContext;
|
||||
|
@ -115,12 +112,8 @@ public class SecurityContext {
|
|||
return this.children;
|
||||
}
|
||||
|
||||
protected OrientGraph getAdminOrientGraph() throws ResourceRegistryException {
|
||||
return ContextUtility.getAdminSecurityContext().getGraph(PermissionMode.WRITER);
|
||||
}
|
||||
|
||||
protected ODatabaseSession getAdminDatabaseSession() throws ResourceRegistryException {
|
||||
return ContextUtility.getAdminSecurityContext().getDatabaseSession(PermissionMode.WRITER);
|
||||
protected ODatabaseDocument getAdminDatabaseDocument() throws ResourceRegistryException {
|
||||
return ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,7 +150,7 @@ public class SecurityContext {
|
|||
* @param orientGraph
|
||||
* @throws ResourceRegistryException
|
||||
*/
|
||||
public void changeParentSecurityContext(SecurityContext newParentSecurityContext, OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
public void changeParentSecurityContext(SecurityContext newParentSecurityContext, ODatabaseDocument orientGraph) throws ResourceRegistryException {
|
||||
if(!hierarchic) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
errorMessage.append("Cannot change parent ");
|
||||
|
@ -210,7 +203,6 @@ public class SecurityContext {
|
|||
|
||||
protected SecurityContext(UUID context, boolean hierarchic) throws ResourceRegistryException {
|
||||
this.context = context;
|
||||
this.factoryMap = new HashMap<>();
|
||||
this.poolMap = new HashMap<>();
|
||||
this.hierarchic = hierarchic;
|
||||
this.children = new HashSet<>();
|
||||
|
@ -247,7 +239,6 @@ public class SecurityContext {
|
|||
String password = DatabaseEnvironment.DEFAULT_PASSWORDS.get(permissionMode);
|
||||
|
||||
pool = new ODatabasePool(DatabaseEnvironment.DB_URI, username, password);
|
||||
//pool.setConnectionStrategy(DatabaseEnvironment.CONNECTION_STRATEGY_PARAMETER.toString());
|
||||
|
||||
pools.put(permissionMode, pool);
|
||||
}
|
||||
|
@ -255,41 +246,6 @@ public class SecurityContext {
|
|||
return pool;
|
||||
}
|
||||
|
||||
private synchronized OrientGraphFactory getFactory(PermissionMode permissionMode, boolean recreate) {
|
||||
OrientGraphFactory factory = null;
|
||||
|
||||
Boolean h = isHierarchicMode();
|
||||
|
||||
Map<PermissionMode,OrientGraphFactory> factories = factoryMap.get(h);
|
||||
if(factories == null) {
|
||||
factories = new HashMap<>();
|
||||
factoryMap.put(h, factories);
|
||||
} else {
|
||||
if(recreate) {
|
||||
factory = factories.get(permissionMode);
|
||||
if(factory!=null) {
|
||||
factory.close();
|
||||
factories.remove(permissionMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
factory = factories.get(permissionMode);
|
||||
|
||||
if(factory == null) {
|
||||
|
||||
String username = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, h);
|
||||
String password = DatabaseEnvironment.DEFAULT_PASSWORDS.get(permissionMode);
|
||||
|
||||
factory = new OrientGraphFactory(DatabaseEnvironment.DB_URI, username, password).setupPool(1, 10);
|
||||
factory.setConnectionStrategy(DatabaseEnvironment.CONNECTION_STRATEGY_PARAMETER.toString());
|
||||
|
||||
factories.put(permissionMode, factory);
|
||||
}
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return context;
|
||||
}
|
||||
|
@ -307,17 +263,18 @@ public class SecurityContext {
|
|||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private OSecurity getOSecurity(OrientGraph orientGraph) {
|
||||
return orientGraph.getRawGraph().getMetadata().getSecurity();
|
||||
private OSecurity getOSecurity(ODatabaseDocument oDatabaseDocument) {
|
||||
return oDatabaseDocument.getMetadata().getSecurity();
|
||||
}
|
||||
|
||||
private OSecurity getOSecurity(ODatabaseSession oDatabaseSession) {
|
||||
return oDatabaseSession.getMetadata().getSecurity();
|
||||
}
|
||||
|
||||
public void addElement(Element element) throws ResourceRegistryException {
|
||||
addElement(element, getAdminOrientGraph());
|
||||
public void addElement(OElement element) throws ResourceRegistryException {
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
||||
adminDatabaseDocument.activateOnCurrentThread();
|
||||
addElement(element, adminDatabaseDocument);
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
protected void allow(OSecurity oSecurity, ODocument oDocument, boolean hierarchic) {
|
||||
|
@ -327,20 +284,25 @@ public class SecurityContext {
|
|||
oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_READ, readerRoleName);
|
||||
}
|
||||
|
||||
public void addElement(Element element, OrientGraph orientGraph) {
|
||||
OrientElement orientElement = (OrientElement) element;
|
||||
ODocument oDocument = orientElement.getRecord();
|
||||
OSecurity oSecurity = getOSecurity(orientGraph);
|
||||
public void addElement(OElement element, ODatabaseDocument oDatabaseDocument) {
|
||||
ODocument oDocument = element.getRecord();
|
||||
OSecurity oSecurity = getOSecurity(oDatabaseDocument);
|
||||
allow(oSecurity, oDocument, false);
|
||||
if(hierarchic) {
|
||||
allow(oSecurity, oDocument, true);
|
||||
}
|
||||
oDocument.save();
|
||||
orientElement.save();
|
||||
element.save();
|
||||
}
|
||||
|
||||
public void removeElement(Element element) throws ResourceRegistryException {
|
||||
removeElement(element, getAdminOrientGraph());
|
||||
public void removeElement(OElement element) throws ResourceRegistryException {
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
||||
adminDatabaseDocument.activateOnCurrentThread();
|
||||
removeElement(element, adminDatabaseDocument);
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
protected void deny(OSecurity oSecurity, ODocument oDocument, boolean hierarchic) {
|
||||
|
@ -358,16 +320,15 @@ public class SecurityContext {
|
|||
|
||||
}
|
||||
|
||||
public void removeElement(Element element, OrientGraph orientGraph) {
|
||||
OrientElement orientElement = (OrientElement) element;
|
||||
ODocument oDocument = orientElement.getRecord();
|
||||
OSecurity oSecurity = getOSecurity(orientGraph);
|
||||
public void removeElement(OElement element, ODatabaseDocument oDatabaseDocument) {
|
||||
ODocument oDocument = element.getRecord();
|
||||
OSecurity oSecurity = getOSecurity(oDatabaseDocument);
|
||||
deny(oSecurity, oDocument, false);
|
||||
if(hierarchic) {
|
||||
deny(oSecurity, oDocument, true);
|
||||
}
|
||||
oDocument.save();
|
||||
orientElement.save();
|
||||
element.save();
|
||||
}
|
||||
|
||||
protected boolean allowed(final ORole role, final ODocument oDocument) {
|
||||
|
@ -379,9 +340,10 @@ public class SecurityContext {
|
|||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
ContextUtility.getHierarchicMode().set(false);
|
||||
ODatabaseSession oDatabaseSession = getDatabaseSession(PermissionMode.READER);
|
||||
ODatabaseDocument oDatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
||||
try {
|
||||
OrientElement element = oDatabaseSession.getRecord(oDocument.getIdentity());
|
||||
oDatabaseDocument.activateOnCurrentThread();
|
||||
ORecord element = oDatabaseDocument.getRecord(oDocument.getIdentity());
|
||||
if(element == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -389,7 +351,7 @@ public class SecurityContext {
|
|||
} catch(Exception e) {
|
||||
return false;
|
||||
} finally {
|
||||
oDatabaseSession.close();
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,16 +366,17 @@ public class SecurityContext {
|
|||
}
|
||||
|
||||
public void create() throws ResourceRegistryException {
|
||||
/*
|
||||
OrientGraph orientGraph = getAdminOrientGraph();
|
||||
create(orientGraph);
|
||||
orientGraph.commit();
|
||||
orientGraph.shutdown();
|
||||
*/
|
||||
ODatabaseSession oDatabaseSession = getAdminDatabaseSession();
|
||||
create(oDatabaseSession);
|
||||
oDatabaseSession.commit();
|
||||
oDatabaseSession.close();
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
||||
adminDatabaseDocument.activateOnCurrentThread();
|
||||
|
||||
create(adminDatabaseDocument);
|
||||
adminDatabaseDocument.commit();
|
||||
adminDatabaseDocument.close();
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
protected ORole addExtraRules(ORole role, PermissionMode permissionMode) {
|
||||
|
@ -476,7 +439,7 @@ public class SecurityContext {
|
|||
logger.trace("Security Context (roles and users) with UUID {} successfully created", context.toString());
|
||||
}
|
||||
|
||||
public void create(OrientGraph orientGraph) {
|
||||
public void create(ODatabaseDocument orientGraph) {
|
||||
OSecurity oSecurity = getOSecurity(orientGraph);
|
||||
createRolesAndUsers(oSecurity);
|
||||
logger.trace("Security Context (roles and users) with UUID {} successfully created", context.toString());
|
||||
|
@ -504,16 +467,17 @@ public class SecurityContext {
|
|||
}
|
||||
|
||||
public void delete() throws ResourceRegistryException {
|
||||
/*
|
||||
OrientGraph orientGraph = getAdminOrientGraph();
|
||||
delete(orientGraph);
|
||||
orientGraph.commit();
|
||||
orientGraph.shutdown();
|
||||
*/
|
||||
ODatabaseSession oDatabaseSession = getAdminDatabaseSession();
|
||||
create(oDatabaseSession);
|
||||
oDatabaseSession.commit();
|
||||
oDatabaseSession.close();
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
ODatabaseDocument adminDatabaseDocument = getAdminDatabaseDocument();
|
||||
adminDatabaseDocument.activateOnCurrentThread();
|
||||
|
||||
delete(adminDatabaseDocument);
|
||||
adminDatabaseDocument.commit();
|
||||
adminDatabaseDocument.close();
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeChildrenHRolesFromParents(OSecurity oSecurity) {
|
||||
|
@ -572,64 +536,18 @@ public class SecurityContext {
|
|||
}
|
||||
}
|
||||
|
||||
public void delete(OrientGraph orientGraph) {
|
||||
public void delete(ODatabaseDocument orientGraph) {
|
||||
OSecurity oSecurity = getOSecurity(orientGraph);
|
||||
delete(oSecurity);
|
||||
}
|
||||
|
||||
public void delete(ODatabaseSession oDatabaseSession) {
|
||||
OSecurity oSecurity = getOSecurity(oDatabaseSession);
|
||||
delete(oSecurity);
|
||||
}
|
||||
|
||||
|
||||
private void delete(OSecurity oSecurity) {
|
||||
logger.trace("Going to remove Security Context (roles and users) with UUID {}", context.toString());
|
||||
deleteRolesAndUsers(oSecurity);
|
||||
logger.trace("Security Context (roles and users) with UUID {} successfully removed", context.toString());
|
||||
}
|
||||
|
||||
public OrientGraph getGraph(PermissionMode permissionMode) throws ResourceRegistryException {
|
||||
try {
|
||||
OrientGraphFactory factory = getFactory(permissionMode, false);
|
||||
OrientGraph orientGraph = null;
|
||||
try {
|
||||
orientGraph = factory.getTx();
|
||||
if(orientGraph.isClosed()) {
|
||||
// Enforcing factory recreation
|
||||
throw new Exception();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
factory = getFactory(permissionMode, true);
|
||||
orientGraph = factory.getTx();
|
||||
}
|
||||
return orientGraph;
|
||||
}catch (Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public OrientGraphNoTx getGraphNoTx(PermissionMode permissionMode) throws ResourceRegistryException {
|
||||
try {
|
||||
OrientGraphFactory factory = getFactory(permissionMode, false);
|
||||
OrientGraphNoTx orientGraphNoTx = null;
|
||||
try {
|
||||
orientGraphNoTx = factory.getNoTx();
|
||||
if(orientGraphNoTx.isClosed()) {
|
||||
// Enforcing factory recreation
|
||||
throw new Exception();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
factory = getFactory(permissionMode, true);
|
||||
orientGraphNoTx = factory.getNoTx();
|
||||
}
|
||||
return orientGraphNoTx;
|
||||
}catch (Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ODatabaseSession getDatabaseSession(PermissionMode permissionMode) throws ResourceRegistryException {
|
||||
public ODatabaseDocument getDatabaseDocument(PermissionMode permissionMode) throws ResourceRegistryException {
|
||||
try {
|
||||
ODatabasePool oDatabasePool = getPool(permissionMode, false);
|
||||
ODatabaseSession oDatabaseSession = null;
|
||||
|
@ -643,28 +561,13 @@ public class SecurityContext {
|
|||
oDatabasePool = getPool(permissionMode, true);
|
||||
oDatabaseSession = oDatabasePool.acquire();
|
||||
}
|
||||
oDatabaseSession.activateOnCurrentThread();
|
||||
return oDatabaseSession;
|
||||
}catch (Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* *
|
||||
* Use {@link #getDatabaseSession(PermissionMode)} instead
|
||||
* /
|
||||
@Deprecated
|
||||
private ODatabaseDocumentTx getDatabaseDocumentTx(PermissionMode permissionMode) {
|
||||
OrientGraphFactory factory = getFactory(permissionMode, false);
|
||||
ODatabaseDocumentTx databaseDocumentTx = factory.getDatabase();
|
||||
if(databaseDocumentTx.isClosed()) {
|
||||
factory.close();
|
||||
factory = getFactory(permissionMode, true);
|
||||
databaseDocumentTx = factory.getDatabase();
|
||||
}
|
||||
return databaseDocumentTx;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s", Context.NAME, getUUID().toString());
|
||||
|
|
|
@ -19,9 +19,9 @@ import org.slf4j.LoggerFactory;
|
|||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -114,7 +114,7 @@ public class HeaderUtility {
|
|||
}
|
||||
}
|
||||
|
||||
public static Header addHeader(Element element, UUID uuid) {
|
||||
public static Header addHeader(OElement element, UUID uuid) {
|
||||
Header header = createHeader(uuid);
|
||||
element.setProperty(ER.HEADER_PROPERTY, header);
|
||||
return header;
|
||||
|
@ -126,11 +126,11 @@ public class HeaderUtility {
|
|||
return header;
|
||||
}
|
||||
|
||||
public static Header getHeader(Element element) throws ResourceRegistryException {
|
||||
public static Header getHeader(OElement element) throws ResourceRegistryException {
|
||||
return Utility.getPropertyDocument(Header.class, element, ER.HEADER_PROPERTY);
|
||||
}
|
||||
|
||||
public static void updateModifiedByAndLastUpdate(Element element) throws ResourceRegistryException {
|
||||
public static void updateModifiedByAndLastUpdate(OElement element) throws ResourceRegistryException {
|
||||
ODocument oDocument = element.getProperty(ER.HEADER_PROPERTY);
|
||||
String modifiedBy = getUser();
|
||||
oDocument.field(Header.MODIFIED_BY_PROPERTY, modifiedBy);
|
||||
|
|
|
@ -18,16 +18,13 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OEdge;
|
||||
import com.orientechnologies.orient.core.record.OElement;
|
||||
import com.orientechnologies.orient.core.record.ORecord;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Graph;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -38,8 +35,8 @@ public class Utility {
|
|||
|
||||
public static final String SHOULD_NOT_OCCUR_ERROR_MESSAGE = "This is really strange and should not occur. Please contact the system administrator.";
|
||||
|
||||
public static JsonNode toJsonNode(Element element, boolean raw) throws ResourceRegistryException {
|
||||
ORecord oRecord = ((OrientElement) element).getRecord();
|
||||
public static JsonNode toJsonNode(OElement element, boolean raw) throws ResourceRegistryException {
|
||||
ORecord oRecord = element.getRecord();
|
||||
return Utility.toJsonNode(oRecord, raw);
|
||||
}
|
||||
|
||||
|
@ -52,8 +49,8 @@ public class Utility {
|
|||
}
|
||||
}
|
||||
|
||||
public static String toJsonString(Element element, boolean raw) {
|
||||
ORecord oRecord = ((OrientElement) element).getRecord();
|
||||
public static String toJsonString(OElement element, boolean raw) {
|
||||
ORecord oRecord = element.getRecord();
|
||||
return Utility.toJsonString(oRecord, raw);
|
||||
}
|
||||
|
||||
|
@ -65,28 +62,33 @@ public class Utility {
|
|||
return oRecord.toJSON("class");
|
||||
}
|
||||
|
||||
public static <El extends Element> El getElementByUUIDAsAdmin(String elementType, UUID uuid,
|
||||
public static <El extends OElement> El getElementByUUIDAsAdmin(String elementType, UUID uuid,
|
||||
Class<? extends El> clz) throws NotFoundException, ResourceRegistryException {
|
||||
OrientGraphNoTx orientGraphNoTx = null;
|
||||
ODatabaseDocument adminDatabaseDocument = null;
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
orientGraphNoTx = adminSecurityContext.getGraphNoTx(PermissionMode.READER);
|
||||
return Utility.getElementByUUID(orientGraphNoTx, elementType, uuid, clz);
|
||||
adminDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
return Utility.getElementByUUID(adminDatabaseDocument, elementType, uuid, clz);
|
||||
} finally {
|
||||
if(orientGraphNoTx != null) {
|
||||
orientGraphNoTx.shutdown();
|
||||
if(adminDatabaseDocument != null) {
|
||||
adminDatabaseDocument.close();
|
||||
}
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <El extends Element> El getElementByUUID(Graph graph, String elementType, UUID uuid,
|
||||
public static <El extends OElement> El getElementByUUID(ODatabaseDocument oDatabaseDocument, String elementType, UUID uuid,
|
||||
Class<? extends El> clz) throws NotFoundException, ResourceRegistryException {
|
||||
|
||||
if(elementType == null || elementType.compareTo("") == 0) {
|
||||
if(Vertex.class.isAssignableFrom(clz)) {
|
||||
if(OVertex.class.isAssignableFrom(clz)) {
|
||||
elementType = Entity.NAME;
|
||||
}
|
||||
if(Edge.class.isAssignableFrom(clz)) {
|
||||
if(OEdge.class.isAssignableFrom(clz)) {
|
||||
elementType = Relation.NAME;
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +99,7 @@ public class Utility {
|
|||
|
||||
OSQLSynchQuery<El> osqlSynchQuery = new OSQLSynchQuery<>(select);
|
||||
|
||||
Iterable<El> elements = ((OrientBaseGraph) graph).command(osqlSynchQuery).execute();
|
||||
Iterable<El> elements = oDatabaseDocument.command(osqlSynchQuery).execute();
|
||||
if(elements == null || !elements.iterator().hasNext()) {
|
||||
String error = String.format("No %s with UUID %s was found", elementType, uuid.toString());
|
||||
logger.info(error);
|
||||
|
@ -117,7 +119,7 @@ public class Utility {
|
|||
return element;
|
||||
}
|
||||
|
||||
public static <P extends BaseProperty> P getPropertyDocument(Class<P> clz, Element element, String property)
|
||||
public static <P extends BaseProperty> P getPropertyDocument(Class<P> clz, OElement element, String property)
|
||||
throws ResourceRegistryException {
|
||||
try {
|
||||
ODocument oDocument = element.getProperty(property);
|
||||
|
@ -129,7 +131,7 @@ public class Utility {
|
|||
}
|
||||
}
|
||||
|
||||
public static UUID getUUID(Element element) throws ResourceRegistryException {
|
||||
public static UUID getUUID(OElement element) throws ResourceRegistryException {
|
||||
/*
|
||||
* ODocument header = element.getProperty(Entity.HEADER_PROPERTY); String
|
||||
* contextID = header.field(Header.UUID_PROPERTY); return
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.orientechnologies.orient.core.db.ODatabaseSession;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.metadata.security.ORole;
|
||||
import com.orientechnologies.orient.core.metadata.security.OSecurity;
|
||||
import com.orientechnologies.orient.core.metadata.security.OUser;
|
||||
|
@ -64,8 +64,8 @@ public class ContextManagementTest extends ContextTest {
|
|||
ContextUtility.getInstance().addSecurityContext(contextSecurityContext.getUUID().toString(),
|
||||
contextSecurityContext);
|
||||
|
||||
ODatabaseSession oDatabaseSession = contextSecurityContext.getDatabaseSession(PermissionMode.READER);
|
||||
OSecurity oSecurity = oDatabaseSession.getMetadata().getSecurity();
|
||||
ODatabaseDocument oDatabaseDocument = contextSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||
OSecurity oSecurity = oDatabaseDocument.getMetadata().getSecurity();
|
||||
|
||||
SecurityContext securityContext = null;
|
||||
if(deleted) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.db.ODatabase.ATTRIBUTES;
|
||||
import com.orientechnologies.orient.core.db.ODatabaseSession;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
|
||||
public class DatabaseEnvironmentTest {
|
||||
|
||||
|
@ -24,9 +24,9 @@ public class DatabaseEnvironmentTest {
|
|||
|
||||
@Test
|
||||
public void testAlterDateTimeFormat() throws ResourceRegistryException {
|
||||
ODatabaseSession oDatabaseSession = ContextUtility.getAdminSecurityContext().getDatabaseSession(PermissionMode.WRITER);
|
||||
DatabaseEnvironment.setDateTimeFormat(oDatabaseSession);
|
||||
String dateTime = oDatabaseSession.get(ATTRIBUTES.DATETIMEFORMAT).toString();
|
||||
ODatabaseDocument oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
DatabaseEnvironment.setDateTimeFormat(oDatabaseDocument);
|
||||
String dateTime = oDatabaseDocument.get(ATTRIBUTES.DATETIMEFORMAT).toString();
|
||||
Assert.assertTrue(dateTime.compareTo(ISConstants.DATETIME_PATTERN)==0);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -714,31 +714,31 @@ public class ERManagementTest extends ContextTest {
|
|||
resourceManagement.setElementType(Service.NAME);
|
||||
|
||||
/* Getting Hosting Node */
|
||||
String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.BOTH, true, null);
|
||||
String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, true, null);
|
||||
List<Resource> resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
Resource resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.OUT, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID)==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.IN, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.BOTH, false, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.OUT, false, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, Direction.IN, false, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
/* END Getting Hosting Node */
|
||||
|
@ -746,29 +746,29 @@ public class ERManagementTest extends ContextTest {
|
|||
|
||||
|
||||
/* Getting EService */
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.BOTH, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID)==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.OUT, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.IN, true, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID)==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.BOTH, false, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.OUT, false, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, Direction.IN, false, null);
|
||||
json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
/* END Getting HostingNode */
|
||||
|
@ -779,12 +779,12 @@ public class ERManagementTest extends ContextTest {
|
|||
|
||||
/* EService --ConsistsOf--> SoftwareFacet*/
|
||||
try {
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.BOTH, true, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.BOTH, true, null);
|
||||
}catch(InvalidQueryException e) {
|
||||
// Ok expected
|
||||
}
|
||||
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.OUT, true, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, true, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==1);
|
||||
resource = resourceList.get(0);
|
||||
|
@ -793,24 +793,24 @@ public class ERManagementTest extends ContextTest {
|
|||
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID)==0);
|
||||
|
||||
try {
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.IN, true, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, true, null);
|
||||
}catch(InvalidQueryException e) {
|
||||
// Ok expected
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.BOTH, false, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.BOTH, false, null);
|
||||
}catch(InvalidQueryException e) {
|
||||
// Ok expected
|
||||
}
|
||||
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.OUT, false, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, false, null);
|
||||
resourceList = ISMapper.unmarshalList(Resource.class, json);
|
||||
Assert.assertTrue(resourceList.size()==0);
|
||||
|
||||
try {
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, Direction.IN, false, null);
|
||||
json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, false, null);
|
||||
}catch(InvalidQueryException e) {
|
||||
// Ok expected
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.junit.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.orientechnologies.orient.core.record.ODirection;
|
||||
|
||||
public class ResourceManagementTest extends ContextTest {
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class ResourceManagementTest extends ContextTest {
|
|||
if (erManagement instanceof ResourceManagement) {
|
||||
boolean[] booleans = new boolean[] {true, false};
|
||||
for(boolean bool : booleans) {
|
||||
String ret = ((ResourceManagement) erManagement).query(relationType, facetType, null, Direction.OUT, bool, constraint);
|
||||
String ret = ((ResourceManagement) erManagement).query(relationType, facetType, null, ODirection.OUT, bool, constraint);
|
||||
logger.debug("Result of query for {}polymorphic {} --{}--> {} with constaint {} is {}", bool ? "" : "NOT ",
|
||||
type, relationType, facetType, constraint, ret);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue