use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class AbstractCswSource method createSubscriptionGetRecordsRequest.
private GetRecordsType createSubscriptionGetRecordsRequest() {
GetRecordsType getRecordsType = new GetRecordsType();
getRecordsType.setVersion(cswVersion);
getRecordsType.setService(CswConstants.CSW);
getRecordsType.setResultType(ResultType.RESULTS);
getRecordsType.setStartPosition(BigInteger.ONE);
getRecordsType.setMaxRecords(BigInteger.TEN);
getRecordsType.setOutputFormat(MediaType.APPLICATION_XML);
getRecordsType.setOutputSchema("urn:catalog:metacard");
getRecordsType.getResponseHandler().add(SystemBaseUrl.EXTERNAL.constructUrl("csw/subscription/event", true));
QueryType queryType = new QueryType();
queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
ObjectFactory objectFactory = new ObjectFactory();
getRecordsType.setAbstractQuery(objectFactory.createQuery(queryType));
return getRecordsType;
}
use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class CswQueryFactoryTest method generateTemporalFilter.
private Filter generateTemporalFilter(JAXBElement<BinaryComparisonOpType> temporalOps) 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.setComparisonOps(temporalOps);
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();
return ((QueryImpl) frameworkQuery.getFilter()).getFilter();
}
use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class CswQueryFactoryTest method testPostGetRecordsValidSort.
@Test
public void testPostGetRecordsValidSort() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
GetRecordsType grr = createDefaultPostRecordsRequest();
grr.setResultType(ResultType.RESULTS);
QueryType query = new QueryType();
SortByType incomingSort = new SortByType();
SortPropertyType propType = new SortPropertyType();
PropertyNameType propName = new PropertyNameType();
propName.setContent(Collections.singletonList(TITLE_TEST_ATTRIBUTE));
propType.setPropertyName(propName);
incomingSort.getSortProperty().add(propType);
query.setSortBy(incomingSort);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
QueryRequest queryRequest = queryFactory.getQuery(grr);
SortBy resultSort = queryRequest.getQuery().getSortBy();
assertThat(resultSort.getPropertyName().getPropertyName(), is(CQL_FRAMEWORK_TEST_ATTRIBUTE));
assertThat(resultSort.getSortOrder(), is(SortOrder.ASCENDING));
}
use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.
the class CswQueryFactoryTest method cqlSpatialQuery.
/**
* Runs a binary Spatial CQL Query, verifying that the right filter class is generated based on
* CQL
*
* @param clz Class of filter to generate
* @param cql CQL Query String
* @throws UnsupportedQueryException
* @throws SourceUnavailableException
* @throws FederationException
* @throws CswException
*/
private <N extends BinarySpatialOperator> void cqlSpatialQuery(Class<N> clz, String cql) 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();
constraint.setCqlText(cql);
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.wfs.v_1_1_0.QueryType in project ddf by codice.
the class CswQueryFactory method getQuery.
public QueryRequest getQuery(GetRecordsType request) throws CswException {
QueryType query = (QueryType) request.getAbstractQuery().getValue();
Filter filter = buildFilter(query.getConstraint());
QueryImpl frameworkQuery = new QueryImpl(filter);
SortBy[] sortBys = buildSort(query.getSortBy());
SortBy[] extSortBys = null;
if (sortBys != null && sortBys.length > 0) {
frameworkQuery.setSortBy(sortBys[0]);
extSortBys = Arrays.copyOfRange(sortBys, 1, sortBys.length);
}
if (ResultType.HITS.equals(request.getResultType()) || request.getMaxRecords().intValue() < 1) {
frameworkQuery.setStartIndex(1);
frameworkQuery.setPageSize(1);
} else {
frameworkQuery.setStartIndex(request.getStartPosition().intValue());
frameworkQuery.setPageSize(request.getMaxRecords().intValue());
}
boolean isEnterprise = request.getDistributedSearch() != null && (request.getDistributedSearch().getHopCount().longValue() > 1);
Map<String, Serializable> properties = new HashMap<>();
if (extSortBys != null && extSortBys.length > 0) {
properties.put(ADDITIONAL_SORT_BYS, extSortBys);
}
QueryRequest queryRequest = getQueryRequest(frameworkQuery, isEnterprise, properties);
return transformQuery(queryRequest, query.getTypeNames());
}
Aggregations