use of ddf.catalog.operation.impl.OperationTransactionImpl 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.impl.OperationTransactionImpl in project ddf by codice.
the class UpdateOperations method populateMetacards.
private UpdateRequest populateMetacards(UpdateRequest updateRequest) throws IngestException {
QueryRequestImpl queryRequest = createQueryRequest(updateRequest);
QueryResponse queryResponse;
try {
queryResponse = queryOperations.doQuery(queryRequest, frameworkProperties.getFederationStrategy());
} catch (FederationException e) {
LOGGER.debug("Unable to complete query for updated metacards.", e);
throw new IngestException("Exception during runtime while performing update");
}
if (!foundAllUpdateRequestMetacards(updateRequest, queryResponse)) {
logFailedQueryInfo(updateRequest, queryResponse);
throw new IngestException("Could not find all metacards specified in request");
}
updateRequest = rewriteRequestToAvoidHistoryConflicts(updateRequest, queryResponse);
// Construct the metacardMap using the metacard's ID in order to match the UpdateRequest
HashMap<String, Metacard> metacardMap = new HashMap<>(queryResponse.getResults().stream().map(Result::getMetacard).collect(Collectors.toMap(metacard -> getAttributeStringValue(metacard, Core.ID), Function.identity())));
updateRequest.getProperties().put(Constants.ATTRIBUTE_UPDATE_MAP_KEY, metacardMap);
updateRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, metacardMap.values()));
return updateRequest;
}
use of ddf.catalog.operation.impl.OperationTransactionImpl in project ddf by codice.
the class CreateOperations method doCreate.
//
// Private helper methods
//
private CreateResponse doCreate(CreateRequest createRequest) throws IngestException, SourceUnavailableException {
CreateResponse createResponse;
Exception ingestError = null;
createRequest = queryOperations.setFlagsOnRequest(createRequest);
createRequest = validateCreateRequest(createRequest);
createRequest = validateLocalSource(createRequest);
String fileNames = "";
if (createRequest != null) {
List<String> fileList = createRequest.getMetacards().stream().filter(Objects::nonNull).map(Metacard::getTitle).collect(Collectors.toList());
fileNames = String.join(", ", fileList);
}
try {
INGEST_LOGGER.info("Started ingesting metacard with titles: {}.", fileNames);
createRequest = injectAttributes(createRequest);
createRequest = setDefaultValues(createRequest);
createRequest = processPreAuthorizationPlugins(createRequest);
createRequest = updateCreateRequestPolicyMap(createRequest);
createRequest = processPrecreateAccessPlugins(createRequest);
createRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.CREATE, Collections.emptyList()));
createRequest = processPreIngestPlugins(createRequest);
createRequest = validateCreateRequest(createRequest);
createResponse = getCreateResponse(createRequest);
createResponse = performRemoteCreate(createRequest, createResponse);
} catch (IngestException iee) {
ingestError = iee;
throw iee;
} catch (StopProcessingException see) {
ingestError = see;
throw new IngestException(PRE_INGEST_ERROR, see);
} catch (RuntimeException re) {
ingestError = re;
throw new InternalIngestException("Exception during runtime while performing create", re);
} finally {
if (createRequest != null && ingestError != null && INGEST_LOGGER.isInfoEnabled()) {
INGEST_LOGGER.info("Error on create operation. {} metacards failed to ingest. {}", createRequest.getMetacards().size(), buildIngestLog(createRequest), ingestError);
}
}
try {
createResponse = validateFixCreateResponse(createResponse, createRequest);
} catch (RuntimeException re) {
LOGGER.info("Exception during runtime while performing doing post create operations (plugins and pubsub)", re);
}
if (createResponse == null) {
// suppress all npe findings for this method.
throw new IngestException("CatalogProvider returned null CreateResponse Object.");
}
return createResponse;
}
use of ddf.catalog.operation.impl.OperationTransactionImpl in project ddf by codice.
the class TestRegistryStore method testDelete.
@Test
public void testDelete() throws Exception {
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
Csw csw = mock(Csw.class);
TransactionResponseType transResponse = mock(TransactionResponseType.class);
TransactionSummaryType transSummary = mock(TransactionSummaryType.class);
when(transResponse.getTransactionSummary()).thenReturn(transSummary);
when(transSummary.getTotalDeleted()).thenReturn(new BigInteger("1"));
when(csw.transaction(any(CswTransactionRequest.class))).thenReturn(transResponse);
when(factory.getClientForSubject(any())).thenReturn(csw);
when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
FilterAdapter mockAdaptor = mock(FilterAdapter.class);
CswFilterFactory filterFactory = new CswFilterFactory(CswAxisOrder.LAT_LON, false);
FilterType filterType = filterFactory.buildPropertyIsLikeFilter(Metacard.ID, "testId", false);
when(mockAdaptor.adapt(any(Filter.class), any(FilterDelegate.class))).thenReturn(filterType);
registryStore.setFilterAdapter(mockAdaptor);
DeleteRequestImpl request = new DeleteRequestImpl(Collections.singletonList(RegistryObjectMetacardType.REGISTRY_ID), "registryId", new HashMap<>());
OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.DELETE, Collections.singletonList(getDefaultMetacard()));
request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
registryStore.delete(request);
verify(filterBuilder).attribute(captor.capture());
assertThat(captor.getValue(), is("id"));
}
use of ddf.catalog.operation.impl.OperationTransactionImpl in project ddf by codice.
the class TestRegistryStore method testUpdate.
@Test
public void testUpdate() throws Exception {
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
TransactionSummaryType tst = new TransactionSummaryType();
tst.setTotalUpdated(new BigInteger("1"));
when(responseType.getTransactionSummary()).thenReturn(tst);
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
UpdateRequestImpl request = new UpdateRequestImpl("testId", getDefaultMetacard());
MetacardImpl updatedMcard = getDefaultMetacard();
updatedMcard.setId("newTestId");
OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Collections.singletonList(updatedMcard));
request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
queryResults.add(new ResultImpl(getDefaultMetacard()));
registryStore.update(request);
assertThat(request.getUpdates().get(0).getValue().getMetadata().contains("value=\"newTestId\""), is(true));
}
Aggregations