use of org.geotoolkit.ogc.xml.v110.SortByType in project ddf by codice.
the class AbstractCswSource method createSortBy.
private SortByType createSortBy(QueryRequest queryRequest) {
Query query = queryRequest.getQuery();
SortByType cswSortBy = null;
if (query != null && query.getSortBy() != null && query.getSortBy().getPropertyName() != null) {
List<SortBy> sortBys = new ArrayList<>();
sortBys.add(query.getSortBy());
Serializable extSortBySer = queryRequest.getPropertyValue(ADDITIONAL_SORT_BYS);
if (extSortBySer instanceof SortBy[]) {
SortBy[] extSortBys = (SortBy[]) extSortBySer;
if (extSortBys.length > 0) {
sortBys.addAll(Arrays.asList(extSortBys));
}
}
for (SortBy sortBy : sortBys) {
SortPropertyType sortProperty = new SortPropertyType();
PropertyNameType propertyName = new PropertyNameType();
if (sortBy.getPropertyName() != null) {
String propName = sortBy.getPropertyName().getPropertyName();
if (propName != null) {
if (Result.TEMPORAL.equals(propName) || Metacard.ANY_DATE.equals(propName)) {
propName = Core.MODIFIED;
} else if (Result.RELEVANCE.equals(propName) || Metacard.ANY_TEXT.equals(propName)) {
propName = Core.TITLE;
} else if (Result.DISTANCE.equals(propName) || Metacard.ANY_GEO.equals(propName)) {
continue;
}
if (cswSortBy == null) {
cswSortBy = new SortByType();
}
propertyName.setContent(Arrays.asList((Object) cswFilterDelegate.mapPropertyName(propName)));
sortProperty.setPropertyName(propertyName);
if (SortOrder.DESCENDING.equals(query.getSortBy().getSortOrder())) {
sortProperty.setSortOrder(SortOrderType.DESC);
} else {
sortProperty.setSortOrder(SortOrderType.ASC);
}
cswSortBy.getSortProperty().add(sortProperty);
}
}
}
} else {
return null;
}
return cswSortBy;
}
use of org.geotoolkit.ogc.xml.v110.SortByType in project ddf by codice.
the class AbstractCswSource method createQuery.
private JAXBElement<QueryType> createQuery(QueryRequest queryRequest, ElementSetType elementSetType, List<QName> elementNames) throws UnsupportedQueryException {
QueryType queryType = new QueryType();
QName queryTypeQName = null;
try {
if (StringUtils.isNotBlank(cswSourceConfiguration.getQueryTypeName())) {
String[] parts = cswSourceConfiguration.getQueryTypeName().split(":");
if (parts.length > 1) {
queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), parts[1], parts[0]);
} else {
queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), cswSourceConfiguration.getQueryTypeName());
}
}
} catch (IllegalArgumentException e) {
LOGGER.debug("Unable to parse query type QName of {}. Defaulting to CSW Record", cswSourceConfiguration.getQueryTypeName());
}
if (queryTypeQName == null) {
queryTypeQName = new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.CSW_RECORD_LOCAL_NAME, CswConstants.CSW_NAMESPACE_PREFIX);
}
QueryRequest transformedQueryRequest = cswQueryFilterTransformerProvider != null ? cswQueryFilterTransformerProvider.getTransformer(cswSourceConfiguration.getQueryTypeName()).map(it -> it.transform(queryRequest, null)).orElse(queryRequest) : queryRequest;
queryType.setTypeNames(Arrays.asList(queryTypeQName));
if (null != elementSetType) {
queryType.setElementSetName(createElementSetName(elementSetType));
} else if (!CollectionUtils.isEmpty(elementNames)) {
queryType.setElementName(elementNames);
} else {
queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
}
SortByType sortBy = createSortBy(transformedQueryRequest);
if (sortBy != null) {
queryType.setSortBy(sortBy);
}
QueryConstraintType constraint = createQueryConstraint(transformedQueryRequest);
if (null != constraint) {
queryType.setConstraint(constraint);
}
ObjectFactory objectFactory = new ObjectFactory();
return objectFactory.createQuery(queryType);
}
use of org.geotoolkit.ogc.xml.v110.SortByType 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 org.geotoolkit.ogc.xml.v110.SortByType in project ddf by codice.
the class WfsSource method buildGetFeatureRequest.
protected GetFeatureType buildGetFeatureRequest(Query query) throws UnsupportedQueryException {
List<ContentType> contentTypes = getContentTypesFromQuery(query);
List<QueryType> queries = new ArrayList<>();
for (Entry<QName, WfsFilterDelegate> filterDelegateEntry : featureTypeFilters.entrySet()) {
if (contentTypes.isEmpty() || isFeatureTypeInQuery(contentTypes, filterDelegateEntry.getKey().getLocalPart())) {
QueryType wfsQuery = new QueryType();
String typeName = null;
if (StringUtils.isEmpty(filterDelegateEntry.getKey().getPrefix())) {
typeName = filterDelegateEntry.getKey().getLocalPart();
} else {
typeName = filterDelegateEntry.getKey().getPrefix() + ":" + filterDelegateEntry.getKey().getLocalPart();
}
if (StringUtils.isNotBlank(srsName)) {
wfsQuery.setSrsName(srsName);
}
wfsQuery.setTypeNames(Arrays.asList(typeName));
wfsQuery.setHandle(filterDelegateEntry.getKey().getLocalPart());
FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
if (filter != null) {
if (areAnyFiltersSet(filter)) {
wfsQuery.setAbstractSelectionClause(new net.opengis.filter.v_2_0_0.ObjectFactory().createFilter(filter));
}
if (!this.disableSorting) {
if (query.getSortBy() != null) {
SortOrder sortOrder = query.getSortBy().getSortOrder();
if (filterDelegateEntry.getValue().isSortingSupported() && filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
if (sortBy != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Sorting using sort order of [{}].", sortOrder.identifier());
}
wfsQuery.setAbstractSortingClause(sortBy);
}
} else if (filterDelegateEntry.getValue().isSortingSupported() && CollectionUtils.isEmpty(filterDelegateEntry.getValue().getAllowedSortOrders())) {
JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
if (sortBy != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No sort orders defined in getCapabilities. Attempting to sort using sort order of [{}].", sortOrder.identifier());
}
wfsQuery.setAbstractSortingClause(sortBy);
}
} else if (filterDelegateEntry.getValue().isSortingSupported() && !filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
LOGGER.debug("Unsupported sort order of [{}]. Supported sort orders are {}.", sortOrder, filterDelegateEntry.getValue().getAllowedSortOrders());
} else if (!filterDelegateEntry.getValue().isSortingSupported()) {
LOGGER.debug("Sorting is not supported.");
}
}
} else {
LOGGER.debug("Sorting is disabled.");
}
queries.add(wfsQuery);
} else {
LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
}
}
}
if (!queries.isEmpty()) {
GetFeatureType getFeatureType = new GetFeatureType();
int pageSize = query.getPageSize();
if (pageSize < 0) {
LOGGER.debug("Page size has a negative value");
throw new UnsupportedQueryException("Unable to build query. Page size has a negative value.");
}
int startIndex = query.getStartIndex();
if (startIndex < 0) {
LOGGER.debug("Start index has a negative value");
throw new UnsupportedQueryException("Unable to build query. Start index has a negative value.");
} else if (startIndex != 0) {
// Convert DDF index of 1 back to index of 0 for WFS 2.0
startIndex = query.getStartIndex() - 1;
} else {
LOGGER.debug("Query already has a start index of 0");
}
getFeatureType.setCount(BigInteger.valueOf(query.getPageSize()));
getFeatureType.setStartIndex(BigInteger.valueOf(startIndex));
List<JAXBElement<?>> incomingQueries = getFeatureType.getAbstractQueryExpression();
for (QueryType queryType : queries) {
incomingQueries.add(new net.opengis.wfs.v_2_0_0.ObjectFactory().createQuery(queryType));
}
logMessage(getFeatureType);
return getFeatureType;
} else {
throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
}
}
use of org.geotoolkit.ogc.xml.v110.SortByType in project ddf by codice.
the class WfsSource method buildSortBy.
private JAXBElement<SortByType> buildSortBy(QName featureType, SortBy incomingSortBy) throws UnsupportedQueryException {
net.opengis.filter.v_2_0_0.ObjectFactory filterObjectFactory = new net.opengis.filter.v_2_0_0.ObjectFactory();
String propertyName = mapSortByPropertyName(featureType, incomingSortBy.getPropertyName().getPropertyName(), metacardToFeatureMappers);
if (propertyName != null) {
SortOrder sortOrder = incomingSortBy.getSortOrder();
SortPropertyType sortPropertyType = filterObjectFactory.createSortPropertyType();
sortPropertyType.setValueReference(propertyName);
if (SortOrder.ASCENDING.equals(sortOrder)) {
sortPropertyType.setSortOrder(SortOrderType.ASC);
} else if (SortOrder.DESCENDING.equals(sortOrder)) {
sortPropertyType.setSortOrder(SortOrderType.DESC);
} else {
throw new UnsupportedQueryException("Unable to build query. Unknown sort order of [" + sortOrder.identifier() + "].");
}
SortByType sortByType = filterObjectFactory.createSortByType();
sortByType.getSortProperty().add(sortPropertyType);
return filterObjectFactory.createSortBy(sortByType);
} else {
return null;
}
}
Aggregations