Reorganizing code
This commit is contained in:
parent
93f5999553
commit
05a8825635
|
@ -27,10 +27,10 @@ public interface ERManagement {
|
|||
|
||||
public SecurityContext getSourceSecurityContext();
|
||||
|
||||
public Map<UUID, JsonNode> internalAddToContext()
|
||||
public void internalAddToContext()
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> addToContext(UUID contextUUID)
|
||||
public void addToContext(UUID contextUUID)
|
||||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
|
||||
|
||||
/**
|
||||
|
@ -41,10 +41,10 @@ public interface ERManagement {
|
|||
|
||||
public SecurityContext getTargetSecurityContext();
|
||||
|
||||
public Map<UUID, JsonNode> internalRemoveFromContext()
|
||||
public void internalRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException;
|
||||
|
||||
public Map<UUID, JsonNode> removeFromContext(UUID contextUUID)
|
||||
public void removeFromContext(UUID contextUUID)
|
||||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
|
||||
|
||||
// public void sanityCheck() throws SchemaViolationException, ResourceRegistryException;
|
||||
|
|
|
@ -299,9 +299,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyAddToContext()
|
||||
protected void reallyAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
if(!dryRun) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
}
|
||||
|
@ -320,15 +319,14 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
relationManagement.setDryRun(dryRun);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(relationManagement.internalAddToContext());
|
||||
relationManagement.internalAddToContext();
|
||||
affectedInstances.putAll(relationManagement.getAffectedInstances());
|
||||
}
|
||||
}
|
||||
|
||||
return affectedInstances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalAddToContext()
|
||||
public void internalAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
setOperation(Operation.ADD_TO_CONTEXT);
|
||||
|
@ -339,7 +337,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
sanityCheck();
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -348,7 +345,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
||||
public void addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
@ -360,12 +357,10 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
sourceSecurityContext = ContextUtility.getCurrentSecurityContext();
|
||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = internalAddToContext();
|
||||
internalAddToContext();
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {} - Reason is {}", typeName, uuid, contextUUID, e.getMessage());
|
||||
if(oDatabaseDocument != null) {
|
||||
|
@ -390,18 +385,17 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext()
|
||||
public void internalRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
setOperation(Operation.REMOVE_FROM_CONTEXT);
|
||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
|
||||
reallyRemoveFromContext();
|
||||
if(!dryRun) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
}
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
sanityCheck();
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -421,7 +415,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
relationManagement.setDryRun(dryRun);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(relationManagement.internalRemoveFromContext());
|
||||
relationManagement.internalRemoveFromContext();
|
||||
affectedInstances.putAll(relationManagement.getAffectedInstances());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -438,7 +433,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
return affectedInstances;
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||
public void removeFromContext(UUID contextUUID)
|
||||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
||||
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
@ -455,8 +450,6 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
if(oDatabaseDocument != null) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
|
@ -240,7 +239,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Map<UUID,JsonNode> reallyAddToContext()
|
||||
protected void reallyAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
|
||||
if(!dryRun) {
|
||||
|
@ -264,10 +263,10 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
relationManagement.setDryRun(dryRun);
|
||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext();
|
||||
affectedInstances.putAll(resourceCharacterisationInstances);
|
||||
relationManagement.internalAddToContext();
|
||||
affectedInstances.putAll(relationManagement.getAffectedInstances());
|
||||
if(relationManagement instanceof ConsistsOfManagement) {
|
||||
facetCounter = facetCounter + resourceCharacterisationInstances.size();
|
||||
facetCounter = facetCounter + relationManagement.getAffectedInstances().size();
|
||||
}
|
||||
relationManagement.sanityCheck();
|
||||
}
|
||||
|
@ -286,7 +285,6 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
}
|
||||
}
|
||||
|
||||
return affectedInstances;
|
||||
}
|
||||
|
||||
public String all(boolean polymorphic) throws ResourceRegistryException {
|
||||
|
|
|
@ -415,11 +415,11 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
* The relation must be added only in the case the target vertex must be added.
|
||||
* Otherwise we have a relation which point to an entity outside of the context.
|
||||
*/
|
||||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRun(dryRun);
|
||||
getTargetEntityManagement().setDryRun(dryRun);
|
||||
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(targetEntityManagement.internalAddToContext());
|
||||
targetEntityManagement.internalAddToContext();
|
||||
affectedInstances.putAll(targetEntityManagement.getAffectedInstances());
|
||||
|
||||
if(!dryRun) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
@ -455,7 +455,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalAddToContext()
|
||||
public void internalAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
operation = Operation.ADD_TO_CONTEXT;
|
||||
|
@ -467,7 +467,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
}
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -478,23 +477,21 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
public Map<UUID,JsonNode> forcedAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
||||
setOperation(Operation.ADD_TO_CONTEXT);
|
||||
|
||||
/* Adding source to Context */
|
||||
ResourceManagement resourceManagement = getSourceEntityManagement();
|
||||
resourceManagement.setDryRun(dryRun);
|
||||
resourceManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
resourceManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(resourceManagement.internalAddToContext());
|
||||
getSourceEntityManagement().setDryRun(dryRun);
|
||||
sourceEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
sourceEntityManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
sourceEntityManagement.internalAddToContext();
|
||||
affectedInstances.putAll(sourceEntityManagement.getAffectedInstances());
|
||||
|
||||
/* Adding target to Context */
|
||||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRun(dryRun);
|
||||
getTargetEntityManagement().setDryRun(dryRun);
|
||||
targetEntityManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext());
|
||||
targetEntityManagement.internalAddToContext();
|
||||
affectedInstances.putAll(targetEntityManagement.getAffectedInstances());
|
||||
|
||||
if(!dryRun) {
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
@ -505,7 +502,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
||||
public void addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
||||
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
try {
|
||||
|
@ -522,8 +519,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
|
||||
contextUUID, e);
|
||||
|
@ -586,7 +581,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
targetEntityManagement.setTargetSecurityContext(targetSecurityContext);
|
||||
switch(removeConstraint) {
|
||||
case cascade:
|
||||
affectedInstances.putAll(targetEntityManagement.internalRemoveFromContext());
|
||||
targetEntityManagement.internalRemoveFromContext();
|
||||
affectedInstances.putAll(targetEntityManagement.getAffectedInstances());
|
||||
break;
|
||||
|
||||
case cascadeWhenOrphan:
|
||||
|
@ -615,7 +611,8 @@ 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());
|
||||
targetEntityManagement.internalRemoveFromContext();
|
||||
affectedInstances.putAll(targetEntityManagement.getAffectedInstances());
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -630,7 +627,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> internalRemoveFromContext()
|
||||
public void internalRemoveFromContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
try {
|
||||
setOperation(Operation.REMOVE_FROM_CONTEXT);
|
||||
|
@ -640,7 +637,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
element.save();
|
||||
}
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -650,7 +646,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||
public void removeFromContext(UUID contextUUID)
|
||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||
|
@ -668,8 +664,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
||||
return affectedInstances;
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
if(oDatabaseDocument != null) {
|
||||
|
|
|
@ -190,16 +190,16 @@ public class SharingManager {
|
|||
|
||||
UUID contextUUID = UUID.fromString(contextId);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<UUID,JsonNode> affectedInstances = null;
|
||||
|
||||
if(operation == SharingOperation.ADD) {
|
||||
affectedInstances = ((ERManagement) elementManagement).addToContext(contextUUID);
|
||||
((ERManagement) elementManagement).addToContext(contextUUID);
|
||||
}else {
|
||||
affectedInstances = ((ERManagement) elementManagement).removeFromContext(contextUUID);
|
||||
((ERManagement) elementManagement).removeFromContext(contextUUID);
|
||||
}
|
||||
|
||||
try {
|
||||
return serializeAffectedInstaces(objectMapper, affectedInstances);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return serializeAffectedInstaces(objectMapper, elementManagement.getAffectedInstances());
|
||||
} catch (Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
|
|
|
@ -153,7 +153,8 @@ public class FacetManagementTest extends ContextTest {
|
|||
facetManagement.setElementType(facetType);
|
||||
facetManagement.setUUID(facet.getHeader().getUUID());
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = facetManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
facetManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
Map<UUID,JsonNode> affectedInstances = facetManagement.getAffectedInstances();
|
||||
Assert.assertTrue(affectedInstances.containsKey(facet.getHeader().getUUID()));
|
||||
Assert.assertTrue(affectedInstances.size()==1);
|
||||
|
||||
|
@ -166,7 +167,8 @@ public class FacetManagementTest extends ContextTest {
|
|||
facetManagement.setElementType(facetType);
|
||||
facetManagement.setUUID(facet.getHeader().getUUID());
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
Map<UUID,JsonNode> affectedInstances = facetManagement.getAffectedInstances();
|
||||
Assert.assertTrue(affectedInstances.containsKey(facet.getHeader().getUUID()));
|
||||
Assert.assertTrue(affectedInstances.size()==1);
|
||||
|
||||
|
|
|
@ -396,7 +396,8 @@ public class BasicTest extends MultiContextTest {
|
|||
|
||||
resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(hnUUID);
|
||||
Map<UUID,JsonNode> affectedInstances = resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
Map<UUID,JsonNode> affectedInstances = resourceManagement.getAffectedInstances();
|
||||
logger.debug("Remove from Context affects the following instances {}", affectedInstances.values());
|
||||
|
||||
// Assert.assertTrue(affectedInstaces);
|
||||
|
|
|
@ -82,7 +82,8 @@ public class MultiContextTest extends ContextTest {
|
|||
resourceManagement.setUUID(r.getHeader().getUUID());
|
||||
resourceManagement.setDryRun(dryRun);
|
||||
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
|
||||
Map<UUID, JsonNode> affectedInstances = resourceManagement.removeFromContext(contextUUID);
|
||||
resourceManagement.removeFromContext(contextUUID);
|
||||
Map<UUID, JsonNode> affectedInstances = resourceManagement.getAffectedInstances();
|
||||
|
||||
SortedSet<UUID> expectedInstancesUUID = new TreeSet<>(expectedInstances.keySet());
|
||||
SortedSet<UUID> affectedInstancesUUID = new TreeSet<>(affectedInstances.keySet());
|
||||
|
@ -189,7 +190,8 @@ public class MultiContextTest extends ContextTest {
|
|||
resourceManagement.setUUID(r.getHeader().getUUID());
|
||||
resourceManagement.setDryRun(dryRun);
|
||||
UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(targetContextFullName).getUUID();
|
||||
Map<UUID, JsonNode> affectedInstances = resourceManagement.addToContext(contextUUID);
|
||||
resourceManagement.addToContext(contextUUID);
|
||||
Map<UUID, JsonNode> affectedInstances = resourceManagement.getAffectedInstances();
|
||||
|
||||
SortedSet<UUID> expectedInstancesUUID = new TreeSet<>(expectedInstances.keySet());
|
||||
SortedSet<UUID> affectedInstancesUUID = new TreeSet<>(affectedInstances.keySet());
|
||||
|
|
Loading…
Reference in New Issue