Search in sources :

Example 1 with Update

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

the class MockMemoryProvider method update.

@Override
public UpdateResponse update(UpdateRequest request) {
    String methodName = "update";
    LOGGER.debug("Entering: {}", methodName);
    hasReceivedUpdate = true;
    hasReceivedUpdateByIdentifier = true;
    List<Entry<Serializable, Metacard>> updatedCards = request.getUpdates();
    Map<String, Serializable> properties = new HashMap<>();
    List<Update> returnedMetacards = new ArrayList<>(updatedCards.size());
    for (Entry<Serializable, Metacard> curCard : updatedCards) {
        if (store.containsKey(curCard.getValue().getId())) {
            LOGGER.debug("Store contains the key");
            Metacard oldMetacard = store.get(curCard.getValue().getId());
            store.put(curCard.getValue().getId(), curCard.getValue());
            properties.put(curCard.getValue().getId(), curCard.getValue());
            LOGGER.debug("adding returnedMetacard");
            returnedMetacards.add(new UpdateImpl(curCard.getValue(), oldMetacard));
        } else {
            LOGGER.debug("Key not contained in the store");
        }
    }
    UpdateResponse response = new UpdateResponseImpl(request, properties, returnedMetacards);
    LOGGER.debug("Exiting:{}", methodName);
    return response;
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) UpdateResponse(ddf.catalog.operation.UpdateResponse) Entry(java.util.Map.Entry) Metacard(ddf.catalog.data.Metacard) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl)

Example 2 with Update

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

the class CatalogBackupPlugin method process.

/**
     * Backs up updated metacards to the file system backup.
     *
     * @param input the {@link UpdateResponse} to process
     * @return {@link UpdateResponse}
     */
@Override
public UpdateResponse process(UpdateResponse input) {
    int size = input.getUpdatedMetacards().size();
    List<Metacard> toDelete = new ArrayList<>(size);
    List<Metacard> toCreate = new ArrayList<>(size);
    for (Update update : input.getUpdatedMetacards()) {
        toDelete.add(update.getOldMetacard());
        toCreate.add(update.getNewMetacard());
    }
    execute(() -> delete(toDelete));
    execute(() -> create(toCreate));
    return input;
}
Also used : Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update)

Example 3 with Update

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

the class ContentProducerDataAccessObject method createContentItem.

public void createContentItem(FileSystemPersistenceProvider fileIdMap, ContentEndpoint endpoint, File ingestedFile, WatchEvent.Kind<Path> eventType, String mimeType, Map<String, Object> headers) throws SourceUnavailableException, IngestException {
    LOGGER.debug("Creating content item.");
    String key = String.valueOf(ingestedFile.getAbsolutePath().hashCode());
    String id = fileIdMap.loadAllKeys().contains(key) ? String.valueOf(fileIdMap.loadFromPersistence(key)) : null;
    if (StandardWatchEventKinds.ENTRY_CREATE.equals(eventType)) {
        CreateStorageRequest createRequest = new CreateStorageRequestImpl(Collections.singletonList(new ContentItemImpl(uuidGenerator.generateUuid(), Files.asByteSource(ingestedFile), mimeType, ingestedFile.getName(), 0L, null)), null);
        processHeaders(headers, createRequest, ingestedFile);
        CreateResponse createResponse = endpoint.getComponent().getCatalogFramework().create(createRequest);
        if (createResponse != null) {
            List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
            for (Metacard metacard : createdMetacards) {
                fileIdMap.store(key, metacard.getId());
                LOGGER.debug("content item created with id = {}", metacard.getId());
            }
        }
    } else if (StandardWatchEventKinds.ENTRY_MODIFY.equals(eventType)) {
        UpdateStorageRequest updateRequest = new UpdateStorageRequestImpl(Collections.singletonList(new ContentItemImpl(id, Files.asByteSource(ingestedFile), mimeType, ingestedFile.getName(), 0, null)), null);
        processHeaders(headers, updateRequest, ingestedFile);
        UpdateResponse updateResponse = endpoint.getComponent().getCatalogFramework().update(updateRequest);
        if (updateResponse != null) {
            List<Update> updatedMetacards = updateResponse.getUpdatedMetacards();
            for (Update update : updatedMetacards) {
                LOGGER.debug("content item updated with id = {}", update.getNewMetacard().getId());
            }
        }
    } else if (StandardWatchEventKinds.ENTRY_DELETE.equals(eventType)) {
        DeleteRequest deleteRequest = new DeleteRequestImpl(id);
        DeleteResponse deleteResponse = endpoint.getComponent().getCatalogFramework().delete(deleteRequest);
        if (deleteResponse != null) {
            List<Metacard> deletedMetacards = deleteResponse.getDeletedMetacards();
            for (Metacard delete : deletedMetacards) {
                fileIdMap.delete(ingestedFile.getAbsolutePath());
                LOGGER.debug("content item deleted with id = {}", delete.getId());
            }
        }
    }
}
Also used : UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) CreateResponse(ddf.catalog.operation.CreateResponse) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Update(ddf.catalog.operation.Update) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) List(java.util.List) DeleteRequest(ddf.catalog.operation.DeleteRequest) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 4 with Update

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

the class CatalogComponentFrameworkTest method testDeleteWithIngestException.

@Test
public /**
     * Operation: DELETE
     * Body contains: 12345678900987654321abcdeffedcba
     */
void testDeleteWithIngestException() 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 String[] metacardIds = new String[metacards.size()];
    for (int i = 0; i < metacards.size(); i++) {
        metacardIds[i] = metacards.get(i).getId();
    }
    DeleteRequest deleteRequest = new DeleteRequestImpl(metacardIds);
    DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap(), metacards);
    when(catalogFramework.delete(any(DeleteRequest.class))).thenThrow(new IngestException());
    // Exercise the route with a DELETE operation
    template.sendBodyAndHeader("direct:sampleInput", metacardIds, "Operation", "DELETE");
    // 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> cardsDeleted = (List<Update>) exchange.getIn().getBody();
    assertListSize(cardsDeleted, 0);
    mockVerifierEndpoint.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Exchange(org.apache.camel.Exchange) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) IngestException(ddf.catalog.source.IngestException) ArrayList(java.util.ArrayList) List(java.util.List) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 5 with Update

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

the class CatalogComponentFrameworkTest method testUpdateWithIngestException.

@Test
public /**
     * Operation: UPDATE
     * Body contains:  Metacard
     */
void testUpdateWithIngestException() 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))).thenThrow(new IngestException());
    // Exercise the route with a UPDATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacards, "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, 0);
    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) IngestException(ddf.catalog.source.IngestException) ArrayList(java.util.ArrayList) List(java.util.List) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Aggregations

Update (ddf.catalog.operation.Update)38 Metacard (ddf.catalog.data.Metacard)32 ArrayList (java.util.ArrayList)25 UpdateResponse (ddf.catalog.operation.UpdateResponse)24 Test (org.junit.Test)20 UpdateRequest (ddf.catalog.operation.UpdateRequest)19 HashMap (java.util.HashMap)18 List (java.util.List)16 Serializable (java.io.Serializable)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)11 CreateResponse (ddf.catalog.operation.CreateResponse)11 DeleteResponse (ddf.catalog.operation.DeleteResponse)11 UpdateImpl (ddf.catalog.operation.impl.UpdateImpl)11 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)11 Result (ddf.catalog.data.Result)10 Entry (java.util.Map.Entry)10 DeleteRequest (ddf.catalog.operation.DeleteRequest)9 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)9 IngestException (ddf.catalog.source.IngestException)9 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)8