Added affected instances variable to ElementManagement

This commit is contained in:
Luca Frosini 2021-03-05 11:59:24 +01:00
parent 9770531b33
commit 93f5999553
15 changed files with 147 additions and 220 deletions

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
@ -88,6 +89,11 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
getWorkingContext();
}
@Override
public Map<UUID,JsonNode> getAffectedInstances() {
throw new UnsupportedOperationException();
}
public String getName() {
if (name == null) {
if (element == null) {
@ -377,7 +383,7 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
}
@Override
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
protected void reallyDelete() throws NotFoundException, ResourceRegistryException {
Iterable<OEdge> iterable = getElement().getEdges(ODirection.OUT);
Iterator<OEdge> iterator = iterable.iterator();
while (iterator.hasNext()) {
@ -391,9 +397,6 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
securityContext.delete(oDatabaseDocument);
ContextCache.getInstance().cleanCache();
return true;
}
@Override

View File

@ -1,5 +1,8 @@
package org.gcube.informationsystem.resourceregistry.contexts.relations;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.informationsystem.base.reference.AccessType;
@ -38,6 +41,11 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
getWorkingContext();
}
@Override
public Map<UUID,JsonNode> getAffectedInstances() {
throw new UnsupportedOperationException();
}
@Override
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
if (workingContext == null) {

View File

@ -93,6 +93,17 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
protected El element;
protected boolean reload;
/**
* Some operation, e.g. delete has a cascade impact which is not know a priori by the client.
* Setting this variable to false the system just simulate the operation so an interested client
* could know the impact in advance.
*
* By the default the system execute effectively the requested operation.
* So this variable is initialised as false.
*
*/
protected boolean dryRun;
/**
* An operation can affects multiple instances (e.g. create, update)
* We need to know if the instance is the entry point of the operation
@ -111,6 +122,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
*/
protected Operation operation;
/**
* A Delete operation has a cascade impact we could want to know the impact
* Instances affected by a delete
*/
protected final Map<UUID,JsonNode> affectedInstances;
protected ElementManagement(AccessType accessType) {
this.accessType = accessType;
@ -125,8 +142,30 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
this.entryPoint = false;
this.operation = null;
/*
* By the default the system execute the operation
* which has a cascade impact so this variable is initialised as false.
*/
this.dryRun = false;
this.affectedInstances = new HashMap<>();
}
public Map<UUID,JsonNode> getAffectedInstances() {
return affectedInstances;
}
public boolean isDryRun() {
return dryRun;
}
public void setDryRun(boolean dryRun) {
this.dryRun = dryRun;
}
protected void setAsEntryPoint() {
this.entryPoint = true;
}
@ -442,16 +481,13 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
}
}
protected abstract boolean reallyDelete() throws NotFoundException, ResourceRegistryException;
protected abstract void reallyDelete() throws NotFoundException, ResourceRegistryException;
public boolean internalDelete() throws NotFoundException, ResourceRegistryException {
public void internalDelete() throws NotFoundException, ResourceRegistryException {
setOperation(Operation.DELETE);
boolean deleted = reallyDelete();
if(deleted) {
reallyDelete();
sanityCheck();
}
return deleted;
}
public void setElement(El element) throws ResourceRegistryException {
if(element == null) {
@ -729,7 +765,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
}
}
public boolean delete() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
public boolean delete() throws NotFoundException, AvailableInAnotherContextException, SchemaViolationException, ResourceRegistryException {
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try {
@ -737,18 +773,16 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
oDatabaseDocument.begin();
setAsEntryPoint();
boolean deleted = internalDelete();
internalDelete();
if(deleted) {
if(!dryRun) {
oDatabaseDocument.commit();
logger.info("{} with UUID {} was successfully deleted.", accessType.getName(), uuid);
}else {
throw new ResourceRegistryException("Error while deleting " + accessType.getName() + " with UUID " + uuid);
oDatabaseDocument.rollback();
}
return deleted;
return true;
} catch(ResourceRegistryException e) {
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid);
if(oDatabaseDocument != null) {

View File

@ -210,17 +210,14 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
logger.info("{} {} successfully updated", typeName, jsonNode);
return edge;
}
@Override
protected boolean reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
protected void reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
targetEntityClass.getSimpleName());
affectedInstances.put(uuid, serializeSelfAsJsonNode());
getElement().delete();
return true;
}
}

View File

@ -13,18 +13,12 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityCo
public interface ERManagement {
public boolean isDryRunContextSharing();
public void setDryRunContextSharing(boolean dryRunContextSharing);
public boolean isHonourPropagationConstraintsInContextSharing();
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing);
public Map<UUID,JsonNode> getAffectedInstances();
public void setAffectedInstances(Map<UUID,JsonNode> affectedInstances);
/**
* Set source security context to evaluate addToContext
* @param sourceSecurityContext the source security context

View File

@ -49,8 +49,9 @@ public class ERManagementUtility {
elementManagement.setODatabaseDocument(oDatabaseDocument);
elementManagement.setUUID(uuid);
elementManagement.setElementType(type);
elementManagement.setDryRun(dryRun);
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
// enforcedInstances.putAll(((ERManagement) elementManagement).internalAddToContext(targetSecurityContext));
((ERManagement) elementManagement).setTargetSecurityContext(targetSecurityContext);
((ERManagement) elementManagement).internalAddToContext();
@ -128,7 +129,7 @@ public class ERManagementUtility {
elementManagement.setODatabaseDocument(oDatabaseDocument);
elementManagement.setUUID(uuid);
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
elementManagement.setDryRun(dryRun);
//enforcedInstances.putAll(((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext));
((ERManagement) elementManagement).setTargetSecurityContext(targetSecurityContext);
((ERManagement) elementManagement).internalRemoveFromContext();

View File

@ -69,21 +69,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
*/
protected SecurityContext targetSecurityContext;
/**
* By the default the system execute the the operation of
* context sharing so this variable is initialised as false.
*
* Setting this variable to false the system just simulate
* the operation of context sharing
* i.e. AddToContext, RemoveFromContext.
*
* This option can also be used in conjunction with
* {@link ElementManagement#honourPropagationConstraintsInContextSharing}=false.
* This allow to simulate a sharing operation which requires
* do not honour the propagation constraints.
*/
protected boolean dryRunContextSharing;
/**
* By the default the system honour the propagation constraints
* so this variable is initialised as true.
@ -116,21 +101,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
*/
protected boolean honourPropagationConstraintsInContextSharing;
/**
* Instances affected by addToContext/removeFromContext
*/
protected Map<UUID,JsonNode> affectedInstances;
@Override
public Map<UUID,JsonNode> getAffectedInstances() {
return affectedInstances;
}
@Override
public void setAffectedInstances(Map<UUID,JsonNode> affectedInstances) {
this.affectedInstances = affectedInstances;
}
@Override
public void setSourceSecurityContext(SecurityContext sourceSecurityContext) {
this.sourceSecurityContext = sourceSecurityContext;
@ -151,18 +121,12 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
return sourceSecurityContext;
}
public boolean isDryRunContextSharing() {
return dryRunContextSharing;
}
public void setDryRunContextSharing(boolean dryRunContextSharing) {
this.dryRunContextSharing = dryRunContextSharing;
}
@Override
public boolean isHonourPropagationConstraintsInContextSharing() {
return honourPropagationConstraintsInContextSharing;
}
@Override
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
}
@ -195,12 +159,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
this.relationManagements = new HashMap<>();
/*
* By the default the system execute the the operation of
* context sharing so this variable is initialised as false.
*/
this.dryRunContextSharing = false;
/*
* By the default the system honour the propagation constraints
* so this variable is initialised as true.
@ -344,9 +302,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
protected Map<UUID,JsonNode> reallyAddToContext()
throws ContextException, ResourceRegistryException {
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
if(!dryRunContextSharing) {
if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
}
@ -361,7 +317,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
for(OEdge edge : edges) {
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
relationManagement.setDryRunContextSharing(dryRunContextSharing);
relationManagement.setDryRun(dryRun);
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
relationManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(relationManagement.internalAddToContext());
@ -376,8 +332,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
throws ContextException, ResourceRegistryException {
try {
setOperation(Operation.ADD_TO_CONTEXT);
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
if(!dryRunContextSharing) {
reallyAddToContext();
if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save();
}
@ -439,7 +395,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
try {
setOperation(Operation.REMOVE_FROM_CONTEXT);
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
if(!dryRunContextSharing) {
if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save();
}
@ -457,21 +413,19 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
protected Map<UUID,JsonNode> reallyRemoveFromContext()
throws ContextException, ResourceRegistryException {
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
if(honourPropagationConstraintsInContextSharing) {
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
for(OEdge edge : edges) {
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
relationManagement.setDryRunContextSharing(dryRunContextSharing);
relationManagement.setDryRun(dryRun);
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
relationManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(relationManagement.internalRemoveFromContext());
}
}
if(!dryRunContextSharing) {
if(!dryRun) {
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
}
/*
@ -497,7 +451,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext();
internalRemoveFromContext();
oDatabaseDocument.commit();
logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID);

View File

@ -78,14 +78,15 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
}
@Override
protected boolean reallyDelete() throws FacetNotFoundException, ResourceRegistryException {
protected void reallyDelete() throws FacetNotFoundException, ResourceRegistryException {
if(entryPoint) {
OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next();
resourceManagement = new ResourceManagement();
resourceManagement.setElement(oVertex);
}
element.delete();
return true;
affectedInstances.put(uuid, serializeSelfAsJsonNode());
getElement().delete();
}
protected void checkResource() throws SchemaViolationException, ResourceRegistryException {

View File

@ -80,8 +80,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
for(OEdge edge : edges) {
@SuppressWarnings("rawtypes")
RelationManagement relationManagement = getRelationManagement(edge);
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
relationManagement.setReload(reload);
if(relationManagement.giveMeSourceEntityManagementAsIs() == null) {
@ -203,9 +202,8 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
return element;
}
@SuppressWarnings("unchecked")
@Override
protected boolean reallyDelete() throws ResourceNotFoundException, ResourceRegistryException {
protected void reallyDelete() throws ResourceNotFoundException, ResourceRegistryException {
// internalDeleteResource(orientGraph, uuid, null);
getElement();
@ -217,8 +215,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
OEdge edge = iterator.next();
OClass oClass = ElementManagementUtility.getOClass(edge);
@SuppressWarnings("rawtypes")
RelationManagement relationManagement = null;
RelationManagement<?,?> relationManagement = null;
if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
relationManagement = new IsRelatedToManagement();
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) {
@ -236,18 +233,17 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
}
element.delete();
// in relations are affected because is the system which ensure this integrity
return true;
affectedInstances.put(uuid, serializeSelfAsJsonNode());
element.delete();
}
@Override
protected Map<UUID,JsonNode> reallyAddToContext()
throws ContextException, ResourceRegistryException {
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
if(!dryRunContextSharing) {
if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
}
@ -265,7 +261,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
for(OEdge edge : edges) {
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
relationManagement.setDryRunContextSharing(dryRunContextSharing);
relationManagement.setDryRun(dryRun);
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
relationManagement.setTargetSecurityContext(targetSecurityContext);
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext();

View File

@ -9,7 +9,6 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.context.reference.entities.Context;
@ -68,21 +67,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
*/
protected SecurityContext targetSecurityContext;
/**
* By the default the system execute the the operation of
* context sharing so this variable is initialised as false.
*
* Setting this variable to false the system just simulate
* the operation of context sharing
* i.e. AddToContext, RemoveFromContext.
*
* This option can also be used in conjunction with
* {@link ElementManagement#honourPropagationConstraintsInContextSharing}=false.
* This allow to simulate a sharing operation which requires
* do not honour the propagation constraints.
*/
protected boolean dryRunContextSharing;
/**
* By the default the system honour the propagation constraints
* so this variable is initialised as true.
@ -115,21 +99,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
*/
protected boolean honourPropagationConstraintsInContextSharing;
/**
* Instances affected by addToContext/removeFromContext
*/
protected Map<UUID,JsonNode> affectedInstances;
@Override
public Map<UUID,JsonNode> getAffectedInstances() {
return affectedInstances;
}
@Override
public void setAffectedInstances(Map<UUID,JsonNode> affectedInstances) {
this.affectedInstances = affectedInstances;
}
@Override
public void setSourceSecurityContext(SecurityContext sourceSecurityContext) {
this.sourceSecurityContext = sourceSecurityContext;
@ -150,25 +119,18 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return sourceSecurityContext;
}
public boolean isDryRunContextSharing() {
return dryRunContextSharing;
}
public void setDryRunContextSharing(boolean dryRunContextSharing) {
this.dryRunContextSharing = dryRunContextSharing;
}
@Override
public boolean isHonourPropagationConstraintsInContextSharing() {
return honourPropagationConstraintsInContextSharing;
}
@Override
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
}
public final PropagationConstraint defaultPropagationConstraint;
/*
public boolean isAvailableOnContext(SecurityContext securityContext) {
try {
return securityContext.isElementInContext(element);
@ -176,18 +138,11 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return false;
}
}
*/
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, PropagationConstraint defaultPropagationConstraint) {
super(accessType, Resource.class, targetEntityClass);
this.defaultPropagationConstraint = defaultPropagationConstraint;
/*
* By the default the system execute the the operation of
* context sharing so this variable is initialised as false.
*/
this.dryRunContextSharing = false;
/*
* By the default the system honour the propagation constraints
* so this variable is initialised as true.
@ -229,39 +184,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return sourceEntityManagement;
}
public ResourceManagement getSourceEntityManagement() throws ResourceRegistryException {
if(sourceEntityManagement == null) {
OVertex source = getElement().getVertex(ODirection.OUT);
sourceEntityManagement = newSourceEntityManagement();
sourceEntityManagement.setElement(source);
}
sourceEntityManagement.setReload(reload);
return sourceEntityManagement;
}
public T getTargetEntityManagement() throws ResourceRegistryException {
if(targetEntityManagement == null) {
OVertex target = getElement().getVertex(ODirection.IN);
targetEntityManagement = newTargetEntityManagement();
targetEntityManagement.setElement(target);
}
targetEntityManagement.setReload(reload);
return targetEntityManagement;
}
public void setSourceEntityManagement(ResourceManagement resourceManagement) {
this.sourceEntityManagement = resourceManagement;
}
public void setTargetEntityManagement(T targetEntityManagement) {
this.targetEntityManagement = targetEntityManagement;
}
@Override
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
return createCompleteJsonNode(true, true);
}
/*
@Override
public JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
JsonNode relation = serializeSelfAsJsonNode();
@ -287,6 +210,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return relation;
}
*/
protected Map<String,JsonNode> fullSerialize(Map<String,JsonNode> visitedSourceResources)
throws ResourceRegistryException {
@ -385,6 +309,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return element;
}
@Override
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setWorkingContext(getWorkingContext());
@ -392,8 +317,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return resourceManagement;
}
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
protected String getEntityTypeNotValidErrroMessage(String entityPosition, String requiredType, String effectiveType) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("The ");
@ -463,8 +386,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
throws ContextException, ResourceRegistryException {
getElement();
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
if(honourPropagationConstraintsInContextSharing) {
AddConstraint addConstraint = AddConstraint.unpropagate;
@ -495,12 +416,12 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
* Otherwise we have a relation which point to an entity outside of the context.
*/
T targetEntityManagement = getTargetEntityManagement();
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
targetEntityManagement.setDryRun(dryRun);
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(targetEntityManagement.internalAddToContext());
if(!dryRunContextSharing) {
if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
}
/*
@ -519,7 +440,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
break;
}
}else {
if(!dryRunContextSharing) {
if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
}
/*
@ -533,13 +454,14 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return affectedInstances;
}
@Override
public Map<UUID,JsonNode> internalAddToContext()
throws ContextException, ResourceRegistryException {
try {
operation = Operation.ADD_TO_CONTEXT;
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
reallyAddToContext();
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
if(!dryRunContextSharing) {
if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save();
}
@ -560,23 +482,21 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
setOperation(Operation.ADD_TO_CONTEXT);
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
/* Adding source to Context */
ResourceManagement resourceManagement = getSourceEntityManagement();
resourceManagement.setDryRunContextSharing(dryRunContextSharing);
resourceManagement.setDryRun(dryRun);
resourceManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
resourceManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(resourceManagement.internalAddToContext());
/* Adding target to Context */
T targetEntityManagement = getTargetEntityManagement();
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
targetEntityManagement.setDryRun(dryRun);
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext());
if(!dryRunContextSharing) {
if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
}
affectedInstances.put(uuid, serializeSelfAsJsonNode());
@ -584,6 +504,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return affectedInstances;
}
@Override
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();
@ -594,7 +515,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
Map<UUID,JsonNode> added = forcedAddToContext();
forcedAddToContext();
sanityCheck();
@ -602,7 +523,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
contextUUID);
return added;
return affectedInstances;
} catch(Exception e) {
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
contextUUID, e);
@ -627,8 +548,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
getSourceEntityManagement().getElement();
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
RemoveConstraint removeConstraint = RemoveConstraint.keep;
try {
@ -656,13 +575,13 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
* In any removeConstraint value the relation MUST be removed from context to
* avoid to have edge having a source outside of the context.
*/
if(!dryRunContextSharing) {
if(!dryRun) {
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
}
affectedInstances.put(uuid, serializeSelfAsJsonNode());
T targetEntityManagement = getTargetEntityManagement();
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
targetEntityManagement.setDryRun(dryRun);
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
switch(removeConstraint) {
@ -710,12 +629,13 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return affectedInstances;
}
@Override
public Map<UUID,JsonNode> internalRemoveFromContext()
throws ContextException, ResourceRegistryException {
try {
setOperation(Operation.REMOVE_FROM_CONTEXT);
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
if(!dryRunContextSharing) {
reallyRemoveFromContext();
if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save();
}
@ -729,6 +649,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
}
}
@Override
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
throws NotFoundException, ContextException, ResourceRegistryException {
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
@ -741,7 +662,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext();
internalRemoveFromContext();
sanityCheck();
@ -774,7 +695,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
}
@Override
protected boolean reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
protected void reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
targetEntityClass.getSimpleName());
@ -802,6 +723,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
}
OVertex target = getTargetEntityManagement().getElement();
affectedInstances.put(uuid, serializeAsJsonNode());
element.delete();
switch(removeConstraint) {
@ -826,11 +748,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
default:
break;
}
return true;
}
@SuppressWarnings("unchecked")
protected Collection<JsonNode> serializeEdges(Iterable<ODocument> edges, boolean postFilterPolymorphic)
throws ResourceRegistryException {
Map<String,JsonNode> visitedSourceResources = new HashMap<>();
@ -842,6 +761,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
continue;
}
@SuppressWarnings("unchecked")
RelationManagement<T, TET> relationManagement = (RelationManagement<T, TET>) ElementManagementUtility.getRelationManagement(getWorkingContext(),
oDatabaseDocument, edge);
visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);

