Search in sources :

Example 51 with DeleteResponse

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

the class RemoteDeleteOperations method doRemoteDelete.

private DeleteResponse doRemoteDelete(DeleteRequest deleteRequest) {
    HashSet<ProcessingDetails> exceptions = new HashSet<>();
    Map<String, Serializable> properties = new HashMap<>();
    List<CatalogStore> stores = opsCatStoreSupport.getCatalogStoresForRequest(deleteRequest, exceptions);
    List<Metacard> metacards = new ArrayList<>();
    for (CatalogStore store : stores) {
        try {
            if (!store.isAvailable()) {
                exceptions.add(new ProcessingDetailsImpl(store.getId(), null, "CatalogStore is not available"));
            } else {
                // TODO: 4/27/17 Address bug in DDF-2970 for overwriting deleted metacards
                DeleteResponse response = store.delete(deleteRequest);
                properties.put(store.getId(), new ArrayList<>(response.getDeletedMetacards()));
                metacards = response.getDeletedMetacards();
            }
        } catch (IngestException e) {
            INGEST_LOGGER.error("Error deleting metacards for CatalogStore {}", store.getId(), e);
            exceptions.add(new ProcessingDetailsImpl(store.getId(), e));
        }
    }
    return new DeleteResponseImpl(deleteRequest, properties, metacards, exceptions);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) CatalogStore(ddf.catalog.source.CatalogStore) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) IngestException(ddf.catalog.source.IngestException) HashSet(java.util.HashSet)

Example 52 with DeleteResponse

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

the class CatalogComponentFrameworkTest method testDeleteWithSingleId.

@Test
public /**
     * Operation: DELETE
     * Body contains: 12345678900987654321abcdeffedcba
     */
void testDeleteWithSingleId() 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))).thenReturn(deleteResponse);
    // 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, 1);
    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) ArrayList(java.util.ArrayList) List(java.util.List) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 53 with DeleteResponse

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

the class DeleteOperations method performLocalDelete.

private DeleteResponse performLocalDelete(DeleteRequest deleteRequest, DeleteStorageRequest deleteStorageRequest) throws IngestException {
    if (!Requests.isLocal(deleteRequest)) {
        return null;
    }
    try {
        sourceOperations.getStorage().delete(deleteStorageRequest);
    } catch (StorageException e) {
        LOGGER.info("Unable to delete stored content items. Not removing stored metacards", e);
        throw new InternalIngestException("Unable to delete stored content items. Not removing stored metacards.", e);
    }
    DeleteResponse deleteResponse = sourceOperations.getCatalog().delete(deleteRequest);
    deleteResponse = injectAttributes(deleteResponse);
    try {
        historian.version(deleteResponse);
    } catch (SourceUnavailableException e) {
        LOGGER.debug("Could not version deleted item!", e);
        throw new IngestException("Could not version deleted Item!");
    }
    return deleteResponse;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) DeleteResponse(ddf.catalog.operation.DeleteResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StorageException(ddf.catalog.content.StorageException)

Example 54 with DeleteResponse

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

the class DeleteOperations method doDelete.

//
// Private helper methods
//
public DeleteResponse doDelete(DeleteRequest deleteRequest, List<String> fanoutTagBlacklist) throws IngestException, SourceUnavailableException {
    DeleteStorageRequest deleteStorageRequest = null;
    DeleteResponse deleteResponse = null;
    deleteRequest = queryOperations.setFlagsOnRequest(deleteRequest);
    deleteRequest = validateDeleteRequest(deleteRequest);
    deleteRequest = validateLocalSource(deleteRequest);
    try {
        deleteRequest = populateMetacards(deleteRequest, fanoutTagBlacklist);
        deleteRequest = preProcessPreAuthorizationPlugins(deleteRequest);
        deleteStorageRequest = new DeleteStorageRequestImpl(getDeleteMetacards(deleteRequest), deleteRequest.getProperties());
        deleteRequest = processPreDeletePolicyPlugins(deleteRequest);
        deleteRequest = processPreDeleteAccessPlugins(deleteRequest);
        deleteRequest = processPreIngestPlugins(deleteRequest);
        deleteRequest = validateDeleteRequest(deleteRequest);
        // Call the Provider delete method
        LOGGER.debug("Calling catalog.delete() with {} entries.", deleteRequest.getAttributeValues().size());
        deleteResponse = performLocalDelete(deleteRequest, deleteStorageRequest);
        deleteResponse = remoteDeleteOperations.performRemoteDelete(deleteRequest, deleteResponse);
        deleteResponse = postProcessPreAuthorizationPlugins(deleteResponse);
        deleteRequest = populateDeleteRequestPolicyMap(deleteRequest, deleteResponse);
        deleteResponse = processPostDeleteAccessPlugins(deleteResponse);
        // Post results to be available for pubsub
        deleteResponse = validateFixDeleteResponse(deleteResponse, deleteRequest);
    } catch (StopProcessingException see) {
        LOGGER.debug(PRE_INGEST_ERROR + see.getMessage(), see);
        throw new IngestException(PRE_INGEST_ERROR + see.getMessage());
    } catch (RuntimeException re) {
        LOGGER.info("Exception during runtime while performing delete", re);
        throw new InternalIngestException("Exception during runtime while performing delete");
    } finally {
        if (deleteStorageRequest != null) {
            try {
                sourceOperations.getStorage().commit(deleteStorageRequest);
            } catch (StorageException e) {
                LOGGER.info("Unable to remove stored content items.", e);
            }
        }
    }
    deleteResponse = doPostIngest(deleteResponse);
    return deleteResponse;
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) StorageException(ddf.catalog.content.StorageException)

Aggregations

DeleteResponse (ddf.catalog.operation.DeleteResponse)54 Test (org.junit.Test)37 Metacard (ddf.catalog.data.Metacard)23 DeleteRequest (ddf.catalog.operation.DeleteRequest)23 ArrayList (java.util.ArrayList)19 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)18 HashMap (java.util.HashMap)17 Serializable (java.io.Serializable)15 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)14 CreateResponse (ddf.catalog.operation.CreateResponse)13 List (java.util.List)11 QueryResponse (ddf.catalog.operation.QueryResponse)9 QueryRequest (ddf.catalog.operation.QueryRequest)8 IngestException (ddf.catalog.source.IngestException)8 Result (ddf.catalog.data.Result)7 UpdateResponse (ddf.catalog.operation.UpdateResponse)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 CatalogFramework (ddf.catalog.CatalogFramework)6 Update (ddf.catalog.operation.Update)6