Search in sources :

Example 61 with UpdateResponse

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

the class SolrProviderUpdate method testUpdatePendingNrtIndex.

@Test
public void testUpdatePendingNrtIndex() throws Exception {
    deleteAll(provider);
    ConfigurationStore.getInstance().setForceAutoCommit(false);
    try {
        MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
        CreateResponse createResponse = create(metacard, provider);
        String id = createResponse.getCreatedMetacards().get(0).getId();
        MockMetacard updatedMetacard = new MockMetacard(Library.getFlagstaffRecord());
        updatedMetacard.setContentTypeName("first");
        UpdateResponse firstUpdateResponse = update(id, updatedMetacard, provider);
        updatedMetacard = new MockMetacard(Library.getFlagstaffRecord());
        updatedMetacard.setContentTypeName("second");
        UpdateResponse secondUpdateResponse = update(id, updatedMetacard, provider);
        verifyContentTypeUpdate(firstUpdateResponse, MockMetacard.DEFAULT_TYPE, "first");
        verifyContentTypeUpdate(secondUpdateResponse, "first", "second");
    } finally {
        ConfigurationStore.getInstance().setForceAutoCommit(true);
    }
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) CreateResponse(ddf.catalog.operation.CreateResponse) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Example 62 with UpdateResponse

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

the class SolrProviderUpdate method testUpdateByMetacardId.

@Test
public void testUpdateByMetacardId() throws Exception {
    deleteAll(provider);
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    MockMetacard metacard2 = new MockMetacard(Library.getShowLowRecord());
    String uri1 = "http://youwillfindme.com/here";
    String uri2 = "http://youwillfindme.com/there";
    metacard1.setResourceURI(new URI(uri1));
    metacard1.setContentTypeName("oldNitf");
    metacard2.setResourceURI(new URI(uri2));
    metacard2.setContentTypeName("oldNitf2");
    metacard2.setResourceSize("25L");
    List<Metacard> list = Arrays.asList(metacard1, metacard2);
    CreateResponse createResponse = create(list, provider);
    List<String> responseStrings = MockMetacard.toStringList(createResponse.getCreatedMetacards());
    assertEquals(2, responseStrings.size());
    // UPDATE
    MockMetacard updatedMetacard1 = new MockMetacard(Library.getTampaRecord());
    MockMetacard updatedMetacard2 = new MockMetacard(Library.getFlagstaffRecord());
    updatedMetacard1.setId(metacard1.getId());
    updatedMetacard1.setContentTypeName("nitf");
    updatedMetacard2.setId(metacard2.getId());
    updatedMetacard2.setResourceURI(new URI(uri2));
    updatedMetacard2.setContentTypeName("nitf2");
    updatedMetacard2.setResourceSize("50L");
    list = Arrays.asList(updatedMetacard1, updatedMetacard2);
    String[] ids = { metacard1.getId(), metacard2.getId() };
    UpdateResponse updateResponse = update(ids, list, provider);
    verifyUpdates(uri1, uri2, updateResponse);
    // READ
    QueryImpl query = new QueryImpl(getFilterBuilder().attribute(Metacard.RESOURCE_URI).is().equalTo().text(uri2));
    query.setRequestsTotalResultsCount(true);
    QueryRequestImpl queryRequest = new QueryRequestImpl(query);
    SourceResponse sourceResponse = provider.query(queryRequest);
    assertEquals(1, sourceResponse.getResults().size());
    for (Result r : sourceResponse.getResults()) {
        assertTrue(r.getMetacard().getMetadata().contains("Cardinals"));
        assertEquals(uri2, r.getMetacard().getResourceURI().toString());
    }
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) URI(java.net.URI) Result(ddf.catalog.data.Result) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Example 63 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 64 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 65 with UpdateResponse

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

the class CatalogBackupPluginTest method testUpdatingOneMissingMetacard.

@Test
public void testUpdatingOneMissingMetacard() throws PluginExecutionException {
    assertThat("The list of metacard IDs has changed sized", METACARD_IDS, arrayWithSize(2));
    // Setup
    CatalogBackupPlugin plugin = getPlugin();
    plugin.process(getCreateResponse(new String[] { METACARD_IDS[0] }));
    UpdateResponse mockUpdateResponse = getUpdateResponse(Arrays.asList(METACARD_IDS));
    // Perform Test
    plugin.process(mockUpdateResponse);
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Test(org.junit.Test)

Aggregations

UpdateResponse (ddf.catalog.operation.UpdateResponse)79 Test (org.junit.Test)56 Metacard (ddf.catalog.data.Metacard)47 Update (ddf.catalog.operation.Update)32 UpdateRequest (ddf.catalog.operation.UpdateRequest)31 ArrayList (java.util.ArrayList)31 Serializable (java.io.Serializable)27 HashMap (java.util.HashMap)26 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)20 CreateResponse (ddf.catalog.operation.CreateResponse)19 List (java.util.List)18 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)15 Result (ddf.catalog.data.Result)14 Map (java.util.Map)14 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)13 IngestException (ddf.catalog.source.IngestException)13 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)12 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)11 DeleteResponse (ddf.catalog.operation.DeleteResponse)11 QueryImpl (ddf.catalog.operation.impl.QueryImpl)11