Search in sources :

Example 6 with SortPropertyType

use of org.geotoolkit.ogc.xml.v110.SortPropertyType in project ddf by codice.

the class WfsSource method buildSortBy.

private SortByType buildSortBy(QName featureType, SortBy incomingSortBy) {
    net.opengis.filter.v_1_1_0.ObjectFactory filterObjectFactory = new net.opengis.filter.v_1_1_0.ObjectFactory();
    String propertyName = mapSortByPropertyName(featureType, incomingSortBy.getPropertyName().getPropertyName(), metacardMappers);
    if (propertyName != null) {
        SortOrder sortOrder = incomingSortBy.getSortOrder();
        SortPropertyType sortPropertyType = filterObjectFactory.createSortPropertyType();
        PropertyNameType propertyNameType = filterObjectFactory.createPropertyNameType();
        List<Serializable> props = Arrays.asList(propertyName);
        propertyNameType.setContent(props);
        sortPropertyType.setPropertyName(propertyNameType);
        if (SortOrder.ASCENDING.equals(sortOrder)) {
            sortPropertyType.setSortOrder(SortOrderType.ASC);
        } else if (SortOrder.DESCENDING.equals(sortOrder)) {
            sortPropertyType.setSortOrder(SortOrderType.DESC);
        } else {
            LOGGER.debug("Unable to build query. Unknown sort order of [{}].", sortOrder == null ? null : sortOrder.identifier());
            return null;
        }
        SortByType sortByType = filterObjectFactory.createSortByType();
        sortByType.getSortProperty().add(sortPropertyType);
        return sortByType;
    }
    return null;
}
Also used : Serializable(java.io.Serializable) SortOrder(org.opengis.filter.sort.SortOrder) SortByType(net.opengis.filter.v_1_1_0.SortByType) ObjectFactory(net.opengis.wfs.v_1_1_0.ObjectFactory) SortPropertyType(net.opengis.filter.v_1_1_0.SortPropertyType) PropertyNameType(net.opengis.filter.v_1_1_0.PropertyNameType)

Example 7 with SortPropertyType

use of org.geotoolkit.ogc.xml.v110.SortPropertyType in project ddf by codice.

the class AbstractCswSource method createSortBy.

private SortByType createSortBy(Query query) {
    SortByType sortBy = null;
    if (query.getSortBy() != null) {
        sortBy = new SortByType();
        SortPropertyType sortProperty = new SortPropertyType();
        PropertyNameType propertyName = new PropertyNameType();
        String propName;
        if (query.getSortBy().getPropertyName() != null) {
            propName = query.getSortBy().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)) {
                    return null;
                }
                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);
                }
                sortBy.getSortProperty().add(sortProperty);
            }
        } else {
            return null;
        }
    }
    return sortBy;
}
Also used : SortPropertyType(net.opengis.filter.v_1_1_0.SortPropertyType) SortByType(net.opengis.filter.v_1_1_0.SortByType) PropertyNameType(net.opengis.filter.v_1_1_0.PropertyNameType)

Example 8 with SortPropertyType

use of org.geotoolkit.ogc.xml.v110.SortPropertyType in project geotoolkit by Geomatys.

the class AbstractGetRecords method getResponseStream.

/**
 * {@inheritDoc}
 */
