Search in sources :

Example 6 with DeleteRequest

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

the class TestMetacardGroomerPlugin method testDelete.

@Test
public void testDelete() throws PluginExecutionException, StopProcessingException, ParseException {
    DeleteRequest inputRequest = new DeleteRequestImpl(SAMPLE_ID);
    DeleteRequest returnedRequest = plugin.process(inputRequest);
    assertNotNull(returnedRequest);
    assertThat(returnedRequest, equalTo(inputRequest));
}
Also used : DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 7 with DeleteRequest

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

the class SolrProviderTest method testDeleteAlternativeAttribute.

/**
     * Testing if another attribute can be used to delete records other than {@link Metacard#ID}
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testDeleteAlternativeAttribute() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    CreateResponse createResponse = create(metacard);
    DeleteResponse deleteResponse = provider.delete(new DeleteRequest() {

        @Override
        public boolean hasProperties() {
            return false;
        }

        @Override
        public Serializable getPropertyValue(String name) {
            return null;
        }

        @Override
        public Set<String> getPropertyNames() {
            return null;
        }

        @Override
        public Map<String, Serializable> getProperties() {
            return null;
        }

        @Override
        public boolean containsPropertyName(String name) {
            return false;
        }

        @Override
        public List<? extends Serializable> getAttributeValues() {
            return Arrays.asList(MockMetacard.DEFAULT_TITLE);
        }

        @Override
        public String getAttributeName() {
            return Metacard.TITLE;
        }
    });
    Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
    verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
    // verify it is really not in SOLR
    Filter filter = filterBuilder.attribute(Metacard.TITLE).like().text(MockMetacard.DEFAULT_TITLE);
    QueryImpl query = new QueryImpl(filter);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    List<Result> results = sourceResponse.getResults();
    assertEquals(0, results.size());
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DeleteRequest(ddf.catalog.operation.DeleteRequest) Map(java.util.Map) Test(org.junit.Test)

Example 8 with DeleteRequest

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

the class SolrProviderTest method testDeleteNoList.

@Test
public void testDeleteNoList() throws IngestException, UnsupportedQueryException {
    /* EMPTY */
    DeleteRequestImpl deleteRequest = new DeleteRequestImpl(new String[0]);
    DeleteResponse results = provider.delete(deleteRequest);
    assertNotNull(results.getDeletedMetacards());
    assertEquals(0, results.getDeletedMetacards().size());
    assertEquals(deleteRequest, results.getRequest());
    /* EMPTY */
    DeleteRequestImpl emptyDeleteRequest = new DeleteRequestImpl(new ArrayList<Serializable>(), DeleteRequest.DELETE_BY_ID, null);
    results = provider.delete(emptyDeleteRequest);
    assertNotNull(results.getDeletedMetacards());
    assertEquals(0, results.getDeletedMetacards().size());
    assertEquals(emptyDeleteRequest, results.getRequest());
    /* NULL */
    DeleteRequest nullDeleteRequest = new DeleteRequestImpl(null, DeleteRequest.DELETE_BY_ID, null);
    results = provider.delete(nullDeleteRequest);
    assertNotNull(results.getDeletedMetacards());
    assertEquals(0, results.getDeletedMetacards().size());
    assertEquals(nullDeleteRequest, results.getRequest());
}
Also used : Serializable(java.io.Serializable) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 9 with DeleteRequest

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

the class CatalogFrameworkImplTest method testInjectsAttributesOnDelete.

