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