@Override
public InputStream getResponseStream() throws IOException {
    final URL url = getURL();
    URLConnection conec = url.openConnection();
    security.secure(conec);
    conec.setDoOutput(true);
    conec.setRequestProperty("Content-Type", "text/xml");
    OutputStream stream = conec.getOutputStream();
    stream = security.encrypt(stream);
    try {
        final Marshaller marsh = POOL.acquireMarshaller();
        /*
             * Getting typeNames value used to build QueryType object
             */
        final List<QName> typNames = new ArrayList<>();
        if (typeNames != null) {
            typNames.add(TypeNames.valueOf(typeNames));
        }
        /*
             * Getting ElementSetType value used to build QueryType object
             */
        ElementSetName esnt = null;
        if (elementSetName != null) {
            esnt = createElementSetName(version, elementSetName);
        }
        /*
             * Getting  SortByType value, default is null
             *
             * @TODO if sortBy is not null we must creates SortByType instance
             * the value can be sortBy=Title:A,Abstract:D where A for ascending order and D for decending.
             * see Table 29 - Parameters in GetRecords operation request in document named
             * OpenGIS Catalogue Services Specification 2.0.2 -ISO Metadata Application Profile
             *
             */
        final SortByType sort;
        if (sortBy != null) {
            String[] fields = sortBy.split(",");
            List<SortPropertyType> sortProps = new ArrayList<>();
            for (String field : fields) {
                String[] split = field.split(":");
                SortOrder sortOrder = split.length == 1 ? null : ("D".equals(split[1]) ? DESCENDING : ASCENDING);
                sortProps.add(new SortPropertyType(split[0], sortOrder));
            }
            sort = new SortByType(sortProps);
        } else {
            sort = null;
        }
        /*
             * Building QueryType from the cql constraint
             */
        QueryConstraint qct = null;
        if (constraint != null && !constraint.isEmpty()) {
            try {
                final FilterType filterType;
                Filter filter = CQL.parseFilter(constraint, new FilterFactoryImpl());
                if (filter instanceof FilterType) {
                    filterType = (FilterType) filter;
                } else {
                    filterType = new FilterType(filter);
                }
                qct = createQueryConstraint(version, filterType, constraintLanguageVersion != null ? constraintLanguageVersion : "1.1.0");
            } catch (CQLException ex) {
                // @TODO maybe use another Exception.
                throw new IllegalArgumentException("Constraint cannot be parsed to filter, the constraint parameter value is not in OGC CQL format.", ex);
            }
        }
        final Query queryType = createQuery(version, typNames, esnt, sort, qct);
        final DistributedSearch ds = createDistributedSearch(version, hopcount);
        final org.geotoolkit.csw.xml.GetRecordsRequest recordsXml = createGetRecord(version, "CSW", resultType, requestId, outputFormat, outputSchema, startPosition, maxRecords, queryType, ds);
        marsh.marshal(recordsXml, stream);
        POOL.recycle(marsh);
    } catch (JAXBException ex) {
        throw new IOException(ex);
    }
    stream.close();
    return security.decrypt(conec.getInputStream());
}
Also used : Query(org.geotoolkit.csw.xml.Query) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SortByType(org.geotoolkit.ogc.xml.v110.SortByType) QueryConstraint(org.geotoolkit.csw.xml.QueryConstraint) URL(java.net.URL) SortPropertyType(org.geotoolkit.ogc.xml.v110.SortPropertyType) Marshaller(javax.xml.bind.Marshaller) ElementSetName(org.geotoolkit.csw.xml.ElementSetName) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) SortOrder(org.opengis.filter.SortOrder) IOException(java.io.IOException) URLConnection(java.net.URLConnection) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) Filter(org.opengis.filter.Filter) DistributedSearch(org.geotoolkit.csw.xml.DistributedSearch) FilterFactoryImpl(org.geotoolkit.filter.FilterFactoryImpl) CQLException(org.apache.sis.cql.CQLException)

Example 9 with SortPropertyType

use of org.geotoolkit.ogc.xml.v110.SortPropertyType in project geotoolkit by Geomatys.

the class OGC110toGTTransformer method visitSortBy.

public List<SortProperty> visitSortBy(final SortByType type) {
    final List<SortProperty> sorts = new ArrayList<>();
    for (final SortPropertyType spt : type.getSortProperty()) {
        final ValueReference pn = visitPropertyName(spt.getValueReference());
        sorts.add(filterFactory.sort(pn, spt.getSortOrder()));
    }
    return sorts;
}
Also used : SortProperty(org.opengis.filter.SortProperty) ArrayList(java.util.ArrayList) SortPropertyType(org.geotoolkit.ogc.xml.v110.SortPropertyType) ValueReference(org.opengis.filter.ValueReference)

Aggregations

PropertyNameType (net.opengis.filter.v_1_1_0.PropertyNameType)5 SortByType (net.opengis.filter.v_1_1_0.SortByType)5 SortPropertyType (net.opengis.filter.v_1_1_0.SortPropertyType)5 ArrayList (java.util.ArrayList)3 SortPropertyType (org.geotoolkit.ogc.xml.v110.SortPropertyType)3 Serializable (java.io.Serializable)2 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 QName (javax.xml.namespace.QName)2 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)2 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)2 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)2 SortByType (org.geotoolkit.ogc.xml.v110.SortByType)2 SortBy (org.opengis.filter.sort.SortBy)2 SortOrder (org.opengis.filter.sort.SortOrder)2 Query (ddf.catalog.operation.Query)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1