Search in sources :

Example 26 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.

the class MetacardValidityMarkerPluginTest method testProcessDelete.

@Test
public void testProcessDelete() throws StopProcessingException, PluginExecutionException {
    DeleteRequestImpl deleteRequest = mock(DeleteRequestImpl.class);
    DeleteRequest returnedDeleteRequest = plugin.process(deleteRequest);
    assertThat(returnedDeleteRequest, is(theInstance(deleteRequest)));
}
Also used : DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 27 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl 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 28 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl 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 29 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderUnavailableDeleteByID.

/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for delete by id.
     *
     * @throws IngestException
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableDeleteByID() throws SourceUnavailableException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
    List<String> ids = new ArrayList<String>();
    ids.add("1234");
    DeleteRequest request = new DeleteRequestImpl((String[]) ids.toArray(new String[ids.size()]));
    // expected to throw exception due to catalog provider being unavailable
    try {
        framework.delete(request);
    } catch (IngestException e) {
        fail();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) CatalogFramework(ddf.catalog.CatalogFramework) ArrayList(java.util.ArrayList) IngestException(ddf.catalog.source.IngestException) Matchers.anyString(org.mockito.Matchers.anyString) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 30 with DeleteRequestImpl

use of ddf.catalog.operation.impl.DeleteRequestImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnDeleteByIdentifier.

@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnDeleteByIdentifier() throws IngestException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    // use exception provider instead of memory
    MockExceptionProvider provider = new MockExceptionProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    // List<MetacardType> identifiers = new ArrayList<MetacardType>();
    // identifiers.add( new MetacardTypeImpl( "id", "1234" ) );
    ArrayList<URI> uris = new ArrayList<URI>();
    DeleteRequest request = new DeleteRequestImpl((URI[]) uris.toArray(new URI[uris.size()]));
    // expected to throw exception due to catalog provider being unavailable
    try {
        framework.delete(request);
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) CatalogFramework(ddf.catalog.CatalogFramework) ArrayList(java.util.ArrayList) URI(java.net.URI) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Aggregations

DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)33 DeleteRequest (ddf.catalog.operation.DeleteRequest)21 Test (org.junit.Test)18 DeleteResponse (ddf.catalog.operation.DeleteResponse)17 ArrayList (java.util.ArrayList)17 Metacard (ddf.catalog.data.Metacard)15 HashMap (java.util.HashMap)11 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)9 CatalogFramework (ddf.catalog.CatalogFramework)8 Serializable (java.io.Serializable)8 List (java.util.List)8 Result (ddf.catalog.data.Result)7 QueryResponse (ddf.catalog.operation.QueryResponse)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 IngestException (ddf.catalog.source.IngestException)7 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)6 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 Filter (org.opengis.filter.Filter)6 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5