Search in sources :

Example 1 with Query

use of org.geotoolkit.csw.xml.Query 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)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 QName (javax.xml.namespace.QName)1 CQLException (org.apache.sis.cql.CQLException)1 DistributedSearch (org.geotoolkit.csw.xml.DistributedSearch)1 ElementSetName (org.geotoolkit.csw.xml.ElementSetName)1 Query (org.geotoolkit.csw.xml.Query)1 QueryConstraint (org.geotoolkit.csw.xml.QueryConstraint)1 FilterFactoryImpl (org.geotoolkit.filter.FilterFactoryImpl)1 FilterType (org.geotoolkit.ogc.xml.v110.FilterType)1 SortByType (org.geotoolkit.ogc.xml.v110.SortByType)1 SortPropertyType (org.geotoolkit.ogc.xml.v110.SortPropertyType)1 Filter (org.opengis.filter.Filter)1 SortOrder (org.opengis.filter.SortOrder)1