Search in sources :

Example 1 with UpdateAction

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction 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 UpdateAction

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction in project ddf by codice.

the class TestTransactionMessageBodyReader method testReadMultipleUpdatesFrom.

@Test
public void testReadMultipleUpdatesFrom() throws IOException, ParseException {
    TransactionMessageBodyReader reader = new TransactionMessageBodyReader(cswRecordConverter, CswQueryFactoryTest.getCswMetacardType(), registry);
    CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(MULTIPLE_UPDATES_REQUEST_XML));
    assertThat(request, notNullValue());
    assertThat(request.getInsertActions().size(), is(0));
    assertThat(request.getDeleteActions().size(), is(0));
    assertThat(request.getUpdateActions().size(), is(2));
    UpdateAction firstUpdateAction = request.getUpdateActions().get(0);
    assertThat(firstUpdateAction, notNullValue());
    assertThat(firstUpdateAction.getMetacard(), notNullValue());
    Metacard metacard = firstUpdateAction.getMetacard();
    assertThat(metacard.getId(), is("123"));
    assertThat(metacard.getTitle(), is("Aliquam fermentum purus quis arcu"));
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = simpleDateFormat.parse("2008-08-10");
    assertThat(metacard.getModifiedDate(), is(date));
    assertThat(metacard.getLocation(), is("POLYGON ((1.0 2.0, 3.0 2.0, 3.0 4.0, 1.0 4.0, 1.0 2.0))"));
    assertThat(firstUpdateAction.getHandle(), is("handle1"));
    assertThat(firstUpdateAction.getTypeName(), is(CswConstants.CSW_RECORD));
    UpdateAction secondUpdateAction = request.getUpdateActions().get(1);
    assertThat(secondUpdateAction, notNullValue());
    assertThat(secondUpdateAction.getMetacard(), nullValue());
    Map<String, Serializable> recordProperties = secondUpdateAction.getRecordProperties();
    assertThat(recordProperties, notNullValue());
    assertThat(recordProperties.size(), is(1));
    Serializable newSubject = recordProperties.get("topic.category");
    assertThat(newSubject, is("foo"));
    QueryConstraintType constraint = secondUpdateAction.getConstraint();
    assertThat(constraint, notNullValue());
    assertThat(constraint.getCqlText().trim(), is("title = 'bar'"));
    assertThat(secondUpdateAction.getHandle(), is("handle2"));
    assertThat(secondUpdateAction.getTypeName(), is(CswConstants.CSW_RECORD));
    assertThat(request.getService(), is(CswConstants.CSW));
    assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
    assertThat(request.isVerbose(), is(false));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 3 with UpdateAction

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction in project ddf by codice.

the class TestTransactionMessageBodyReader method testReadUpdateByConstraintFrom.

@Test
public void testReadUpdateByConstraintFrom() throws IOException, ParseException {
    TransactionMessageBodyReader reader = new TransactionMessageBodyReader(mock(Converter.class), CswQueryFactoryTest.getCswMetacardType(), registry);
    CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(UPDATE_REQUEST_BY_CONSTRAINT_XML));
    assertThat(request, notNullValue());
    assertThat(request.getInsertActions().size(), is(0));
    assertThat(request.getDeleteActions().size(), is(0));
    assertThat(request.getUpdateActions().size(), is(1));
    UpdateAction updateAction = request.getUpdateActions().get(0);
    assertThat(updateAction, notNullValue());
    assertThat(updateAction.getMetacard(), nullValue());
    Map<String, Serializable> recordProperties = updateAction.getRecordProperties();
    assertThat(recordProperties, notNullValue());
    assertThat(recordProperties.size(), is(4));
    Serializable newSubjectValue = recordProperties.get(Topic.CATEGORY);
    assertThat(newSubjectValue, notNullValue());
    assertThat(newSubjectValue, is("Foo"));
    Serializable newDateValue = recordProperties.get("modified");
    assertThat(newDateValue, notNullValue());
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = simpleDateFormat.parse("2015-07-21");
    assertThat(newDateValue, is(date));
    Serializable newLocationValue = recordProperties.get("location");
    assertThat(newLocationValue, notNullValue());
    assertThat(newLocationValue, is("POLYGON ((1.0 2.0, 3.0 2.0, 3.0 4.0, 1.0 4.0, 1.0 2.0))"));
    Serializable newFormatValue = recordProperties.get("media.format");
    // No <Value> was specified in the request.
    assertThat(newFormatValue, nullValue());
    QueryConstraintType constraint = updateAction.getConstraint();
    assertThat(constraint, notNullValue());
    FilterType filter = constraint.getFilter();
    assertThat(filter, notNullValue());
    assertThat(filter.isSetComparisonOps(), is(true));
    assertThat(filter.isSetLogicOps(), is(false));
    assertThat(filter.isSetSpatialOps(), is(false));
    assertThat(request.getService(), is(CswConstants.CSW));
    assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
    assertThat(request.isVerbose(), is(false));
}
Also used : Serializable(java.io.Serializable) FilterType(net.opengis.filter.v_1_1_0.FilterType) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Converter(com.thoughtworks.xstream.converters.Converter) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 4 with UpdateAction

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction in project ddf by codice.

