use of org.codice.ddf.commands.util.CatalogCommandException in project ddf by codice.
the class RemoveCommand method executeRemoveFromStore.
private Object executeRemoveFromStore() throws CatalogCommandException {
try {
int batchCount = 0;
int deletedCount = 0;
if (CollectionUtils.isNotEmpty(ids) && !hasFilter()) {
deletedCount = deletedIdsPassedAsArguments();
}
if (hasFilter()) {
QueryRequestImpl queryRequest = new QueryRequestImpl(new QueryImpl(getFilter()), false);
String[] idsToDelete = getNextQueryBatch(queryRequest);
while (idsToDelete.length > 0) {
if (CollectionUtils.isNotEmpty(ids)) {
idsToDelete = Arrays.asList(idsToDelete).stream().filter(id -> ids.contains(id)).toArray(String[]::new);
}
DeleteRequestImpl deleteRequest = new DeleteRequestImpl(idsToDelete);
LOGGER.debug("Attempting to delete {} metacards from batch {}", idsToDelete.length, ++batchCount);
DeleteResponse deleteResponse = catalogFramework.delete(deleteRequest);
deletedCount += deleteResponse.getDeletedMetacards().size();
idsToDelete = getNextQueryBatch(queryRequest);
}
}
if (deletedCount > 0) {
printSuccessMessage(deletedCount + " documents successfully deleted.");
LOGGER.debug("{} documents removed using catalog:remove command", deletedCount);
} else {
printErrorMessage("No documents match provided IDs or filter");
LOGGER.debug("No documents deleted using the catalog:remove command");
}
} catch (IngestException | SourceUnavailableException | ParseException | CQLException e) {
throw new CatalogCommandException("Error executing catalog:remove", e);
}
return null;
}
use of org.codice.ddf.commands.util.CatalogCommandException in project ddf by codice.
the class ValidateCommand method getMetacardsFromCatalogInternal.
private List<Metacard> getMetacardsFromCatalogInternal() throws CatalogCommandException {
List<Metacard> results = new ArrayList<>();
try {
QueryImpl query = new QueryImpl(getFilter());
SourceResponse response = getCatalog().query(new QueryRequestImpl(query));
List<Result> resultList = response.getResults();
if (resultList != null) {
results.addAll(resultList.stream().map(Result::getMetacard).filter(Objects::nonNull).collect(Collectors.toList()));
}
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException | CQLException | ParseException e) {
throw new CatalogCommandException("Error executing catalog:validate", e);
}
return results;
}
Aggregations