Going to improve sanity check to manage the
addToContext/removeFromContext actions
This commit is contained in:
parent
83ca22a15e
commit
9cf40bf2fa
|
@ -101,6 +101,37 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
protected El element;
|
||||
protected boolean reload;
|
||||
|
||||
/**
|
||||
* An operation can affects multiple instances (e.g. addToContext)
|
||||
* We need to know if the instance is the entry point of the operation
|
||||
* or if it is just a subordinated operation.
|
||||
* This is required for example in addTocontext to trigger sanity check
|
||||
* in the Resource when the action is performed directly on the Facet,
|
||||
* or the Resource sanity check is not required to be triggered
|
||||
* because the entry point of the action already take care
|
||||
* of triggering this action (e.g. the addToContext was invoked on the Resource and
|
||||
* each describing Facets must not trigger multiple time the sanityCheck).
|
||||
*/
|
||||
protected boolean entryPoint;
|
||||
|
||||
protected ElementManagement(AccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
|
||||
this.ignoreKeys = new HashSet<String>();
|
||||
|
||||
this.ignoreStartWithKeys = new HashSet<String>();
|
||||
|
||||
this.ignoreStartWithKeys.add(ElementManagement.AT);
|
||||
this.ignoreStartWithKeys.add(ElementManagement.UNDERSCORE);
|
||||
|
||||
this.reload = false;
|
||||
|
||||
this.entryPoint = false;
|
||||
|
||||
// this.superClassesToBeExcluded = new HashSet<>();
|
||||
|
||||
}
|
||||
|
||||
public void cleanCachedSerialization() {
|
||||
this.self = null;
|
||||
this.complete = null;
|
||||
|
@ -110,6 +141,14 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
public boolean isEntryPoint() {
|
||||
return entryPoint;
|
||||
}
|
||||
|
||||
public void setEntryPoint(boolean entryPoint) {
|
||||
this.entryPoint = entryPoint;
|
||||
}
|
||||
|
||||
public boolean isReload() {
|
||||
return reload;
|
||||
}
|
||||
|
@ -135,22 +174,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
this.workingContext = workingContext;
|
||||
}
|
||||
|
||||
protected ElementManagement(AccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
|
||||
this.ignoreKeys = new HashSet<String>();
|
||||
|
||||
this.ignoreStartWithKeys = new HashSet<String>();
|
||||
|
||||
this.ignoreStartWithKeys.add(ElementManagement.AT);
|
||||
this.ignoreStartWithKeys.add(ElementManagement.UNDERSCORE);
|
||||
|
||||
this.reload = false;
|
||||
|
||||
// this.superClassesToBeExcluded = new HashSet<>();
|
||||
|
||||
}
|
||||
|
||||
public void setUUID(UUID uuid) throws ResourceRegistryException {
|
||||
this.uuid = uuid;
|
||||
if(jsonNode != null) {
|
||||
|
|
|
@ -344,13 +344,16 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
workingContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalAddToContext(targetSecurityContext);
|
||||
|
||||
sanityCheck();
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
||||
|
@ -431,14 +434,15 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
workingContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
// check here
|
||||
sanityCheck();
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
|
|
@ -529,14 +529,17 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
||||
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
workingContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> added = forcedAddToContext(targetSecurityContext);
|
||||
|
||||
sanityCheck();
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID);
|
||||
|
@ -553,6 +556,10 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
if(oDatabaseDocument != null) {
|
||||
oDatabaseDocument.close();
|
||||
}
|
||||
|
||||
if(current!=null) {
|
||||
current.activateOnCurrentThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,13 +673,16 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||
workingContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
sanityCheck();
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ public class InstancesManager extends BaseRest {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
||||
erManagement.setEntryPoint(true);
|
||||
return erManagement.all(polymorphic);
|
||||
}
|
||||
|
||||
|
@ -103,6 +104,7 @@ public class InstancesManager extends BaseRest {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
||||
erManagement.setEntryPoint(true);
|
||||
|
||||
try {
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
|
@ -142,7 +144,7 @@ public class InstancesManager extends BaseRest {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
||||
|
||||
erManagement.setEntryPoint(true);
|
||||
erManagement.setElementType(type);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
return erManagement.read().toString();
|
||||
|
@ -168,6 +170,7 @@ public class InstancesManager extends BaseRest {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
||||
erManagement.setEntryPoint(true);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
erManagement.setElementType(type);
|
||||
erManagement.setJson(json);
|
||||
|
@ -190,6 +193,7 @@ public class InstancesManager extends BaseRest {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
||||
erManagement.setEntryPoint(true);
|
||||
erManagement.setUUID(UUID.fromString(uuid));
|
||||
erManagement.delete();
|
||||
|
||||
|
@ -218,6 +222,7 @@ public class InstancesManager extends BaseRest {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
||||
erManagement.setEntryPoint(true);
|
||||
erManagement.setUUID(UUID.fromString(instanceId));
|
||||
return erManagement.getContexts();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.Sharing
|
|||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagementUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -79,8 +78,8 @@ public class SharingManager {
|
|||
* The body contains the list of instances to add/remove to/from the context identified by CONTEXT_UUID
|
||||
*
|
||||
*/
|
||||
@POST
|
||||
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}")
|
||||
// @POST
|
||||
// @Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}")
|
||||
public String addRemoveNoPropagationConstraint(
|
||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation,
|
||||
|
@ -121,12 +120,13 @@ public class SharingManager {
|
|||
expectedInstances.put(uuid, node);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
UUID contextUUID = UUID.fromString(contextId);
|
||||
Map<UUID,JsonNode> affectedInstances = null;
|
||||
if(operation == SharingOperation.ADD) {
|
||||
affectedInstances = ERManagementUtility.addToContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
// affectedInstances = ERManagementUtility.addToContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
}else {
|
||||
affectedInstances = ERManagementUtility.removeFromContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
// affectedInstances = ERManagementUtility.removeFromContextNoPropagationConstraint(expectedInstances, contextUUID, dryRun);
|
||||
}
|
||||
|
||||
return serializeAffectedInstaces(objectMapper, affectedInstances);
|
||||
|
@ -185,6 +185,7 @@ public class SharingManager {
|
|||
CalledMethodProvider.instance.set(calledMethod.toString());
|
||||
|
||||
ElementManagement<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||
elementManagement.setEntryPoint(true);
|
||||
elementManagement.setUUID(UUID.fromString(instanceId));
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
|
||||
|
|
Loading…
Reference in New Issue