Search in sources :

Example 6 with DeleteStorageRequest

use of ddf.catalog.content.operation.DeleteStorageRequest in project ddf by codice.

the class HistorianTest method testDeleteResponse.

@Test
public void testDeleteResponse() throws SourceUnavailableException, IngestException, StorageException {
    Metacard metacard = getMetacardUpdatePair().get(0);
    storeMetacard(metacard);
    // Send a delete request
    DeleteStorageRequest deleteStorageRequest = new DeleteStorageRequestImpl(Collections.singletonList(metacard), new HashMap<>());
    storageProvider.delete(deleteStorageRequest);
    // Version delete request
    DeleteRequest deleteRequest = new DeleteRequestImpl("deleteRequest");
    DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap<>(), Collections.singletonList(metacard));
    historian.version(deleteResponse);
    // Only the version metacard is left
    assertThat(storageProvider.storageMap.size(), equalTo(1));
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 7 with DeleteStorageRequest

use of ddf.catalog.content.operation.DeleteStorageRequest in project ddf by codice.

the class HistorianTest method testDeleteResponseSetSkipFlag.

@Test
public void testDeleteResponseSetSkipFlag() throws SourceUnavailableException, IngestException, StorageException {
    Metacard metacard = getMetacardUpdatePair().get(0);
    storeMetacard(metacard);
    // Send a delete request
    DeleteStorageRequest deleteStorageRequest = new DeleteStorageRequestImpl(Collections.singletonList(metacard), new HashMap<>());
    storageProvider.delete(deleteStorageRequest);
    // Version delete request
    DeleteRequest deleteRequest = new DeleteRequestImpl("deleteRequest");
    DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap<>(), Collections.singletonList(metacard));
    historian.version(deleteResponse);
    assertThat(deleteResponse.getProperties(), hasEntry(MetacardVersion.SKIP_VERSIONING, true));
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 8 with DeleteStorageRequest

use of ddf.catalog.content.operation.DeleteStorageRequest in project ddf by codice.

the class FileSystemStorageProviderTest method testDeleteWithSimilarIds.

@Test
public void testDeleteWithSimilarIds() throws Exception {
    CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
    String id = createResponse.getCreatedContentItems().get(0).getId();
    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
    String badId = id.substring(0, 6) + uuid.substring(6, uuid.length() - 1);
    boolean hadError = false;
    try {
        CreateStorageResponse badCreateResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, badId, "");
    } catch (AssertionError e) {
        // bad id is not a valid ID
        hadError = true;
    } finally {
        if (!hadError) {
            fail("Create succeeded when it should not have! " + badId + "Should not be valid!");
        }
        hadError = false;
    }
    DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
    when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
    DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
    List<ContentItem> items = deleteResponse.getDeletedContentItems();
    ContentItem item = items.get(0);
    LOGGER.debug("Item retrieved: {}", item);
    assertEquals(id, item.getId());
    assertThat(item.getFilename(), is(""));
    provider.commit(deleteRequest);
    try {
        assertReadRequest(createResponse.getCreatedContentItems().get(0).getUri(), NITF_MIME_TYPE);
    } catch (StorageException e) {
        // The item was deleted so it shouldn't have found it
        hadError = true;
    } finally {
        if (!hadError) {
            fail("read succeeded when it should not have! ");
        }
    }
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 9 with DeleteStorageRequest

use of ddf.catalog.content.operation.DeleteStorageRequest 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)

Example 10 with DeleteStorageRequest

use of ddf.catalog.content.operation.DeleteStorageRequest in project ddf by codice.

the class InMemoryStorageProvider method delete.

@Override
public DeleteStorageResponse delete(DeleteStorageRequest deleteRequest) throws StorageException {
    if (deleteRequest == null) {
        throw new StorageException("delete request can't be null");
    }
    List<ContentItem> itemsToDelete = new ArrayList<>();
    for (Metacard metacard : deleteRequest.getMetacards()) {
        List<ContentItem> tmp = storageMap.values().stream().filter(item -> item.getMetacard().getId().equals(metacard.getId())).collect(Collectors.toList());
        if (tmp.isEmpty()) {
            throw new StorageException("can't delete a metacard that isn't stored");
        }
        itemsToDelete.addAll(tmp);
    }
    for (ContentItem item : itemsToDelete) {
        deleteMap.put(item.getUri(), item);
    }
    return new DeleteStorageResponseImpl(deleteRequest, itemsToDelete);
}
Also used : CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) ArrayList(java.util.ArrayList) StorageRequest(ddf.catalog.content.operation.StorageRequest) CreateStorageResponseImpl(ddf.catalog.content.operation.impl.CreateStorageResponseImpl) StorageException(ddf.catalog.content.StorageException) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ReadStorageResponseImpl(ddf.catalog.content.operation.impl.ReadStorageResponseImpl) List(java.util.List) ContentItem(ddf.catalog.content.data.ContentItem) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageResponseImpl(ddf.catalog.content.operation.impl.DeleteStorageResponseImpl) UpdateStorageResponseImpl(ddf.catalog.content.operation.impl.UpdateStorageResponseImpl) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) StorageProvider(ddf.catalog.content.StorageProvider) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem) DeleteStorageResponseImpl(ddf.catalog.content.operation.impl.DeleteStorageResponseImpl)

Aggregations

DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)10 DeleteStorageRequestImpl (ddf.catalog.content.operation.impl.DeleteStorageRequestImpl)9 Test (org.junit.Test)8 ContentItem (ddf.catalog.content.data.ContentItem)7 DeleteStorageResponse (ddf.catalog.content.operation.DeleteStorageResponse)7 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)6 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)6 Metacard (ddf.catalog.data.Metacard)4 StorageException (ddf.catalog.content.StorageException)3 DeleteResponse (ddf.catalog.operation.DeleteResponse)3 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)2 DeleteRequest (ddf.catalog.operation.DeleteRequest)2 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)2 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)2 HashMap (java.util.HashMap)2 StorageProvider (ddf.catalog.content.StorageProvider)1 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)1 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)1