use of ddf.catalog.operation.impl.DeleteRequestImpl 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.impl.DeleteRequestImpl 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);
}
}
use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.
the class FederationAdminServiceImpl method deleteRegistryEntriesByRegistryIds.
@Override
public void deleteRegistryEntriesByRegistryIds(List<String> registryIds, Set<String> destinations) throws FederationAdminException {
if (CollectionUtils.isEmpty(registryIds)) {
throw new FederationAdminException("An empty list of registry ids to be deleted was received. Nothing to delete.");
}
List<Serializable> serializableIds = new ArrayList<>(registryIds);
Map<String, Serializable> properties = new HashMap<>();
String deleteField = RegistryObjectMetacardType.REGISTRY_ID;
if (CollectionUtils.isNotEmpty(destinations)) {
deleteField = Metacard.ID;
try {
List<Metacard> localMetacards = security.runWithSubjectOrElevate(() -> this.getRegistryMetacardsByRegistryIds(registryIds));
List<Filter> idFilters = localMetacards.stream().map(e -> filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(e.getId())).collect(Collectors.toList());
Filter baseFilter = filterBuilder.allOf(getBasicFilter(RegistryConstants.REGISTRY_TAG_INTERNAL));
List<Metacard> toDelete = security.runWithSubjectOrElevate(() -> this.getRegistryMetacardsByFilter(filterBuilder.allOf(baseFilter, filterBuilder.anyOf(idFilters)), destinations));
serializableIds = toDelete.stream().map(e -> e.getId()).collect(Collectors.toList());
} catch (SecurityServiceException | InvocationTargetException e) {
throw new FederationAdminException("Error looking up metacards to delete.", e);
}
}
DeleteRequest deleteRequest = new DeleteRequestImpl(serializableIds, deleteField, 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 registry id.";
LOGGER.debug("{} Registry Ids provided: {}", message, registryIds);
throw new FederationAdminException(message, e);
}
}
use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderUnavailableDeleteByID.
/**
* Tests that the framework properly throws a catalog exception when the local provider is not
* available for delete by id.
*
* @throws IngestException
* @throws SourceUnavailableException
*/
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableDeleteByID() 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<String> ids = new ArrayList<String>();
ids.add("1234");
DeleteRequest request = new DeleteRequestImpl((String[]) ids.toArray(new String[ids.size()]));
// expected to throw exception due to catalog provider being unavailable
try {
framework.delete(request);
} catch (IngestException e) {
fail();
}
}
use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnDeleteByIdentifier.
@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnDeleteByIdentifier() throws IngestException {
MockEventProcessor eventAdmin = new MockEventProcessor();
// use exception provider instead of memory
MockExceptionProvider provider = new MockExceptionProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, null);
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
// List<MetacardType> identifiers = new ArrayList<MetacardType>();
// identifiers.add( new MetacardTypeImpl( "id", "1234" ) );
ArrayList<URI> uris = new ArrayList<URI>();
DeleteRequest request = new DeleteRequestImpl((URI[]) uris.toArray(new URI[uris.size()]));
// expected to throw exception due to catalog provider being unavailable
try {
framework.delete(request);
} catch (SourceUnavailableException e) {
fail();
}
}
Aggregations