View File

@ -186,7 +186,7 @@ public class SharingManager {
ElementManagement<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
elementManagement.setUUID(UUID.fromString(instanceId));
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
elementManagement.setDryRun(dryRun);
UUID contextUUID = UUID.fromString(contextId);

View File

@ -1,6 +1,8 @@
package org.gcube.informationsystem.resourceregistry.types.entities;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.AccessType;
@ -40,6 +42,11 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
this.typeName = TypeMapper.getType(clz);
}
@Override
public Map<UUID,JsonNode> getAffectedInstances() {
throw new UnsupportedOperationException();
}
@Override
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
if (workingContext == null) {
@ -87,10 +94,9 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
}
@Override
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
protected void reallyDelete() throws NotFoundException, ResourceRegistryException {
logger.debug("Going to remove {} for {}", this.typeName, getName());
getElement().delete();
return true;
}
@Override

View File

@ -1,6 +1,8 @@
package org.gcube.informationsystem.resourceregistry.types.properties;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.AccessType;
@ -47,6 +49,11 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
setWorkingContext(securityContext);
}
@Override
public Map<UUID,JsonNode> getAffectedInstances() {
throw new UnsupportedOperationException();
}
@Override
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
if(workingContext == null) {
@ -94,10 +101,9 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
}
@Override
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
protected void reallyDelete() throws NotFoundException, ResourceRegistryException {
logger.debug("Going to remove {} for {}", EntityType.NAME, getName());
getElement().delete();
return true;
}
@Override

