Search in sources :

Example 31 with DeleteRequestImpl

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

the class ExportCommand method doDelete.

private void doDelete(List<ExportItem> exportedItems, List<ExportItem> exportedContentItems) {
    Instant start;
    console.println("Starting delete");
    start = Instant.now();
    for (ExportItem exportedContentItem : exportedContentItems) {
        try {
            DeleteStorageRequestImpl deleteRequest = new DeleteStorageRequestImpl(Collections.singletonList(new IdAndUriMetacard(exportedContentItem.getId(), exportedContentItem.getResourceUri())), exportedContentItem.getId(), Collections.emptyMap());
            storageProvider.delete(deleteRequest);
            storageProvider.commit(deleteRequest);
        } catch (StorageException e) {
            printErrorMessage("Could not delete content for metacard: " + exportedContentItem.toString());
        }
    }
    for (ExportItem exported : exportedItems) {
        try {
            catalogProvider.delete(new DeleteRequestImpl(exported.getId()));
        } catch (IngestException e) {
            printErrorMessage("Could not delete metacard: " + exported.toString());
        }
    }
    // delete items from cache
    try {
        getCacheProxy().removeById(exportedItems.stream().map(ExportItem::getId).collect(Collectors.toList()).toArray(new String[exportedItems.size()]));
    } catch (Exception e) {
        LOGGER.warn("Could not delete all exported items from cache (Results will eventually expire)", e);
    }
    console.println("Metacards and Content deleted in: " + getFormattedDuration(start));
    console.println("Number of metacards deleted: " + exportedItems.size());
    console.println("Number of content deleted: " + exportedContentItems.size());
}
Also used : DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) ExportItem(org.codice.ddf.commands.catalog.export.ExportItem) Instant(java.time.Instant) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) IdAndUriMetacard(org.codice.ddf.commands.catalog.export.IdAndUriMetacard) IngestException(ddf.catalog.source.IngestException) StorageException(ddf.catalog.content.StorageException) URISyntaxException(java.net.URISyntaxException) ParseException(java.text.ParseException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ZipException(net.lingala.zip4j.exception.ZipException) StorageException(ddf.catalog.content.StorageException) CatalogCommandRuntimeException(org.codice.ddf.commands.util.CatalogCommandRuntimeException) CQLException(org.geotools.filter.text.cql2.CQLException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException)

Example 32 with DeleteRequestImpl

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

the class OperationPluginTest method testPluginWithRole.

private void testPluginWithRole(String role) throws Exception {
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
    HashMap<String, Set<String>> perms = new HashMap<>();
    Set<String> roles = new HashSet<>();
    roles.add(role);
    perms.put("Roles", roles);
    properties.put(PolicyPlugin.OPERATION_SECURITY, perms);
    CreateRequestImpl request = new CreateRequestImpl(new ArrayList<>(), properties);
    QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class), properties);
    UpdateRequestImpl updateRequest = new UpdateRequestImpl(new ArrayList<>(), "", properties);
    DeleteRequestImpl deleteRequest = new DeleteRequestImpl(new String[] { "" }, properties);
    ResourceRequestById resourceRequestById = new ResourceRequestById("", properties);
    plugin.processPreCreate(request);
    plugin.processPreQuery(queryRequest);
    plugin.processPreUpdate(updateRequest, new HashMap<>());
    plugin.processPreDelete(deleteRequest);
    plugin.processPreResource(resourceRequestById);
}
Also used : Serializable(java.io.Serializable) HashSet(java.util.HashSet) Set(java.util.Set) Query(ddf.catalog.operation.Query) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) HashSet(java.util.HashSet)

Example 33 with DeleteRequestImpl

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

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