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

View File

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

View File

@ -93,6 +93,17 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
protected El element; protected El element;
protected boolean reload; 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) * An operation can affects multiple instances (e.g. create, update)
* We need to know if the instance is the entry point of the operation * 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; 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) { protected ElementManagement(AccessType accessType) {
this.accessType = accessType; this.accessType = accessType;
@ -125,8 +142,30 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
this.entryPoint = false; this.entryPoint = false;
this.operation = null; 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() { protected void setAsEntryPoint() {
this.entryPoint = true; this.entryPoint = true;
} }
@ -442,15 +481,12 @@ 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); setOperation(Operation.DELETE);
boolean deleted = reallyDelete(); reallyDelete();
if(deleted) { sanityCheck();
sanityCheck();
}
return deleted;
} }
public void setElement(El element) throws ResourceRegistryException { public void setElement(El element) throws ResourceRegistryException {
@ -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); logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try { try {
@ -737,18 +773,16 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
oDatabaseDocument.begin(); oDatabaseDocument.begin();
setAsEntryPoint(); setAsEntryPoint();
boolean deleted = internalDelete(); internalDelete();
if(deleted) { if(!dryRun) {
oDatabaseDocument.commit(); oDatabaseDocument.commit();
logger.info("{} with UUID {} was successfully deleted.", accessType.getName(), uuid); logger.info("{} with UUID {} was successfully deleted.", accessType.getName(), uuid);
} else { }else {
throw new ResourceRegistryException("Error while deleting " + accessType.getName() + " with UUID " + uuid); oDatabaseDocument.rollback();
} }
return true;
return deleted;
} catch(ResourceRegistryException e) { } catch(ResourceRegistryException e) {
logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid); logger.error("Unable to delete {} with UUID {}", accessType.getName(), uuid);
if(oDatabaseDocument != null) { if(oDatabaseDocument != null) {

View File

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

View File

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

View File

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

View File

@ -69,21 +69,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
*/ */
protected SecurityContext targetSecurityContext; 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 * By the default the system honour the propagation constraints
* so this variable is initialised as true. * so this variable is initialised as true.
@ -116,21 +101,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
*/ */
protected boolean honourPropagationConstraintsInContextSharing; 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 @Override
public void setSourceSecurityContext(SecurityContext sourceSecurityContext) { public void setSourceSecurityContext(SecurityContext sourceSecurityContext) {
this.sourceSecurityContext = sourceSecurityContext; this.sourceSecurityContext = sourceSecurityContext;
@ -151,18 +121,12 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
return sourceSecurityContext; return sourceSecurityContext;
} }
public boolean isDryRunContextSharing() { @Override
return dryRunContextSharing;
}
public void setDryRunContextSharing(boolean dryRunContextSharing) {
this.dryRunContextSharing = dryRunContextSharing;
}
public boolean isHonourPropagationConstraintsInContextSharing() { public boolean isHonourPropagationConstraintsInContextSharing() {
return honourPropagationConstraintsInContextSharing; return honourPropagationConstraintsInContextSharing;
} }
@Override
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) { public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing; this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
} }
@ -195,12 +159,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
this.relationManagements = new HashMap<>(); 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 * By the default the system honour the propagation constraints
* so this variable is initialised as true. * 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() protected Map<UUID,JsonNode> reallyAddToContext()
throws ContextException, ResourceRegistryException { throws ContextException, ResourceRegistryException {
Map<UUID,JsonNode> affectedInstances = new HashMap<>(); if(!dryRun) {
if(!dryRunContextSharing) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument); targetSecurityContext.addElement(getElement(), oDatabaseDocument);
} }
@ -361,7 +317,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
for(OEdge edge : edges) { for(OEdge edge : edges) {
RelationManagement<?,?> relationManagement = getRelationManagement(edge); RelationManagement<?,?> relationManagement = getRelationManagement(edge);
relationManagement.setDryRunContextSharing(dryRunContextSharing); relationManagement.setDryRun(dryRun);
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
relationManagement.setTargetSecurityContext(targetSecurityContext); relationManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(relationManagement.internalAddToContext()); affectedInstances.putAll(relationManagement.internalAddToContext());
@ -376,8 +332,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
throws ContextException, ResourceRegistryException { throws ContextException, ResourceRegistryException {
try { try {
setOperation(Operation.ADD_TO_CONTEXT); setOperation(Operation.ADD_TO_CONTEXT);
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(); reallyAddToContext();
if(!dryRunContextSharing) { if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element); HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save(); element.save();
} }
@ -439,7 +395,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
try { try {
setOperation(Operation.REMOVE_FROM_CONTEXT); setOperation(Operation.REMOVE_FROM_CONTEXT);
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(); Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
if(!dryRunContextSharing) { if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element); HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save(); element.save();
} }
@ -457,21 +413,19 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
protected Map<UUID,JsonNode> reallyRemoveFromContext() protected Map<UUID,JsonNode> reallyRemoveFromContext()
throws ContextException, ResourceRegistryException { throws ContextException, ResourceRegistryException {
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
if(honourPropagationConstraintsInContextSharing) { if(honourPropagationConstraintsInContextSharing) {
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT); Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
for(OEdge edge : edges) { for(OEdge edge : edges) {
RelationManagement<?,?> relationManagement = getRelationManagement(edge); RelationManagement<?,?> relationManagement = getRelationManagement(edge);
relationManagement.setDryRunContextSharing(dryRunContextSharing); relationManagement.setDryRun(dryRun);
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
relationManagement.setTargetSecurityContext(targetSecurityContext); relationManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(relationManagement.internalRemoveFromContext()); affectedInstances.putAll(relationManagement.internalRemoveFromContext());
} }
} }
if(!dryRunContextSharing) { if(!dryRun) {
targetSecurityContext.removeElement(getElement(), oDatabaseDocument); targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
} }
/* /*
@ -497,7 +451,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(); internalRemoveFromContext();
oDatabaseDocument.commit(); oDatabaseDocument.commit();
logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID); 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 @Override
protected boolean reallyDelete() throws FacetNotFoundException, ResourceRegistryException { protected void reallyDelete() throws FacetNotFoundException, ResourceRegistryException {
if(entryPoint) { if(entryPoint) {
OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next(); OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next();
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setElement(oVertex); resourceManagement.setElement(oVertex);
} }
element.delete();
return true; affectedInstances.put(uuid, serializeSelfAsJsonNode());
getElement().delete();
} }
protected void checkResource() throws SchemaViolationException, ResourceRegistryException { 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); Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
for(OEdge edge : edges) { for(OEdge edge : edges) {
@SuppressWarnings("rawtypes") RelationManagement<?,?> relationManagement = getRelationManagement(edge);
RelationManagement relationManagement = getRelationManagement(edge);
relationManagement.setReload(reload); relationManagement.setReload(reload);
if(relationManagement.giveMeSourceEntityManagementAsIs() == null) { if(relationManagement.giveMeSourceEntityManagementAsIs() == null) {
@ -203,9 +202,8 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
return element; return element;
} }
@SuppressWarnings("unchecked")
@Override @Override
protected boolean reallyDelete() throws ResourceNotFoundException, ResourceRegistryException { protected void reallyDelete() throws ResourceNotFoundException, ResourceRegistryException {
// internalDeleteResource(orientGraph, uuid, null); // internalDeleteResource(orientGraph, uuid, null);
getElement(); getElement();
@ -217,8 +215,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
OEdge edge = iterator.next(); OEdge edge = iterator.next();
OClass oClass = ElementManagementUtility.getOClass(edge); OClass oClass = ElementManagementUtility.getOClass(edge);
@SuppressWarnings("rawtypes") RelationManagement<?,?> relationManagement = null;
RelationManagement relationManagement = null;
if(oClass.isSubClassOf(IsRelatedTo.NAME)) { if(oClass.isSubClassOf(IsRelatedTo.NAME)) {
relationManagement = new IsRelatedToManagement(); relationManagement = new IsRelatedToManagement();
} else if(oClass.isSubClassOf(ConsistsOf.NAME)) { } 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 @Override
protected Map<UUID,JsonNode> reallyAddToContext() protected Map<UUID,JsonNode> reallyAddToContext()
throws ContextException, ResourceRegistryException { throws ContextException, ResourceRegistryException {
Map<UUID,JsonNode> affectedInstances = new HashMap<>(); if(!dryRun) {
if(!dryRunContextSharing) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument); targetSecurityContext.addElement(getElement(), oDatabaseDocument);
} }
@ -265,7 +261,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
for(OEdge edge : edges) { for(OEdge edge : edges) {
RelationManagement<?,?> relationManagement = getRelationManagement(edge); RelationManagement<?,?> relationManagement = getRelationManagement(edge);
relationManagement.setDryRunContextSharing(dryRunContextSharing); relationManagement.setDryRun(dryRun);
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
relationManagement.setTargetSecurityContext(targetSecurityContext); relationManagement.setTargetSecurityContext(targetSecurityContext);
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext(); 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.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; 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.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.relations.RelationElement; import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.context.reference.entities.Context;
@ -68,21 +67,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
*/ */
protected SecurityContext targetSecurityContext; 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 * By the default the system honour the propagation constraints
* so this variable is initialised as true. * so this variable is initialised as true.
@ -115,21 +99,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
*/ */
protected boolean honourPropagationConstraintsInContextSharing; 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 @Override
public void setSourceSecurityContext(SecurityContext sourceSecurityContext) { public void setSourceSecurityContext(SecurityContext sourceSecurityContext) {
this.sourceSecurityContext = sourceSecurityContext; this.sourceSecurityContext = sourceSecurityContext;
@ -150,25 +119,18 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return sourceSecurityContext; return sourceSecurityContext;
} }
public boolean isDryRunContextSharing() { @Override
return dryRunContextSharing;
}
public void setDryRunContextSharing(boolean dryRunContextSharing) {
this.dryRunContextSharing = dryRunContextSharing;
}
public boolean isHonourPropagationConstraintsInContextSharing() { public boolean isHonourPropagationConstraintsInContextSharing() {
return honourPropagationConstraintsInContextSharing; return honourPropagationConstraintsInContextSharing;
} }
@Override
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) { public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing; this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
} }
public final PropagationConstraint defaultPropagationConstraint; public final PropagationConstraint defaultPropagationConstraint;
/*
public boolean isAvailableOnContext(SecurityContext securityContext) { public boolean isAvailableOnContext(SecurityContext securityContext) {
try { try {
return securityContext.isElementInContext(element); return securityContext.isElementInContext(element);
@ -176,18 +138,11 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return false; return false;
} }
} }
*/
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, PropagationConstraint defaultPropagationConstraint) { protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, PropagationConstraint defaultPropagationConstraint) {
super(accessType, Resource.class, targetEntityClass); super(accessType, Resource.class, targetEntityClass);
this.defaultPropagationConstraint = defaultPropagationConstraint; 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 * By the default the system honour the propagation constraints
* so this variable is initialised as true. * so this variable is initialised as true.
@ -229,39 +184,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return sourceEntityManagement; 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 @Override
public JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget) throws ResourceRegistryException { public JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
JsonNode relation = serializeSelfAsJsonNode(); JsonNode relation = serializeSelfAsJsonNode();
@ -287,6 +210,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return relation; return relation;
} }
*/
protected Map<String,JsonNode> fullSerialize(Map<String,JsonNode> visitedSourceResources) protected Map<String,JsonNode> fullSerialize(Map<String,JsonNode> visitedSourceResources)
throws ResourceRegistryException { throws ResourceRegistryException {
@ -385,6 +309,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return element; return element;
} }
@Override
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException { protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setWorkingContext(getWorkingContext()); resourceManagement.setWorkingContext(getWorkingContext());
@ -392,8 +317,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return resourceManagement; return resourceManagement;
} }
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
protected String getEntityTypeNotValidErrroMessage(String entityPosition, String requiredType, String effectiveType) { protected String getEntityTypeNotValidErrroMessage(String entityPosition, String requiredType, String effectiveType) {
StringBuffer stringBuffer = new StringBuffer(); StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("The "); stringBuffer.append("The ");
@ -463,8 +386,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
throws ContextException, ResourceRegistryException { throws ContextException, ResourceRegistryException {
getElement(); getElement();
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
if(honourPropagationConstraintsInContextSharing) { if(honourPropagationConstraintsInContextSharing) {
AddConstraint addConstraint = AddConstraint.unpropagate; 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. * Otherwise we have a relation which point to an entity outside of the context.
*/ */
T targetEntityManagement = getTargetEntityManagement(); T targetEntityManagement = getTargetEntityManagement();
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing); targetEntityManagement.setDryRun(dryRun);
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
targetEntityManagement.setTargetSecurityContext(targetSecurityContext); targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(targetEntityManagement.internalAddToContext()); affectedInstances.putAll(targetEntityManagement.internalAddToContext());
if(!dryRunContextSharing) { if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument); targetSecurityContext.addElement(getElement(), oDatabaseDocument);
} }
/* /*
@ -519,7 +440,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
break; break;
} }
}else { }else {
if(!dryRunContextSharing) { if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument); targetSecurityContext.addElement(getElement(), oDatabaseDocument);
} }
/* /*
@ -533,13 +454,14 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return affectedInstances; return affectedInstances;
} }
@Override
public Map<UUID,JsonNode> internalAddToContext() public Map<UUID,JsonNode> internalAddToContext()
throws ContextException, ResourceRegistryException { throws ContextException, ResourceRegistryException {
try { try {
operation = Operation.ADD_TO_CONTEXT; operation = Operation.ADD_TO_CONTEXT;
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(); reallyAddToContext();
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) { if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
if(!dryRunContextSharing) { if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element); HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save(); element.save();
} }
@ -560,23 +482,21 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
setOperation(Operation.ADD_TO_CONTEXT); setOperation(Operation.ADD_TO_CONTEXT);
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
/* Adding source to Context */ /* Adding source to Context */
ResourceManagement resourceManagement = getSourceEntityManagement(); ResourceManagement resourceManagement = getSourceEntityManagement();
resourceManagement.setDryRunContextSharing(dryRunContextSharing); resourceManagement.setDryRun(dryRun);
resourceManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); resourceManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
resourceManagement.setTargetSecurityContext(targetSecurityContext); resourceManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(resourceManagement.internalAddToContext()); affectedInstances.putAll(resourceManagement.internalAddToContext());
/* Adding target to Context */ /* Adding target to Context */
T targetEntityManagement = getTargetEntityManagement(); T targetEntityManagement = getTargetEntityManagement();
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing); targetEntityManagement.setDryRun(dryRun);
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
targetEntityManagement.setTargetSecurityContext(targetSecurityContext); targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext()); affectedInstances.putAll(getTargetEntityManagement().internalAddToContext());
if(!dryRunContextSharing) { if(!dryRun) {
targetSecurityContext.addElement(getElement(), oDatabaseDocument); targetSecurityContext.addElement(getElement(), oDatabaseDocument);
} }
affectedInstances.put(uuid, serializeSelfAsJsonNode()); affectedInstances.put(uuid, serializeSelfAsJsonNode());
@ -584,6 +504,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return affectedInstances; return affectedInstances;
} }
@Override
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException { 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); logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
@ -594,7 +515,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
Map<UUID,JsonNode> added = forcedAddToContext(); forcedAddToContext();
sanityCheck(); 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, logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
contextUUID); contextUUID);
return added; return affectedInstances;
} catch(Exception e) { } catch(Exception e) {
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
contextUUID, e); contextUUID, e);
@ -627,8 +548,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
getSourceEntityManagement().getElement(); getSourceEntityManagement().getElement();
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
RemoveConstraint removeConstraint = RemoveConstraint.keep; RemoveConstraint removeConstraint = RemoveConstraint.keep;
try { 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 * In any removeConstraint value the relation MUST be removed from context to
* avoid to have edge having a source outside of the context. * avoid to have edge having a source outside of the context.
*/ */
if(!dryRunContextSharing) { if(!dryRun) {
targetSecurityContext.removeElement(getElement(), oDatabaseDocument); targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
} }
affectedInstances.put(uuid, serializeSelfAsJsonNode()); affectedInstances.put(uuid, serializeSelfAsJsonNode());
T targetEntityManagement = getTargetEntityManagement(); T targetEntityManagement = getTargetEntityManagement();
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing); targetEntityManagement.setDryRun(dryRun);
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing); targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
targetEntityManagement.setTargetSecurityContext(targetSecurityContext); targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
switch(removeConstraint) { switch(removeConstraint) {
@ -710,12 +629,13 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return affectedInstances; return affectedInstances;
} }
@Override
public Map<UUID,JsonNode> internalRemoveFromContext() public Map<UUID,JsonNode> internalRemoveFromContext()
throws ContextException, ResourceRegistryException { throws ContextException, ResourceRegistryException {
try { try {
setOperation(Operation.REMOVE_FROM_CONTEXT); setOperation(Operation.REMOVE_FROM_CONTEXT);
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(); reallyRemoveFromContext();
if(!dryRunContextSharing) { if(!dryRun) {
HeaderUtility.updateModifiedByAndLastUpdate(element); HeaderUtility.updateModifiedByAndLastUpdate(element);
element.save(); element.save();
} }
@ -729,6 +649,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
} }
} }
@Override
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID) public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
throws NotFoundException, ContextException, ResourceRegistryException { throws NotFoundException, ContextException, ResourceRegistryException {
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID); 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); targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(); internalRemoveFromContext();
sanityCheck(); sanityCheck();
@ -774,7 +695,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
} }
@Override @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, logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
targetEntityClass.getSimpleName()); targetEntityClass.getSimpleName());
@ -802,6 +723,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
} }
OVertex target = getTargetEntityManagement().getElement(); OVertex target = getTargetEntityManagement().getElement();
affectedInstances.put(uuid, serializeAsJsonNode());
element.delete(); element.delete();
switch(removeConstraint) { switch(removeConstraint) {
@ -826,11 +748,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
default: default:
break; break;
} }
return true;
} }
@SuppressWarnings("unchecked")
protected Collection<JsonNode> serializeEdges(Iterable<ODocument> edges, boolean postFilterPolymorphic) protected Collection<JsonNode> serializeEdges(Iterable<ODocument> edges, boolean postFilterPolymorphic)
throws ResourceRegistryException { throws ResourceRegistryException {
Map<String,JsonNode> visitedSourceResources = new HashMap<>(); Map<String,JsonNode> visitedSourceResources = new HashMap<>();
@ -842,6 +761,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
continue; continue;
} }
@SuppressWarnings("unchecked")
RelationManagement<T, TET> relationManagement = (RelationManagement<T, TET>) ElementManagementUtility.getRelationManagement(getWorkingContext(), RelationManagement<T, TET> relationManagement = (RelationManagement<T, TET>) ElementManagementUtility.getRelationManagement(getWorkingContext(),
oDatabaseDocument, edge); oDatabaseDocument, edge);
visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources); visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);

View File

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

View File

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

View File

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

View File

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

View File

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