Refs #10238: Refactor Context Port Type

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

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158789 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-11-23 15:37:53 +00:00
parent d9fe526386
commit 6899669ccf
2 changed files with 36 additions and 27 deletions

View File

@ -190,6 +190,7 @@ public class ContextManagement extends EntityManagement<Context> {
@Override @Override
protected Vertex reallyCreate() throws ERAlreadyPresentException, ResourceRegistryException { protected Vertex reallyCreate() throws ERAlreadyPresentException, ResourceRegistryException {
try {
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY); JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
if (isParentOfJsonNode!=null && !(isParentOfJsonNode instanceof NullNode)) { if (isParentOfJsonNode!=null && !(isParentOfJsonNode instanceof NullNode)) {
@ -201,6 +202,8 @@ public class ContextManagement extends EntityManagement<Context> {
checkContext(parentContext); checkContext(parentContext);
createVertex(); createVertex();
SecurityContext.createSecurityContext(orientGraph, uuid);
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph); IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
isParentOfManagement.setJSON(isParentOfJsonNode); isParentOfManagement.setJSON(isParentOfJsonNode);
isParentOfManagement.setSourceEntityManagement(parentContext); isParentOfManagement.setSourceEntityManagement(parentContext);
@ -214,6 +217,12 @@ public class ContextManagement extends EntityManagement<Context> {
} }
return getElement(); return getElement();
}catch (Exception e) {
if(uuid!=null) {
SecurityContext.deleteSecurityContext(orientGraph, uuid);
}
throw e;
}
} }
@Override @Override
@ -291,6 +300,8 @@ public class ContextManagement extends EntityManagement<Context> {
element = (Vertex) ERManagement.updateProperties(oClass, getElement(), jsonNode, ignoreKeys, ignoreStartWithKeys); element = (Vertex) ERManagement.updateProperties(oClass, getElement(), jsonNode, ignoreKeys, ignoreStartWithKeys);
ContextUtility.invalidContextUUIDCache(uuid);
return element; return element;
} }
@ -337,6 +348,9 @@ public class ContextManagement extends EntityManagement<Context> {
element.remove(); element.remove();
ContextUtility.invalidContextUUIDCache(uuid);
SecurityContext.deleteSecurityContext(orientGraph, uuid);
return true; return true;
} }

View File

@ -150,7 +150,6 @@ public class SecurityContext {
readerUser.save(); readerUser.save();
logger.trace("{} created", readerUser); logger.trace("{} created", readerUser);
oDatabaseDocumentTx.commit();
logger.trace( logger.trace(
"Security Context (roles and users) with UUID {} successfully created", "Security Context (roles and users) with UUID {} successfully created",
@ -158,7 +157,7 @@ public class SecurityContext {
} }
public static void deleteSecurityContext(OrientGraph orientGraph, public static void deleteSecurityContext(OrientGraph orientGraph,
UUID context, boolean commit) { UUID context) {
logger.trace( logger.trace(
"Going to remove Security Context (roles and users) with UUID {}", "Going to remove Security Context (roles and users) with UUID {}",
@ -206,10 +205,6 @@ public class SecurityContext {
logger.error("{} was not dropped successfully", role); logger.error("{} was not dropped successfully", role);
} }
if(commit){
oDatabaseDocumentTx.commit();
}
logger.trace( logger.trace(
"Security Context (roles and users) with UUID {} successfully removed", "Security Context (roles and users) with UUID {} successfully removed",
context.toString()); context.toString());