Search in sources :

Example 21 with DeleteRequestImpl

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

the class SolrProviderTestCase method deleteAllIn.

protected static void deleteAllIn(SolrCatalogProvider solrProvider, int methodNameIndex) throws IngestException, UnsupportedQueryException {
    messageBreak(Thread.currentThread().getStackTrace()[methodNameIndex].getMethodName() + "()");
    boolean isCaseSensitive = false;
    boolean isFuzzy = false;
    QueryImpl query = null;
    SourceResponse sourceResponse = null;
    CommonQueryBuilder queryBuilder = new CommonQueryBuilder();
    query = queryBuilder.like(Metacard.ID, "*", isCaseSensitive, isFuzzy);
    query.setPageSize(ALL_RESULTS);
    sourceResponse = solrProvider.query(new QueryRequestImpl(query));
    List<String> ids = new ArrayList<String>();
    for (Result r : sourceResponse.getResults()) {
        ids.add(r.getMetacard().getId());
    }
    LOGGER.info("Records found for deletion: {}", ids);
    provider.delete(new DeleteRequestImpl(ids.toArray(new String[ids.size()])));
    LOGGER.info("Deletion complete. -----------");
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ArrayList(java.util.ArrayList) Result(ddf.catalog.data.Result)

Example 22 with DeleteRequestImpl

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

the class CatalogFrameworkImplTest method testProviderUnavailableDeleteByIdentifier.

/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for delete by identifier.
     *
     * @throws IngestException
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableDeleteByIdentifier() throws SourceUnavailableException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
    List<URI> uris = new ArrayList<URI>();
    try {
        uris.add(new URI("id://1234"));
        DeleteRequest request = new DeleteRequestImpl((URI[]) uris.toArray(new URI[uris.size()]));
        // expected to throw exception due to catalog provider being
        // unavailable
        framework.delete(request);
    } catch (URISyntaxException e) {
        fail();
    } catch (IngestException e) {
        fail();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) CatalogFramework(ddf.catalog.CatalogFramework) ArrayList(java.util.ArrayList) IngestException(ddf.catalog.source.IngestException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 23 with DeleteRequestImpl

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

the class FanoutCatalogFrameworkTest method testBlacklistedTagDeleteRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagDeleteRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    doReturn(true).when(catalogProvider).isAvailable();
    StorageProvider storageProvider = new MockMemoryStorageProvider();
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterAdapter filterAdapter = mock(FilterAdapter.class);
    ValidationQueryFactory validationQueryFactory = new ValidationQueryFactory(filterAdapter, filterBuilder);
    QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class));
    ResultImpl result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<>();
    results.add(result);
    QueryResponseImpl queryResponse = new QueryResponseImpl(queryRequest, results, 1);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(anyList(), any())).thenReturn(queryResponse);
    QueryResponsePostProcessor queryResponsePostProcessor = mock(QueryResponsePostProcessor.class);
    doNothing().when(queryResponsePostProcessor).processResponse(any());
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setFilterBuilder(filterBuilder);
    frameworkProperties.setValidationQueryFactory(validationQueryFactory);
    frameworkProperties.setFederationStrategy(strategy);
    frameworkProperties.setQueryResponsePostProcessor(queryResponsePostProcessor);
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
    sourceOperations.bind(catalogProvider);
    sourceOperations.bind(storageProvider);
    TransformOperations transformOperations = new TransformOperations(frameworkProperties);
    QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
    ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
    DeleteOperations deleteOperations = new DeleteOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, null);
    deleteOperations.setOpsCatStoreSupport(opsCatStore);
    framework = new CatalogFrameworkImpl(null, null, deleteOperations, queryOperations, resourceOperations, sourceOperations, transformOperations);
    framework.setId(NEW_SOURCE_ID);
    framework.setFanoutEnabled(true);
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    DeleteRequest request = new DeleteRequestImpl(metacard.getId());
    framework.delete(request);
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) Query(ddf.catalog.operation.Query) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) ArrayList(java.util.ArrayList) FilterAdapter(ddf.catalog.filter.FilterAdapter) ResultImpl(ddf.catalog.data.impl.ResultImpl) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) Result(ddf.catalog.data.Result) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) SourceOperations(ddf.catalog.impl.operations.SourceOperations) FederationStrategy(ddf.catalog.federation.FederationStrategy) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ValidationQueryFactory(ddf.catalog.cache.solr.impl.ValidationQueryFactory) StorageProvider(ddf.catalog.content.StorageProvider) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) TransformOperations(ddf.catalog.impl.operations.TransformOperations) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryOperations(ddf.catalog.impl.operations.QueryOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 24 with DeleteRequestImpl

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

the class TestRegistryStore method testDelete.

@Test
public void testDelete() throws Exception {
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    Csw csw = mock(Csw.class);
    TransactionResponseType transResponse = mock(TransactionResponseType.class);
    TransactionSummaryType transSummary = mock(TransactionSummaryType.class);
    when(transResponse.getTransactionSummary()).thenReturn(transSummary);
    when(transSummary.getTotalDeleted()).thenReturn(new BigInteger("1"));
    when(csw.transaction(any(CswTransactionRequest.class))).thenReturn(transResponse);
    when(factory.getClientForSubject(any())).thenReturn(csw);
    when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
    FilterAdapter mockAdaptor = mock(FilterAdapter.class);
    CswFilterFactory filterFactory = new CswFilterFactory(CswAxisOrder.LAT_LON, false);
    FilterType filterType = filterFactory.buildPropertyIsLikeFilter(Metacard.ID, "testId", false);
    when(mockAdaptor.adapt(any(Filter.class), any(FilterDelegate.class))).thenReturn(filterType);
    registryStore.setFilterAdapter(mockAdaptor);
    DeleteRequestImpl request = new DeleteRequestImpl(Collections.singletonList(RegistryObjectMetacardType.REGISTRY_ID), "registryId", new HashMap<>());
    OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.DELETE, Collections.singletonList(getDefaultMetacard()));
    request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
    registryStore.delete(request);
    verify(filterBuilder).attribute(captor.capture());
    assertThat(captor.getValue(), is("id"));
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) FilterDelegate(ddf.catalog.filter.FilterDelegate) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) FilterAdapter(ddf.catalog.filter.FilterAdapter) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) FilterType(net.opengis.filter.v_1_1_0.FilterType) Filter(org.opengis.filter.Filter) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) CswFilterFactory(org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterFactory) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 25 with DeleteRequestImpl

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