@Test
public void testInjectsAttributesOnDelete() throws Exception {
    final String title = "Delete this";
    final String injectAttributeName = "new attribute";
    final double injectAttributeValue = 11.1;
    final MetacardImpl metacard = new MetacardImpl();
    metacard.setTitle(title);
    metacard.setAttribute(injectAttributeName, injectAttributeValue);
    final String id = framework.create(new CreateRequestImpl(Collections.singletonList(metacard), null)).getCreatedMetacards().get(0).getId();
    final DeleteRequest request = new DeleteRequestImpl(id);
    final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
    stubMetacardInjection(injectAttribute);
    List<Result> mockFederationResults = Stream.of(metacard).map(m -> {
        Result mockResult = mock(Result.class);
        when(mockResult.getMetacard()).thenReturn(m);
        return mockResult;
    }).collect(Collectors.toList());
    QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
    when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
    when(mockRemoteDeleteOperations.performRemoteDelete(any(), any())).then(returnsSecondArg());
    deleteOperations.setRemoteDeleteOperations(mockRemoteDeleteOperations);
    final DeleteResponse response = framework.delete(request);
    final Metacard deletedMetacard = response.getDeletedMetacards().get(0);
    final MetacardType originalMetacardType = metacard.getMetacardType();
    final MetacardType deletedMetacardType = deletedMetacard.getMetacardType();
    assertThat(deletedMetacardType.getName(), is(originalMetacardType.getName()));
    final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
    expectedAttributeDescriptors.add(injectAttribute);
    assertThat(deletedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
    assertThat(deletedMetacard.getTitle(), is(title));
    assertThat(deletedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) AttributeRegistryImpl(ddf.catalog.data.impl.AttributeRegistryImpl) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) CreateRequest(ddf.catalog.operation.CreateRequest) BinaryContent(ddf.catalog.data.BinaryContent) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) AttributeType(ddf.catalog.data.AttributeType) FilterFactory(org.opengis.filter.FilterFactory) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) CreateOperations(ddf.catalog.impl.operations.CreateOperations) RemoteDeleteOperations(ddf.catalog.impl.operations.RemoteDeleteOperations) ServiceReference(org.osgi.framework.ServiceReference) InputTransformer(ddf.catalog.transform.InputTransformer) PostResourcePlugin(ddf.catalog.plugin.PostResourcePlugin) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Set(java.util.Set) SourceOperations(ddf.catalog.impl.operations.SourceOperations) MimeTypeResolver(ddf.mime.MimeTypeResolver) Serializable(java.io.Serializable) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Matchers.any(org.mockito.Matchers.any) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) BASIC_METACARD(ddf.catalog.data.impl.BasicTypes.BASIC_METACARD) Stream(java.util.stream.Stream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) Assert.assertFalse(org.junit.Assert.assertFalse) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) Matchers.is(org.hamcrest.Matchers.is) UpdateResponse(ddf.catalog.operation.UpdateResponse) BasicTypes(ddf.catalog.data.impl.BasicTypes) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Mockito.mock(org.mockito.Mockito.mock) ResourceResponse(ddf.catalog.operation.ResourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) AdditionalAnswers.returnsSecondArg(org.mockito.AdditionalAnswers.returnsSecondArg) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) Resource(ddf.catalog.resource.Resource) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) Source(ddf.catalog.source.Source) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) TestWatchman(org.junit.rules.TestWatchman) ContentItem(ddf.catalog.content.data.ContentItem) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) SourceInfoRequestSources(ddf.catalog.operation.impl.SourceInfoRequestSources) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ByteSource(com.google.common.io.ByteSource) Result(ddf.catalog.data.Result) TransformOperations(ddf.catalog.impl.operations.TransformOperations) Before(org.junit.Before) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ContentType(ddf.catalog.data.ContentType) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) Historian(ddf.catalog.history.Historian) IngestException(ddf.catalog.source.IngestException) Assert.assertTrue(org.junit.Assert.assertTrue) StopProcessingException(ddf.catalog.plugin.StopProcessingException) IOException(java.io.IOException) Test(org.junit.Test) Subject(ddf.security.Subject) AttributeInjector(ddf.catalog.data.AttributeInjector) FederationException(ddf.catalog.federation.FederationException) AttributeInjectorImpl(ddf.catalog.data.inject.AttributeInjectorImpl) DAYS(java.time.temporal.ChronoUnit.DAYS) Query(ddf.catalog.operation.Query) ValidationQueryFactory(ddf.catalog.cache.solr.impl.ValidationQueryFactory) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Assert.assertEquals(org.junit.Assert.assertEquals) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) PreQueryPlugin(ddf.catalog.plugin.PreQueryPlugin) CatalogStore(ddf.catalog.source.CatalogStore) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) Date(java.util.Date) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) URISyntaxException(java.net.URISyntaxException) MethodRule(org.junit.rules.MethodRule) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) LoggerFactory(org.slf4j.LoggerFactory) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) SourceDescriptor(ddf.catalog.source.SourceDescriptor) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Assert.fail(org.junit.Assert.fail) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) CachedSource(ddf.catalog.util.impl.CachedSource) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) Matchers.isA(org.mockito.Matchers.isA) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) FederatedSource(ddf.catalog.source.FederatedSource) MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) ResultImpl(ddf.catalog.data.impl.ResultImpl) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) ResourceReader(ddf.catalog.resource.ResourceReader) UUID(java.util.UUID) SourceMonitor(ddf.catalog.source.SourceMonitor) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) DeleteRequest(ddf.catalog.operation.DeleteRequest) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) Matchers.anyMap(org.mockito.Matchers.anyMap) Entry(java.util.Map.Entry) FederationStrategy(ddf.catalog.federation.FederationStrategy) FilterBuilder(ddf.catalog.filter.FilterBuilder) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) HashMap(java.util.HashMap) Update(ddf.catalog.operation.Update) DefaultAttributeValueRegistry(ddf.catalog.data.DefaultAttributeValueRegistry) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) Matchers.anyObject(org.mockito.Matchers.anyObject) MimeType(javax.activation.MimeType) SourcePoller(ddf.catalog.util.impl.SourcePoller) SecurityConstants(ddf.security.SecurityConstants) StorageProvider(ddf.catalog.content.StorageProvider) OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) Mockito.when(org.mockito.Mockito.when) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) Mockito.verify(org.mockito.Mockito.verify) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) SourceResponse(ddf.catalog.operation.SourceResponse) Rule(org.junit.Rule) Ignore(org.junit.Ignore) CatalogProvider(ddf.catalog.source.CatalogProvider) ThreadContext(org.apache.shiro.util.ThreadContext) QueryOperations(ddf.catalog.impl.operations.QueryOperations) Filter(org.opengis.filter.Filter) Matchers.anyList(org.mockito.Matchers.anyList) Collections(java.util.Collections) InputStream(java.io.InputStream) QueryRequest(ddf.catalog.operation.QueryRequest) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Matchers.anyString(org.mockito.Matchers.anyString) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Result(ddf.catalog.data.Result) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with DeleteRequest

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

