The target context is now a class variable
This commit is contained in:
parent
9cf40bf2fa
commit
a6a45d50e2
|
@ -21,13 +21,15 @@ public interface ERManagement {
|
|||
|
||||
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing);
|
||||
|
||||
public Map<UUID, JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||
public Map<UUID, JsonNode> internalAddToContext()
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> addToContext(UUID contextUUID)
|
||||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
public void setTargetSecurityContext(SecurityContext targetSecurityContext);
|
||||
|
||||
public Map<UUID, JsonNode> internalRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> removeFromContext(UUID contextUUID)
|
||||
|
|
|
@ -52,7 +52,8 @@ public class ERManagementUtility {
|
|||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
// enforcedInstances.putAll(((ERManagement) elementManagement).internalAddToContext(targetSecurityContext));
|
||||
((ERManagement) elementManagement).internalAddToContext(targetSecurityContext);
|
||||
((ERManagement) elementManagement).setTargetSecurityContext(targetSecurityContext);
|
||||
((ERManagement) elementManagement).internalAddToContext();
|
||||
instancesManagement.put(uuid, elementManagement);
|
||||
}
|
||||
|
||||
|
@ -129,7 +130,8 @@ public class ERManagementUtility {
|
|||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
//enforcedInstances.putAll(((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext));
|
||||
((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext);
|
||||
((ERManagement) elementManagement).setTargetSecurityContext(targetSecurityContext);
|
||||
((ERManagement) elementManagement).internalRemoveFromContext();
|
||||
instancesManagement.put(uuid, elementManagement);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ import com.orientechnologies.orient.core.sql.executor.OResultSet;
|
|||
*/
|
||||
public abstract class EntityManagement<E extends Entity, ET extends EntityType> extends EntityElementManagement<E, ET> implements ERManagement {
|
||||
|
||||
/**
|
||||
* The target context of an addToContex/RemoveFromContext
|
||||
*/
|
||||
protected SecurityContext targetSecurityContext;
|
||||
|
||||
/**
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
|
@ -105,6 +110,11 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
*/
|
||||
protected boolean honourPropagationConstraintsInContextSharing;
|
||||
|
||||
@Override
|
||||
public void setTargetSecurityContext(SecurityContext targetSecurityContext) {
|
||||
this.targetSecurityContext = targetSecurityContext;
|
||||
}
|
||||
|
||||
public boolean isDryRunContextSharing() {
|
||||
return dryRunContextSharing;
|
||||
}
|
||||
|
@ -292,7 +302,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
protected Map<UUID,JsonNode> reallyAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
@ -314,7 +324,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
|
||||
relationManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
affectedInstances.putAll(relationManagement.internalAddToContext(targetSecurityContext));
|
||||
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(relationManagement.internalAddToContext());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,10 +333,10 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||
public Map<UUID,JsonNode> internalAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
|
@ -348,9 +359,9 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalAddToContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> affectedInstances = internalAddToContext();
|
||||
|
||||
sanityCheck();
|
||||
|
||||
|
@ -382,10 +393,10 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
|
@ -400,7 +411,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
@ -412,7 +423,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
|
||||
relationManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
affectedInstances.putAll(relationManagement.internalRemoveFromContext(targetSecurityContext));
|
||||
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(relationManagement.internalRemoveFromContext());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -438,9 +450,9 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext();
|
||||
|
||||
sanityCheck();
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||
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.instances.model.relations.ConsistsOfManagement;
|
||||
|
@ -244,7 +243,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
protected Map<UUID,JsonNode> reallyAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||
|
@ -269,7 +268,8 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
|
||||
relationManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext(targetSecurityContext);
|
||||
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext();
|
||||
if(relationManagement instanceof ConsistsOfManagement) {
|
||||
facetCounter = facetCounter + resourceCharacterisationInstances.size();
|
||||
}
|
||||
|
|
|
@ -57,6 +57,11 @@ import com.orientechnologies.orient.core.record.impl.ODocument;
|
|||
public abstract class RelationManagement<T extends EntityManagement<? extends Entity, TET>, TET extends EntityType>
|
||||
extends RelationElementManagement<ResourceManagement, T, ResourceType, TET> implements ERManagement {
|
||||
|
||||
/**
|
||||
* The target context of an addToContex/RemoveFromContext
|
||||
*/
|
||||
protected SecurityContext targetSecurityContext;
|
||||
|
||||
/**
|
||||
* By the default the system execute the the operation of
|
||||
* context sharing so this variable is initialised as false.
|
||||
|
@ -104,6 +109,11 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
*/
|
||||
protected boolean honourPropagationConstraintsInContextSharing;
|
||||
|
||||
@Override
|
||||
public void setTargetSecurityContext(SecurityContext targetSecurityContext) {
|
||||
this.targetSecurityContext = targetSecurityContext;
|
||||
}
|
||||
|
||||
public boolean isDryRunContextSharing() {
|
||||
return dryRunContextSharing;
|
||||
}
|
||||
|
@ -408,7 +418,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
protected Map<UUID,JsonNode> reallyAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
||||
|
@ -446,7 +456,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
affectedInstances.putAll(targetEntityManagement.internalAddToContext(targetSecurityContext));
|
||||
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(targetEntityManagement.internalAddToContext());
|
||||
|
||||
if(!dryRunContextSharing) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
@ -481,10 +492,10 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
return affectedInstances;
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||
public Map<UUID,JsonNode> internalAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
|
||||
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
|
@ -501,7 +512,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> forcedAddToContext(SecurityContext targetSecurityContext)
|
||||
public Map<UUID,JsonNode> forcedAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
||||
|
@ -511,13 +522,15 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
ResourceManagement resourceManagement = getSourceEntityManagement();
|
||||
resourceManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
resourceManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
affectedInstances.putAll(resourceManagement.internalAddToContext(targetSecurityContext));
|
||||
resourceManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(resourceManagement.internalAddToContext());
|
||||
|
||||
/* Adding target to Context */
|
||||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext(targetSecurityContext));
|
||||
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext());
|
||||
|
||||
if(!dryRunContextSharing) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
@ -534,9 +547,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
workingContext = ContextUtility.getAdminSecurityContext();
|
||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> added = forcedAddToContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> added = forcedAddToContext();
|
||||
|
||||
sanityCheck();
|
||||
|
||||
|
@ -563,7 +576,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
protected Map<UUID,JsonNode> reallyRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
||||
|
@ -604,10 +617,10 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
|
||||
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
switch(removeConstraint) {
|
||||
case cascade:
|
||||
affectedInstances.putAll(targetEntityManagement.internalRemoveFromContext(targetSecurityContext));
|
||||
affectedInstances.putAll(targetEntityManagement.internalRemoveFromContext());
|
||||
break;
|
||||
|
||||
case cascadeWhenOrphan:
|
||||
|
@ -636,7 +649,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from {}.",
|
||||
element, target, edge, removeConstraint, targetSecurityContext);
|
||||
} else {
|
||||
affectedInstances.putAll(targetEntityManagement.internalRemoveFromContext(targetSecurityContext));
|
||||
affectedInstances.putAll(targetEntityManagement.internalRemoveFromContext());
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -650,10 +663,10 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
return affectedInstances;
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
|
||||
if(!dryRunContextSharing) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
|
@ -677,9 +690,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||
oDatabaseDocument.begin();
|
||||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext();
|
||||
|
||||
sanityCheck();
|
||||
|
||||
|
|
Loading…
Reference in New Issue