use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType 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));
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.
the class CswEndpoint method updateRecords.
private int updateRecords(UpdateAction updateAction) throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
if (updateAction.getMetacard() != null) {
Metacard newRecord = updateAction.getMetacard();
if (newRecord.getId() != null) {
UpdateRequest updateRequest = new UpdateRequestImpl(newRecord.getId(), newRecord);
LOGGER.debug("Attempting to update {} ", newRecord.getId());
UpdateResponse updateResponse = framework.update(updateRequest);
return updateResponse.getUpdatedMetacards().size();
} else {
throw new CswException("Unable to update record. No ID was specified in the request.", CswConstants.MISSING_PARAMETER_VALUE, updateAction.getHandle());
}
} else if (updateAction.getConstraint() != null) {
QueryConstraintType constraint = updateAction.getConstraint();
QueryRequest queryRequest = queryFactory.getQuery(constraint);
queryRequest = queryFactory.updateQueryRequestTags(queryRequest, schemaTransformerManager.getTransformerSchemaForId(updateAction.getTypeName()));
QueryResponse response = framework.query(queryRequest);
if (response.getHits() > 0) {
Map<String, Serializable> recordProperties = updateAction.getRecordProperties();
List<String> updatedMetacardIdsList = new ArrayList<>();
List<Metacard> updatedMetacards = new ArrayList<>();
for (Result result : response.getResults()) {
Metacard metacard = result.getMetacard();
if (metacard != null) {
for (Entry<String, Serializable> recordProperty : recordProperties.entrySet()) {
Attribute attribute = new AttributeImpl(recordProperty.getKey(), recordProperty.getValue());
metacard.setAttribute(attribute);
}
updatedMetacardIdsList.add(metacard.getId());
updatedMetacards.add(metacard);
}
}
if (updatedMetacardIdsList.size() > 0) {
String[] updatedMetacardIds = updatedMetacardIdsList.toArray(new String[updatedMetacardIdsList.size()]);
UpdateRequest updateRequest = new UpdateRequestImpl(updatedMetacardIds, updatedMetacards);
LOGGER.debug("Attempting to update {} metacards.", updatedMetacardIdsList.size());
UpdateResponse updateResponse = framework.update(updateRequest);
return updateResponse.getUpdatedMetacards().size();
}
}
}
return 0;
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.
the class AbstractCswSource method createQueryConstraint.
private QueryConstraintType createQueryConstraint(Query query) throws UnsupportedQueryException {
FilterType filter = createFilter(query);
if (null == filter) {
return null;
}
QueryConstraintType queryConstraintType = new QueryConstraintType();
queryConstraintType.setVersion(CswConstants.CONSTRAINT_VERSION);
if (isConstraintCql || cswSourceConfiguration.isCqlForced()) {
queryConstraintType.setCqlText(CswCqlTextFilter.getInstance().getCqlText(filter));
} else {
queryConstraintType.setFilter(filter);
}
return queryConstraintType;
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType 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));
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType 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));
}
Aggregations