use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.
the class CswEndpointTest 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());
QueryResponse emptyResponse = new QueryResponseImpl(null, Collections.emptyList(), 0);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse).thenReturn(emptyResponse);
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 UpdateActionImpl(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"));
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.
the class CswQueryFactoryTest method testMultipleQueryFilterTransformers.
@Test
public void testMultipleQueryFilterTransformers() throws CswException {
List<String> namespaces = Arrays.asList("{namespace}one", "{namespace}two");
QueryConstraintType constraint = mock(QueryConstraintType.class);
when(constraint.isSetCqlText()).thenReturn(true);
when(constraint.getCqlText()).thenReturn(CQL_CONTEXTUAL_LIKE_QUERY);
for (String namespace : namespaces) {
QueryRequest request = mock(QueryRequest.class);
addQueryFilterTransformer(namespace, request);
QueryRequest result = queryFactory.getQuery(constraint, namespace);
assertThat(result, equalTo(request));
}
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.
the class CswQueryFactoryTest method testPostGetRecordsFunctionCQLQuery.
@Test
public void testPostGetRecordsFunctionCQLQuery() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
GetRecordsType grr = createDefaultPostRecordsRequest();
QueryType query = new QueryType();
List<QName> typeNames = new ArrayList<>();
typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
query.setTypeNames(typeNames);
QueryConstraintType constraint = new QueryConstraintType();
constraint.setCqlText(CQL_CONTEXTUAL_FUNCTION_QUERY);
query.setConstraint(constraint);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
QueryRequest queryRequest = queryFactory.getQuery(grr);
QueryImpl frameworkQuery = (QueryImpl) queryRequest.getQuery();
Filter queryFilter = ((QueryImpl) frameworkQuery.getFilter()).getFilter();
assertThat(queryFilter, instanceOf(PropertyIsEqualTo.class));
PropertyIsEqualTo equalTo = (PropertyIsEqualTo) queryFilter;
assertThat(equalTo.getExpression1(), instanceOf(Function.class));
Function function = (Function) equalTo.getExpression1();
assertThat(equalTo.getExpression2(), instanceOf(Literal.class));
Literal literal = (Literal) equalTo.getExpression2();
assertThat(function.getName(), is("proximity"));
assertThat(function.getParameters().get(0).evaluate(null), is(CONTEXTUAL_TEST_ATTRIBUTE));
assertThat(function.getParameters().get(1).evaluate(null), is(1L));
assertThat(function.getParameters().get(2).evaluate(null), is(CQL_CONTEXTUAL_PATTERN));
assertThat(literal.getValue(), is(true));
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.
the class CswQueryFactoryTest method ogcSpatialQuery.
/**
* Runs a binary Spatial OGC Query, verifying that the right filter class is generated based on
* OGC Filter
*
* @param spatialOps BinarySpatialOps query
* @throws UnsupportedQueryException
* @throws SourceUnavailableException
* @throws FederationException
* @throws CswException
*/
private <N extends BinarySpatialOperator> void ogcSpatialQuery(Class<N> clz, JAXBElement<BinarySpatialOpType> spatialOps) throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
GetRecordsType grr = createDefaultPostRecordsRequest();
QueryType query = new QueryType();
List<QName> typeNames = new ArrayList<>();
typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
query.setTypeNames(typeNames);
QueryConstraintType constraint = new QueryConstraintType();
FilterType filter = new FilterType();
filter.setSpatialOps(spatialOps);
constraint.setFilter(filter);
query.setConstraint(constraint);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
Filter queryFilter = ((QueryImpl) frameworkQuery.getFilter()).getFilter();
assertThat(queryFilter, instanceOf(clz));
@SuppressWarnings("unchecked") N spatial = (N) queryFilter;
assertThat(((LiteralExpressionImpl) spatial.getExpression2()).getValue(), is(polygon));
assertThat(((AttributeExpressionImpl) spatial.getExpression1()).getPropertyName(), is(SPATIAL_TEST_ATTRIBUTE));
}
use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.
the class CswEndpointTest method testPostGetRecordsHits.
@Test
public void testPostGetRecordsHits() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
GetRecordsType grr = createDefaultPostRecordsRequest();
grr.setResultType(ResultType.HITS);
QueryType query = new QueryType();
List<QName> typeNames = new ArrayList<>();
typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
query.setTypeNames(typeNames);
QueryConstraintType constraint = new QueryConstraintType();
constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY);
query.setConstraint(constraint);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
CswRecordCollection collection = csw.getRecords(grr);
assertThat(collection.getCswRecords(), is(empty()));
assertThat(collection.getResultType(), is(ResultType.HITS));
}
Aggregations