View File

@ -1,7 +1,10 @@
package org.gcube.informationsystem.resourceregistry.types.relations;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
@ -50,6 +53,11 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
setWorkingContext(securityContext);
}
@Override
public Map<UUID,JsonNode> getAffectedInstances() {
throw new UnsupportedOperationException();
}
@Override
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
if (workingContext == null) {
@ -123,10 +131,9 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
}
@Override
protected boolean reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
protected void reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
logger.debug("Going to remove {} for {}", RelationType.NAME, getName());
getElement().delete();
return true;
}
@Override

View File

@ -80,7 +80,7 @@ public class MultiContextTest extends ContextTest {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(TypeMapper.getType(r.getClass()));
resourceManagement.setUUID(r.getHeader().getUUID());
resourceManagement.setDryRunContextSharing(dryRun);
resourceManagement.setDryRun(dryRun);
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
Map<UUID, JsonNode> affectedInstances = resourceManagement.removeFromContext(contextUUID);
@ -187,7 +187,7 @@ public class MultiContextTest extends ContextTest {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(TypeMapper.getType(r));
resourceManagement.setUUID(r.getHeader().getUUID());
resourceManagement.setDryRunContextSharing(dryRun);
resourceManagement.setDryRun(dryRun);
UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(targetContextFullName).getUUID();
Map<UUID, JsonNode> affectedInstances = resourceManagement.addToContext(contextUUID);