Search in sources :

Example 11 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.

the class HistorianTest method testDeleteResponseNoContentItems.

@Test
public void testDeleteResponseNoContentItems() throws SourceUnavailableException, IngestException, StorageException {
    Metacard metacard = getMetacardUpdatePair().get(0);
    DeleteRequest deleteRequest = new DeleteRequestImpl("deleteRequest");
    DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap<>(), Collections.singletonList(metacard));
    historian.version(deleteResponse);
    assertThat(storageProvider.storageMap.size(), equalTo(0));
}
Also used : 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 12 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl 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 13 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.

the class RESTEndpoint method deleteDocument.

/**
     * REST Delete. Deletes a record from the catalog.
     *
     * @param id
     * @return
     */
@DELETE
@Path("/{id}")
public Response deleteDocument(@PathParam("id") String id, @Context HttpServletRequest httpRequest) {
    LOGGER.debug("DELETE");
    Response response;
    try {
        if (id != null) {
            DeleteRequestImpl deleteReq = new DeleteRequestImpl(id);
            catalogFramework.delete(deleteReq);
            response = Response.ok(id).build();
            LOGGER.debug("Attempting to delete Metacard with id: {}", id);
        } else {
            String errorMessage = "ID of entry not specified, cannot do DELETE.";
            LOGGER.info(errorMessage);
            throw new ServerErrorException(errorMessage, Status.BAD_REQUEST);
        }
    } catch (SourceUnavailableException ce) {
        String exceptionMessage = "Could not delete entry from catalog since the source is unavailable: ";
        LOGGER.info(exceptionMessage, ce);
        throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
    } catch (InternalIngestException e) {
        String exceptionMessage = "Error deleting entry from catalog: ";
        LOGGER.info(exceptionMessage, e);
        throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
    } catch (IngestException e) {
        String exceptionMessage = "Error deleting entry from catalog: ";
        LOGGER.info(exceptionMessage, e);
        throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
    }
    return response;
}
Also used : SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) InternalIngestException(ddf.catalog.source.InternalIngestException) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) IngestException(ddf.catalog.source.IngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 14 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl 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 15 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl 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)

Aggregations

DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)33 DeleteRequest (ddf.catalog.operation.DeleteRequest)21 Test (org.junit.Test)18 DeleteResponse (ddf.catalog.operation.DeleteResponse)17 ArrayList (java.util.ArrayList)17 Metacard (ddf.catalog.data.Metacard)15 HashMap (java.util.HashMap)11 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)9 CatalogFramework (ddf.catalog.CatalogFramework)8 Serializable (java.io.Serializable)8 List (java.util.List)8 Result (ddf.catalog.data.Result)7 QueryResponse (ddf.catalog.operation.QueryResponse)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 IngestException (ddf.catalog.source.IngestException)7 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)6 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 Filter (org.opengis.filter.Filter)6 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5