Search in sources :

Example 1 with OPERATION_TRANSACTION_KEY

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();
}
Also used : OperationTransaction(ddf.catalog.operation.OperationTransaction) ResourceResponse(ddf.catalog.operation.ResourceResponse) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Logger(org.slf4j.Logger) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) StopProcessingException(ddf.catalog.plugin.StopProcessingException) OperationTransaction(ddf.catalog.operation.OperationTransaction) OPERATION_TRANSACTION_KEY(ddf.catalog.Constants.OPERATION_TRANSACTION_KEY) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) List(java.util.List) Permissions(ddf.security.permission.Permissions) Attribute(ddf.catalog.data.Attribute) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) ResourceRequest(ddf.catalog.operation.ResourceRequest) NoSuchElementException(java.util.NoSuchElementException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with OPERATION_TRANSACTION_KEY

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();
}
Also used : OperationTransaction(ddf.catalog.operation.OperationTransaction) ResourceResponse(ddf.catalog.operation.ResourceResponse) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Logger(org.slf4j.Logger) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) LoggerFactory(org.slf4j.LoggerFactory) StopProcessingException(ddf.catalog.plugin.StopProcessingException) OperationTransaction(ddf.catalog.operation.OperationTransaction) OPERATION_TRANSACTION_KEY(ddf.catalog.Constants.OPERATION_TRANSACTION_KEY) StringUtils(org.apache.commons.lang3.StringUtils) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) List(java.util.List) Permissions(ddf.security.permission.Permissions) Requests(ddf.catalog.util.impl.Requests) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) ResourceRequest(ddf.catalog.operation.ResourceRequest) URI(java.net.URI) NoSuchElementException(java.util.NoSuchElementException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

OPERATION_TRANSACTION_KEY (ddf.catalog.Constants.OPERATION_TRANSACTION_KEY)2 Metacard (ddf.catalog.data.Metacard)2 Result (ddf.catalog.data.Result)2 OperationTransaction (ddf.catalog.operation.OperationTransaction)2 Query (ddf.catalog.operation.Query)2 ResourceRequest (ddf.catalog.operation.ResourceRequest)2 ResourceResponse (ddf.catalog.operation.ResourceResponse)2 PolicyPlugin (ddf.catalog.plugin.PolicyPlugin)2 PolicyResponse (ddf.catalog.plugin.PolicyResponse)2 StopProcessingException (ddf.catalog.plugin.StopProcessingException)2 PolicyResponseImpl (ddf.catalog.plugin.impl.PolicyResponseImpl)2 Permissions (ddf.security.permission.Permissions)2 Serializable (java.io.Serializable)2 List (java.util.List)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Attribute (ddf.catalog.data.Attribute)1 Requests (ddf.catalog.util.impl.Requests)1