use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class RemoteDeleteOperationsTest method testNonEmptyStoreNotAvailableExpectProcessingErrors.
@Test
public void testNonEmptyStoreNotAvailableExpectProcessingErrors() throws Exception {
when(opsCatStoreSupport.isCatalogStoreRequest(deleteRequest)).thenReturn(true);
remoteDeleteOperations.setOpsCatStoreSupport(opsCatStoreSupport);
deleteResponse = null;
CatalogStore catalogStoreMock = mock(CatalogStore.class);
ArrayList<CatalogStore> stores = new ArrayList<>();
stores.add(catalogStoreMock);
when(opsCatStoreSupport.getCatalogStoresForRequest(any(), any())).thenReturn(stores);
when(catalogStoreMock.isAvailable()).thenReturn(false);
DeleteResponse resultDeleteResponse = remoteDeleteOperations.performRemoteDelete(deleteRequest, deleteResponse);
assertThat("Assert processing error occurs", resultDeleteResponse.getProcessingErrors().size() >= 1);
verify(opsCatStoreSupport).isCatalogStoreRequest(deleteRequest);
verify(opsCatStoreSupport).getCatalogStoresForRequest(any(), any());
verify(catalogStoreMock).isAvailable();
}
use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class Historian method version.
/**
* Versions deleted {@link Metacard}s.
*
* @param deleteResponse Versions this responses deleted metacards
*/
public DeleteResponse version(DeleteResponse deleteResponse) throws SourceUnavailableException, IngestException {
if (doSkip(deleteResponse)) {
return deleteResponse;
}
setSkipFlag(deleteResponse);
List<Metacard> deletedMetacards = deleteResponse.getDeletedMetacards().stream().filter(isNotVersionNorDeleted).collect(Collectors.toList());
// [ContentItem.getId: content items]
Map<String, List<ContentItem>> contentItems = getContent(getReadStorageRequests(deletedMetacards));
Function<String, Action> getAction = (id) -> contentItems.containsKey(id) ? Action.DELETED_CONTENT : Action.DELETED;
// [MetacardVersion.VERSION_OF_ID: versioned metacard]
Map<String, Metacard> versionedMap = getVersionMetacards(deletedMetacards, getAction, (Subject) deleteResponse.getRequest().getProperties().get(SecurityConstants.SECURITY_SUBJECT));
CreateStorageResponse createStorageResponse = versionContentItems(contentItems, versionedMap);
if (createStorageResponse != null) {
setResourceUriForContent(/*Mutable*/
versionedMap, createStorageResponse);
}
executeAsSystem(() -> catalogProvider().create(new CreateRequestImpl(new ArrayList<>(versionedMap.values()))));
String emailAddress = SubjectUtils.getEmailAddress((Subject) deleteResponse.getProperties().get(SecurityConstants.SECURITY_SUBJECT));
List<Metacard> deletionMetacards = versionedMap.entrySet().stream().map(s -> new DeletedMetacardImpl(uuidGenerator.generateUuid(), s.getKey(), emailAddress, s.getValue().getId(), MetacardVersionImpl.toMetacard(s.getValue(), metacardTypes))).collect(Collectors.toList());
executeAsSystem(() -> catalogProvider().create(new CreateRequestImpl(deletionMetacards, new HashMap<>())));
return deleteResponse;
}
use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class CswEndpoint method deleteRecords.
private int deleteRecords(DeleteAction deleteAction) throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
QueryRequest queryRequest = queryFactory.getQuery(deleteAction.getConstraint());
queryRequest = queryFactory.updateQueryRequestTags(queryRequest, schemaTransformerManager.getTransformerSchemaForId(deleteAction.getTypeName()));
QueryResponse response = framework.query(queryRequest);
List<String> ids = new ArrayList<>();
for (Result result : response.getResults()) {
if (result != null && result.getMetacard() != null) {
ids.add(result.getMetacard().getId());
}
}
if (ids.size() > 0) {
DeleteRequestImpl deleteRequest = new DeleteRequestImpl(ids.toArray(new String[ids.size()]));
LOGGER.debug("Attempting to delete {} metacards. ", ids.size());
DeleteResponse deleteResponse = framework.delete(deleteRequest);
return deleteResponse.getDeletedMetacards().size();
}
return 0;
}
use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class HistorianTest method testDeleteResponseNoContentItems.
@Test
public void testDeleteResponseNoContentItems() throws SourceUnavailableException, IngestException, StorageException {
Metacard metacard = getMetacardUpdatePair().get(0);
DeleteRequest deleteRequest = new DeleteRequestImpl("deleteRequest");
DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap<>(), Collections.singletonList(metacard));
historian.version(deleteResponse);
assertThat(storageProvider.storageMap.size(), equalTo(0));
}
use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class HistorianTest method testDeleteResponseSetSkipFlag.
@Test
public void testDeleteResponseSetSkipFlag() throws SourceUnavailableException, IngestException, StorageException {
Metacard metacard = getMetacardUpdatePair().get(0);
storeMetacard(metacard);
// Send a delete request
DeleteStorageRequest deleteStorageRequest = new DeleteStorageRequestImpl(Collections.singletonList(metacard), new HashMap<>());
storageProvider.delete(deleteStorageRequest);
// Version delete request
DeleteRequest deleteRequest = new DeleteRequestImpl("deleteRequest");
DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap<>(), Collections.singletonList(metacard));
historian.version(deleteResponse);
assertThat(deleteResponse.getProperties(), hasEntry(MetacardVersion.SKIP_VERSIONING, true));
}
Aggregations