Search in sources :

Example 46 with UpdateResponse

use of ddf.catalog.operation.UpdateResponse in project ddf by codice.

the class UpdateOperations method update.

//
// Delegate methods
//
public UpdateResponse update(UpdateRequest updateRequest) throws IngestException, SourceUnavailableException {
    UpdateResponse updateResponse = doUpdate(updateRequest);
    updateResponse = doPostIngest(updateResponse);
    return updateResponse;
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse)

Example 47 with UpdateResponse

use of ddf.catalog.operation.UpdateResponse in project ddf by codice.

the class FrameworkProducer method update.

/**
     * Updates metacard(s) in the catalog using the Catalog Framework.
     *
     * @param exchange
     *            The {@link org.apache.camel.Exchange} can contain a
     *            {@link org.apache.camel.Message} with a body of type {@link java.util.List} of
     *            Metacard or a single Metacard.
     * @throws ddf.catalog.source.SourceUnavailableException
     * @throws ddf.catalog.source.IngestException
     * @throws ddf.camel.component.catalog.framework.FrameworkProducerException
     */
private void update(final Exchange exchange) throws SourceUnavailableException, IngestException, FrameworkProducerException {
    UpdateResponse updateResponse = null;
    // read in data from exchange
    final List<Metacard> metacardsToBeUpdated = readBodyDataAsMetacards(exchange);
    // process data if valid
    if (!validateList(metacardsToBeUpdated, Metacard.class)) {
        processCatalogResponse(updateResponse, exchange);
        throw new FrameworkProducerException("Validation of Metacard list failed");
    }
    LOGGER.debug("Validation of Metacard list passed...");
    final String[] metacardIds = new String[metacardsToBeUpdated.size()];
    for (int i = 0; i < metacardsToBeUpdated.size(); i++) {
        metacardIds[i] = metacardsToBeUpdated.get(i).getId();
    }
    final UpdateRequest updateRequest = new UpdateRequestImpl(metacardIds, metacardsToBeUpdated);
    final int expectedNumberOfUpdatedMetacards = metacardsToBeUpdated.size();
    if (expectedNumberOfUpdatedMetacards < 1) {
        LOGGER.debug("Empty list of Metacards...nothing to process");
        processCatalogResponse(updateResponse, exchange);
        return;
    }
    LOGGER.debug("Making UPDATE call to Catalog Framework...");
    updateResponse = catalogFramework.update(updateRequest);
    if (updateResponse == null) {
        LOGGER.debug("UpdateResponse is null from catalog framework");
        processCatalogResponse(updateResponse, exchange);
        return;
    }
    final List<Update> updatedMetacards = updateResponse.getUpdatedMetacards();
    if (updatedMetacards == null) {
        LOGGER.debug("UpdateResponse returned null metacards list");
        processCatalogResponse(updateResponse, exchange);
        return;
    }
    final int numberOfUpdatedMetacards = updatedMetacards.size();
    if (numberOfUpdatedMetacards != expectedNumberOfUpdatedMetacards) {
        LOGGER.debug("Expected {} metacards updated but only {} were successfully updated", expectedNumberOfUpdatedMetacards, numberOfUpdatedMetacards);
        processCatalogResponse(updateResponse, exchange);
        return;
    }
    LOGGER.debug("Updated {} metacards", numberOfUpdatedMetacards);
    processCatalogResponse(updateResponse, exchange);
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Update(ddf.catalog.operation.Update) Endpoint(org.apache.camel.Endpoint)

Example 48 with UpdateResponse

use of ddf.catalog.operation.UpdateResponse in project ddf by codice.

the class CatalogBackupPluginTest method getUpdateResponse.

private UpdateResponse getUpdateResponse(List<String> oldMetacardIds) {
    List<Update> updatedMetacards = new ArrayList<>(oldMetacardIds.size());
    int i = 0;
    for (String oldMetacardId : oldMetacardIds) {
        Metacard oldMetacard = getMetacard(oldMetacardId, BASE_OLD_TITLE + i);
        Metacard newMetacard = getMetacard(oldMetacardId, BASE_NEW_TITLE + i);
        // Create UpdateResponse
        Update mockUpdate = mock(Update.class);
        when(mockUpdate.getOldMetacard()).thenReturn(oldMetacard);
        when(mockUpdate.getNewMetacard()).thenReturn(newMetacard);
        updatedMetacards.add(mockUpdate);
        i++;
    }
    UpdateRequest request = mock(UpdateRequest.class);
    UpdateResponse mockUpdateResponse = mock(UpdateResponse.class);
    when(mockUpdateResponse.getUpdatedMetacards()).thenReturn(updatedMetacards);
    when(mockUpdateResponse.getRequest()).thenReturn(request);
    return mockUpdateResponse;
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update)

Example 49 with UpdateResponse

use of ddf.catalog.operation.UpdateResponse in project ddf by codice.

the class CatalogComponentFrameworkTest method testUpdateWithSingleMetacard.

@Test
public /**
     * Operation: UPDATE
     * Body contains:  Metacard
     */
void testUpdateWithSingleMetacard() throws Exception {
    resetMocks();
    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);
    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);
    // setup mock catalog framework
    final Update update = new UpdateImpl(metacard1, metacard2);
    List<Update> updates = new ArrayList<Update>();
    updates.add(update);
    final String[] metacardIds = new String[metacards.size()];
    for (int i = 0; i < metacards.size(); i++) {
        metacardIds[i] = metacards.get(i).getId();
    }
    UpdateRequest updateRequest = new UpdateRequestImpl(metacardIds, metacards);
    UpdateResponse updateResponse = new UpdateResponseImpl(updateRequest, new HashMap(), updates);
    when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(updateResponse);
    // Exercise the route with a UPDATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacard1, "Operation", "UPDATE");
    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Update> cardsUpdated = (List<Update>) exchange.getIn().getBody();
    assertListSize(cardsUpdated, 1);
    mockVerifierEndpoint.assertIsSatisfied();
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) UpdateRequest(ddf.catalog.operation.UpdateRequest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Exchange(org.apache.camel.Exchange) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) ArrayList(java.util.ArrayList) List(java.util.List) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 50 with UpdateResponse

