Implementing strategy for add/remove to/from context no follow
This commit is contained in:
parent
d4f4ac9468
commit
dd2e363a51
|
@ -792,7 +792,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
}else {
|
}else {
|
||||||
if(operationValidator==null) {
|
if(operationValidator==null) {
|
||||||
throw new ResourceRegistryException("A removeFromContext operation which must not honour PropagationConstraints have to provide an " + OperationValidator.class.getSimpleName());
|
throw new ResourceRegistryException("AddFromContext operation which must not honour PropagationConstraints have to provide an " + OperationValidator.class.getSimpleName());
|
||||||
}
|
}
|
||||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
|
@ -845,7 +845,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
}else {
|
}else {
|
||||||
if(operationValidator==null) {
|
if(operationValidator==null) {
|
||||||
throw new ResourceRegistryException("A removeFromContext operation which must not honour PropagationConstraints have to provide an " + OperationValidator.class.getSimpleName());
|
throw new ResourceRegistryException("RemoveFromContext operation which must not honour PropagationConstraints have to provide an " + OperationValidator.class.getSimpleName());
|
||||||
}
|
}
|
||||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
|
|
|
@ -8,6 +8,7 @@ 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.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -15,24 +16,24 @@ public class SharingOperationValidator implements OperationValidator {
|
||||||
|
|
||||||
protected static Logger logger = LoggerFactory.getLogger(SharingOperationValidator.class);
|
protected static Logger logger = LoggerFactory.getLogger(SharingOperationValidator.class);
|
||||||
|
|
||||||
protected final Map<UUID, JsonNode> expectedInstaces;
|
protected final Map<UUID, JsonNode> expectedInstances;
|
||||||
protected final String operation;
|
protected final SharingOperation sharingOperation;
|
||||||
|
|
||||||
public SharingOperationValidator(Map<UUID, JsonNode> expectedInstaces, String operation) {
|
public SharingOperationValidator(Map<UUID, JsonNode> expectedInstances, SharingOperation sharingOperation) {
|
||||||
this.expectedInstaces = expectedInstaces;
|
this.expectedInstances = expectedInstances;
|
||||||
this.operation = operation;
|
this.sharingOperation = sharingOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidOperation(Map<UUID, JsonNode> affectedInstances) throws ResourceRegistryException {
|
public boolean isValidOperation(Map<UUID, JsonNode> affectedInstances) throws ResourceRegistryException {
|
||||||
Set<UUID> expectedUUIDSet = expectedInstaces.keySet();
|
Set<UUID> expectedUUIDSet = expectedInstances.keySet();
|
||||||
Set<UUID> affectedUUIDSet = new HashSet<>(affectedInstances.keySet());
|
Set<UUID> affectedUUIDSet = new HashSet<>(affectedInstances.keySet());
|
||||||
|
|
||||||
affectedUUIDSet.removeAll(expectedUUIDSet);
|
affectedUUIDSet.removeAll(expectedUUIDSet);
|
||||||
if(affectedUUIDSet.size()>0) {
|
if(affectedUUIDSet.size()>0) {
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
stringBuffer.append("To keep the integrity of the IS the operation ");
|
stringBuffer.append("To keep the integrity of the IS the operation ");
|
||||||
stringBuffer.append(operation);
|
stringBuffer.append(sharingOperation.toString());
|
||||||
stringBuffer.append(" affects more instances than the requested by the client. The operation will be aborted. ");
|
stringBuffer.append(" affects more instances than the requested by the client. The operation will be aborted. ");
|
||||||
stringBuffer.append("Additional affected instances are ");
|
stringBuffer.append("Additional affected instances are ");
|
||||||
stringBuffer.append(affectedUUIDSet.toString());
|
stringBuffer.append(affectedUUIDSet.toString());
|
||||||
|
@ -42,12 +43,12 @@ public class SharingOperationValidator implements OperationValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(UUID expectedUUID : expectedUUIDSet) {
|
for(UUID expectedUUID : expectedUUIDSet) {
|
||||||
JsonNode expectedJsonNode = expectedInstaces.get(expectedUUID);
|
JsonNode expectedJsonNode = expectedInstances.get(expectedUUID);
|
||||||
JsonNode affectedJsonNode = affectedInstances.get(expectedUUID);
|
JsonNode affectedJsonNode = affectedInstances.get(expectedUUID);
|
||||||
if(affectedJsonNode==null) {
|
if(affectedJsonNode==null) {
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
stringBuffer.append("The operation ");
|
stringBuffer.append("The operation ");
|
||||||
stringBuffer.append(operation);
|
stringBuffer.append(sharingOperation.toString());
|
||||||
stringBuffer.append(" did not affected the instance with UUID ");
|
stringBuffer.append(" did not affected the instance with UUID ");
|
||||||
stringBuffer.append(expectedUUID.toString());
|
stringBuffer.append(expectedUUID.toString());
|
||||||
stringBuffer.append(" ");
|
stringBuffer.append(" ");
|
||||||
|
|
|
@ -26,6 +26,7 @@ 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.instances.model.SharingOperationValidator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -127,7 +128,8 @@ public class SharingManager {
|
||||||
elementManagement.setHonourPropagationConstraintsInContextSharing(false);
|
elementManagement.setHonourPropagationConstraintsInContextSharing(false);
|
||||||
elementManagement.setDryRunContextSharing(dryRun);
|
elementManagement.setDryRunContextSharing(dryRun);
|
||||||
UUID contextUUID = UUID.fromString(contextId);
|
UUID contextUUID = UUID.fromString(contextId);
|
||||||
Map<UUID,JsonNode> affectedInstances = elementManagement.addToContext(contextUUID);
|
SharingOperationValidator sharingOperationValidator = new SharingOperationValidator(expectedInstances, operation);
|
||||||
|
Map<UUID,JsonNode> affectedInstances = elementManagement.addToContext(contextUUID, sharingOperationValidator);
|
||||||
|
|
||||||
return serializeAffectedInstaces(objectMapper, affectedInstances);
|
return serializeAffectedInstaces(objectMapper, affectedInstances);
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
|
|
Loading…
Reference in New Issue