Search in sources :

Example 1 with DeleteType

use of net.opengis.cat.csw.v_2_0_2.DeleteType in project ddf by codice.

the class TestTransactionRequestConverter method testMultipleOperations.

@Test
public void testMultipleOperations() throws Exception {
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(METACARD_ID);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(true);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    InsertAction insertAction = new InsertAction(CswConstants.CSW_METACARD_TYPE_NAME, null, Arrays.asList(metacard));
    transactionRequest.getInsertActions().add(insertAction);
    UpdateAction updateAction = new UpdateAction(metacard, CswConstants.CSW_METACARD_TYPE_NAME, null);
    transactionRequest.getUpdateActions().add(updateAction);
    DeleteType deleteType = new DeleteType();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("identifier = " + METACARD_ID);
    deleteType.setConstraint(queryConstraintType);
    DeleteAction deleteAction = new DeleteAction(deleteType, null);
    transactionRequest.getDeleteActions().add(deleteAction);
    String xml = xStream.toXML(transactionRequest);
    Diff diff = XMLUnit.compareXML(xml, EXPECTED_MULTI_OP_XML);
    assertThat(diff.similar(), is(true));
}
Also used : UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) Diff(org.custommonkey.xmlunit.Diff) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Test(org.junit.Test)

Example 2 with DeleteType

use of net.opengis.cat.csw.v_2_0_2.DeleteType in project ddf by codice.

the class TestCswEndpoint method testDeleteTransaction.

@Test
public void testDeleteTransaction() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    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();
    List<Result> results = new ArrayList<>();
    results.add(new ResultImpl(new MetacardImpl()));
    results.add(new ResultImpl(new MetacardImpl()));
    QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
    doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
    List<Metacard> deletedMetacards = new ArrayList<>();
    deletedMetacards.add(new MetacardImpl());
    deletedMetacards.add(new MetacardImpl());
    DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, deletedMetacards);
    doReturn(deleteResponse).when(catalogFramework).delete(any(DeleteRequest.class));
    DeleteAction deleteAction = new DeleteAction(deleteType, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
    CswTransactionRequest deleteRequest = new CswTransactionRequest();
    deleteRequest.getDeleteActions().add(deleteAction);
    deleteRequest.setVersion(CswConstants.VERSION_2_0_2);
    deleteRequest.setService(CswConstants.CSW);
    deleteRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(deleteRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(2));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(0));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 3 with DeleteType

use of net.opengis.cat.csw.v_2_0_2.DeleteType 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 4 with DeleteType

use of net.opengis.cat.csw.v_2_0_2.DeleteType in project ddf by codice.

the class TestTransactionRequestConverter method testValidDeleteMarshal.

@Test
public void testValidDeleteMarshal() throws SAXException, IOException, XpathException {
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(METACARD_ID);
    DeleteType deleteType = new DeleteType();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("identifier = " + METACARD_ID);
    deleteType.setConstraint(queryConstraintType);
    DeleteAction deleteAction = new DeleteAction(deleteType, null);
    transactionRequest.getDeleteActions().add(deleteAction);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(true);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    String xml = xStream.toXML(transactionRequest);
    Diff diff = XMLUnit.compareXML(xml, EXPECTED_DELETE_XML);
    assertThat(diff.similar(), is(true));
}
Also used : Diff(org.custommonkey.xmlunit.Diff) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Test(org.junit.Test)

Example 5 with DeleteType

use of net.opengis.cat.csw.v_2_0_2.DeleteType in project ddf by codice.

the class TransactionRequestConverterTest method testValidDeleteMarshal.

@Test
public void testValidDeleteMarshal() throws SAXException, IOException, XpathException {
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(METACARD_ID);
    DeleteType deleteType = new DeleteType();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("identifier = " + METACARD_ID);
    deleteType.setConstraint(queryConstraintType);
    DeleteAction deleteAction = new DeleteActionImpl(deleteType, null);
    transactionRequest.getDeleteActions().add(deleteAction);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(true);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    String xml = xStream.toXML(transactionRequest);
    Diff diff = XMLUnit.compareXML(xml, EXPECTED_DELETE_XML);
    assertThat(diff.similar(), is(true));
}
Also used : Diff(org.custommonkey.xmlunit.Diff) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) 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) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Test(org.junit.Test)

Aggregations

DeleteType (net.opengis.cat.csw.v_2_0_2.DeleteType)9 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 DeleteActionImpl (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl)5 Metacard (ddf.catalog.data.Metacard)4 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)4 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)4 DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction)4 Result (ddf.catalog.data.Result)3 ResultImpl (ddf.catalog.data.impl.ResultImpl)3 DeleteRequest (ddf.catalog.operation.DeleteRequest)3 DeleteResponse (ddf.catalog.operation.DeleteResponse)3 QueryRequest (ddf.catalog.operation.QueryRequest)3 QueryResponse (ddf.catalog.operation.QueryResponse)3 IngestException (ddf.catalog.source.IngestException)3 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)3 HashMap (java.util.HashMap)3