use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.
the class ExportCommand method doDelete.
private void doDelete(List<ExportItem> exportedItems, List<ExportItem> exportedContentItems) {
Instant start;
console.println("Starting delete");
start = Instant.now();
for (ExportItem exportedContentItem : exportedContentItems) {
try {
DeleteStorageRequestImpl deleteRequest = new DeleteStorageRequestImpl(Collections.singletonList(new IdAndUriMetacard(exportedContentItem.getId(), exportedContentItem.getResourceUri())), exportedContentItem.getId(), Collections.emptyMap());
storageProvider.delete(deleteRequest);
storageProvider.commit(deleteRequest);
} catch (StorageException e) {
printErrorMessage("Could not delete content for metacard: " + exportedContentItem.toString());
}
}
for (ExportItem exported : exportedItems) {
try {
catalogProvider.delete(new DeleteRequestImpl(exported.getId()));
} catch (IngestException e) {
printErrorMessage("Could not delete metacard: " + exported.toString());
}
}
// delete items from cache
try {
getCacheProxy().removeById(exportedItems.stream().map(ExportItem::getId).collect(Collectors.toList()).toArray(new String[exportedItems.size()]));
} catch (Exception e) {
LOGGER.warn("Could not delete all exported items from cache (Results will eventually expire)", e);
}
console.println("Metacards and Content deleted in: " + getFormattedDuration(start));
console.println("Number of metacards deleted: " + exportedItems.size());
console.println("Number of content deleted: " + exportedContentItems.size());
}
use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.
the class OperationPluginTest method testPluginWithRole.
private void testPluginWithRole(String role) throws Exception {
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
HashMap<String, Set<String>> perms = new HashMap<>();
Set<String> roles = new HashSet<>();
roles.add(role);
perms.put("Roles", roles);
properties.put(PolicyPlugin.OPERATION_SECURITY, perms);
CreateRequestImpl request = new CreateRequestImpl(new ArrayList<>(), properties);
QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class), properties);
UpdateRequestImpl updateRequest = new UpdateRequestImpl(new ArrayList<>(), "", properties);
DeleteRequestImpl deleteRequest = new DeleteRequestImpl(new String[] { "" }, properties);
ResourceRequestById resourceRequestById = new ResourceRequestById("", properties);
plugin.processPreCreate(request);
plugin.processPreQuery(queryRequest);
plugin.processPreUpdate(updateRequest, new HashMap<>());
plugin.processPreDelete(deleteRequest);
plugin.processPreResource(resourceRequestById);
}
use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.
the class CatalogComponentFrameworkTest method testDeleteWithSingleId.
@Test
public /**
* Operation: DELETE
* Body contains: 12345678900987654321abcdeffedcba
*/
void testDeleteWithSingleId() throws Exception {
resetMocks();
// Setup expectations to verify
final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
mockVerifierEndpoint.expectedMessageCount(1);
final List<Metacard> metacards = new ArrayList<Metacard>();
metacards.add(metacard1);
// setup mock catalog framework
final String[] metacardIds = new String[metacards.size()];
for (int i = 0; i < metacards.size(); i++) {
metacardIds[i] = metacards.get(i).getId();
}
DeleteRequest deleteRequest = new DeleteRequestImpl(metacardIds);
DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap(), metacards);
when(catalogFramework.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
// Exercise the route with a DELETE operation
template.sendBodyAndHeader("direct:sampleInput", metacardIds, "Operation", "DELETE");
// Verify that the number of metacards in the exchange after the records
// is identical to the input
assertListSize(mockVerifierEndpoint.getExchanges(), 1);
final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
final List<Update> cardsDeleted = (List<Update>) exchange.getIn().getBody();
assertListSize(cardsDeleted, 1);
mockVerifierEndpoint.assertIsSatisfied();
}
Aggregations