Search in sources :

Example 1 with DeleteAction

use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.

the class CswEndpointTest method testDeleteBatching.

@Test
public void testDeleteBatching() throws Exception {
    // configure query responses
    queryResponseBatch = getQueryResponseBatch(500, 800);
    QueryResponse[] qrRest = queryResponseBatch.subList(1, queryResponseBatch.size()).toArray(new QueryResponse[0]);
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponseBatch.get(0), qrRest);
    // configure delete responses
    DeleteType deleteType = mock(DeleteType.class);
    doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
    doReturn("").when(deleteType).getHandle();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("title = \"foo\"");
    doReturn(queryConstraintType).when(deleteType).getConstraint();
    when(deleteResponse.getDeletedMetacards()).thenReturn(populateMetacardList(1));
    when(catalogFramework.delete(any(DeleteRequest.class))).thenAnswer((Answer<DeleteResponse>) invocation -> deleteResponse);
    DeleteAction deleteAction = new DeleteActionImpl(deleteType, DefaultCswRecordMap.getPrefixToUriMapping());
    CswTransactionRequest deleteRequest = new CswTransactionRequest();
    deleteRequest.getDeleteActions().add(deleteAction);
    TransactionResponseType response = csw.transaction(deleteRequest);
    assertThat(response.getTransactionSummary().getTotalDeleted().intValue(), equalTo(800));
    verify(catalogFramework, times(4)).query(any());
    verify(catalogFramework, times(800)).delete(any());
}
Also used : UpdateActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateActionImpl) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CreateRequest(ddf.catalog.operation.CreateRequest) Matchers.hasItems(org.hamcrest.Matchers.hasItems) MediaType(javax.ws.rs.core.MediaType) ServiceIdentification(net.opengis.ows.v_1_0_0.ServiceIdentification) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ComparisonOperatorType(net.opengis.filter.v_1_1_0.ComparisonOperatorType) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) Mockito.doReturn(org.mockito.Mockito.doReturn) ServiceReference(org.osgi.framework.ServiceReference) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) ParseException(org.locationtech.jts.io.ParseException) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) Matchers.is(org.hamcrest.Matchers.is) CswConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.CswConstants) UpdateResponse(ddf.catalog.operation.UpdateResponse) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) CswRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRequest) Mockito.mock(org.mockito.Mockito.mock) ResourceResponse(ddf.catalog.operation.ResourceResponse) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) Iterables(com.google.common.collect.Iterables) DescribeRecordRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.DescribeRecordRequest) DefaultCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.common.converter.DefaultCswRecordMap) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Answer(org.mockito.stubbing.Answer) Subject(org.apache.shiro.subject.Subject) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CswActionTransformerProvider(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswActionTransformerProvider) Result(ddf.catalog.data.Result) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) IngestException(ddf.catalog.source.IngestException) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) ServiceProvider(net.opengis.ows.v_1_0_0.ServiceProvider) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) FederationException(ddf.catalog.federation.FederationException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Query(ddf.catalog.operation.Query) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Matchers.hasItem(org.hamcrest.Matchers.hasItem) GetRecordsRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest) ArrayDeque(java.util.ArrayDeque) Mockito.reset(org.mockito.Mockito.reset) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryFilterTransformer(ddf.catalog.transform.QueryFilterTransformer) URL(java.net.URL) DescribeRecordResponseType(net.opengis.cat.csw.v_2_0_2.DescribeRecordResponseType) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) SectionsType(net.opengis.ows.v_1_0_0.SectionsType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) InsertActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertActionImpl) Assert.fail(org.junit.Assert.fail) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) URI(java.net.URI) DeleteActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl) Bundle(org.osgi.framework.Bundle) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Collection(java.util.Collection) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ResultImpl(ddf.catalog.data.impl.ResultImpl) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) BundleContext(org.osgi.framework.BundleContext) DeleteRequest(ddf.catalog.operation.DeleteRequest) Objects(java.util.Objects) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Operation(net.opengis.ows.v_1_0_0.Operation) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Queue(java.util.Queue) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) DescribeRecordType(net.opengis.cat.csw.v_2_0_2.DescribeRecordType) ResultType(net.opengis.cat.csw.v_2_0_2.ResultType) Update(ddf.catalog.operation.Update) SchemaComponentType(net.opengis.cat.csw.v_2_0_2.SchemaComponentType) HashSet(java.util.HashSet) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) SortBy(org.opengis.filter.sort.SortBy) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) OperationsMetadata(net.opengis.ows.v_1_0_0.OperationsMetadata) Metacard(ddf.catalog.data.Metacard) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) MimeType(javax.activation.MimeType) UpdateRequest(ddf.catalog.operation.UpdateRequest) GmdConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.GmdConstants) LinkedList(java.util.LinkedList) DomainType(net.opengis.ows.v_1_0_0.DomainType) JAXBContext(javax.xml.bind.JAXBContext) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Matchers.empty(org.hamcrest.Matchers.empty) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) Logger(org.slf4j.Logger) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) Collectors.toList(java.util.stream.Collectors.toList) SourceResponse(ddf.catalog.operation.SourceResponse) ThreadContext(org.apache.shiro.util.ThreadContext) AcceptVersionsType(net.opengis.ows.v_1_0_0.AcceptVersionsType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Collections(java.util.Collections) DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) DeleteActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 2 with DeleteAction

