Search in sources :

Example 31 with DeleteResponse

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

the class RemoveCommand method executeRemoveFromStore.

private Object executeRemoveFromStore() throws Exception {
    CatalogFacade catalogProvider = getCatalog();
    if (hasFilter()) {
        QueryImpl query = new QueryImpl(getFilter());
        query.setRequestsTotalResultsCount(true);
        query.setPageSize(-1);
        Map<String, Serializable> properties = new HashMap<>();
        properties.put("mode", "native");
        SourceResponse queryResponse = catalogProvider.query(new QueryRequestImpl(query, properties));
        final List<String> idsFromFilteredQuery = queryResponse.getResults().stream().map(result -> result.getMetacard().getId()).collect(Collectors.toList());
        if (ids == null) {
            ids = idsFromFilteredQuery;
        } else {
            ids = ids.stream().filter(id -> idsFromFilteredQuery.contains(id)).collect(Collectors.toList());
        }
    }
    final int numberOfMetacardsToRemove = ids.size();
    if (numberOfMetacardsToRemove > 0) {
        printSuccessMessage("Found " + numberOfMetacardsToRemove + " metacards to remove.");
    } else {
        printErrorMessage("No records found meeting filter criteria.");
        return null;
    }
    DeleteRequestImpl request = new DeleteRequestImpl(ids.toArray(new String[numberOfMetacardsToRemove]));
    DeleteResponse response = catalogProvider.delete(request);
    if (response.getDeletedMetacards().size() > 0) {
        printSuccessMessage(ids + " successfully deleted.");
        LOGGER.info(ids + " removed using catalog:remove command");
    } else {
        printErrorMessage(ids + " could not be deleted.");
        LOGGER.info(ids + " could not be deleted using catalog:remove command");
    }
    return null;
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Arrays(java.util.Arrays) QueryImpl(ddf.catalog.operation.impl.QueryImpl) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Argument(org.apache.karaf.shell.api.action.Argument) DeleteResponse(ddf.catalog.operation.DeleteResponse) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Command(org.apache.karaf.shell.api.action.Command) List(java.util.List) SourceResponse(ddf.catalog.operation.SourceResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) Service(org.apache.karaf.shell.api.action.lifecycle.Service) CatalogFacade(org.codice.ddf.commands.catalog.facade.CatalogFacade) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Option(org.apache.karaf.shell.api.action.Option) Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CatalogFacade(org.codice.ddf.commands.catalog.facade.CatalogFacade)

Example 32 with DeleteResponse

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

the class RemoveAllCommandTest method testExecuteWithSubject.

/**
     * Checks the forced (-f) generic case.
     *
     * @throws Exception
     */
@Test
public void testExecuteWithSubject() throws Exception {
    // given
    RemoveAllCommand removeAllCommand = new RemoveAllCommand();
    final CatalogFramework catalogFramework = mock(CatalogFramework.class);
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(getResultList(10));
    when(catalogFramework.query(isA(QueryRequest.class))).thenReturn(queryResponse);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    when(deleteResponse.getDeletedMetacards()).thenReturn(getMetacardList(10));
    when(catalogFramework.delete(isA(DeleteRequest.class))).thenReturn(deleteResponse);
    removeAllCommand.catalogFramework = catalogFramework;
    removeAllCommand.filterBuilder = new GeotoolsFilterBuilder();
    removeAllCommand.batchSize = 11;
    removeAllCommand.force = true;
    // when
    removeAllCommand.executeWithSubject();
    // then
    verify(catalogFramework, times(1)).delete(isA(DeleteRequest.class));
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) CatalogFramework(ddf.catalog.CatalogFramework) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 33 with DeleteResponse

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

the class CachingFederationStrategyTest method testProcessDeleteResponse.

@Test
public void testProcessDeleteResponse() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
    DeleteResponse response = new DeleteResponseImpl(mock(DeleteRequestImpl.class), testMap, new ArrayList<>());
    response = strategy.process(response);
    assertThat(response.getPropertyValue(Constants.SERVICE_TITLE), is(MOCK_RESPONSE_TITLE));
}
Also used : Serializable(java.io.Serializable) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Test(org.junit.Test)

Example 34 with DeleteResponse

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

the class CachingFederationStrategyTest method testProcessDeleteResponseNotLocal.

@Test
public void testProcessDeleteResponseNotLocal() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
    testMap.put(Constants.LOCAL_DESTINATION_KEY, false);
    DeleteResponse response = mock(DeleteResponse.class);
    DeleteRequest request = mock(DeleteRequest.class);
    when(request.hasProperties()).thenReturn(true);
    when(request.getProperties()).thenReturn(testMap);
    when(response.getRequest()).thenReturn(request);
    assertThat(response, is(strategy.process(response)));
}
Also used : Serializable(java.io.Serializable) DeleteResponse(ddf.catalog.operation.DeleteResponse) HashMap(java.util.HashMap) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 35 with DeleteResponse

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

the class TestCswEndpoint method testDeleteTransaction.

@Test
public void testDeleteTransaction() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    DeleteType deleteType = mock(DeleteType.class);
    doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
    doReturn("").when(deleteType).getHandle();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("title = \"foo\"");
    doReturn(queryConstraintType).when(deleteType).getConstraint();
    List<Result> results = new ArrayList<>();
    results.add(new ResultImpl(new MetacardImpl()));
    results.add(new ResultImpl(new MetacardImpl()));
    QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
    doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
    List<Metacard> deletedMetacards = new ArrayList<>();
    deletedMetacards.add(new MetacardImpl());
    deletedMetacards.add(new MetacardImpl());
    DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, deletedMetacards);
    doReturn(deleteResponse).when(catalogFramework).delete(any(DeleteRequest.class));
    DeleteAction deleteAction = new DeleteAction(deleteType, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
    CswTransactionRequest deleteRequest = new CswTransactionRequest();
    deleteRequest.getDeleteActions().add(deleteAction);
    deleteRequest.setVersion(CswConstants.VERSION_2_0_2);
    deleteRequest.setService(CswConstants.CSW);
    deleteRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(deleteRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(2));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(0));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

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