Search in sources :

Example 1 with CatalogCommandException

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;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) CatalogCommandException(org.codice.ddf.commands.util.CatalogCommandException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) IngestException(ddf.catalog.source.IngestException) ParseException(java.text.ParseException) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 2 with CatalogCommandException

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;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceResponse(ddf.catalog.operation.SourceResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) CatalogCommandException(org.codice.ddf.commands.util.CatalogCommandException) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Objects(java.util.Objects) CQLException(org.geotools.filter.text.cql2.CQLException) ParseException(java.text.ParseException)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)2 ParseException (java.text.ParseException)2 CatalogCommandException (org.codice.ddf.commands.util.CatalogCommandException)2 CQLException (org.geotools.filter.text.cql2.CQLException)2 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 FederationException (ddf.catalog.federation.FederationException)1 DeleteResponse (ddf.catalog.operation.DeleteResponse)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)1 IngestException (ddf.catalog.source.IngestException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1