use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.

the class CswEndpoint method deleteRecords.

private int deleteRecords(DeleteAction deleteAction) throws CswException, UnsupportedQueryException {
    final DeleteAction transformDeleteAction = transformDeleteAction(deleteAction);
    QueryRequest queryRequest = queryFactory.getQuery(transformDeleteAction.getConstraint(), transformDeleteAction.getTypeName());
    queryRequest = queryFactory.updateQueryRequestTags(queryRequest, schemaTransformerManager.getTransformerSchemaForId(transformDeleteAction.getTypeName()));
    int batchCount = 1;
    int deletedCount = 0;
    String[] idsToDelete = getNextQueryBatch(queryRequest);
    CompletionService<DeleteResponse> deleteCompletionService = new ExecutorCompletionService<>(queryExecutor);
    while (idsToDelete.length > 0) {
        LOGGER.debug("Attempting to delete {} metacards from batch {}.", idsToDelete.length, ++batchCount);
        final Subject subject = SecurityUtils.getSubject();
        for (final String id : idsToDelete) {
            Callable<DeleteResponse> callable = () -> {
                try {
                    DeleteRequestImpl deleteRequest = new DeleteRequestImpl(id);
                    return framework.delete(deleteRequest);
                } catch (IngestException | SourceUnavailableException | CatalogQueryException e) {
                    LOGGER.debug("Unable to delete record: {}", id, e);
                    throw new CswException(UNABLE_TO_DELETE_MSG, CswConstants.TRANSACTION_FAILED, transformDeleteAction.getHandle());
                }
            };
            Callable<DeleteResponse> deleteCallable = subject.associateWith(callable);
            deleteCompletionService.submit(deleteCallable);
        }
        for (int i = 0; i < idsToDelete.length; i++) {
            try {
                Future<DeleteResponse> completedFuture = deleteCompletionService.take();
                try {
                    deletedCount += completedFuture.get().getDeletedMetacards().size();
                } catch (ExecutionException | CancellationException e) {
                    LOGGER.debug("Error deleting Metacard", e);
                    throw new CswException(UNABLE_TO_DELETE_MSG, CswConstants.TRANSACTION_FAILED, deleteAction.getHandle());
                }
            } catch (InterruptedException e) {
                LOGGER.debug("Metacard delete interrupted", e);
                Thread.currentThread().interrupt();
                break;
            }
        }
        idsToDelete = getNextQueryBatch(queryRequest);
    }
    return deletedCount;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Subject(org.apache.shiro.subject.Subject) DeleteResponse(ddf.catalog.operation.DeleteResponse) CancellationException(java.util.concurrent.CancellationException) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with DeleteAction

use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.

the class CswEndpoint method transaction.

@Override
@POST
@Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
public TransactionResponseType transaction(CswTransactionRequest request) throws CswException {
    if (request == null) {
        throw new CswException("TransactionRequest request is null");
    }
    TransactionResponseType response = new TransactionResponseType();
    TransactionSummaryType summary = new TransactionSummaryType();
    summary.setTotalInserted(BigInteger.valueOf(0));
    summary.setTotalUpdated(BigInteger.valueOf(0));
    summary.setTotalDeleted(BigInteger.valueOf(0));
    response.setTransactionSummary(summary);
    response.setVersion(CswConstants.VERSION_2_0_2);
    int numInserted = 0;
    final Subject subject = SecurityUtils.getSubject();
    for (InsertAction insertAction : request.getInsertActions()) {
        final InsertAction transformInsertAction = transformInsertAction(insertAction);
        List<Metacard> metacards = transformInsertAction.getRecords();
        CompletionService<CreateResponse> completionService = new ExecutorCompletionService<>(queryExecutor);
        for (Metacard record : metacards) {
            CreateRequest createRequest = new CreateRequestImpl(record);
            Callable<CreateResponse> callable = () -> {
                try {
                    return framework.create(createRequest);
                } catch (IngestException | SourceUnavailableException e) {
                    LOGGER.debug("Unable to insert record(s)", e);
                    throw new CswException("Unable to insert record(s).", CswConstants.TRANSACTION_FAILED, transformInsertAction.getHandle());
                }
            };
            Callable<CreateResponse> createCallable = subject.associateWith(callable);
            completionService.submit(createCallable);
        }
        for (int i = 0; i < metacards.size(); i++) {
            try {
                Future<CreateResponse> completedFuture = completionService.take();
                try {
                    CreateResponse futureResponse = completedFuture.get();
                    numInserted += futureResponse.getCreatedMetacards().size();
                    if (request.isVerbose()) {
                        response.getInsertResult().add(getInsertResultFromResponse(futureResponse));
                    }
                } catch (ExecutionException | CancellationException e) {
                    LOGGER.debug("Error ingesting Metacard", e);
                    throw new CswException("Unable to insert record(s).", CswConstants.TRANSACTION_FAILED, insertAction.getHandle());
                }
            } catch (InterruptedException e) {
                LOGGER.debug("Metacard ingest interrupted", e);
                Thread.currentThread().interrupt();
                break;
            }
        }
    }
    LOGGER.debug("{} records inserted.", numInserted);
    response.getTransactionSummary().setTotalInserted(BigInteger.valueOf(numInserted));
    int numUpdated = 0;
    List<UpdateAction> updateActions = request.getUpdateActions();
    CompletionService<Integer> updateCompletionService = new ExecutorCompletionService<>(queryExecutor);
    for (final UpdateAction updateAction : updateActions) {
        Callable<Integer> callable = () -> {
            try {
                return updateRecords(subject, updateAction);
            } catch (CswException | FederationException | IngestException | SourceUnavailableException | UnsupportedQueryException | CatalogQueryException e) {
                LOGGER.debug(UNABLE_TO_UPDATE_MSG, e);
                throw new CswException(UNABLE_TO_UPDATE_MSG, CswConstants.TRANSACTION_FAILED, updateAction.getHandle());
            }
        };
        Callable<Integer> updateCallable = subject.associateWith(callable);
        updateCompletionService.submit(updateCallable);
    }
    for (int i = 0; i < updateActions.size(); i++) {
        try {
            Future<Integer> completedFuture = updateCompletionService.take();
            try {
                numUpdated += completedFuture.get();
            } catch (ExecutionException | CancellationException e) {
                LOGGER.debug("Error updating Metacard", e);
                throw new CswException(UNABLE_TO_UPDATE_MSG, CswConstants.TRANSACTION_FAILED, "Update");
            }
        } catch (InterruptedException e) {
            LOGGER.debug("Metacard update interrupted", e);
            Thread.currentThread().interrupt();
            break;
        }
    }
    LOGGER.debug("{} records updated.", numUpdated);
    response.getTransactionSummary().setTotalUpdated(BigInteger.valueOf(numUpdated));
    int numDeleted = 0;
    for (DeleteAction deleteAction : request.getDeleteActions()) {
        try {
            numDeleted += deleteRecords(deleteAction);
        } catch (Exception e) {
            LOGGER.debug(UNABLE_TO_DELETE_MSG, e);
            throw new CswException(UNABLE_TO_DELETE_MSG, CswConstants.TRANSACTION_FAILED, deleteAction.getHandle());
        }
    }
    LOGGER.debug("{} records deleted.", numDeleted);
    response.getTransactionSummary().setTotalDeleted(BigInteger.valueOf(numDeleted));
    return response;
}
Also used : CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) ExecutionException(java.util.concurrent.ExecutionException) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) Subject(org.apache.shiro.subject.Subject) CancellationException(java.util.concurrent.CancellationException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) MimeTypeParseException(javax.activation.MimeTypeParseException) ParseException(org.locationtech.jts.io.ParseException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CatalogQueryException(ddf.catalog.util.impl.CatalogQueryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BigInteger(java.math.BigInteger) Metacard(ddf.catalog.data.Metacard) CancellationException(java.util.concurrent.CancellationException) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with DeleteAction

use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.

the class TransactionRequestConverter method marshal.

@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) {
    if (o == null || !CswTransactionRequest.class.isAssignableFrom(o.getClass())) {
        return;
    }
    CswTransactionRequest request = (CswTransactionRequest) o;
    writer.addAttribute(CswConstants.SERVICE, request.getService());
    writer.addAttribute(CswConstants.VERSION, request.getVersion());
    writer.addAttribute(CswConstants.VERBOSE_RESPONSE, String.valueOf(request.isVerbose()));
    writer.addAttribute(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.CSW_NAMESPACE_PREFIX, CswConstants.CSW_OUTPUT_SCHEMA);
    writer.addAttribute(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.OGC_NAMESPACE_PREFIX, CswConstants.OGC_SCHEMA);
    for (InsertAction insertAction : request.getInsertActions()) {
        writer.startNode(CswConstants.CSW_TRANSACTION_INSERT_NODE);
        writer.addAttribute(CswConstants.TYPE_NAME_PARAMETER, insertAction.getTypeName());
        marshallingContext.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.ID);
        marshallingContext.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, insertAction.getTypeName());
        for (Metacard metacard : insertAction.getRecords()) {
            marshallingContext.convertAnother(metacard, delegatingTransformer);
        }
        writer.endNode();
    }
    for (UpdateAction updateAction : request.getUpdateActions()) {
        writer.startNode(CswConstants.CSW_TRANSACTION_UPDATE_NODE);
        writer.addAttribute(CswConstants.TYPE_NAME_PARAMETER, updateAction.getTypeName());
        marshallingContext.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.ID);
        marshallingContext.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, updateAction.getTypeName());
        marshallingContext.convertAnother(updateAction.getMetacard(), delegatingTransformer);
        writer.endNode();
    }
    for (DeleteAction deleteAction : request.getDeleteActions()) {
        writer.startNode(CswConstants.CSW_TRANSACTION_DELETE_NODE);
        writer.addAttribute(CswConstants.TYPE_NAME_PARAMETER, deleteAction.getTypeName());
        writer.startNode(CswConstants.CSW_CONSTRAINT);
        writer.addAttribute(CswConstants.VERSION, CswConstants.CONSTRAINT_VERSION);
        writer.startNode(CswConstants.CSW_CQL_TEXT);
        writer.setValue(deleteAction.getConstraint().getCqlText());
        writer.endNode();
        writer.endNode();
        writer.endNode();
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction)

