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(element != null) {
OrientElement orientElement = (OrientElement) element;
OMetadata oMetadata = orientElement.getGraph().getRawGraph().getMetadata();
OMetadata oMetadata = orientElement.getRecord().getDatabase().getMetadata();
OSchema oSchema = oMetadata.getSchema();
String type = orientElement.getRecord().getClassName();
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.utils.ISMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;

View File

@ -25,45 +25,45 @@ 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.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;
public class ContextManagementTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(ContextManagementTest.class);
public static final String CTX_NAME_A = "A";
public static final String CTX_NAME_B = "B";
public static final String CTX_NAME_C = "C";
protected void assertions(Context pre, Context post, boolean checkParent, boolean create)
throws ResourceRegistryException {
if (checkParent) {
if (pre.getHeader() != null) {
if(checkParent) {
if(pre.getHeader() != null) {
FacetManagementTest.checkHeader(post, pre.getHeader().getUUID(), create);
} else {
FacetManagementTest.checkHeader(post, null, create);
}
}
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 postParent = post.getParent().getSource();
assertions(preParent, postParent, false, false);
}
}
protected void roleUserAssertions(UUID uuid, UUID oldParentUUID, boolean deleted) throws ResourceRegistryException {
ContextSecurityContext contextSecurityContext = new ContextSecurityContext();
ContextUtility.getInstance().addSecurityContext(contextSecurityContext.getUUID().toString(),
contextSecurityContext);
OrientGraph orientGraph = contextSecurityContext.getGraph(PermissionMode.READER);
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata().getSecurity();
ODatabaseSession oDatabaseSession = contextSecurityContext.getDatabaseSession(PermissionMode.READER);
OSecurity oSecurity = oDatabaseSession.getMetadata().getSecurity();
SecurityContext securityContext = null;
if(deleted) {
@ -71,31 +71,32 @@ public class ContextManagementTest extends ScopedTest {
} else {
securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
}
boolean[] booleanArray = new boolean[] { false, true };
for (boolean hierarchic : booleanArray) {
for (PermissionMode permissionMode : PermissionMode.values()) {
boolean[] booleanArray = new boolean[] {false, true};
for(boolean hierarchic : booleanArray) {
for(PermissionMode permissionMode : PermissionMode.values()) {
String role = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.ROLE, hierarchic);
ORole oRole = oSecurity.getRole(role);
Assert.assertEquals(oRole == null, deleted);
String user = securityContext.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic);
OUser oUser = oSecurity.getUser(user);
Assert.assertEquals(oUser == null, deleted);
if(oUser!=null) {
if(oUser != null) {
Assert.assertTrue(oUser.hasRole(oRole.getName(), false));
}
if(hierarchic) {
SecurityContext parent = null;
if(deleted){
if(oldParentUUID!=null) {
if(deleted) {
if(oldParentUUID != null) {
parent = ContextUtility.getInstance().getSecurityContextByUUID(oldParentUUID);
}
}
parent = securityContext.getParentSecurityContext();
while(parent!=null) {
String parentUser = parent.getSecurityRoleOrUserName(permissionMode, SecurityType.USER, hierarchic);
while(parent != null) {
String parentUser = parent.getSecurityRoleOrUserName(permissionMode, SecurityType.USER,
hierarchic);
OUser parentOUser = oSecurity.getUser(parentUser);
Assert.assertTrue(parentOUser != null);
Assert.assertEquals(parentOUser.hasRole(oRole.getName(), false), !deleted);
@ -106,7 +107,7 @@ public class ContextManagementTest extends ScopedTest {
}
}
}
protected Context read(UUID uuid) throws ResourceRegistryException, IOException {
ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(uuid);
@ -115,7 +116,7 @@ public class ContextManagementTest extends ScopedTest {
roleUserAssertions(uuid, null, false);
return ISMapper.unmarshal(Context.class, contextString);
}
protected Context create(Context context) throws ResourceRegistryException, IOException {
ContextManagement contextManagement = new ContextManagement();
contextManagement.setJson(ISMapper.marshal(context));
@ -126,7 +127,7 @@ public class ContextManagementTest extends ScopedTest {
roleUserAssertions(c.getHeader().getUUID(), null, false);
return c;
}
protected Context update(Context context) throws ResourceRegistryException, IOException {
ContextManagement contextManagement = new ContextManagement();
contextManagement.setJson(ISMapper.marshal(context));
@ -137,7 +138,7 @@ public class ContextManagementTest extends ScopedTest {
roleUserAssertions(c.getHeader().getUUID(), null, false);
return c;
}
protected boolean delete(UUID uuid) throws ResourceRegistryException {
ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(uuid);
@ -145,7 +146,7 @@ public class ContextManagementTest extends ScopedTest {
SecurityContext securityContext = ContextUtility.getInstance().getSecurityContextByUUID(uuid);
UUID oldParentUUID = null;
if(securityContext.getParentSecurityContext()!=null) {
if(securityContext.getParentSecurityContext() != null) {
oldParentUUID = securityContext.getParentSecurityContext().getUUID();
}
@ -155,35 +156,35 @@ public class ContextManagementTest extends ScopedTest {
logger.debug("Deleted {} with UUID {}", Context.NAME, uuid);
return deleted;
}
protected boolean delete(Context context) throws ResourceRegistryException {
return delete(context.getHeader().getUUID());
}
protected void invalidCreate(Context context) throws ResourceRegistryException, IOException {
try {
Context c = create(context);
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));
}
}
protected void invalidUpdate(Context context) throws ResourceRegistryException, IOException {
try {
Context c = update(context);
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));
}
}
protected void invalidDelete(Context context) throws ResourceRegistryException, JsonProcessingException {
String contextString = ISMapper.marshal(context);
try {
delete(context);
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);
}
}
@ -193,34 +194,34 @@ public class ContextManagementTest extends ScopedTest {
Context contextA1 = new ContextImpl(CTX_NAME_A);
contextA1 = create(contextA1);
// ________A1________
Context contextA2 = new ContextImpl(CTX_NAME_A);
contextA2.setParent(contextA1);
contextA2 = create(contextA2);
// ________A1________
// ___A2
Context contextB3 = new ContextImpl(CTX_NAME_B);
contextB3.setParent(contextA2);
contextB3 = create(contextB3);
// ________A1________
// ___A2
// B3
Context contextB4 = new ContextImpl(CTX_NAME_B);
contextB4.setParent(contextA1);
contextB4 = create(contextB4);
// ________A1________
// ___A2_______B4____
// B3
Context contextA5 = new ContextImpl(CTX_NAME_A);
contextA5.setParent(contextB4);
contextA5 = create(contextA5);
// ________A1________
// ___A2_______B4____
// B3______________A5
invalidCreate(contextA1); // Trying to recreate A1. Fails
invalidCreate(contextA2); // Trying to recreate A2. Fails
invalidCreate(contextB3); // Trying to recreate B3. Fails
@ -242,20 +243,20 @@ public class ContextManagementTest extends ScopedTest {
// _____A1____B4_____
// __A2__________A5__
// B3
contextB4.setParent(contextA1);
update(contextB4);
// ________A1________
// ___A2_______B4____
// B3______________A5
// Trying to rename with the new name A. It fails due to A5.
contextB3.setName(CTX_NAME_A);
update(contextB3);
// ________A1________
// ___A2_______B4____
// A3______________A5
// After Restoring name B, trying to move B3 as child of A1. It fails due to B4.
contextB3.setName(CTX_NAME_B);
contextB3.setParent(contextA1);
@ -263,7 +264,7 @@ public class ContextManagementTest extends ScopedTest {
// ________A1________
// ___A2_______B4____
// A3______________A5
// Restoring A3 (was B3) as B3 and with parent A2.OK.
contextB3.setName(CTX_NAME_B);
contextB3.setParent(contextA2);
@ -271,12 +272,12 @@ public class ContextManagementTest extends ScopedTest {
// ________A1________
// ___A2_______B4____
// B3______________A5
// This update should not has eny effects except updating the lastUpdateTime.
contextB3.setName(CTX_NAME_B);
contextB3.setParent(contextA2);
update(contextB3);
// Trying to move A5 as child of A1. It fails due to A2.
contextA5.setParent(contextA1);
invalidUpdate(contextA5);
@ -285,49 +286,49 @@ public class ContextManagementTest extends ScopedTest {
// ________A1________
// ___A2_______B4____
// B3______________A5
// Moving B3 as child of B4. OK.
contextB3.setParent(contextB4);
update(contextB3);
// ________A1________
// ___A2_______B4____
// ________B3______A5
// Restoring the initial situation by moving B3 as child of A2. OK.
contextB3.setParent(contextA2);
update(contextB3);
// ________A1________
// ___A2_______B4____
// B3______________A5
// Renaming B3 as C3. OK.
contextB3.setName(CTX_NAME_C);
update(contextB3);
// ________A1________
// ___A2_______B4____
// C3______________A5
// Moving C3 (was B3) as child of A1. Now it is possible. OK.
contextB3.setParent(contextA1);
update(contextB3);
// ________A1________
// ___A2___C3___B4___
// ________________A5
// Trying to rename C3 (was B3) newly to B3. Fails due to B4.
contextB3.setName(CTX_NAME_B);
invalidUpdate(contextB3);
// ________A1________
// ___A2___C3___B4___
// ________________A5
// Moving back C3 (was B3) as child of A2. OK.
contextB3.setParent(contextA2);
update(contextB3);
// ________A1________
// ___A2_______B4____
// C3______________A5
// Renaming C3 (was B3) to B3. OK.
contextB3.setName(CTX_NAME_B);
update(contextB3);
@ -372,7 +373,6 @@ public class ContextManagementTest extends ScopedTest {
// B3______________A5
*/
// The following delete are not allowed because they are not child contexts
invalidDelete(contextA1);
invalidDelete(contextA2);
@ -382,34 +382,34 @@ public class ContextManagementTest extends ScopedTest {
// ________A1________
// ___A2_______B4____
// B3
try {
delete(contextA5);
} catch (ContextNotFoundException e) {
} catch(ContextNotFoundException e) {
logger.debug("The context with uuid {} was not found. (Was already deleted)",
contextA5.getHeader().getUUID());
}
delete(contextB3);
// ________A1________
// ___A2_______B4____
delete(contextB4);
// ________A1________
// ___A2
delete(contextA2);
// ________A1________
Context contextC = new ContextImpl(CTX_NAME_C);
contextC.setHeader(new HeaderImpl(contextA1.getHeader().getUUID()));
invalidCreate(contextC);
delete(contextA1);
logger.debug("The DB should be now clean");
}
private List<Context> getAll() throws Exception{
private List<Context> getAll() throws Exception {
ContextManagement contextManagement = new ContextManagement();
String allString = contextManagement.all(false);
logger.trace(allString);
@ -437,10 +437,10 @@ public class ContextManagementTest extends ScopedTest {
@Test
public void testGetAll() throws Exception {
List<Context> contexts = getAll();
for (Context context : contexts) {
for(Context context : contexts) {
logger.trace(ISMapper.marshal(context));
List<IsParentOf<Context, Context>> children = context.getChildren();
for (IsParentOf<Context, Context> child : children) {
List<IsParentOf<Context,Context>> children = context.getChildren();
for(IsParentOf<Context,Context> child : children) {
Assert.assertTrue(child.getSource() == context);
Context childContext = child.getTarget();
Assert.assertTrue(childContext.getParent().getSource() == context);
@ -448,18 +448,17 @@ public class ContextManagementTest extends ScopedTest {
roleUserAssertions(context.getHeader().getUUID(), null, false);
}
}
// @Test
public void readContext() throws ResourceRegistryException, IOException {
Context context = read(UUID.fromString(""));
logger.debug("{}", context);
}
// @Test
public void deleteContext() throws ResourceRegistryException, IOException {
Context context = read(UUID.fromString(""));
delete(context);
}
}