diff --git a/pom.xml b/pom.xml
index 828f842..709a593 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,23 +60,18 @@
+
- com.orientechnologies
-
- orientdb-client
- 3.0.42
-
-
- org.graalvm.tools
- chromeinspector
-
-
+ com.arcadedb
+ arcadedb-engine
+ 23.4.1
+
+ com.arcadedb
+ arcadedb-network
+ 23.4.1
+
+
org.gcube.common
gxHTTP
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/ResourceInitializer.java b/src/main/java/org/gcube/informationsystem/resourceregistry/ResourceInitializer.java
index c484721..3c30b77 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/ResourceInitializer.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/ResourceInitializer.java
@@ -23,7 +23,7 @@ public class ResourceInitializer extends ResourceConfig {
public ResourceInitializer() {
packages(Access.class.getPackage().toString());
- logger.info("The server is going to use OrientDB at {}", DatabaseEnvironment.DB_URI);
+ logger.info("The server is going to use OrientDB at {}:{}/{}", DatabaseEnvironment.HOST, DatabaseEnvironment.PORT, DatabaseEnvironment.DB);
}
}
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java
index 71fdb48..74c81d7 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java
@@ -16,17 +16,18 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecur
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
-import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
+import org.gcube.informationsystem.resourceregistry.utils.DBUtility;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
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.executor.OResult;
-import com.orientechnologies.orient.core.sql.executor.OResultSet;
+import com.arcadedb.graph.MutableVertex;
+import com.arcadedb.graph.Vertex;
+import com.arcadedb.graph.Vertex.DIRECTION;
+import com.arcadedb.query.sql.executor.Result;
+import com.arcadedb.query.sql.executor.ResultSet;
+import com.arcadedb.remote.RemoteDatabase;
+
/**
* @author Luca Frosini (ISTI - CNR)
@@ -76,8 +77,8 @@ public class ContextUtility {
}
public synchronized SecurityContext getSecurityContextByFullName(String fullName) throws ContextException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument oDatabaseDocument = null;
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase database = null;
try {
SecurityContext securityContext = null;
@@ -91,9 +92,9 @@ public class ContextUtility {
if(securityContext==null) {
logger.trace("{} for {} is not in cache. Going to get it", SecurityContext.class.getSimpleName(),
fullName);
- oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER);
+ database = getAdminSecurityContext().getRemoteDatabase(PermissionMode.READER);
- OVertex contextVertex = getContextVertexByFullName(oDatabaseDocument, fullName);
+ MutableVertex contextVertex = getContextVertexByFullName(database, fullName);
uuid = UUIDUtility.getUUID(contextVertex);
@@ -110,13 +111,13 @@ public class ContextUtility {
} catch(Exception e) {
throw new ContextException("Unable to retrieve Context UUID from current Context", e);
} finally {
- if(oDatabaseDocument!=null) {
- oDatabaseDocument.close();
+ if(database!=null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
@@ -124,36 +125,36 @@ public class ContextUtility {
return getSecurityContextByUUID(uuid, null);
}
- public static ODatabaseDocument getCurrentODatabaseDocumentFromThreadLocal() {
- ODatabaseDocument current = null;
+ public static RemoteDatabase getCurrentODatabaseDocumentFromThreadLocal() {
+ RemoteDatabase current = null;
try {
- current = (ODatabaseDocument) ODatabaseRecordThreadLocal.instance().get();
+ // current = (RemoteDatabase) ODatabaseRecordThreadLocal.instance().get();
}catch (Exception e) {
// It is possible that there is no current ODatabaseDocument
}
return current;
}
- private OVertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument oDatabaseDocument = null;
+ private Vertex getContextVertexByUUID(UUID uuid) throws ResourceRegistryException {
+ RemoteDatabase current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase database = null;
try {
- oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER);
- OVertex oVertex = OrientDBUtility.getElementByUUID(oDatabaseDocument, Context.NAME, uuid,
- OVertex.class);
- return oVertex;
+ database = getAdminSecurityContext().getRemoteDatabase(PermissionMode.READER);
+ Vertex vertex = DBUtility.getElementByUUID(database, Context.NAME, uuid,
+ Vertex.class);
+ return vertex;
} finally {
- if(oDatabaseDocument!=null) {
- oDatabaseDocument.close();
+ if(database!=null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
- private SecurityContext getSecurityContextByUUID(UUID uuid, OVertex contextVertex) throws ResourceRegistryException {
+ private SecurityContext getSecurityContextByUUID(UUID uuid, Vertex contextVertex) throws ResourceRegistryException {
SecurityContext securityContext = contexts.get(uuid);
if(securityContext == null) {
@@ -163,7 +164,7 @@ public class ContextUtility {
if(contextVertex == null) {
contextVertex = getContextVertexByUUID(uuid);
}
- OVertex parentVertex = contextVertex.getVertices(ODirection.IN, IsParentOf.NAME).iterator().next();
+ Vertex parentVertex = contextVertex.getVertices(DIRECTION.IN, IsParentOf.NAME).iterator().next();
if(parentVertex != null) {
UUID parentUUID = UUIDUtility.getUUID(parentVertex);
@@ -187,8 +188,8 @@ public class ContextUtility {
}
*/
- private OVertex getContextVertexByFullName(ODatabaseDocument oDatabaseDocument, String fullName) throws ResourceRegistryException {
- logger.trace("Going to get {} {} with full name '{}'", Context.NAME, OVertex.class.getSimpleName(), fullName);
+ private MutableVertex getContextVertexByFullName(RemoteDatabase database , String fullName) throws ResourceRegistryException {
+ logger.trace("Going to get {} {} with full name '{}'", Context.NAME, Vertex.class.getSimpleName(), fullName);
ScopeBean scopeBean = new ScopeBean(fullName);
String name = scopeBean.name();
@@ -198,16 +199,16 @@ public class ContextUtility {
Map map = new HashMap<>();
map.put("name", name);
- OResultSet resultSet = oDatabaseDocument.query(select, map);
+ ResultSet resultSet = database.command("sql", select, map);
if(resultSet == null || !resultSet.hasNext()) {
throw new ContextNotFoundException("Error retrieving context with name " + fullName);
}
- OResult oResult = resultSet.next();
- OVertex context = ElementManagementUtility.getElementFromOptional(oResult.getVertex());
+ Result result = resultSet.next();
+ MutableVertex context = (MutableVertex) ElementManagementUtility.getElementFromOptional(result.getVertex());
- logger.trace("Context Representing Vertex : {}", OrientDBUtility.getAsStringForLogging(context));
+ logger.trace("Context Representing Vertex : {}", DBUtility.getAsStringForLogging(context));
if(resultSet.hasNext()) {
throw new ContextNotFoundException("Found more than one context with name " + name
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java
index bbd34bd..7ce0367 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java
@@ -33,7 +33,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityCo
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
import org.gcube.informationsystem.resourceregistry.queries.operators.QueryConditionalOperator;
import org.gcube.informationsystem.resourceregistry.queries.operators.QueryLogicalOperator;
-import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
+import org.gcube.informationsystem.resourceregistry.utils.DBUtility;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.utils.UUIDManager;
@@ -41,12 +41,12 @@ import org.gcube.informationsystem.utils.UUIDUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-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.executor.OResultSet;
+import com.arcadedb.database.Document;
+import com.arcadedb.graph.Edge;
+import com.arcadedb.graph.Vertex;
+import com.arcadedb.graph.Vertex.DIRECTION;
+import com.arcadedb.query.sql.executor.ResultSet;
+import com.arcadedb.remote.RemoteDatabase;
/**
* @author Luca Frosini (ISTI - CNR)
@@ -70,9 +70,9 @@ public class ContextManagement extends EntityElementManagement {}", errorMessage, select);
- OResultSet resultSet = oDatabaseDocument.command(select.toString(), new HashMap<>());
+ ResultSet resultSet = database.command("sql", select.toString(), new HashMap<>());
if (resultSet != null && resultSet.hasNext()) {
throw new ContextAlreadyPresentException(errorMessage.toString());
@@ -180,13 +180,13 @@ public class ContextManagement extends EntityElementManagement parents = getElement().getEdges(ODirection.IN);
- for (OEdge edge : parents) {
+ Iterable parents = getElement().getEdges(DIRECTION.IN);
+ for (Edge edge : parents) {
if (++count > 1) {
throw new ContextException("A " + Context.NAME + " can not have more than one parent");
}
try {
- IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
+ IsParentOfManagement isParentOfManagement = new IsParentOfManagement(database);
isParentOfManagement.setElement(edge);
isParentOfManagement.includeSource(true);
isParentOfManagement.includeTarget(false);
@@ -195,24 +195,24 @@ public class ContextManagement extends EntityElementManagement childrenEdges = getElement().getEdges(ODirection.OUT);
- for (OEdge edge : childrenEdges) {
+ Iterable childrenEdges = getElement().getEdges(DIRECTION.OUT);
+ for (Edge edge : childrenEdges) {
- IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
+ IsParentOfManagement isParentOfManagement = new IsParentOfManagement(database);
isParentOfManagement.setElement(edge);
try {
JsonNode isParentOf = isParentOfManagement.serializeAsJsonNode();
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
} catch (ResourceRegistryException e) {
- logger.error("Unable to correctly serialize {}. {}", edge, OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
+ logger.error("Unable to correctly serialize {}. {}", edge, DBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
throw e;
} catch (Exception e) {
- logger.error("Unable to correctly serialize {}. {}", edge, OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
+ logger.error("Unable to correctly serialize {}. {}", edge, DBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
throw new ResourceRegistryException(e);
}
}
@@ -221,7 +221,7 @@ public class ContextManagement extends EntityElementManagement iterable = getElement().getVertices(ODirection.IN, IsParentOf.NAME);
- for (OVertex p : iterable) {
+ Iterable iterable = getElement().getVertices(DIRECTION.IN, IsParentOf.NAME);
+ for (Vertex p : iterable) {
if (found) {
String message = String.format("{} has more than one parent. {}", Context.NAME,
- OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
+ DBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
throw new ResourceRegistryException(message.toString());
}
parent = p;
@@ -297,7 +297,7 @@ public class ContextManagement extends EntityElementManagement edges = getElement().getEdges(ODirection.IN, IsParentOf.NAME);
+ Iterable edges = getElement().getEdges(DIRECTION.IN, IsParentOf.NAME);
if (edges != null && edges.iterator().hasNext()) {
- Iterator edgeIterator = edges.iterator();
- OEdge edge = edgeIterator.next();
+ Iterator edgeIterator = edges.iterator();
+ Edge edge = edgeIterator.next();
IsParentOfManagement isParentOfManagement = new IsParentOfManagement();
isParentOfManagement.setElement(edge);
isParentOfManagement.internalDelete();
if (edgeIterator.hasNext()) {
throw new ContextException(
- "Seems that the Context has more than one Parent. " + OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
+ "Seems that the Context has more than one Parent. " + DBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
}
}
if (newParentContextManagement != null) {
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
- IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
+ IsParentOfManagement isParentOfManagement = new IsParentOfManagement(database);
isParentOfManagement.setJsonNode(isParentOfJsonNode);
isParentOfManagement.setSourceEntityManagement(newParentContextManagement);
isParentOfManagement.setTargetEntityManagement(this);
@@ -388,13 +388,13 @@ public class ContextManagement extends EntityElementManagement iterable = getElement().getEdges(ODirection.OUT);
- Iterator iterator = iterable.iterator();
+ Iterable iterable = getElement().getEdges(DIRECTION.OUT);
+ Iterator iterator = iterable.iterator();
while (iterator.hasNext()) {
throw new ContextException("Cannot remove a " + Context.NAME + " having children");
}
@@ -403,7 +403,7 @@ public class ContextManagement extends EntityElementManagement iterable = oDatabaseDocument.browseClass(typeName, polymorphic);
- for (ODocument vertex : iterable) {
+ Iterable iterable = database.browseClass(typeName, polymorphic);
+ for (Document vertex : iterable) {
ContextManagement contextManagement = new ContextManagement();
contextManagement.setForceIncludeMeta(forceIncludeMeta);
contextManagement.setForceIncludeAllMeta(forceIncludeAllMeta);
- contextManagement.setElement((OVertex) vertex);
+ contextManagement.setElement((Vertex) vertex);
try {
JsonNode jsonObject = contextManagement.serializeAsJsonNode();
arrayNode.add(jsonObject);
} catch (ResourceRegistryException e) {
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
- vertex.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
+ vertex.toString(), DBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
}
}
try {
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java
index 6c72e09..0173ee5 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java
@@ -18,12 +18,13 @@ import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextMan
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.instances.base.relations.RelationElementManagement;
-import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
+import org.gcube.informationsystem.resourceregistry.utils.DBUtility;
import org.gcube.informationsystem.types.reference.entities.EntityType;
-import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
-import com.orientechnologies.orient.core.record.ODirection;
-import com.orientechnologies.orient.core.record.OVertex;
+import com.arcadedb.graph.Vertex;
+import com.arcadedb.graph.Vertex.DIRECTION;
+import com.arcadedb.remote.RemoteDatabase;
+
/**
* @author Luca Frosini (ISTI - CNR)
@@ -34,9 +35,9 @@ public class IsParentOfManagement extends RelationElementManagement> poolMap;
+ protected final Map> databasesMap;
protected SecurityContext parentSecurityContext;
@@ -120,8 +124,8 @@ public class SecurityContext {
return this.children;
}
- protected ODatabaseDocument getAdminDatabaseDocument() throws ResourceRegistryException {
- return ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
+ protected RemoteDatabase getAdminDatabaseDocument() throws ResourceRegistryException {
+ return ContextUtility.getAdminSecurityContext().getRemoteDatabase(PermissionMode.WRITER);
}
/**
@@ -158,7 +162,7 @@ public class SecurityContext {
* @param orientGraph
* @throws ResourceRegistryException
*/
- public void changeParentSecurityContext(SecurityContext newParentSecurityContext, ODatabaseDocument orientGraph) throws ResourceRegistryException {
+ public void changeParentSecurityContext(SecurityContext newParentSecurityContext, RemoteDatabase database) throws ResourceRegistryException {
if(!hierarchical) {
StringBuilder errorMessage = new StringBuilder();
errorMessage.append("Cannot change parent ");
@@ -166,13 +170,13 @@ public class SecurityContext {
errorMessage.append(" to non hierarchic ");
errorMessage.append(SecurityContext.class.getSimpleName());
errorMessage.append(". ");
- errorMessage.append(OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
+ errorMessage.append(DBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
final String error = errorMessage.toString();
logger.error(error);
throw new RuntimeException(error);
}
- OSecurity oSecurity = getOSecurity(orientGraph);
+// OSecurity oSecurity = getOSecurity(database);
Set allChildren = getAllChildren();
@@ -191,19 +195,19 @@ public class SecurityContext {
*
*/
oldParents.removeAll(newParents);
- removeChildrenHRolesFromParents(oSecurity, oldParents, allChildren);
+ removeChildrenHRolesFromParents(database, oldParents, allChildren);
setParentSecurityContext(newParentSecurityContext);
if(newParentSecurityContext!=null){
for(PermissionMode permissionMode : PermissionMode.values()) {
- List roles = new ArrayList<>();
+ List roles = new ArrayList<>();
for(SecurityContext child : allChildren) {
String roleName = child.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, true);
- ORole role = oSecurity.getRole(roleName);
+ Role role = database.getRole(roleName);
roles.add(role);
}
- newParentSecurityContext.addHierarchicalRoleToParent(oSecurity, permissionMode, roles.toArray(new ORole[allChildren.size()]));
+ newParentSecurityContext.addHierarchicalRoleToParent(database, permissionMode, roles.toArray(new Role[allChildren.size()]));
}
}
@@ -211,7 +215,7 @@ public class SecurityContext {
protected SecurityContext(UUID context, boolean hierarchical) throws ResourceRegistryException {
this.context = context;
- this.poolMap = new HashMap<>();
+ this.databasesMap = new HashMap<>();
this.hierarchical = hierarchical;
this.children = new HashSet<>();
}
@@ -220,38 +224,38 @@ public class SecurityContext {
this(context, true);
}
- private synchronized ODatabasePool getPool(PermissionMode permissionMode, boolean recreate) {
- ODatabasePool pool = null;
+ private synchronized RemoteDatabase getPool(PermissionMode permissionMode, boolean recreate) {
+ RemoteDatabase db = null;
Boolean h = isHierarchicalMode();
- Map pools = poolMap.get(h);
- if(pools == null) {
- pools = new HashMap<>();
- poolMap.put(h, pools);
+ Map databases = databasesMap.get(h);
+ if(databases == null) {
+ databases = new HashMap<>();
+ databasesMap.put(h, databases);
} else {
if(recreate) {
- pool = pools.get(permissionMode);
- if(pool!=null) {
- pool.close();
- pools.remove(permissionMode);
+ db = databases.get(permissionMode);
+ if(db!=null) {
+ db.close();
+ databases.remove(permissionMode);
}
}
}
- pool = pools.get(permissionMode);
+ db = databases.get(permissionMode);
- if(pool == null) {
+ if(db == null) {
String username = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, h);
String password = DatabaseEnvironment.DEFAULT_PASSWORDS.get(permissionMode);
- pool = new ODatabasePool(DatabaseEnvironment.DB_URI, username, password);
+ db = new RemoteDatabase(DatabaseEnvironment.HOST, DatabaseEnvironment.PORT, DatabaseEnvironment.DB ,username, password);
- pools.put(permissionMode, pool);
+ databases.put(permissionMode, db);
}
- return pool;
+ return db;
}
public UUID getUUID() {
@@ -283,16 +287,12 @@ public class SecurityContext {
return stringBuilder.toString();
}
- private OSecurity getOSecurity(ODatabaseDocument oDatabaseDocument) {
- return oDatabaseDocument.getMetadata().getSecurity();
- }
-
- public static Set getContexts(OElement element) {
+ public static Set getContexts(Document element) {
Set contexts = new HashSet<>();
ORecordLazySet oRecordLazySet = element.getProperty(OSecurity.ALLOW_ALL_FIELD);
- for (OIdentifiable oIdentifiable : oRecordLazySet) {
- ODocument oDocument = (ODocument) oIdentifiable;
- String name = oDocument.getProperty("name");
+ for (Identifiable identifiable : oRecordLazySet) {
+ Document oDocument = (Document) identifiable;
+ String name = oDocument.getString("name");
if (name.startsWith(getRoleOrUserName(PermissionMode.WRITER, SecurityType.ROLE))
|| name.startsWith(getRoleOrUserName(PermissionMode.READER, SecurityType.ROLE))) {
String[] list = name.split("_");
@@ -308,111 +308,104 @@ public class SecurityContext {
}
- public void addElement(OElement element) throws ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument adminDatabaseDocument = null;
+ public void addElement(Document element) throws ResourceRegistryException {
+ RemoteDatabase current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase adminDatabase = null;
try {
- adminDatabaseDocument = getAdminDatabaseDocument();
- addElement(element, adminDatabaseDocument);
+ adminDatabase = getAdminDatabaseDocument();
+ addElement(element, adminDatabase);
}finally {
- if(adminDatabaseDocument!=null) {
- adminDatabaseDocument.close();
+ if(adminDatabase!=null) {
+ adminDatabase.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
- protected void allow(OSecurity oSecurity, ODocument oDocument, boolean hierarchic) {
+ protected void allow(RemoteDatabase database, Document document, boolean hierarchic) {
String writerRoleName = getSecurityRoleOrUserName(PermissionMode.WRITER, SecurityType.ROLE, hierarchic);
- oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_ALL, writerRoleName);
+
+ oSecurity.allowRole(document, RestrictedOperation.ALLOW_ALL, writerRoleName);
+
String readerRoleName = getSecurityRoleOrUserName(PermissionMode.READER, SecurityType.ROLE, hierarchic);
- oSecurity.allowRole(oDocument, ORestrictedOperation.ALLOW_READ, readerRoleName);
+
+ oSecurity.allowRole(document, RestrictedOperation.ALLOW_READ, readerRoleName);
}
- public boolean isElementInContext(final OElement element) throws ResourceRegistryException {
- ORID orid = element.getIdentity();
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument contextODatabaseDocument = null;
+ public boolean isElementInContext(final Document element) throws ResourceRegistryException {
+ RID rid = element.getIdentity();
+ RemoteDatabase current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase database = null;
try {
- contextODatabaseDocument = getDatabaseDocument(PermissionMode.READER);
+ database = getRemoteDatabase(PermissionMode.READER);
- ORecord oRecord = contextODatabaseDocument.getRecord(orid);
- if(oRecord==null) {
- return false;
- }
- return true;
+ return database.existsRecord(rid);
} finally {
- if(contextODatabaseDocument!=null) {
- contextODatabaseDocument.close();
+ if(database!=null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
- public void addElement(OElement element, ODatabaseDocument oDatabaseDocument) {
- ODocument oDocument = element.getRecord();
- OSecurity oSecurity = getOSecurity(oDatabaseDocument);
- allow(oSecurity, oDocument, false);
+ public void addElement(Document document, RemoteDatabase database) {
+ allow(database, document, false);
if(hierarchical) {
- allow(oSecurity, oDocument, true);
+ allow(database, document, true);
}
- oDocument.save();
- element.save();
+// document.save();
}
- public void removeElement(OElement element) throws ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument adminDatabaseDocument = null;
+ public void removeElement(Document document) throws ResourceRegistryException {
+ RemoteDatabase current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase adminDatabase = null;
try {
- adminDatabaseDocument = getAdminDatabaseDocument();
- removeElement(element, adminDatabaseDocument);
+ adminDatabase = getAdminDatabaseDocument();
+ removeElement(document, adminDatabase);
}finally {
- if(adminDatabaseDocument!=null) {
- adminDatabaseDocument.close();
+ if(adminDatabase!=null) {
+ adminDatabase.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
- protected void deny(OSecurity oSecurity, ODocument oDocument, boolean hierarchical) {
+ protected void deny(RemoteDatabase database, Document document, boolean hierarchical) {
// The element could be created in such a context so the writerUser for the
// context is allowed by default because it was the creator
String writerUserName = getSecurityRoleOrUserName(PermissionMode.WRITER, SecurityType.USER, hierarchical);
- oSecurity.denyUser(oDocument, ORestrictedOperation.ALLOW_ALL, writerUserName);
+ oSecurity.denyUser(document, RestrictedOperation.ALLOW_ALL, writerUserName);
String readerUserName = getSecurityRoleOrUserName(PermissionMode.WRITER, SecurityType.USER, hierarchical);
- oSecurity.denyUser(oDocument, ORestrictedOperation.ALLOW_READ, readerUserName);
+ oSecurity.denyUser(document, RestrictedOperation.ALLOW_READ, readerUserName);
String writerRoleName = getSecurityRoleOrUserName(PermissionMode.WRITER, SecurityType.ROLE, hierarchical);
- oSecurity.denyRole(oDocument, ORestrictedOperation.ALLOW_ALL, writerRoleName);
+ oSecurity.denyRole(document, RestrictedOperation.ALLOW_ALL, writerRoleName);
String readerRoleName = getSecurityRoleOrUserName(PermissionMode.READER, SecurityType.ROLE, hierarchical);
- oSecurity.denyRole(oDocument, ORestrictedOperation.ALLOW_READ, readerRoleName);
+ oSecurity.denyRole(document, RestrictedOperation.ALLOW_READ, readerRoleName);
}
- public void removeElement(OElement element, ODatabaseDocument oDatabaseDocument) {
- ODocument oDocument = element.getRecord();
- OSecurity oSecurity = getOSecurity(oDatabaseDocument);
- deny(oSecurity, oDocument, false);
+ public void removeElement(Document document, RemoteDatabase database) {
+ deny(database, document, false);
if(hierarchical) {
- deny(oSecurity, oDocument, true);
+ deny(database, document, true);
}
- oDocument.save();
- element.save();
+// document.save();
}
- protected boolean allowed(final ORole role, final ODocument oDocument) {
+ protected boolean allowed(final ORole role, final Document document) {
ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -422,26 +415,22 @@ public class SecurityContext {
public Boolean call() throws Exception {
RequestUtility.getRequestInfo().get().setHierarchicalMode(false);
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument oDatabaseDocument = null;
+ RemoteDatabase current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase database = null;
try {
- oDatabaseDocument = getDatabaseDocument(PermissionMode.READER);
- oDatabaseDocument.activateOnCurrentThread();
- ORecord element = oDatabaseDocument.getRecord(oDocument.getIdentity());
- if(element == null) {
- return false;
- }
- return true;
+ database = getRemoteDatabase(PermissionMode.READER);
+ // database.activateOnCurrentThread();
+ return database.existsRecord(document.getIdentity());
} catch(Exception e) {
return false;
} finally {
- if(oDatabaseDocument!=null) {
- oDatabaseDocument.close();
+ if(database!=null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
@@ -456,48 +445,48 @@ public class SecurityContext {
}
public void create() throws ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument adminDatabaseDocument = null;
+ RemoteDatabase current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase adminDatabase = null;
try {
- adminDatabaseDocument = getAdminDatabaseDocument();
+ adminDatabase = getAdminDatabaseDocument();
- create(adminDatabaseDocument);
+ create(adminDatabase);
- adminDatabaseDocument.commit();
+ adminDatabase.commit();
} finally {
- if(adminDatabaseDocument!=null) {
- adminDatabaseDocument.close();
+ if(adminDatabase!=null) {
+ adminDatabase.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
- protected ORole addExtraRules(ORole role, PermissionMode permissionMode) {
+ protected Role addExtraRules(Role role, PermissionMode permissionMode) {
return role;
}
- protected ORole getSuperRole(OSecurity oSecurity, PermissionMode permissionMode) {
+ protected Role getSuperRole(RemoteDatabase database, PermissionMode permissionMode) {
String superRoleName = permissionMode.name().toLowerCase();
- return oSecurity.getRole(superRoleName);
+ return database.getRole(superRoleName);
}
- protected void addHierarchicalRoleToParent(OSecurity oSecurity, PermissionMode permissionMode, ORole... roles) {
+ protected void addHierarchicalRoleToParent(RemoteDatabase database, PermissionMode permissionMode, ORole... roles) {
String userName = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, true);
- OUser user = oSecurity.getUser(userName);
- for(ORole role : roles) {
+ User user = database.getUser(userName);
+ for(Role role : roles) {
user.addRole(role);
}
user.save();
if(getParentSecurityContext() != null) {
- getParentSecurityContext().addHierarchicalRoleToParent(oSecurity, permissionMode, roles);
+ getParentSecurityContext().addHierarchicalRoleToParent(database, permissionMode, roles);
}
}
- protected void createRolesAndUsers(OSecurity oSecurity) {
+ protected void createRolesAndUsers(RemoteDatabase database) {
boolean[] booleanArray;
if(hierarchical) {
booleanArray = new boolean[] {false, true};
@@ -507,20 +496,20 @@ public class SecurityContext {
for(boolean hierarchical : booleanArray) {
for(PermissionMode permissionMode : PermissionMode.values()) {
- ORole superRole = getSuperRole(oSecurity, permissionMode);
+ Role superRole = getSuperRole(database, permissionMode);
String roleName = getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, hierarchical);
- ORole role = oSecurity.createRole(roleName, superRole, ALLOW_MODES.DENY_ALL_BUT);
+ Role role = database.createRole(roleName, superRole, ALLOW_MODES.DENY_ALL_BUT);
addExtraRules(role, permissionMode);
role.save();
logger.trace("{} created", role);
if(hierarchical && getParentSecurityContext() != null) {
- getParentSecurityContext().addHierarchicalRoleToParent(oSecurity, permissionMode, role);
+ getParentSecurityContext().addHierarchicalRoleToParent(database, permissionMode, role);
}
String userName = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchical);
- OUser user = oSecurity.createUser(userName, DatabaseEnvironment.DEFAULT_PASSWORDS.get(permissionMode),
+ User user = database.createUser(userName, DatabaseEnvironment.DEFAULT_PASSWORDS.get(permissionMode),
role);
user.save();
logger.trace("{} created", user);
@@ -529,70 +518,64 @@ public class SecurityContext {
}
- public void create(ODatabaseDocument oDatabaseDocument) {
- OSecurity oSecurity = getOSecurity(oDatabaseDocument);
- createRolesAndUsers(oSecurity);
+ public void create(RemoteDatabase database) {
+ createRolesAndUsers(database);
logger.trace("Security Context (roles and users) with UUID {} successfully created", context.toString());
}
- private void drop(OSecurity oSecurity, String name, SecurityType securityType) {
- boolean dropped = false;
+ private void drop(RemoteDatabase database, String name, SecurityType securityType) {
switch(securityType) {
case ROLE:
- dropped = oSecurity.dropRole(name);
+ database.dropRole(name);
break;
case USER:
- dropped = oSecurity.dropUser(name);
+ database.dropUser(name);
break;
default:
break;
}
- if(dropped) {
- logger.trace("{} successfully dropped", name);
- } else {
- logger.error("{} was not dropped successfully", name);
- }
+ logger.trace("{} successfully dropped", name);
}
public void delete() throws ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
- ODatabaseDocument adminDatabaseDocument = null;
+ RemoteDatabase remoteDatabase = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+ RemoteDatabase database = null;
try {
- adminDatabaseDocument = getAdminDatabaseDocument();
+ database = getAdminDatabaseDocument();
- delete(adminDatabaseDocument);
+ delete(database);
- adminDatabaseDocument.commit();
+ database.commit();
} finally {
- if(adminDatabaseDocument!=null) {
- adminDatabaseDocument.close();
+ if(database!=null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
- protected void removeChildrenHRolesFromParents(OSecurity oSecurity) {
+ protected void removeChildrenHRolesFromParents(RemoteDatabase remoteDatabase) {
Set parents = getAllParents();
Set allChildren = getAllChildren();
- removeChildrenHRolesFromParents(oSecurity, parents, allChildren);
+ removeChildrenHRolesFromParents(remoteDatabase, parents, allChildren);
}
- protected void removeChildrenHRolesFromParents(OSecurity oSecurity, Set parents, Set children) {
+ protected void removeChildrenHRolesFromParents(RemoteDatabase remoteDatabase, Set parents, Set children) {
for(SecurityContext parent : parents) {
- parent.removeChildrenHRolesFromMyHUsers(oSecurity, children);
+ parent.removeChildrenHRolesFromMyHUsers(remoteDatabase, children);
}
}
- protected void removeChildrenHRolesFromMyHUsers(OSecurity oSecurity, Set children) {
+ protected void removeChildrenHRolesFromMyHUsers(RemoteDatabase database, Set children) {
for(PermissionMode permissionMode : PermissionMode.values()) {
String userName = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, true);
- OUser user = oSecurity.getUser(userName);
+ User user = database.getUser(userName);
for(SecurityContext child : children) {
String roleName = child.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, true);
logger.debug("Going to remove {} from {}", roleName, userName);
@@ -604,16 +587,16 @@ public class SecurityContext {
}
- protected void removeHierarchicRoleFromMyHUser(OSecurity oSecurity, PermissionMode permissionMode, String roleName) {
+ protected void removeHierarchicRoleFromMyHUser(RemoteDatabase database, PermissionMode permissionMode, String roleName) {
String userName = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, true);
- OUser user = oSecurity.getUser(userName);
+ User user = database.getUser(userName);
logger.debug("Going to remove {} from {}", roleName, userName);
boolean removed = user.removeRole(roleName);
logger.trace("{} {} removed from {}", roleName, removed ? "successfully" : "NOT", userName);
user.save();
}
- protected void deleteRolesAndUsers(OSecurity oSecurity) {
+ protected void deleteRolesAndUsers(RemoteDatabase remoteDatabase) {
boolean[] booleanArray;
if(hierarchical) {
booleanArray = new boolean[] {false, true};
@@ -622,47 +605,45 @@ public class SecurityContext {
}
for(boolean hierarchic : booleanArray) {
if(hierarchic) {
- removeChildrenHRolesFromParents(oSecurity);
+ removeChildrenHRolesFromParents(remoteDatabase);
}
for(PermissionMode permissionMode : PermissionMode.values()) {
for(SecurityType securityType : SecurityType.values()) {
String name = getSecurityRoleOrUserName(permissionMode, securityType, hierarchic);
- drop(oSecurity, name, securityType);
+ drop(remoteDatabase, name, securityType);
}
}
}
}
- public void delete(ODatabaseDocument orientGraph) {
- OSecurity oSecurity = getOSecurity(orientGraph);
- delete(oSecurity);
- }
-
- private void delete(OSecurity oSecurity) {
+ public void delete(RemoteDatabase remoteDatabase) {
+// OSecurity oSecurity = getOSecurity(orientGraph);
logger.trace("Going to remove Security Context (roles and users) with UUID {}", context.toString());
- deleteRolesAndUsers(oSecurity);
+ deleteRolesAndUsers(remoteDatabase);
logger.trace("Security Context (roles and users) with UUID {} successfully removed", context.toString());
}
- public ODatabaseDocument getDatabaseDocument(PermissionMode permissionMode) throws ResourceRegistryException {
- try {
- ODatabasePool oDatabasePool = getPool(permissionMode, false);
- ODatabaseSession oDatabaseSession = null;
- try {
- oDatabaseSession = oDatabasePool.acquire();
- if(oDatabaseSession.isClosed()) {
- // Enforcing pool recreation
- throw new Exception();
- }
- }catch (Exception e) {
- oDatabasePool = getPool(permissionMode, true);
- oDatabaseSession = oDatabasePool.acquire();
- }
- oDatabaseSession.activateOnCurrentThread();
- return oDatabaseSession;
- }catch (Exception e) {
- throw new ResourceRegistryException(e);
- }
+ public RemoteDatabase getRemoteDatabase(PermissionMode permissionMode) throws ResourceRegistryException {
+// try {
+// ODatabasePool oDatabasePool = getPool(permissionMode, false);
+// ODatabaseSession oDatabaseSession = null;
+// try {
+// oDatabaseSession = oDatabasePool.acquire();
+// if(oDatabaseSession.isClosed()) {
+// // Enforcing pool recreation
+// throw new Exception();
+// }
+// }catch (Exception e) {
+// oDatabasePool = getPool(permissionMode, true);
+// oDatabaseSession = oDatabasePool.acquire();
+// }
+// oDatabaseSession.activateOnCurrentThread();
+// return oDatabaseSession;
+// }catch (Exception e) {
+// throw new ResourceRegistryException(e);
+// }
+
+ return null;
}
@Override
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java
index 281e80b..2714324 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseEnvironment.java
@@ -45,22 +45,8 @@ import org.gcube.informationsystem.types.reference.relations.RelationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.orientechnologies.common.log.OLogManager;
-import com.orientechnologies.orient.client.remote.OStorageRemote.CONNECTION_STRATEGY;
-import com.orientechnologies.orient.core.db.ODatabase.ATTRIBUTES;
-import com.orientechnologies.orient.core.db.ODatabasePool;
-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.orientechnologies.orient.core.record.OElement;
+import com.arcadedb.database.Document;
+import com.arcadedb.remote.RemoteDatabase;
/**
* @author Luca Frosini (ISTI - CNR)
@@ -71,12 +57,13 @@ public class DatabaseEnvironment {
protected static final String PROPERTY_FILENAME = "config.properties";
+ public static final String HOST;
private static final String HOST_VARNAME = "HOST";
- private static final String REMOTE_PROTOCOL;
- private static final String REMOTE_PROTOCOL_VARNAME = "REMOTE_PROTOCOL";
+ public static final int PORT;
+ private static final String PORT_VARNAME = "REMOTE_PROTOCOL";
- private static final String DB;
+ public static final String DB;
private static final String DB_VARNAME = "DB";
private static final String ROOT_USERNAME;
@@ -87,36 +74,25 @@ public class DatabaseEnvironment {
public static final String DEFAULT_ADMIN_ROLE = "admin";
- private static final String CHANGED_ADMIN_USERNAME;
- private static final String CHANGED_ADMIN_USERNAME_VARNAME = "CHANGED_ADMIN_USERNAME";
+ private static final String ADMIN_USERNAME;
+ private static final String ADMIN_USERNAME_VARNAME = "ADMIN_USERNAME";
- private static final String CHANGED_ADMIN_PASSWORD;
- private static final String CHANGED_ADMIN_PASSWORD_VARNAME = "CHANGED_ADMIN_PASSWORD";
+ private static final String ADMIN_PASSWORD;
+ private static final String ADMIN_PASSWORD_VARNAME = "ADMIN_PASSWORD";
- private static final String DEFAULT_CREATED_WRITER_USER_PASSWORD;
- private static final String DEFAULT_CREATED_WRITER_USER_PASSWORD_VARNAME = "DEFAULT_CREATED_WRITER_USER_PASSWORD";
+ private static final String WRITER_USER_PASSWORD;
+ private static final String WRITER_USER_PASSWORD_VARNAME = "WRITER_USER_PASSWORD";
- private static final String DEFAULT_CREATED_READER_USER_PASSWORD;
- private static final String DEFAULT_CREATED_READER_USER_PASSWORD_VARNAME = "DEFAULT_CREATED_READER_USER_PASSWORD";
+ private static final String READER_USER_PASSWORD;
+ private static final String READER_USER_PASSWORD_VARNAME = "READER_USER_PASSWORD";
public static final Map DEFAULT_PASSWORDS;
- private static final String HOSTS;
-
- private static final String SERVER_URI;
- public static final String DB_URI;
-
- public static final CONNECTION_STRATEGY CONNECTION_STRATEGY_PARAMETER = CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT;
-
-
protected static final String DB_KEY_FILENAME_VARNAME = "DB_KEY_FILENAME";
protected static final String DB_KEY_ALGORITHM_VARNAME = "DB_KEY_ALGORITHM";
private static final Key KEY;
- public static final String VERTEX_CLASS_NAME = OClass.VERTEX_CLASS_NAME;
- public static final String EDGE_CLASS_NAME = OClass.EDGE_CLASS_NAME;
-
static {
Properties properties = new Properties();
InputStream input = null;
@@ -128,41 +104,25 @@ public class DatabaseEnvironment {
// load a properties file
properties.load(input);
- HOSTS = properties.getProperty(HOST_VARNAME);
+ HOST = properties.getProperty(HOST_VARNAME);
- REMOTE_PROTOCOL = properties.getProperty(REMOTE_PROTOCOL_VARNAME);
+ PORT = Integer.valueOf(properties.getProperty(PORT_VARNAME));
DB = properties.getProperty(DB_VARNAME);
- SERVER_URI = REMOTE_PROTOCOL + HOSTS;
- DB_URI = SERVER_URI + "/" + DB;
ROOT_USERNAME = properties.getProperty(ROOT_USERNAME_VARNAME);
ROOT_PASSWORD = properties.getProperty(ROOT_PASSWORD_VARNAME);
- String changedAdminUsername = null;
- try {
- changedAdminUsername = properties.getProperty(CHANGED_ADMIN_USERNAME_VARNAME);
- if(changedAdminUsername == null) {
- // To be compliant with old configuration.properties which does not have
- // CHANGED_ADMIN_USERNAME property we use the db name as admin username
- changedAdminUsername = DB;
- }
- } catch(Exception e) {
- // To be compliant with old configuration.properties which does not have
- // CHANGED_ADMIN_USERNAME property we use the db name as admin username
- changedAdminUsername = DB;
- }
- CHANGED_ADMIN_USERNAME = changedAdminUsername;
+ ADMIN_USERNAME = properties.getProperty(ADMIN_USERNAME_VARNAME);
+ ADMIN_PASSWORD = properties.getProperty(ADMIN_PASSWORD_VARNAME);
- CHANGED_ADMIN_PASSWORD = properties.getProperty(CHANGED_ADMIN_PASSWORD_VARNAME);
-
- DEFAULT_CREATED_WRITER_USER_PASSWORD = properties.getProperty(DEFAULT_CREATED_WRITER_USER_PASSWORD_VARNAME);
- DEFAULT_CREATED_READER_USER_PASSWORD = properties.getProperty(DEFAULT_CREATED_READER_USER_PASSWORD_VARNAME);
+ WRITER_USER_PASSWORD = properties.getProperty(WRITER_USER_PASSWORD_VARNAME);
+ READER_USER_PASSWORD = properties.getProperty(READER_USER_PASSWORD_VARNAME);
DEFAULT_PASSWORDS = new HashMap();
- DEFAULT_PASSWORDS.put(PermissionMode.WRITER, DEFAULT_CREATED_WRITER_USER_PASSWORD);
- DEFAULT_PASSWORDS.put(PermissionMode.READER, DEFAULT_CREATED_READER_USER_PASSWORD);
+ DEFAULT_PASSWORDS.put(PermissionMode.WRITER, WRITER_USER_PASSWORD);
+ DEFAULT_PASSWORDS.put(PermissionMode.READER, READER_USER_PASSWORD);
} catch(Throwable e) {
logger.error("Unable to load properties from {}", PROPERTY_FILENAME);
@@ -172,16 +132,15 @@ public class DatabaseEnvironment {
// Used to Persist Context and their relations
try {
- boolean created = initGraphDB();
+
+ logger.info("Connecting as {} to {}:{}/{}", ROOT_USERNAME, HOST, PORT, DB);
+ RemoteDatabase database = new RemoteDatabase(HOST, PORT, DB, ADMIN_USERNAME, ADMIN_PASSWORD);
+
+ boolean created = initGraphDB(database);
if(created) {
- ODatabasePool pool = new ODatabasePool(DatabaseEnvironment.DB_URI, CHANGED_ADMIN_USERNAME,
- CHANGED_ADMIN_PASSWORD);
- ODatabaseDocument oDatabaseDocument = pool.acquire();
- AdminSecurityContext.getInstance().create(oDatabaseDocument);
- oDatabaseDocument.commit();
- oDatabaseDocument.close();
- pool.close();
+
+ AdminSecurityContext.getInstance().create(database);
QueryTemplatesSecurityContext.getInstance().create();
TypeSecurityContext.getInstance().create();
@@ -236,7 +195,7 @@ public class DatabaseEnvironment {
schemaToBeCreated.add(Property.class);
schemaToBeCreated.add(Metadata.class);
for(Class extends Element> clazz : schemaToBeCreated) {
- ElementManagement extends OElement,?> erManagement = new PropertyTypeDefinitionManagement();
+ ElementManagement extends Document,?> erManagement = new PropertyTypeDefinitionManagement();
erManagement.setJson(TypeMapper.serializeType(clazz));
erManagement.create();
}
@@ -310,15 +269,15 @@ public class DatabaseEnvironment {
}
}
- protected static void setDateTimeFormat(ODatabaseDocument oDatabaseDocument) {
- oDatabaseDocument.set(ATTRIBUTES.DATETIMEFORMAT, Element.DATETIME_PATTERN);
+ protected static void setDateTimeFormat(RemoteDatabase database) {
+ // TODO
+ // oDatabaseDocument.set(ATTRIBUTES.DATETIMEFORMAT, Element.DATETIME_PATTERN);
}
- @Deprecated
- // This code must be removed for OrientDB versions higher than 3.2.X
- protected static void setRecordLevelSecurity(OMetadata oMetadata) {
- logger.trace(
- "Setting Record-level Security (see https://orientdb.org/docs/3.2.x/security/Database-Security.html#record-level-security-deprecated-in-v-31)");
+ protected static void setRecordLevelSecurity(RemoteDatabase database) {
+ logger.trace("Setting Record-level Security");
+
+ /*
OSchema oSchema = oMetadata.getSchema();
OClass oRestricted = oSchema.getClass(OSecurity.RESTRICTED_CLASSNAME);
@@ -327,51 +286,41 @@ public class DatabaseEnvironment {
OClass e = oSchema.getClass(EDGE_CLASS_NAME);
e.addSuperClass(oRestricted);
+ */
}
- private static boolean initGraphDB() throws Exception {
- OLogManager.instance().setWarnEnabled(false);
- OLogManager.instance().setErrorEnabled(false);
- OLogManager.instance().setInfoEnabled(false);
- OLogManager.instance().setDebugEnabled(false);
+ private static boolean initGraphDB(RemoteDatabase database) throws Exception {
+
+
- logger.info("Connecting as {} to {}", ROOT_USERNAME, DB_URI);
- OrientDB orientDB = new OrientDB(SERVER_URI, ROOT_USERNAME, ROOT_PASSWORD, OrientDBConfig.defaultConfig());
try {
- if(!orientDB.exists(DB)) {
+ if(!!database.exists()) {
- logger.info("The database {} does not exist. Going to create it.", DB_URI);
- orientDB.create(DB, ODatabaseType.PLOCAL);
+ logger.info("The database {} does not exist. Going to create it.", DB);
+ database.create();
- ODatabasePool pool = new ODatabasePool(orientDB, DB, ROOT_USERNAME, ROOT_PASSWORD);
- ODatabaseSession oDatabaseSession = pool.acquire();
+ DatabaseEnvironment.setDateTimeFormat(database);
- DatabaseEnvironment.setDateTimeFormat(oDatabaseSession);
+ List databases = new ArrayList<>();
+ databases.add(DB);
- OMetadata oMetadata = oDatabaseSession.getMetadata();
- OSecurity oSecurity = oMetadata.getSecurity();
+ // TODO Create Role
+// ORole adminRole = oSecurity.getRole(DEFAULT_ADMIN_ROLE);
+// OUser newAdminUser = oSecurity.createUser(CHANGED_ADMIN_USERNAME, CHANGED_ADMIN_PASSWORD, adminRole);
+//
+ logger.trace("Creating new admin named '{}'", ADMIN_USERNAME);
+ database.createUser(ADMIN_USERNAME, ADMIN_PASSWORD, databases);
+ setRecordLevelSecurity(database);
- logger.trace("Creating new admin named '{}'", CHANGED_ADMIN_USERNAME);
- ORole adminRole = oSecurity.getRole(DEFAULT_ADMIN_ROLE);
- OUser newAdminUser = oSecurity.createUser(CHANGED_ADMIN_USERNAME, CHANGED_ADMIN_PASSWORD, adminRole);
- newAdminUser.save();
-
- DatabaseEnvironment.changeDefaultAdminPassword(oSecurity);
-
- setRecordLevelSecurity(oMetadata);
-
- oDatabaseSession.commit();
- oDatabaseSession.close();
-
- pool.close();
+ database.commit();
return true;
}
return false;
} finally {
- orientDB.close();
+ database.close();
}
}
@@ -379,28 +328,4 @@ public class DatabaseEnvironment {
return KEY;
}
- @Deprecated
- // This code must be removed for OrientDB versions higher than 3.2.X
- public static void changeDefaultAdminPassword(OSecurity oSecurity) {
- for(PermissionMode permissionMode : DEFAULT_PASSWORDS.keySet()) {
- try {
- logger.trace("Going to update password for user {}", permissionMode.toString());
- OUser oUser = oSecurity.getUser(permissionMode.toString());
- oUser.setPassword(DEFAULT_PASSWORDS.get(permissionMode));
- oUser.save();
- logger.trace("Updated password for user {}", permissionMode.toString());
- }catch (Exception e) {
- logger.trace("Unable to update password for user {}. {}", permissionMode.toString(), e.getMessage());
- throw new RuntimeException(e);
- }
- }
-
- try {
- logger.trace("Removing 'admin' user");
- oSecurity.dropUser("admin");
- }catch (Exception e) {
- logger.info("Unable to delete admin user. {}", e.getMessage());
- }
- }
-
}
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java
index 97ece1e..49426b3 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java
@@ -30,7 +30,6 @@ import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.properties.Metadata;
-import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
@@ -52,7 +51,7 @@ import org.gcube.informationsystem.resourceregistry.types.CachedType;
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
import org.gcube.informationsystem.resourceregistry.utils.MetadataOrient;
import org.gcube.informationsystem.resourceregistry.utils.MetadataUtility;
-import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
+import org.gcube.informationsystem.resourceregistry.utils.DBUtility;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
@@ -63,18 +62,17 @@ import org.gcube.informationsystem.utils.UUIDManager;
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.orientechnologies.orient.core.metadata.schema.OProperty;
-import com.orientechnologies.orient.core.metadata.schema.OType;
-import com.orientechnologies.orient.core.record.OElement;
-import com.orientechnologies.orient.core.record.impl.ODocument;
-import com.orientechnologies.orient.core.util.ODateHelper;
+import com.arcadedb.database.Document;
+import com.arcadedb.database.MutableDocument;
+import com.arcadedb.graph.Vertex.DIRECTION;
+import com.arcadedb.remote.RemoteDatabase;
+import com.arcadedb.schema.DocumentType;
+import com.arcadedb.schema.Property;
/**
* @author Luca Frosini (ISTI - CNR)
*/
-public abstract class ElementManagement {
+public abstract class ElementManagement {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -89,11 +87,12 @@ public abstract class ElementManagement {
protected Class elementClass;
protected final AccessType accessType;
- protected ODatabaseDocument oDatabaseDocument;
+ protected RemoteDatabase database;
protected UUID uuid;
protected JsonNode jsonNode;
- protected OClass oClass;
+// protected OClass documentType;
+ protected DocumentType documentType;
protected String typeName;
protected JsonNode self;
@@ -182,6 +181,19 @@ public abstract class ElementManagement {
this.forceIncludeMeta = false;
this.forceIncludeAllMeta = false;
}
+
+ public static DIRECTION opposite(DIRECTION d) {
+ switch (d) {
+ case IN:
+ return DIRECTION.OUT;
+
+ case OUT:
+ return DIRECTION.IN;
+
+ default:
+ return d;
+ }
+ }
public boolean isForceIncludeMeta() {
return forceIncludeMeta;
@@ -278,28 +290,24 @@ public abstract class ElementManagement {
checkJsonNode();
}
- public void setODatabaseDocument(ODatabaseDocument oDatabaseDocument) {
- this.oDatabaseDocument = oDatabaseDocument;
+ public void setDatabase(RemoteDatabase remoteDatabase) {
+ this.database = remoteDatabase;
}
- public void setOClass(OClass oClass) {
- this.oClass = oClass;
- }
-
- protected OClass getOClass() throws SchemaException, ResourceRegistryException {
- if(oClass == null) {
+ protected DocumentType getDocumentType() throws SchemaException, ResourceRegistryException {
+ if(documentType == null) {
if(element != null) {
try {
- oClass = ElementManagementUtility.getOClass(element);
+ documentType = ElementManagementUtility.getDocumentType(element);
if(typeName==null) {
- typeName = oClass.getName();
+ typeName = documentType.getName();
}
- getCachedType().setOClass(oClass);
+ getCachedType().setDocumentType(documentType);
}catch (ResourceRegistryException e) {
try {
- oClass = getCachedType().getOClass();
+ documentType = getCachedType().getDocumentType();
if(typeName==null) {
- typeName = oClass.getName();
+ typeName = documentType.getName();
}
}catch (Exception e1) {
throw e;
@@ -309,14 +317,14 @@ public abstract class ElementManagement {
if(typeName==null) {
throw new SchemaException("Unknown type name. Please set it first.");
}
- oClass = getCachedType().getOClass();
+ documentType = getCachedType().getDocumentType();
AccessType gotAccessType = cachedType.getAccessType();
if(accessType!=gotAccessType) {
throw new SchemaException(typeName + " is not a " + accessType.getName());
}
}
}
- return oClass;
+ return documentType;
}
@SuppressWarnings("unchecked")
@@ -349,7 +357,7 @@ public abstract class ElementManagement {
public String getTypeName() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
if(typeName==null) {
if(element!=null) {
- typeName = getOClass().getName();
+ typeName = getDocumentType().getName();
}
if(typeName==null && jsonNode!=null) {
@@ -380,7 +388,7 @@ public abstract class ElementManagement {
if(this.typeName == null) {
this.typeName = TypeUtility.getTypeName(jsonNode);
- getOClass();
+ getDocumentType();
} else {
checkERMatch();
}
@@ -396,7 +404,7 @@ public abstract class ElementManagement {
throw new ResourceRegistryException(error);
}
}
- getOClass();
+ getDocumentType();
}
@@ -414,8 +422,8 @@ public abstract class ElementManagement {
}
}
- private void analizeProperty(OElement element, String key, ObjectNode objectNode) throws ResourceRegistryException {
- Object object = element.getProperty(key);
+ private void analizeProperty(Document element, String key, ObjectNode objectNode) throws ResourceRegistryException {
+ Object object = element.get(key);
if(object == null) {
objectNode.replace(key, null);
return;
@@ -432,7 +440,7 @@ public abstract class ElementManagement {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();
- OElement element = getElement();
+ El element = getElement();
Set keys = element.getPropertyNames();
/* Add first these key to provide an order in Json */
@@ -539,13 +547,13 @@ public abstract class ElementManagement {
element = reallyCreate();
- element.setProperty(IdentifiableElement.ID_PROPERTY, uuid.toString());
+ ((MutableDocument) element).set(IdentifiableElement.ID_PROPERTY, uuid.toString());
MetadataUtility.addMetadata(element);
- getWorkingContext().addElement(element, oDatabaseDocument);
+ getWorkingContext().addElement(element, database);
- element.save();
+// element.save();
sanityCheck();
@@ -567,7 +575,7 @@ public abstract class ElementManagement {
MetadataUtility.updateModifiedByAndLastUpdate(element);
- element.save();
+// element.save();
sanityCheck();
@@ -601,8 +609,8 @@ public abstract class ElementManagement {
}
this.element = element;
this.uuid = UUIDUtility.getUUID(element);
- OClass oClass = getOClass();
- this.typeName = oClass.getName();
+ DocumentType documentType = getDocumentType();
+ this.typeName = documentType.getName();
}
protected abstract NotFoundException getSpecificNotFoundException(NotFoundException e);
@@ -634,7 +642,7 @@ public abstract class ElementManagement {
if(uuid == null) {
throw new NotFoundException("null UUID does not allow to retrieve the Element");
}
- return OrientDBUtility.getElementByUUID(oDatabaseDocument, typeName == null ? accessType.getName() : typeName, uuid,
+ return DBUtility.getElementByUUID(database, typeName == null ? accessType.getName() : typeName, uuid,
elementClass);
} catch(NotFoundException e) {
throw getSpecificNotFoundException(e);
@@ -647,7 +655,7 @@ public abstract class ElementManagement {
public El retrieveElementFromAnyContext() throws NotFoundException, ResourceRegistryException {
try {
- return OrientDBUtility.getElementByUUIDAsAdmin(typeName == null ? accessType.getName() : typeName, uuid,
+ return DBUtility.getElementByUUIDAsAdmin(typeName == null ? accessType.getName() : typeName, uuid,
elementClass);
} catch(NotFoundException e) {
throw getSpecificNotFoundException(e);
@@ -661,9 +669,9 @@ public abstract class ElementManagement {
public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException;
public String all(boolean polymorphic) throws ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
- oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
+ database = getWorkingContext().getRemoteDatabase(PermissionMode.READER);
setAsEntryPoint();
setOperation(Operation.QUERY);
return reallyGetAll(polymorphic);
@@ -672,20 +680,19 @@ public abstract class ElementManagement {
} catch(Exception e) {
throw new ResourceRegistryException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
- }
-
- if(current!=null) {
- current.activateOnCurrentThread();
+ if(database != null) {
+ database.close();
}
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
- oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
+ database = getWorkingContext().getRemoteDatabase(PermissionMode.READER);
setAsEntryPoint();
setOperation(Operation.EXISTS);
@@ -699,22 +706,22 @@ public abstract class ElementManagement {
logger.error("Unable to find {} with UUID {}", accessType.getName(), uuid, e);
throw new ResourceRegistryException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
+ if(database != null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// database.activateOnCurrentThread();
+// }
}
}
public String createOrUpdate()
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
- oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
- oDatabaseDocument.begin();
+ database = getWorkingContext().getRemoteDatabase(PermissionMode.WRITER);
+ database.begin();
boolean update = false;
try {
setAsEntryPoint();
@@ -729,7 +736,7 @@ public abstract class ElementManagement {
internalCreate();
}
- oDatabaseDocument.commit();
+ database.commit();
if(update) {
setReload(true);
@@ -741,38 +748,37 @@ public abstract class ElementManagement {
} catch(ResourceRegistryException e) {
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw e;
} catch(Exception e) {
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid, e);
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw new ResourceRegistryException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
+ if(database != null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
public String create() throws AlreadyPresentException, ResourceRegistryException {
-
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
- oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
- oDatabaseDocument.begin();
+ database = getWorkingContext().getRemoteDatabase(PermissionMode.WRITER);
+ database.begin();
setAsEntryPoint();
internalCreate();
- oDatabaseDocument.commit();
+ database.commit();
// TODO Notify to subscriptionNotification
@@ -780,32 +786,31 @@ public abstract class ElementManagement {
} catch(ResourceRegistryException e) {
logger.error("Unable to create {}", accessType.getName());
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw e;
} catch(Exception e) {
logger.error("Unable to create {}", accessType.getName(), e);
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw new ResourceRegistryException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
+ if(database != null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
-
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
- oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
+ database = getWorkingContext().getRemoteDatabase(PermissionMode.READER);
setAsEntryPoint();
setOperation(Operation.READ);
@@ -820,27 +825,26 @@ public abstract class ElementManagement {
logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid, e);
throw new ResourceRegistryException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
+ if(database != null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
-
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
- oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
- oDatabaseDocument.begin();
+ database = getWorkingContext().getRemoteDatabase(PermissionMode.WRITER);
+ database.begin();
setAsEntryPoint();
internalUpdate();
- oDatabaseDocument.commit();
+ database.commit();
setReload(true);
@@ -850,74 +854,74 @@ public abstract class ElementManagement {
} catch(ResourceRegistryException e) {
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw e;
} catch(Exception e) {
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid, e);
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw new ResourceRegistryException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
+ if(database != null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
public void delete() throws NotFoundException, AvailableInAnotherContextException, SchemaViolationException, ResourceRegistryException {
logger.trace("Going to delete {} instance with UUID {}", accessType.getName(), uuid);
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
// oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
- oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
- oDatabaseDocument.begin();
+ database = getWorkingContext().getRemoteDatabase(PermissionMode.WRITER);
+ database.begin();
setAsEntryPoint();
internalDelete();
if(!dryRun) {
- oDatabaseDocument.commit();
+ database.commit();
logger.info("{} with UUID {} was successfully deleted.", accessType.getName(), uuid);
}else {
- oDatabaseDocument.rollback();
+ database.rollback();
}
} catch(ResourceRegistryException e) {
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid);
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw e;
} catch(Exception e) {
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid, e);
- if(oDatabaseDocument != null) {
- oDatabaseDocument.rollback();
+ if(database != null) {
+ database.rollback();
}
throw new ResourceRegistryException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
+ if(database != null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
public Set getContextsSet() throws NotFoundException, ContextException, ResourceRegistryException {
logger.trace("Going to get contexts for {} instance with UUID {}", typeName, uuid);
- ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
+// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
- oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
+ database = adminSecurityContext.getRemoteDatabase(PermissionMode.READER);
setAsEntryPoint();
setOperation(Operation.GET_METADATA);
@@ -931,13 +935,13 @@ public abstract class ElementManagement {
logger.error("Unable to get contexts for {} with UUID {}", typeName, uuid, e);
throw new ContextException(e);
} finally {
- if(oDatabaseDocument != null) {
- oDatabaseDocument.close();
+ if(database != null) {
+ database.close();
}
- if(current!=null) {
- current.activateOnCurrentThread();
- }
+// if(current!=null) {
+// current.activateOnCurrentThread();
+// }
}
}
@@ -1071,39 +1075,40 @@ public abstract class ElementManagement {
return map;
}
- public void setProperty(OProperty oProperty, String key, JsonNode value) throws Exception {
- switch (oProperty.getType()) {
+ public void setProperty(Property property, String key, JsonNode value) throws Exception {
+
+ switch (property.getType()) {
case EMBEDDED:
- ODocument oDocument = PropertyElementManagement.getPropertyDocument(value);
- element.setProperty(key, oDocument, OType.EMBEDDED);
+ Document document = PropertyElementManagement.getPropertyDocument(value);
+ ((MutableDocument) element).set(key, document, com.arcadedb.schema.Type.EMBEDDED);
break;
- case EMBEDDEDLIST:
+ case LIST:
List