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;
}
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));
}
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));
}
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)));
}
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);
}
Aggregations