use of ddf.catalog.operation.OperationTransaction in project ddf by codice.
the class WorkspacePreIngestPluginTest method update.
private static UpdateRequest update(Metacard original, Metacard updated) {
UpdateRequestImpl request = new UpdateRequestImpl(original.getId(), updated);
OperationTransaction transaction = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Arrays.asList(original));
request.setProperties(Collections.singletonMap(Constants.OPERATION_TRANSACTION_KEY, transaction));
return request;
}
use of ddf.catalog.operation.OperationTransaction in project ddf by codice.
the class RegistryStoreImpl method update.
@Override
public UpdateResponse update(UpdateRequest request) throws IngestException {
if (request.getUpdates().stream().map(e -> RegistryUtility.getRegistryId(e.getValue())).anyMatch(Objects::isNull)) {
throw new IngestException("One or more of the metacards is not a registry metacard");
}
Map<String, Metacard> updatedMetacards = request.getUpdates().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getValue()), Map.Entry::getValue));
Map<String, Metacard> origMetacards = ((OperationTransaction) request.getPropertyValue(Constants.OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards().stream().collect(Collectors.toMap(RegistryUtility::getRegistryId, e -> e));
//update the new metacards with the id from the orig so that they can be found on the remote system
try {
for (Map.Entry<String, Metacard> entry : updatedMetacards.entrySet()) {
setMetacardExtID(entry.getValue(), origMetacards.get(entry.getKey()).getId());
}
} catch (ParserException e) {
throw new IngestException("Could not update metacards id", e);
}
return super.update(request);
}
use of ddf.catalog.operation.OperationTransaction 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;
previous = previousStateMetacards.stream().filter(x -> x.getId().equals(newMetacard.getId())).findFirst().orElse(null);
return pointOfContactChanged(newMetacard, previous) ? new PolicyResponseImpl(null, permissionMap) : new PolicyResponseImpl();
}
use of ddf.catalog.operation.OperationTransaction 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 = previousStateMetacards.stream().filter((x) -> x.getId().equals(input.getId())).findFirst().orElse(null);
if (previous == null) {
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();
}
use of ddf.catalog.operation.OperationTransaction in project ddf by codice.
the class IdentificationPluginTest method testSetTransientAttributesOnUpdateMetacard.
@Test
public void testSetTransientAttributesOnUpdateMetacard() throws Exception {
String xml = convert("/registry-no-extid.xml");
MetacardImpl previousMetacard = new MetacardImpl();
previousMetacard.setAttribute(Metacard.ID, "MetacardId");
previousMetacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "MetacardId");
previousMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
previousMetacard.setAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, "Published Locations");
previousMetacard.setAttribute(RegistryObjectMetacardType.LAST_PUBLISHED, "Last Published Time");
previousMetacard.setAttribute(Metacard.MODIFIED, new Date().from(Instant.now()));
OperationTransaction operationTransaction = new OperationTransactionImpl(null, Collections.singletonList(previousMetacard));
Map<String, Serializable> properties = new HashMap<>();
properties.put(Constants.OPERATION_TRANSACTION_KEY, operationTransaction);
List<Map.Entry<Serializable, Metacard>> updatedEntries = new ArrayList<>();
MetacardImpl updateMetacard = new MetacardImpl();
updateMetacard.setAttribute(Metacard.ID, "MetacardId");
updateMetacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "MetacardId");
updateMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
updateMetacard.setAttribute(Metacard.MODIFIED, new Date().from(Instant.now()));
updateMetacard.setAttribute(Metacard.METADATA, xml);
updatedEntries.add(new AbstractMap.SimpleEntry<>(updateMetacard.getId(), updateMetacard));
UpdateRequest updateRequest = new UpdateRequestImpl(updatedEntries, Metacard.ID, properties);
UpdateRequest processedUpdateRequest = identificationPlugin.process(updateRequest);
Metacard processedMetacard = processedUpdateRequest.getUpdates().get(0).getValue();
assertThat(processedMetacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS).getValue(), is("Published Locations"));
assertThat(processedMetacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED).getValue(), is("Last Published Time"));
}
Aggregations