Search in sources :

Example 41 with DeleteResponse

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);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteRequest(ddf.catalog.operation.DeleteRequest)

Example 42 with DeleteResponse

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);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) CreateRequest(ddf.catalog.operation.CreateRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) LoggerFactory(org.slf4j.LoggerFactory) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Map(java.util.Map) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Bundle(org.osgi.framework.Bundle) InputTransformer(ddf.catalog.transform.InputTransformer) PrintWriter(java.io.PrintWriter) SortByImpl(org.geotools.filter.SortByImpl) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) Set(java.util.Set) ParserException(org.codice.ddf.parser.ParserException) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Objects(java.util.Objects) DeleteRequest(ddf.catalog.operation.DeleteRequest) IOUtils(org.apache.commons.io.IOUtils) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) SlotTypeHelper(org.codice.ddf.registry.schemabindings.helper.SlotTypeHelper) Optional(java.util.Optional) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UpdateResponse(ddf.catalog.operation.UpdateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterBuilder(ddf.catalog.filter.FilterBuilder) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashMap(java.util.HashMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) SecurityServiceException(ddf.security.service.SecurityServiceException) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) SortBy(org.opengis.filter.sort.SortBy) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) InternationalStringTypeHelper(org.codice.ddf.registry.schemabindings.helper.InternationalStringTypeHelper) Result(ddf.catalog.data.Result) SortOrder(org.opengis.filter.sort.SortOrder) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) Security(org.codice.ddf.security.common.Security) StringWriter(java.io.StringWriter) IOException(java.io.IOException) AbstractMap(java.util.AbstractMap) PropertyName(org.opengis.filter.expression.PropertyName) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) DeleteRequest(ddf.catalog.operation.DeleteRequest)

Example 43 with DeleteResponse

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

Example 44 with DeleteResponse

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));
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) CreateResponse(ddf.catalog.operation.CreateResponse) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 45 with DeleteResponse

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);
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) 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