Search in sources :

Example 26 with DeleteResponse

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();
}
Also used : CatalogStore(ddf.catalog.source.CatalogStore) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 27 with DeleteResponse

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;
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) DeletedMetacardImpl(ddf.catalog.core.versioning.impl.DeletedMetacardImpl) Map(java.util.Map) Action(ddf.catalog.core.versioning.MetacardVersion.Action) SubjectUtils(ddf.security.SubjectUtils) Bundle(org.osgi.framework.Bundle) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) MetacardVersionImpl(ddf.catalog.core.versioning.impl.MetacardVersionImpl) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) MetacardType(ddf.catalog.data.MetacardType) Objects(java.util.Objects) StorageException(ddf.catalog.content.StorageException) List(java.util.List) Operation(ddf.catalog.operation.Operation) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Optional(java.util.Optional) UpdateResponse(ddf.catalog.operation.UpdateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) FilterBuilder(ddf.catalog.filter.FilterBuilder) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) DeleteResponse(ddf.catalog.operation.DeleteResponse) Function(java.util.function.Function) Update(ddf.catalog.operation.Update) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) SKIP_VERSIONING(ddf.catalog.core.versioning.MetacardVersion.SKIP_VERSIONING) ContentItem(ddf.catalog.content.data.ContentItem) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) SecurityConstants(ddf.security.SecurityConstants) StorageProvider(ddf.catalog.content.StorageProvider) ByteSource(com.google.common.io.ByteSource) Result(ddf.catalog.data.Result) Hashtable(java.util.Hashtable) Nullable(javax.annotation.Nullable) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) Security(org.codice.ddf.security.common.Security) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) Subject(ddf.security.Subject) TimeUnit(java.util.concurrent.TimeUnit) StorageRequest(ddf.catalog.content.operation.StorageRequest) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) SourceResponse(ddf.catalog.operation.SourceResponse) CatalogProvider(ddf.catalog.source.CatalogProvider) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) InputStream(java.io.InputStream) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) Action(ddf.catalog.core.versioning.MetacardVersion.Action) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Metacard(ddf.catalog.data.Metacard) DeletedMetacardImpl(ddf.catalog.core.versioning.impl.DeletedMetacardImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) List(java.util.List) ArrayList(java.util.ArrayList)

Example 28 with 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;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ArrayList(java.util.ArrayList) Result(ddf.catalog.data.Result)

Example 29 with DeleteResponse

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));
}
Also used : DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 30 with DeleteResponse

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));
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Aggregations

DeleteResponse (ddf.catalog.operation.DeleteResponse)54 Test (org.junit.Test)37 Metacard (ddf.catalog.data.Metacard)23 DeleteRequest (ddf.catalog.operation.DeleteRequest)23 ArrayList (java.util.ArrayList)19 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)18 HashMap (java.util.HashMap)17 Serializable (java.io.Serializable)15 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)14 CreateResponse (ddf.catalog.operation.CreateResponse)13 List (java.util.List)11 QueryResponse (ddf.catalog.operation.QueryResponse)9 QueryRequest (ddf.catalog.operation.QueryRequest)8 IngestException (ddf.catalog.source.IngestException)8 Result (ddf.catalog.data.Result)7 UpdateResponse (ddf.catalog.operation.UpdateResponse)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 CatalogFramework (ddf.catalog.CatalogFramework)6 Update (ddf.catalog.operation.Update)6