the class MetacardApplication method attemptDeleteDeletedMetacard.

private void attemptDeleteDeletedMetacard(String id) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    LOGGER.trace("Attemping to delete metacard [{}]", id);
    Filter tags = filterBuilder.attribute(Metacard.TAGS).is().like().text(DeletedMetacard.DELETED_TAG);
    Filter deletion = filterBuilder.attribute(DeletedMetacard.DELETION_OF_ID).is().like().text(id);
    Filter filter = filterBuilder.allOf(tags, deletion);
    QueryResponse response = null;
    try {
        response = catalogFramework.query(new QueryRequestImpl(new QueryImpl(filter), false));
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.debug("Could not find the deleted metacard marker to delete", e);
    }
    if (response == null || response.getResults() == null || response.getResults().size() != 1) {
        LOGGER.debug("There should have been one deleted metacard marker");
        return;
    }
    final QueryResponse _response = response;
    try {
        executeAsSystem(() -> catalogFramework.delete(new DeleteRequestImpl(_response.getResults().get(0).getMetacard().getId())));
    } catch (ExecutionException e) {
        LOGGER.debug("Could not delete the deleted metacard marker", e);
    }
    LOGGER.trace("Deleted delete marker metacard successfully");
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) FederationException(ddf.catalog.federation.FederationException) ExecutionException(org.apache.shiro.subject.ExecutionException)

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