use of ddf.catalog.operation.DeleteResponse 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.DeleteResponse 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.DeleteResponse in project ddf by codice.
the class CatalogMetricsTest method catalogDeleteMetric.
@Test
public void catalogDeleteMetric() throws Exception {
DeleteRequest request = mock(DeleteRequest.class);
DeleteResponse response = mock(DeleteResponse.class);
List<Metacard> deletedList = mock(List.class);
when(deletedList.size()).thenReturn(100);
when(response.getRequest()).thenReturn(request);
when(response.getDeletedMetacards()).thenReturn(deletedList);
underTest.process(response);
assertThat(underTest.deletedMetacards.getCount(), is(100L));
}
use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class RegistryIdPostIngestPluginTest method testProcessDeleteInternal.
@Test
public void testProcessDeleteInternal() throws Exception {
CreateResponse createResponse = new CreateResponseImpl(null, null, Collections.singletonList(getDefaultInternalMetacard()));
registryIdPostIngestPlugin.process(createResponse);
DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, Collections.singletonList(getDefaultInternalMetacard()));
registryIdPostIngestPlugin.process(deleteResponse);
assertThat(registryIdPostIngestPlugin.getRemoteMetacardIds().size(), equalTo(0));
}
use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class CatalogBackupPluginTest method testDeleteResponseFailToDeleteAllMetacards.
@Test
public void testDeleteResponseFailToDeleteAllMetacards() {
DeleteResponse mockDeleteResponse = getDeleteResponse(Arrays.asList(METACARD_IDS));
// Perform Test
getPlugin().process(mockDeleteResponse);
}
Aggregations