Example 5 with DeleteAction

use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.

the class TransactionMessageBodyReaderTest method testReadInsertAndDeleteFrom.

@Test
public void testReadInsertAndDeleteFrom() throws IOException {
    Converter mockConverter = mock(Converter.class);
    when(mockConverter.canConvert(any(Class.class))).thenReturn(true);
    when(mockConverter.unmarshal(any(HierarchicalStreamReader.class), any(UnmarshallingContext.class))).thenReturn(mock(Metacard.class));
    TransactionMessageBodyReader reader = new TransactionMessageBodyReader(mockConverter, CswQueryFactoryTest.getCswMetacardType(), registry);
    CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(INSERT_AND_DELETE_REQUEST_XML, StandardCharsets.UTF_8));
    assertThat(request, notNullValue());
    assertThat(request.getDeleteActions().size(), is(1));
    assertThat(request.getInsertActions().size(), is(1));
    assertThat(request.getUpdateActions().size(), is(0));
    DeleteAction deleteAction = request.getDeleteActions().get(0);
    assertThat(deleteAction, notNullValue());
    assertThat(deleteAction.getTypeName(), is(CswConstants.CSW_RECORD));
    assertThat(deleteAction.getHandle(), is("something"));
    assertThat(deleteAction.getConstraint(), notNullValue());
    assertThat(deleteAction.getConstraint().getCqlText().trim(), is("title = 'foo'"));
    InsertAction insertAction = request.getInsertActions().get(0);
    assertThat(insertAction, notNullValue());
    assertThat(insertAction.getRecords().size(), is(1));
    assertThat(request.getService(), is(CswConstants.CSW));
    assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
    assertThat(request.isVerbose(), is(true));
}
Also used : Metacard(ddf.catalog.data.Metacard) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) Converter(com.thoughtworks.xstream.converters.Converter) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) UnmarshallingContext(com.thoughtworks.xstream.converters.UnmarshallingContext) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Aggregations

DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction)12 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)10 Test (org.junit.Test)8 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction)6 Metacard (ddf.catalog.data.Metacard)5 InsertAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction)5 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 IngestException (ddf.catalog.source.IngestException)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4 DeleteType (net.opengis.cat.csw.v_2_0_2.DeleteType)4 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)4 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)4 DeleteActionImpl (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl)4 Converter (com.thoughtworks.xstream.converters.Converter)3 FederationException (ddf.catalog.federation.FederationException)3 CreateRequest (ddf.catalog.operation.CreateRequest)3 DeleteResponse (ddf.catalog.operation.DeleteResponse)3 QueryRequest (ddf.catalog.operation.QueryRequest)3 Subject (org.apache.shiro.subject.Subject)3