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));
}
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));
}
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(""));
}
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);
}
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));
}
Aggregations