parent
60c96b6a91
commit
a10323735d
|
@ -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;
|
||||||
|
@ -432,13 +433,13 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -101,13 +104,13 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,69 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
protected El element;
|
protected El element;
|
||||||
protected boolean reload;
|
protected boolean reload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* To revert a previous operation or for particular a maintenance
|
||||||
|
* we could request to the service do not honour the propagation
|
||||||
|
* constraints but under certain conditions and with some limitation
|
||||||
|
* only.
|
||||||
|
* These limitation are required to keep the system in a consistent
|
||||||
|
* state.
|
||||||
|
* In fact, this directive is only valid for Resources and IsRelatedTo
|
||||||
|
* relations. We need to take in account that to add an
|
||||||
|
* IsRelatedTo to a context always the source and target
|
||||||
|
* Resources must be in such a Context.
|
||||||
|
* Please also take into account that adding a Resource
|
||||||
|
* to a context always imply to honour the propagation constraints
|
||||||
|
* of ConsistsOf relations. In fact, a resource must be characterised
|
||||||
|
* least by one facet in any context it belongs. Giving that we
|
||||||
|
* cannot made assumption on which facets must be used.
|
||||||
|
* A way could be to consider just the facets are mandatory for such a
|
||||||
|
* Resource Type, but the type could not have mandatory facets
|
||||||
|
* (even every Resource Type in the gCube Model has one mandatory facet).
|
||||||
|
* As counterpart, when a Resource is removed from a Context all the facets
|
||||||
|
* charactering it must be removed.
|
||||||
|
*
|
||||||
|
* This option can also be used in conjunction with
|
||||||
|
* {@link ElementManagement#dryRunContextSharing}=true.
|
||||||
|
* This allow to simulate a sharing operation which requires
|
||||||
|
* do not honour the propagation constraints.
|
||||||
|
*/
|
||||||
|
protected boolean honourPropagationConstraintsInContextSharing;
|
||||||
|
|
||||||
|
public boolean isDryRunContextSharing() {
|
||||||
|
return dryRunContextSharing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDryRunContextSharing(boolean dryRunContextSharing) {
|
||||||
|
this.dryRunContextSharing = dryRunContextSharing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHonourPropagationConstraintsInContextSharing() {
|
||||||
|
return honourPropagationConstraintsInContextSharing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHonourPropagationConstraintsInContextSharing(boolean honourPropagationConstraintsInContextSharing) {
|
||||||
|
this.honourPropagationConstraintsInContextSharing = honourPropagationConstraintsInContextSharing;
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
@ -128,6 +191,19 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
this.reload = false;
|
this.reload = false;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
this.honourPropagationConstraintsInContextSharing = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUUID(UUID uuid) throws ResourceRegistryException {
|
public void setUUID(UUID uuid) throws ResourceRegistryException {
|
||||||
|
@ -327,16 +403,19 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
return reallyDelete();
|
return reallyDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected abstract Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException;
|
throws ContextException, ResourceRegistryException;
|
||||||
|
|
||||||
public boolean internalAddToContext(SecurityContext targetSecurityContext)
|
public Map<UUID,JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
boolean ret = reallyAddToContext(targetSecurityContext);
|
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(targetSecurityContext);
|
||||||
|
if(!dryRunContextSharing) {
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
element.save();
|
element.save();
|
||||||
return ret && true;
|
}
|
||||||
|
affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -345,16 +424,19 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected abstract Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException;
|
throws ContextException, ResourceRegistryException;
|
||||||
|
|
||||||
public boolean internalRemoveFromContext(SecurityContext targetSecurityContext)
|
public Map<UUID,JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
boolean ret = reallyRemoveFromContext(targetSecurityContext);
|
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext(targetSecurityContext);
|
||||||
|
if(!dryRunContextSharing) {
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
element.save();
|
element.save();
|
||||||
return ret && true;
|
}
|
||||||
|
affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -681,7 +763,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addToContext(UUID contextUUID)
|
public Map<UUID,JsonNode> addToContext(UUID contextUUID)
|
||||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
|
@ -691,12 +773,12 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
boolean added = internalAddToContext(targetSecurityContext);
|
Map<UUID,JsonNode> affecteElements = internalAddToContext(targetSecurityContext);
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
|
|
||||||
return added;
|
return affecteElements;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID);
|
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
if(oDatabaseDocument != null) {
|
if(oDatabaseDocument != null) {
|
||||||
|
@ -720,7 +802,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean 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 {}", elementType, uuid, contextUUID);
|
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
|
@ -730,13 +812,12 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
boolean removed = internalRemoveFromContext(targetSecurityContext);
|
Map<UUID,JsonNode> affecteElements = internalRemoveFromContext(targetSecurityContext);
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid,
|
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
contextUUID);
|
|
||||||
|
|
||||||
return removed;
|
return affecteElements;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
if(oDatabaseDocument != null) {
|
if(oDatabaseDocument != null) {
|
||||||
|
|
|
@ -191,37 +191,53 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
|
|
||||||
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
|
/*
|
||||||
|
* DO NOT UNCOMMENT
|
||||||
|
* the instance is added internalAddToContext() function after
|
||||||
|
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||||
|
* affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
*/
|
||||||
|
|
||||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||||
|
|
||||||
for(OEdge edge : edges) {
|
for(OEdge edge : edges) {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
RelationManagement relationManagement = getRelationManagement(edge);
|
RelationManagement relationManagement = getRelationManagement(edge);
|
||||||
relationManagement.internalAddToContext(targetSecurityContext);
|
affectedInstances.putAll(relationManagement.internalAddToContext(targetSecurityContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
|
|
||||||
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||||
|
|
||||||
for(OEdge edge : edges) {
|
for(OEdge edge : edges) {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
RelationManagement relationManagement = getRelationManagement(edge);
|
RelationManagement relationManagement = getRelationManagement(edge);
|
||||||
relationManagement.internalRemoveFromContext(targetSecurityContext);
|
affectedInstances.putAll(relationManagement.internalRemoveFromContext(targetSecurityContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||||
|
/*
|
||||||
|
* DO NOT UNCOMMENT
|
||||||
|
* the instance is added internalAddToContext() function after
|
||||||
|
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||||
|
* affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
*/
|
||||||
|
|
||||||
return true;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,11 +47,21 @@ import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
public abstract class RelationManagement<T extends EntityManagement<? extends Entity>>
|
public abstract class RelationManagement<T extends EntityManagement<? extends Entity>>
|
||||||
extends RelationElementManagement<ResourceManagement, T>{
|
extends RelationElementManagement<ResourceManagement, T>{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used in AddToContext. The Relation must add/check also the source entity
|
||||||
|
*/
|
||||||
|
public boolean checkContextOfSourceEntity;
|
||||||
|
|
||||||
|
public void setCheckContextOfSourceEntity(boolean checkContextOfSourceEntity) {
|
||||||
|
this.checkContextOfSourceEntity = checkContextOfSourceEntity;
|
||||||
|
}
|
||||||
|
|
||||||
public final PropagationConstraint defaultPropagationConstraint;
|
public final PropagationConstraint defaultPropagationConstraint;
|
||||||
|
|
||||||
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;
|
||||||
|
this.checkContextOfSourceEntity = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph,
|
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph,
|
||||||
|
@ -260,10 +270,12 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
AddConstraint addConstraint = AddConstraint.unpropagate;
|
AddConstraint addConstraint = AddConstraint.unpropagate;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -292,9 +304,15 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
* The relation must be added only in the case the target vertex must be added.
|
* 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.
|
* Otherwise we have a relation which point to an entity outside of the context.
|
||||||
*/
|
*/
|
||||||
getTargetEntityManagement().internalAddToContext(targetSecurityContext);
|
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext(targetSecurityContext));
|
||||||
|
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
|
/*
|
||||||
|
* DO NOT UNCOMMENT
|
||||||
|
* the instance is added internalAddToContext() function after
|
||||||
|
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||||
|
* affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
*/
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -305,30 +323,34 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean forcedAddToContext(SecurityContext targetSecurityContext)
|
public Map<UUID,JsonNode> forcedAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
|
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
/* Adding source to Context */
|
/* Adding source to Context */
|
||||||
getSourceEntityManagement().internalAddToContext(targetSecurityContext);
|
affectedInstances.putAll(getSourceEntityManagement().internalAddToContext(targetSecurityContext));
|
||||||
|
|
||||||
/* Adding target to Context */
|
/* Adding target to Context */
|
||||||
getTargetEntityManagement().internalAddToContext(targetSecurityContext);
|
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext(targetSecurityContext));
|
||||||
|
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
|
affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
|
||||||
return true;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -357,10 +379,11 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
* avoid to have edge having a source outside of the context.
|
* avoid to have edge having a source outside of the context.
|
||||||
*/
|
*/
|
||||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||||
|
affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
|
||||||
switch(removeConstraint) {
|
switch(removeConstraint) {
|
||||||
case cascade:
|
case cascade:
|
||||||
getTargetEntityManagement().internalRemoveFromContext(targetSecurityContext);
|
affectedInstances.putAll(getTargetEntityManagement().internalRemoveFromContext(targetSecurityContext));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cascadeWhenOrphan:
|
case cascadeWhenOrphan:
|
||||||
|
@ -386,10 +409,10 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
|
|
||||||
if(count > 0) {
|
if(count > 0) {
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from .",
|
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from {}.",
|
||||||
element, target, edge, removeConstraint, targetSecurityContext);
|
element, target, edge, removeConstraint, targetSecurityContext);
|
||||||
} else {
|
} else {
|
||||||
getTargetEntityManagement().internalRemoveFromContext(targetSecurityContext);
|
affectedInstances.putAll(getTargetEntityManagement().internalRemoveFromContext(targetSecurityContext));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -400,7 +423,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -495,7 +518,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean 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);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -503,7 +526,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
|
|
||||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
boolean added = forcedAddToContext(targetSecurityContext);
|
Map<UUID,JsonNode> added = forcedAddToContext(targetSecurityContext);
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
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,
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.rest;
|
package org.gcube.informationsystem.resourceregistry.rest;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.core.Response.Status;
|
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
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.common.authorization.library.provider.CalledMethodProvider;
|
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
||||||
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||||
|
@ -21,7 +26,6 @@ import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.rest.extrahttpmethods.PATCH;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -33,6 +37,19 @@ public class SharingManager {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SharingManager.class);
|
private static Logger logger = LoggerFactory.getLogger(SharingManager.class);
|
||||||
|
|
||||||
|
protected String serializeAffectedInstaces(ObjectMapper objectMapper, Map<UUID,JsonNode> affectedInstances) throws ResourceRegistryException {
|
||||||
|
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||||
|
for(JsonNode jsonNode : affectedInstances.values()) {
|
||||||
|
arrayNode.add(jsonNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return objectMapper.writeValueAsString(arrayNode);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add/Remove to/from the context identified by CONTEXT_UUID path parameter the list of instances contained in the body of the request.
|
* Add/Remove to/from the context identified by CONTEXT_UUID path parameter the list of instances contained in the body of the request.
|
||||||
* The the body is the following
|
* The the body is the following
|
||||||
|
@ -55,91 +72,81 @@ public class SharingManager {
|
||||||
* where
|
* where
|
||||||
* 67062c11-9c3a-4906-870d-7df6a43408b0/ is the Context UUID
|
* 67062c11-9c3a-4906-870d-7df6a43408b0/ is the Context UUID
|
||||||
*
|
*
|
||||||
* The body contains the list of instances to add/remvoe to/from the context identified by CONTEXT_UUID
|
* The body contains the list of instances to add/remove to/from the context identified by CONTEXT_UUID
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PATCH
|
@POST
|
||||||
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}")
|
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}")
|
||||||
public boolean addRemoveToFromContextNoPropagationConstraint(
|
public String addRemoveToFromContextNoPropagationConstraint(
|
||||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||||
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation,
|
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation,
|
||||||
|
@QueryParam(SharingPath.DRY_RUN_QUERY_PARAMETER) Boolean dryRun,
|
||||||
String body)
|
String body)
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
logger.info("Requested to add to {} with UUID {} the following instances {}", Context.NAME, contextId, body);
|
try {
|
||||||
|
StringBuffer calledMethod = new StringBuffer();
|
||||||
|
if(dryRun==null) {
|
||||||
|
dryRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dryRun) {
|
||||||
|
calledMethod.append("dryRun");
|
||||||
|
}
|
||||||
|
|
||||||
if(operation == SharingOperation.ADD) {
|
if(operation == SharingOperation.ADD) {
|
||||||
CalledMethodProvider.instance.set("addToContextNoPropagationConstraint");
|
logger.info("Requested {} {} to {} with UUID {}", dryRun? "a dry run for adding": "to add", body, Context.NAME, contextId);
|
||||||
|
calledMethod.append("AddToContext");
|
||||||
}else {
|
}else {
|
||||||
CalledMethodProvider.instance.set("removeFromContextNoPropagationConstraint");
|
logger.info("Requested {} {} from {} with UUID {}", dryRun? "a dry run for removing": "to remove", body, Context.NAME, contextId);
|
||||||
|
calledMethod.append("RemoveFromContext");
|
||||||
}
|
}
|
||||||
|
calledMethod.append("NoPropagationConstraint");
|
||||||
|
CalledMethodProvider.instance.set(calledMethod.toString());
|
||||||
|
|
||||||
/*
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
boolean success = true;
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
for(any element in body) {
|
|
||||||
String type = ""; // get type
|
|
||||||
UUID instanceUUID = UUID.fromString("");
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
|
||||||
elementManagement.setUUID(instanceUUID);
|
|
||||||
// success = success && return elementManagement.addToContextNoPropagationConstraint(UUID.fromString(contextId), body);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
ArrayNode arrayNode = (ArrayNode) objectMapper.readTree(body);
|
||||||
*
|
for(JsonNode node : arrayNode) {
|
||||||
* Get the list of instances affected by an add/remove to/from context the target instance identified by UUID path parameter
|
|
||||||
*
|
|
||||||
* GET /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}?operation=(ADD|REMOVE)
|
|
||||||
*
|
|
||||||
* e.g
|
|
||||||
* GET /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=ADD
|
|
||||||
* GET /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=REMOVE
|
|
||||||
*
|
|
||||||
* where
|
|
||||||
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID and
|
|
||||||
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}/"
|
|
||||||
+ AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
|
||||||
public String checkAddRemove(
|
|
||||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
|
||||||
@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
|
||||||
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
|
|
||||||
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation)
|
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
||||||
|
|
||||||
logger.info("Requested to add {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME, contextId);
|
|
||||||
|
|
||||||
if(operation == SharingOperation.ADD) {
|
|
||||||
CalledMethodProvider.instance.set("dryRunAddToContext");
|
|
||||||
}else {
|
|
||||||
CalledMethodProvider.instance.set("dryRunRemoveFromContext");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
String type = node.get(Element.CLASS_PROPERTY).asText();
|
||||||
|
String instanceId = node.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText();
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
elementManagement.setUUID(UUID.fromString(instanceId));
|
elementManagement.setUUID(UUID.fromString(instanceId));
|
||||||
|
elementManagement.setDryRunContextSharing(dryRun);
|
||||||
|
|
||||||
|
ArrayNode ret = null;
|
||||||
if(operation == SharingOperation.ADD) {
|
if(operation == SharingOperation.ADD) {
|
||||||
// elementManagement.dryRunAddToContext(UUID.fromString(contextId));
|
affectedInstances.putAll(elementManagement.addToContext(UUID.fromString(contextId)));
|
||||||
}else {
|
}else {
|
||||||
// elementManagement.dryRunRemoveFromContext(UUID.fromString(contextId));
|
affectedInstances.putAll(elementManagement.removeFromContext(UUID.fromString(contextId)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serializeAffectedInstaces(objectMapper, affectedInstances);
|
||||||
|
}catch (ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}
|
* Add/Remove an instance from context. The operation can have a cascade effect due to propagation constraint.
|
||||||
|
*
|
||||||
|
* Return the list of instances affected by an add/remove to/from context the target instance identified by UUID path parameter
|
||||||
|
*
|
||||||
|
* POST /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}?operation=(ADD|REMOVE)&[dryRun=true]
|
||||||
|
*
|
||||||
* e.g
|
* e.g
|
||||||
* POST /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8
|
* POST /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=ADD&dryRun=true
|
||||||
* Where
|
* POST /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=REMOVE&dryRun=true
|
||||||
|
*
|
||||||
|
* where
|
||||||
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID and
|
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID and
|
||||||
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
||||||
*
|
*
|
||||||
|
@ -147,51 +154,51 @@ public class SharingManager {
|
||||||
@POST
|
@POST
|
||||||
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}/"
|
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}/"
|
||||||
+ AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
+ AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
||||||
public boolean add(
|
public String addRemove(
|
||||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||||
@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
||||||
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId)
|
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
|
||||||
|
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation,
|
||||||
|
@QueryParam(SharingPath.DRY_RUN_QUERY_PARAMETER) Boolean dryRun)
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
logger.info("Requested to add {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME, contextId);
|
StringBuffer calledMethod = new StringBuffer();
|
||||||
// setRESTCalledMethod(HTTPMETHOD.PUT, type);
|
if(dryRun==null) {
|
||||||
CalledMethodProvider.instance.set("addToContext");
|
dryRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dryRun) {
|
||||||
|
calledMethod.append("dryRun");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(operation == SharingOperation.ADD) {
|
||||||
|
logger.info("Requested {} {} with UUID {} to {} with UUID {}", dryRun? "a dry run for adding": "to add", type, instanceId, Context.NAME, contextId);
|
||||||
|
calledMethod.append("AddToContext");
|
||||||
|
}else {
|
||||||
|
logger.info("Requested {} {} with UUID {} from {} with UUID {}", dryRun? "a dry run for removing": "to remove", type, instanceId, Context.NAME, contextId);
|
||||||
|
calledMethod.append("RemoveFromContext");
|
||||||
|
}
|
||||||
|
|
||||||
|
CalledMethodProvider.instance.set(calledMethod.toString());
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
elementManagement.setUUID(UUID.fromString(instanceId));
|
elementManagement.setUUID(UUID.fromString(instanceId));
|
||||||
return elementManagement.addToContext(UUID.fromString(contextId));
|
elementManagement.setDryRunContextSharing(dryRun);
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
Map<UUID,JsonNode> affectedInstances = null;
|
||||||
|
if(operation == SharingOperation.ADD) {
|
||||||
|
affectedInstances = elementManagement.addToContext(UUID.fromString(contextId));
|
||||||
|
}else {
|
||||||
|
affectedInstances = elementManagement.removeFromContext(UUID.fromString(contextId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
try {
|
||||||
* DELETE /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}
|
return serializeAffectedInstaces(objectMapper, affectedInstances);
|
||||||
* e.g
|
} catch (Exception e) {
|
||||||
* DELETE /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8
|
throw new ResourceRegistryException(e);
|
||||||
* Where
|
}
|
||||||
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID and
|
|
||||||
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@DELETE
|
|
||||||
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}/"
|
|
||||||
+ AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
|
||||||
public Response remove(
|
|
||||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
|
||||||
@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
|
||||||
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId)
|
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
||||||
logger.info("Requested to remove {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME,
|
|
||||||
contextId);
|
|
||||||
|
|
||||||
CalledMethodProvider.instance.set("removeFromContext");
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
|
||||||
elementManagement.setUUID(UUID.fromString(instanceId));
|
|
||||||
elementManagement.removeFromContext(UUID.fromString(contextId));
|
|
||||||
|
|
||||||
return Response.status(Status.NO_CONTENT).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -196,13 +198,13 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -188,13 +190,13 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -194,13 +197,13 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.instances.model.entity;
|
package org.gcube.informationsystem.resourceregistry.instances.model.entity;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||||
|
@ -145,28 +147,30 @@ public class FacetManagementTest extends ContextTest {
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <F extends Facet> boolean addToContext(F facet) throws Exception {
|
protected <F extends Facet> Map<UUID,JsonNode> addToContext(F facet) throws Exception {
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
String facetType = Utility.getTypeName(facet);
|
String facetType = Utility.getTypeName(facet);
|
||||||
facetManagement.setElementType(facetType);
|
facetManagement.setElementType(facetType);
|
||||||
facetManagement.setUUID(facet.getHeader().getUUID());
|
facetManagement.setUUID(facet.getHeader().getUUID());
|
||||||
|
|
||||||
boolean added = facetManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
Map<UUID,JsonNode> affectedInstances = facetManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||||
Assert.assertTrue(added);
|
Assert.assertTrue(affectedInstances.containsKey(facet.getHeader().getUUID()));
|
||||||
|
Assert.assertTrue(affectedInstances.size()==1);
|
||||||
|
|
||||||
return added;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <F extends Facet> boolean removeFromContext(F facet) throws Exception {
|
protected <F extends Facet> Map<UUID,JsonNode> removeFromContext(F facet) throws Exception {
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
String facetType = Utility.getTypeName(facet);
|
String facetType = Utility.getTypeName(facet);
|
||||||
facetManagement.setElementType(facetType);
|
facetManagement.setElementType(facetType);
|
||||||
facetManagement.setUUID(facet.getHeader().getUUID());
|
facetManagement.setUUID(facet.getHeader().getUUID());
|
||||||
|
|
||||||
boolean added = facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
Map<UUID,JsonNode> affectedInstances = facetManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||||
Assert.assertTrue(added);
|
Assert.assertTrue(affectedInstances.containsKey(facet.getHeader().getUUID()));
|
||||||
|
Assert.assertTrue(affectedInstances.size()==1);
|
||||||
|
|
||||||
return added;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ActionFunction<F extends Facet> {
|
interface ActionFunction<F extends Facet> {
|
||||||
|
|
|
@ -9,9 +9,12 @@ import java.net.URL;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
|
@ -281,8 +284,9 @@ public class BasicTest extends ContextTest {
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(uuid);
|
resourceManagement.setUUID(uuid);
|
||||||
|
|
||||||
boolean addedToContext = resourceManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
Map<UUID, JsonNode> affectedInstaces = resourceManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||||
Assert.assertTrue(addedToContext);
|
|
||||||
|
Assert.assertTrue(affectedInstaces);
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(uuid);
|
resourceManagement.setUUID(uuid);
|
||||||
|
@ -439,8 +443,8 @@ public class BasicTest extends ContextTest {
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(hnUUID);
|
resourceManagement.setUUID(hnUUID);
|
||||||
boolean removed = resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
Map<String,JsonNode> affectedInstaces = resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||||
Assert.assertTrue(removed);
|
Assert.assertTrue(affectedInstaces);
|
||||||
|
|
||||||
/* The cascading MUST remove the relation and the target so that
|
/* The cascading MUST remove the relation and the target so that
|
||||||
* I MUST not be able to read Activates relation and EService
|
* I MUST not be able to read Activates relation and EService
|
||||||
|
|
Loading…
Reference in New Issue