use of ddf.catalog.operation.DeleteRequest in project ddf by codice.
the class TestCswEndpoint method testDeleteTransaction.
@Test
public void testDeleteTransaction() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
DeleteType deleteType = mock(DeleteType.class);
doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
doReturn("").when(deleteType).getHandle();
QueryConstraintType queryConstraintType = new QueryConstraintType();
queryConstraintType.setCqlText("title = \"foo\"");
doReturn(queryConstraintType).when(deleteType).getConstraint();
List<Result> results = new ArrayList<>();
results.add(new ResultImpl(new MetacardImpl()));
results.add(new ResultImpl(new MetacardImpl()));
QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
List<Metacard> deletedMetacards = new ArrayList<>();
deletedMetacards.add(new MetacardImpl());
deletedMetacards.add(new MetacardImpl());
DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, deletedMetacards);
doReturn(deleteResponse).when(catalogFramework).delete(any(DeleteRequest.class));
DeleteAction deleteAction = new DeleteAction(deleteType, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
CswTransactionRequest deleteRequest = new CswTransactionRequest();
deleteRequest.getDeleteActions().add(deleteAction);
deleteRequest.setVersion(CswConstants.VERSION_2_0_2);
deleteRequest.setService(CswConstants.CSW);
deleteRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(deleteRequest);
assertThat(response, notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary, notNullValue());
assertThat(summary.getTotalDeleted().intValue(), is(2));
assertThat(summary.getTotalInserted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(0));
verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
}
use of ddf.catalog.operation.DeleteRequest 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.DeleteRequest 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.DeleteRequest in project ddf by codice.
the class MetacardValidityMarkerPluginTest method testProcessDelete.
@Test
public void testProcessDelete() throws StopProcessingException, PluginExecutionException {
DeleteRequestImpl deleteRequest = mock(DeleteRequestImpl.class);
DeleteRequest returnedDeleteRequest = plugin.process(deleteRequest);
assertThat(returnedDeleteRequest, is(theInstance(deleteRequest)));
}
use of ddf.catalog.operation.DeleteRequest in project ddf by codice.
the class FederationAdminServiceImpl method deleteRegistryEntriesByMetacardIds.
@Override
public void deleteRegistryEntriesByMetacardIds(List<String> metacardIds, Set<String> destinations) throws FederationAdminException {
if (CollectionUtils.isEmpty(metacardIds)) {
throw new FederationAdminException("An empty list of metacard ids to be deleted was received. Nothing to delete.");
}
List<Serializable> serializableIds = new ArrayList<>(metacardIds);
Map<String, Serializable> properties = new HashMap<>();
DeleteRequest deleteRequest = new DeleteRequestImpl(serializableIds, Metacard.ID, properties, destinations);
try {
DeleteResponse deleteResponse = security.runWithSubjectOrElevate(() -> catalogFramework.delete(deleteRequest));
if (!deleteResponse.getProcessingErrors().isEmpty()) {
throw new FederationAdminException("Processing error occurred while deleting registry entry. Details" + System.lineSeparator() + stringifyProcessingErrors(deleteResponse.getProcessingErrors()));
}
} catch (SecurityServiceException | InvocationTargetException e) {
String message = "Error deleting registry entries by metacard ids.";
LOGGER.debug("{} Metacard Ids provided: {}", message, metacardIds);
throw new FederationAdminException(message, e);
}
}
Aggregations