Search in sources :

Example 16 with CswTransactionRequest

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

the class TestTransactionRequestConverter method testValidUpdateMarshal.

@Test
public void testValidUpdateMarshal() throws SAXException, IOException, XpathException {
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(METACARD_ID);
    UpdateAction updateAction = new UpdateAction(metacard, CswConstants.CSW_METACARD_TYPE_NAME, null);
    transactionRequest.getUpdateActions().add(updateAction);
    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_UPDATE_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) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 17 with CswTransactionRequest

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

the class TestTransactionRequestConverter method testUnmarshalUpdateWholeRecord.

@Test
public void testUnmarshalUpdateWholeRecord() throws Exception {
    String updateRequest = IOUtils.toString(TestTransactionRequestConverter.class.getResourceAsStream("/updateWholeRecordRequest.xml"));
    CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(updateRequest);
    assertThat(request.getDeleteActions(), emptyCollectionOf(DeleteAction.class));
    assertThat(request.getUpdateActions(), hasSize(1));
    assertThat(request.getInsertActions(), emptyCollectionOf(InsertAction.class));
    UpdateAction action = request.getUpdateActions().get(0);
    assertThat(action.getTypeName(), is(CswConstants.CSW_RECORD));
}
Also used : UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) 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) Test(org.junit.Test)

Example 18 with CswTransactionRequest

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

the class TestTransactionRequestConverter method testUnmarshalByProperty.

@Test
public void testUnmarshalByProperty() throws Exception {
    String updateRequest = IOUtils.toString(TestTransactionRequestConverter.class.getResourceAsStream("/updateByPropertyRequest.xml"));
    CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(updateRequest);
    assertThat(request.getDeleteActions(), emptyCollectionOf(DeleteAction.class));
    assertThat(request.getUpdateActions(), hasSize(1));
    assertThat(request.getInsertActions(), emptyCollectionOf(InsertAction.class));
    UpdateAction action = request.getUpdateActions().get(0);
    assertThat(action.getTypeName(), is(CswConstants.CSW_RECORD));
    assertThat(action.getConstraint(), notNullValue());
    assertThat(action.getRecordProperties().size(), is(5));
    assertThat(action.getRecordProperties().get("title"), is("Updated Title"));
    assertThat(action.getRecordProperties().get("created"), is(CswUnmarshallHelper.convertToDate("2015-08-25")));
    assertThat(action.getRecordProperties().get("datatype"), is(Arrays.asList("ABC", "DEF", "GHI")));
    assertThat(action.getRecordProperties().get("language"), is(""));
    assertThat(action.getRecordProperties().get("language"), is(""));
}
Also used : UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) 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) Test(org.junit.Test)

Example 19 with CswTransactionRequest

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

the class AbstractCswStore method update.

@Override
public UpdateResponse update(UpdateRequest updateRequest) throws IngestException {
    Map<String, Serializable> properties = new HashMap<>();
    validateOperation();
    Subject subject = (Subject) updateRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT);
    Csw csw = factory.getClientForSubject(subject);
    CswTransactionRequest transactionRequest = getTransactionRequest();
    OperationTransaction opTrans = (OperationTransaction) updateRequest.getPropertyValue(Constants.OPERATION_TRANSACTION_KEY);
    String insertTypeName = schemaTransformerManager.getTransformerIdForSchema(cswSourceConfiguration.getOutputSchema());
    HashSet<ProcessingDetails> errors = new HashSet<>();
    if (insertTypeName == null) {
        insertTypeName = CswConstants.CSW_RECORD;
    }
    ArrayList<Metacard> updatedMetacards = new ArrayList<>(updateRequest.getUpdates().size());
    ArrayList<Filter> updatedMetacardFilters = new ArrayList<>(updateRequest.getUpdates().size());
    for (Map.Entry<Serializable, Metacard> update : updateRequest.getUpdates()) {
        Metacard metacard = update.getValue();
        properties.put(metacard.getId(), metacard);
        updatedMetacardFilters.add(filterBuilder.attribute(updateRequest.getAttributeName()).is().equalTo().text(update.getKey().toString()));
        transactionRequest.getUpdateActions().add(new UpdateAction(metacard, insertTypeName, null));
    }
    try {
        TransactionResponseType response = csw.transaction(transactionRequest);
        if (response.getTransactionSummary().getTotalUpdated().longValue() != updateRequest.getUpdates().size()) {
            errors.add(new ProcessingDetailsImpl(this.getId(), null, "One or more updates failed"));
        }
    } catch (CswException e) {
        throw new IngestException("Csw Transaction Failed.", e);
    }
    try {
        updatedMetacards.addAll(transactionQuery(updatedMetacardFilters, subject));
    } catch (UnsupportedQueryException e) {
        errors.add(new ProcessingDetailsImpl(this.getId(), e, "Failed to retrieve updated metacards"));
    }
    return new UpdateResponseImpl(updateRequest, properties, updatedMetacards, new ArrayList(opTrans.getPreviousStateMetacards()), errors);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) OperationTransaction(ddf.catalog.operation.OperationTransaction) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) IngestException(ddf.catalog.source.IngestException) HashSet(java.util.HashSet) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Subject(ddf.security.Subject) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Map(java.util.Map) DefaultCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.common.converter.DefaultCswRecordMap) HashMap(java.util.HashMap)

Example 20 with CswTransactionRequest

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

the class TestTransactionMessageBodyReader method testReadUpdateByNewRecordFrom.

@Test
public void testReadUpdateByNewRecordFrom() throws IOException, ParseException {
    TransactionMessageBodyReader reader = new TransactionMessageBodyReader(cswRecordConverter, CswQueryFactoryTest.getCswMetacardType(), registry);
    CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(UPDATE_REQUEST_BY_RECORD_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(), notNullValue());
    Metacard metacard = updateAction.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(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) 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) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Aggregations

CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)27 Test (org.junit.Test)20 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction)14 DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction)13 InsertAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction)13 Metacard (ddf.catalog.data.Metacard)10 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)8 ArrayList (java.util.ArrayList)7 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)7 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)7 Serializable (java.io.Serializable)6 CswRecordConverter (org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter)6 Converter (com.thoughtworks.xstream.converters.Converter)5 DeleteType (net.opengis.cat.csw.v_2_0_2.DeleteType)5 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)5 HashMap (java.util.HashMap)4 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)3 IngestException (ddf.catalog.source.IngestException)3 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)3