use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class WfsSourceTest method testTwoPropertyQuery.
@Test
public void testTwoPropertyQuery() throws Exception {
mapSchemaToFeatures(TWO_TEXT_PROPERTY_SCHEMA, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
// The Text Properties should be ORed
assertThat(query.getFilter().isSetLogicOps(), is(true));
assertThat(query.getFilter().getLogicOps().getValue(), is(instanceOf(BinaryLogicOpType.class)));
}
use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class WfsSourceTest method testContentTypeQuery.
@Test
public void testContentTypeQuery() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
Filter propertyIsLikeFilter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
Filter contentTypeFilter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(// .text(SAMPLE_FEATURE[0].getLocalPart());
sampleFeatures.get(0).getLocalPart());
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.allOf(propertyIsLikeFilter, contentTypeFilter));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
QueryType query = getFeatureType.getQuery().get(0);
// SAMPLE_FEATURE[0]));
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetComparisonOps(), is(true));
assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
}
use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class WfsSourceTest method testTwoFeatureTypesQuery.
@Test
public void testTwoFeatureTypesQuery() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, TWO_FEATURES);
setUpMocks(null, null, TWO_FEATURES, TWO_FEATURES);
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(TWO_FEATURES));
Collections.sort(getFeatureType.getQuery(), QUERY_TYPE_COMPARATOR);
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetComparisonOps(), is(true));
assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
QueryType query2 = getFeatureType.getQuery().get(1);
assertThat(query2.getTypeName().get(0), is(sampleFeatures.get(1)));
assertThat(query2.getFilter().isSetComparisonOps(), is(true));
assertThat(query2.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
}
use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class CswEndpoint method queryCsw.
private CswRecordCollection queryCsw(GetRecordsType request) throws CswException {
if (LOGGER.isDebugEnabled()) {
try {
Writer writer = new StringWriter();
try {
Marshaller marshaller = CswQueryFactory.getJaxBContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
JAXBElement<GetRecordsType> jaxbElement = new ObjectFactory().createGetRecords(request);
marshaller.marshal(jaxbElement, writer);
} catch (JAXBException e) {
LOGGER.debug("Unable to marshall {} to XML", GetRecordsType.class, e);
}
LOGGER.debug(writer.toString());
} catch (Exception e) {
LOGGER.debug("Unable to create debug message for getRecordsType", e);
}
}
QueryType query = (QueryType) request.getAbstractQuery().getValue();
CswRecordCollection response = new CswRecordCollection();
response.setRequest(request);
response.setOutputSchema(request.getOutputSchema());
response.setMimeType(request.getOutputFormat());
response.setElementName(query.getElementName());
response.setElementSetType((query.getElementSetName() != null) ? query.getElementSetName().getValue() : null);
response.setResultType((ResultType) ObjectUtils.defaultIfNull(request.getResultType(), ResultType.HITS));
if (ResultType.HITS.equals(request.getResultType()) || ResultType.RESULTS.equals(request.getResultType())) {
QueryRequest queryRequest = queryFactory.getQuery(request);
try {
queryRequest = queryFactory.updateQueryRequestTags(queryRequest, request.getOutputSchema());
LOGGER.debug("Attempting to execute paged query: {}", queryRequest);
AtomicLong hitCount = new AtomicLong(0);
QueryFunction qf = qr -> {
SourceResponse sr = framework.query(qr);
hitCount.compareAndSet(0, sr.getHits());
return sr;
};
ResultIterable results = ResultIterable.resultIterable(qf, queryRequest, request.getMaxRecords().intValue());
List<Result> resultList = results.stream().collect(Collectors.toList());
// The hitCount Atomic is used here instead of just defaulting
// to the size of the resultList because the size of the resultList
// can be limited to request.getMaxRecords().intValue() which would
// lead to an incorrect response for hits.
// hitCount is set within the QueryFunction and will correspond to
// all responses.
long totalHits = hitCount.get();
totalHits = totalHits != 0 ? totalHits : resultList.size();
QueryResponse queryResponse = new QueryResponseImpl(queryRequest, resultList, totalHits);
response.setSourceResponse(queryResponse);
} catch (UnsupportedQueryException | CatalogQueryException e) {
LOGGER.debug("Unable to query", e);
throw new CswException(e);
}
}
return response;
}
use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class CswSourceTest method testQueryWithSorting.
@Test
public void testQueryWithSorting() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
final String TITLE = "title";
// Setup
final String searchPhrase = "*";
final int pageSize = 1;
final int numRecordsReturned = 1;
final long numRecordsMatched = 1;
setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
try {
configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
} catch (CswException e) {
fail("Could not configure Mock Remote CSW: " + e.getMessage());
}
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(TITLE, SortOrder.DESCENDING);
query.setProperties(ImmutableMap.of(SecurityConstants.SECURITY_SUBJECT, mock(Subject.class)));
query.setSortBy(sortBy);
AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
cswSource.setCswUrl(URL);
cswSource.setId(ID);
// Perform test
SourceResponse response = cswSource.query(getQueryRequestWithSubject(query));
// Verify
Assert.assertNotNull(response);
assertThat(response.getResults().size(), is(numRecordsReturned));
assertThat(response.getHits(), is(numRecordsMatched));
ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
try {
verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
} catch (CswException e) {
fail("Could not verify mock CSW record count: " + e.getMessage());
}
GetRecordsType getRecordsType = captor.getValue();
QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
assertThat(cswQuery.getSortBy().getSortProperty().size(), is(1));
assertThat(cswQuery.getSortBy().getSortProperty().get(0).getPropertyName().getContent().get(0).toString(), equalTo(TITLE));
assertThat(cswQuery.getSortBy().getSortProperty().get(0).getSortOrder(), is(SortOrderType.DESC));
}
Aggregations