the class TestCswEndpoint method testUpdateTransactionWithNewRecord.

@Test
public void testUpdateTransactionWithNewRecord() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    List<Update> updatedMetacards = new ArrayList<>();
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
    doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
    MetacardImpl updatedMetacard = new MetacardImpl();
    updatedMetacard.setId("123");
    UpdateAction updateAction = new UpdateAction(updatedMetacard, CswConstants.CSW_RECORD, "");
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    transactionRequest.getUpdateActions().add(updateAction);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(transactionRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(0));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(1));
    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);
    ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
    UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
    assertThat(actualUpdateRequest.getUpdates().size(), is(1));
    assertThat(actualUpdateRequest.getUpdates().get(0).getValue().getId(), is("123"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Test(org.junit.Test)

Example 5 with UpdateAction

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction in project ddf by codice.

the class TestCswEndpoint method testUpdateTransactionWithConstraint.

@Test
public void testUpdateTransactionWithConstraint() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    List<Result> results = new ArrayList<>();
    MetacardImpl firstResult = new MetacardImpl();
    firstResult.setId("123");
    firstResult.setTitle("Title one");
    firstResult.setAttribute("subject", "Subject one");
    results.add(new ResultImpl(firstResult));
    MetacardImpl secondResult = new MetacardImpl();
    secondResult.setId("789");
    secondResult.setTitle("Title two");
    secondResult.setAttribute("subject", "Subject two");
    results.add(new ResultImpl(secondResult));
    QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
    doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
    List<Update> updatedMetacards = new ArrayList<>();
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
    doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
    Map<String, Serializable> recordProperties = new HashMap<>();
    recordProperties.put("title", "foo");
    recordProperties.put("subject", "bar");
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText("title = 'fake'");
    UpdateAction updateAction = new UpdateAction(recordProperties, CswConstants.CSW_RECORD, "", constraint, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
    CswTransactionRequest updateRequest = new CswTransactionRequest();
    updateRequest.getUpdateActions().add(updateAction);
    updateRequest.setVersion(CswConstants.VERSION_2_0_2);
    updateRequest.setService(CswConstants.CSW);
    updateRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(updateRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(0));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(2));
    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);
    ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
    UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
    List<Map.Entry<Serializable, Metacard>> updates = actualUpdateRequest.getUpdates();
    assertThat(updates.size(), is(2));
    Metacard firstUpdate = updates.get(0).getValue();
    assertThat(firstUpdate.getId(), is("123"));
    assertThat(firstUpdate.getTitle(), is("foo"));
    assertThat(firstUpdate.getAttribute("subject").getValue(), is("bar"));
    Metacard secondUpdate = updates.get(1).getValue();
    assertThat(secondUpdate.getId(), is("789"));
    assertThat(secondUpdate.getTitle(), is("foo"));
    assertThat(secondUpdate.getAttribute("subject").getValue(), is("bar"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Aggregations

CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)9 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction)9 Test (org.junit.Test)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)4 Metacard (ddf.catalog.data.Metacard)3 Serializable (java.io.Serializable)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction)3 InsertAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction)3 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)3 Update (ddf.catalog.operation.Update)2 UpdateRequest (ddf.catalog.operation.UpdateRequest)2 UpdateResponse (ddf.catalog.operation.UpdateResponse)2 UpdateImpl (ddf.catalog.operation.impl.UpdateImpl)2 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)2 ArrayList (java.util.ArrayList)2 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)2 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)2