use of ddf.catalog.Constants.OPERATION_TRANSACTION_KEY in project ddf by codice.
the class PointOfContactPolicyPlugin method processPreUpdate.
@Override
public PolicyResponse processPreUpdate(Metacard newMetacard, Map<String, Serializable> properties) throws StopProcessingException {
//If it's not a resource metacard, don't apply the policy.
if (!newMetacard.getTags().isEmpty() && !newMetacard.getTags().contains("resource")) {
return new PolicyResponseImpl();
}
List<Metacard> previousStateMetacards = ((OperationTransaction) properties.get(OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards();
Metacard previous;
try {
previous = previousStateMetacards.stream().filter((x) -> x.getId().equals(newMetacard.getId())).findFirst().get();
} catch (NoSuchElementException e) {
LOGGER.debug("Cannot locate metacard {} for update.", newMetacard.getId());
return new PolicyResponseImpl();
}
return pointOfContactChanged(newMetacard, previous) ? new PolicyResponseImpl(null, PERMISSION_MAP) : new PolicyResponseImpl();
}
use of ddf.catalog.Constants.OPERATION_TRANSACTION_KEY in project ddf by codice.
the class ResourceUriPolicy method processPreUpdate.
@Override
public PolicyResponse processPreUpdate(Metacard input, Map<String, Serializable> properties) throws StopProcessingException {
if (!Requests.isLocal(properties)) {
return new PolicyResponseImpl();
}
PolicyResponseImpl policyResponse = new PolicyResponseImpl(null, Permissions.parsePermissionsFromString(getUpdatePermissions()));
List<Metacard> previousStateMetacards = ((OperationTransaction) properties.get(OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards();
Metacard previous;
try {
previous = previousStateMetacards.stream().filter((x) -> x.getId().equals(input.getId())).findFirst().get();
} catch (NoSuchElementException e) {
LOGGER.debug("Cannot locate metacard {} for update. Applying permissions to the item", input.getId());
return policyResponse;
}
return requiresPermission(input.getResourceURI(), previous.getResourceURI()) ? policyResponse : new PolicyResponseImpl();
}
Aggregations