Search in sources :

Example 1 with ResultTypeType

use of net.opengis.wfs.v_1_1_0.ResultTypeType in project ddf by codice.

the class WfsSource method buildGetFeatureRequest.

private ExtendedGetFeatureType buildGetFeatureRequest(Query query, ResultTypeType resultType, BigInteger maxFeatures) 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();
            wfsQuery.setTypeName(Collections.singletonList(filterDelegateEntry.getKey()));
            if (StringUtils.isNotBlank(srsName)) {
                wfsQuery.setSrsName(srsName);
            }
            FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
            if (filter != null) {
                if (areAnyFiltersSet(filter)) {
                    wfsQuery.setFilter(filter);
                }
                if (!this.disableSorting && query.getSortBy() != null && query.getSortBy().getPropertyName() != null && query.getSortBy().getPropertyName().getPropertyName() != null) {
                    SortByType sortByType = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
                    if (sortByType != null && sortByType.getSortProperty() != null && sortByType.getSortProperty().size() > 0) {
                        LOGGER.debug("Sorting using sort property [{}] and sort order [{}].", sortByType.getSortProperty().get(0).getPropertyName(), sortByType.getSortProperty().get(0).getSortOrder());
                        wfsQuery.setSortBy(sortByType);
                    } else {
                        throw new UnsupportedQueryException("Source " + this.getId() + " does not support specified sort property " + query.getSortBy().getPropertyName().getPropertyName());
                    }
                } else {
                    LOGGER.debug("Sorting is disabled or sort not specified.");
                }
                queries.add(wfsQuery);
            } else {
                LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
            }
        }
    }
    if (!queries.isEmpty()) {
        ExtendedGetFeatureType getFeatureType = new ExtendedGetFeatureType();
        getFeatureType.setMaxFeatures(maxFeatures);
        getFeatureType.getQuery().addAll(queries);
        getFeatureType.setService(Wfs11Constants.WFS);
        getFeatureType.setVersion(Wfs11Constants.VERSION_1_1_0);
        getFeatureType.setResultType(resultType);
        if (supportsStartIndex && resultType.equals(ResultTypeType.RESULTS)) {
            // Convert DDF index of 1 back to index of 0 for WFS
            getFeatureType.setStartIndex(BigInteger.valueOf(query.getStartIndex() - 1));
        }
        logMessage(getFeatureType);
        return getFeatureType;
    } else {
        throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
    }
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) SortByType(net.opengis.filter.v_1_1_0.SortByType) QueryType(net.opengis.wfs.v_1_1_0.QueryType)

Aggregations

ContentType (ddf.catalog.data.ContentType)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 FilterType (net.opengis.filter.v_1_1_0.FilterType)1 SortByType (net.opengis.filter.v_1_1_0.SortByType)1 QueryType (net.opengis.wfs.v_1_1_0.QueryType)1