use of ddf.catalog.operation.UpdateResponse in project ddf by codice.

the class CatalogMetricsTest method catalogUpdateMetric.

@Test
public void catalogUpdateMetric() throws Exception {
    UpdateRequest request = mock(UpdateRequest.class);
    UpdateResponse response = mock(UpdateResponse.class);
    List<Update> updatedList = mock(List.class);
    when(updatedList.size()).thenReturn(100);
    when(response.getRequest()).thenReturn(request);
    when(response.getUpdatedMetacards()).thenReturn(updatedList);
    underTest.process(response);
    assertThat(underTest.updatedMetacards.getCount(), is(100L));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateRequest(ddf.catalog.operation.UpdateRequest) Update(ddf.catalog.operation.Update) Test(org.junit.Test)

Aggregations

UpdateResponse (ddf.catalog.operation.UpdateResponse)57 Test (org.junit.Test)38 Metacard (ddf.catalog.data.Metacard)36 HashMap (java.util.HashMap)24 UpdateRequest (ddf.catalog.operation.UpdateRequest)22 Serializable (java.io.Serializable)22 ArrayList (java.util.ArrayList)22 Update (ddf.catalog.operation.Update)21 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)15 List (java.util.List)15 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)14 CreateResponse (ddf.catalog.operation.CreateResponse)13 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)11 Map (java.util.Map)11 ContentItem (ddf.catalog.content.data.ContentItem)10 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)10 Result (ddf.catalog.data.Result)10 IngestException (ddf.catalog.source.IngestException)10 DeleteResponse (ddf.catalog.operation.DeleteResponse)9 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)9