Search in sources :

Example 1 with OperationTransactionImpl

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;
}
Also used : OperationTransaction(ddf.catalog.operation.OperationTransaction) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl)

Example 2 with OperationTransactionImpl

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) HashMap(java.util.HashMap) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result)

Example 3 with OperationTransactionImpl

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;
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) InternalIngestException(ddf.catalog.source.InternalIngestException) CreateResponse(ddf.catalog.operation.CreateResponse) Objects(java.util.Objects) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) StorageException(ddf.catalog.content.StorageException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) IOException(java.io.IOException)

Example 4 with OperationTransactionImpl

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"));
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) FilterDelegate(ddf.catalog.filter.FilterDelegate) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) FilterAdapter(ddf.catalog.filter.FilterAdapter) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) FilterType(net.opengis.filter.v_1_1_0.FilterType) Filter(org.opengis.filter.Filter) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) CswFilterFactory(org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterFactory) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 5 with OperationTransactionImpl

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));
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) BigInteger(java.math.BigInteger) ResultImpl(ddf.catalog.data.impl.ResultImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Aggregations

OperationTransactionImpl (ddf.catalog.operation.impl.OperationTransactionImpl)8 Metacard (ddf.catalog.data.Metacard)4 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)4 Test (org.junit.Test)4 OperationTransaction (ddf.catalog.operation.OperationTransaction)3 IngestException (ddf.catalog.source.IngestException)3 InternalIngestException (ddf.catalog.source.InternalIngestException)3 HashMap (java.util.HashMap)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 FederationException (ddf.catalog.federation.FederationException)2 QueryResponse (ddf.catalog.operation.QueryResponse)2 UpdateRequest (ddf.catalog.operation.UpdateRequest)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 StopProcessingException (ddf.catalog.plugin.StopProcessingException)2 Serializable (java.io.Serializable)2 BigInteger (java.math.BigInteger)2 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)2 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)2