Fixes #13180: Migrate OrientDB from version 2.2.X to 3.0.X

Task-Url: https://support.d4science.org/issues/13180

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@177123 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-02-13 15:53:17 +00:00
parent 1e14003aa8
commit e7e7cc588e
3 changed files with 68 additions and 70 deletions

View File

@ -156,7 +156,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
if(oClass == null) { if(oClass == null) {
if(element != null) { if(element != null) {
OrientElement orientElement = (OrientElement) element; OrientElement orientElement = (OrientElement) element;
OMetadata oMetadata = orientElement.getGraph().getRawGraph().getMetadata(); OMetadata oMetadata = orientElement.getRecord().getDatabase().getMetadata();
OSchema oSchema = oMetadata.getSchema(); OSchema oSchema = oMetadata.getSchema();
String type = orientElement.getRecord().getClassName(); String type = orientElement.getRecord().getClassName();
oClass = oSchema.getClass(type); oClass = oSchema.getClass(type);

View File

@ -31,7 +31,6 @@ import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintO
import org.gcube.informationsystem.resourceregistry.utils.Utility; import org.gcube.informationsystem.resourceregistry.utils.Utility;
import org.gcube.informationsystem.utils.ISMapper; import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;

View File

@ -25,10 +25,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.metadata.security.ORole; import com.orientechnologies.orient.core.metadata.security.ORole;
import com.orientechnologies.orient.core.metadata.security.OSecurity; import com.orientechnologies.orient.core.metadata.security.OSecurity;
import com.orientechnologies.orient.core.metadata.security.OUser; import com.orientechnologies.orient.core.metadata.security.OUser;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
public class ContextManagementTest extends ScopedTest { public class ContextManagementTest extends ScopedTest {
@ -40,8 +40,8 @@ public class ContextManagementTest extends ScopedTest {
protected void assertions(Context pre, Context post, boolean checkParent, boolean create) protected void assertions(Context pre, Context post, boolean checkParent, boolean create)
throws ResourceRegistryException { throws ResourceRegistryException {
if (checkParent) { if(checkParent) {
if (pre.getHeader() != null) { if(pre.getHeader() != null) {
FacetManagementTest.checkHeader(post, pre.getHeader().getUUID(), create); FacetManagementTest.checkHeader(post, pre.getHeader().getUUID(), create);
} else { } else {
FacetManagementTest.checkHeader(post, null, create); FacetManagementTest.checkHeader(post, null, create);
@ -49,7 +49,7 @@ public class ContextManagementTest extends ScopedTest {
} }
Assert.assertTrue(pre.getName().compareTo(post.getName()) == 0); Assert.assertTrue(pre.getName().compareTo(post.getName()) == 0);
if (checkParent && pre.getParent() != null && post.getParent() != null) { if(checkParent && pre.getParent() != null && post.getParent() != null) {
Context preParent = pre.getParent().getSource(); Context preParent = pre.getParent().getSource();
Context postParent = post.getParent().getSource(); Context postParent = post.getParent().getSource();
assertions(preParent, postParent, false, false); assertions(preParent, postParent, false, false);
@ -62,8 +62,8 @@ public class ContextManagementTest extends ScopedTest {
ContextUtility.getInstance().addSecurityContext(contextSecurityContext.getUUID().toString(), ContextUtility.getInstance().addSecurityContext(contextSecurityContext.getUUID().toString(),
contextSecurityContext); contextSecurityContext);
OrientGraph orientGraph = contextSecurityContext.getGraph(PermissionMode.READER); ODatabaseSession oDatabaseSession = contextSecurityContext.getDatabaseSession(PermissionMode.READER);
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata().getSecurity(); OSecurity oSecurity = oDatabaseSession.getMetadata().getSecurity();
SecurityContext securityContext = null; SecurityContext securityContext = null;
if(deleted) { if(deleted) {
@ -72,9 +72,9 @@ public class ContextManagementTest extends ScopedTest {
securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid); securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
} }
boolean[] booleanArray = new boolean[] { false, true }; boolean[] booleanArray = new boolean[] {false, true};
for (boolean hierarchic : booleanArray) { for(boolean hierarchic : booleanArray) {
for (PermissionMode permissionMode : PermissionMode.values()) { for(PermissionMode permissionMode : PermissionMode.values()) {
String role = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, hierarchic); String role = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, hierarchic);
ORole oRole = oSecurity.getRole(role); ORole oRole = oSecurity.getRole(role);
Assert.assertEquals(oRole == null, deleted); Assert.assertEquals(oRole == null, deleted);
@ -82,20 +82,21 @@ public class ContextManagementTest extends ScopedTest {
String user = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic); String user = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic);
OUser oUser = oSecurity.getUser(user); OUser oUser = oSecurity.getUser(user);
Assert.assertEquals(oUser == null, deleted); Assert.assertEquals(oUser == null, deleted);
if(oUser!=null) { if(oUser != null) {
Assert.assertTrue(oUser.hasRole(oRole.getName(), false)); Assert.assertTrue(oUser.hasRole(oRole.getName(), false));
} }
if(hierarchic) { if(hierarchic) {
SecurityContext parent = null; SecurityContext parent = null;
if(deleted){ if(deleted) {
if(oldParentUUID!=null) { if(oldParentUUID != null) {
parent = ContextUtility.getInstance().getSecurityContextByUUID(oldParentUUID); parent = ContextUtility.getInstance().getSecurityContextByUUID(oldParentUUID);
} }
} }
parent = securityContext.getParentSecurityContext(); parent = securityContext.getParentSecurityContext();
while(parent!=null) { while(parent != null) {
String parentUser = parent.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic); String parentUser = parent.getSecurityRoleOrUserName(permissionMode, SecurityType.USER,
hierarchic);
OUser parentOUser = oSecurity.getUser(parentUser); OUser parentOUser = oSecurity.getUser(parentUser);
Assert.assertTrue(parentOUser != null); Assert.assertTrue(parentOUser != null);
Assert.assertEquals(parentOUser.hasRole(oRole.getName(), false), !deleted); Assert.assertEquals(parentOUser.hasRole(oRole.getName(), false), !deleted);
@ -145,7 +146,7 @@ public class ContextManagementTest extends ScopedTest {
SecurityContext securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid); SecurityContext securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
UUID oldParentUUID = null; UUID oldParentUUID = null;
if(securityContext.getParentSecurityContext()!=null) { if(securityContext.getParentSecurityContext() != null) {
oldParentUUID = securityContext.getParentSecurityContext().getUUID(); oldParentUUID = securityContext.getParentSecurityContext().getUUID();
} }
@ -164,7 +165,7 @@ public class ContextManagementTest extends ScopedTest {
try { try {
Context c = create(context); Context c = create(context);
throw new RuntimeException(ISMapper.marshal(c) + " was created successfully. This is not what we expected"); throw new RuntimeException(ISMapper.marshal(c) + " was created successfully. This is not what we expected");
} catch (ContextAlreadyPresentException e) { } catch(ContextAlreadyPresentException e) {
logger.debug("As expected {} cannot be created.", ISMapper.marshal(context)); logger.debug("As expected {} cannot be created.", ISMapper.marshal(context));
} }
} }
@ -173,7 +174,7 @@ public class ContextManagementTest extends ScopedTest {
try { try {
Context c = update(context); Context c = update(context);
throw new RuntimeException(ISMapper.marshal(c) + " was updated successfully. This is not what we expected"); throw new RuntimeException(ISMapper.marshal(c) + " was updated successfully. This is not what we expected");
} catch (ContextAlreadyPresentException e) { } catch(ContextAlreadyPresentException e) {
logger.debug("As expected {} cannot be updated.", ISMapper.marshal(context)); logger.debug("As expected {} cannot be updated.", ISMapper.marshal(context));
} }
} }
@ -183,7 +184,7 @@ public class ContextManagementTest extends ScopedTest {
try { try {
delete(context); delete(context);
throw new RuntimeException(contextString + " was deleted successfully. This is not what we expected"); throw new RuntimeException(contextString + " was deleted successfully. This is not what we expected");
} catch (ContextException e) { } catch(ContextException e) {
logger.debug("As expected {} cannot be deleted.", contextString); logger.debug("As expected {} cannot be deleted.", contextString);
} }
} }
@ -372,7 +373,6 @@ public class ContextManagementTest extends ScopedTest {
// B3______________A5 // B3______________A5
*/ */
// The following delete are not allowed because they are not child contexts // The following delete are not allowed because they are not child contexts
invalidDelete(contextA1); invalidDelete(contextA1);
invalidDelete(contextA2); invalidDelete(contextA2);
@ -385,7 +385,7 @@ public class ContextManagementTest extends ScopedTest {
try { try {
delete(contextA5); delete(contextA5);
} catch (ContextNotFoundException e) { } catch(ContextNotFoundException e) {
logger.debug("The context with uuid {} was not found. (Was already deleted)", logger.debug("The context with uuid {} was not found. (Was already deleted)",
contextA5.getHeader().getUUID()); contextA5.getHeader().getUUID());
} }
@ -409,7 +409,7 @@ public class ContextManagementTest extends ScopedTest {
logger.debug("The DB should be now clean"); logger.debug("The DB should be now clean");
} }
private List<Context> getAll() throws Exception{ private List<Context> getAll() throws Exception {
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
String allString = contextManagement.all(false); String allString = contextManagement.all(false);
logger.trace(allString); logger.trace(allString);
@ -437,10 +437,10 @@ public class ContextManagementTest extends ScopedTest {
@Test @Test
public void testGetAll() throws Exception { public void testGetAll() throws Exception {
List<Context> contexts = getAll(); List<Context> contexts = getAll();
for (Context context : contexts) { for(Context context : contexts) {
logger.trace(ISMapper.marshal(context)); logger.trace(ISMapper.marshal(context));
List<IsParentOf<Context, Context>> children = context.getChildren(); List<IsParentOf<Context,Context>> children = context.getChildren();
for (IsParentOf<Context, Context> child : children) { for(IsParentOf<Context,Context> child : children) {
Assert.assertTrue(child.getSource() == context); Assert.assertTrue(child.getSource() == context);
Context childContext = child.getTarget(); Context childContext = child.getTarget();
Assert.assertTrue(childContext.getParent().getSource() == context); Assert.assertTrue(childContext.getParent().getSource() == context);
@ -455,7 +455,6 @@ public class ContextManagementTest extends ScopedTest {
logger.debug("{}", context); logger.debug("{}", context);
} }
// @Test // @Test
public void deleteContext() throws ResourceRegistryException, IOException { public void deleteContext() throws ResourceRegistryException, IOException {
Context context = read(UUID.fromString("")); Context context = read(UUID.fromString(""));