the class CatalogFrameworkImplTest method testDeleteWithStores.

// TODO (DDF-2436) -
@Ignore
@Test
public void testDeleteWithStores() throws Exception {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    Map<String, CatalogStore> storeMap = new HashMap<>();
    Map<String, FederatedSource> sourceMap = new HashMap<>();
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
    storeMap.put(store.getId(), store);
    sourceMap.put(store.getId(), store);
    CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
    List<Metacard> metacards = new ArrayList<>();
    String id = UUID.randomUUID().toString().replaceAll("-", "");
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(id);
    newCard.setAttribute("myKey", "myValue1");
    metacards.add(newCard);
    Map<String, Serializable> reqProps = new HashMap<>();
    HashSet<String> destinations = new HashSet<>();
    destinations.add("mockMemoryProvider");
    destinations.add("catalogStoreId-1");
    framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    DeleteRequest deleteRequest = new DeleteRequestImpl(Collections.singletonList(id), Metacard.ID, new HashMap<>(), destinations);
    DeleteResponse response = framework.delete(deleteRequest);
    assertThat(response.getDeletedMetacards().size(), is(1));
    QueryResponse queryResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), true));
    assertThat(queryResponse.getResults().size(), is(0));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) FilterFactory(org.opengis.filter.FilterFactory) CatalogStore(ddf.catalog.source.CatalogStore) QueryImpl(ddf.catalog.operation.impl.QueryImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashSet(java.util.HashSet) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DeleteRequest (ddf.catalog.operation.DeleteRequest)39 Test (org.junit.Test)29 DeleteResponse (ddf.catalog.operation.DeleteResponse)22 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)22 Metacard (ddf.catalog.data.Metacard)18 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)11 Serializable (java.io.Serializable)10 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)9 List (java.util.List)9 CatalogFramework (ddf.catalog.CatalogFramework)7 QueryResponse (ddf.catalog.operation.QueryResponse)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 Result (ddf.catalog.data.Result)6 QueryRequest (ddf.catalog.operation.QueryRequest)6 ContentType (ddf.catalog.data.ContentType)5 ResourceRequest (ddf.catalog.operation.ResourceRequest)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 Filter (org.opengis.filter.Filter)5 ResultImpl (ddf.catalog.data.impl.ResultImpl)4