Search in sources :

Example 16 with SortByType

use of org.geotoolkit.ogc.xml.v110.SortByType 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 17 with SortByType

use of org.geotoolkit.ogc.xml.v110.SortByType 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

ArrayList (java.util.ArrayList)9 SortByType (net.opengis.filter.v_1_1_0.SortByType)8 QName (javax.xml.namespace.QName)6 SortByType (net.opengis.filter.v_2_0_0.SortByType)6 SortBy (org.opengis.filter.sort.SortBy)6 PropertyNameType (net.opengis.filter.v_1_1_0.PropertyNameType)5 SortPropertyType (net.opengis.filter.v_1_1_0.SortPropertyType)5 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)5 QueryType (net.opengis.wfs.v_2_0_0.QueryType)5 Test (org.junit.Test)5 SortByImpl (ddf.catalog.filter.impl.SortByImpl)4 QueryImpl (ddf.catalog.operation.impl.QueryImpl)4 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)4 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)3 JAXBElement (javax.xml.bind.JAXBElement)3 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)3 SortPropertyType (org.geotoolkit.ogc.xml.v110.SortPropertyType)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ContentType (ddf.catalog.data.ContentType)2