Search in sources :

Example 1 with SortPropertyType

use of org.geotoolkit.ogc.xml.v110.SortPropertyType 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;
}
Also used : Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) 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 2 with SortPropertyType

use of org.geotoolkit.ogc.xml.v110.SortPropertyType 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));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SortBy(org.opengis.filter.sort.SortBy) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) SortPropertyType(net.opengis.filter.v_1_1_0.SortPropertyType) SortByType(net.opengis.filter.v_1_1_0.SortByType) JAXBElement(javax.xml.bind.JAXBElement) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) PropertyNameType(net.opengis.filter.v_1_1_0.PropertyNameType) Test(org.junit.Test)

Example 3 with SortPropertyType

use of org.geotoolkit.ogc.xml.v110.SortPropertyType 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;
    }
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SortOrder(org.opengis.filter.sort.SortOrder) SortPropertyType(net.opengis.filter.v_2_0_0.SortPropertyType) SortByType(net.opengis.filter.v_2_0_0.SortByType)

Example 4 with SortPropertyType

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

the class FilterXMLBindingTest method filterMarshalingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws JAXBException
 */
@Test
public void filterMarshalingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    /*
         * Test marshalling spatial filter
         */
    DirectPositionType lowerCorner = new DirectPositionType(10.0, 11.0);
    DirectPositionType upperCorner = new DirectPositionType(10.0, 11.0);
    EnvelopeType envelope = new EnvelopeType(lowerCorner, upperCorner, "EPSG:4326");
    OverlapsType filterElement = new OverlapsType(new PropertyNameType("boundingBox"), envelope);
    FilterType filter = new FilterType(filterElement);
    StringWriter sw = new StringWriter();
    marshaller.marshal(filter, sw);
    String result = sw.toString();
    String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "    <ogc:Overlaps>" + '\n' + "        <ogc:PropertyName>boundingBox</ogc:PropertyName>" + '\n' + "        <gml:Envelope srsName=\"EPSG:4326\">" + '\n' + "            <gml:lowerCorner>10.0 11.0</gml:lowerCorner>" + '\n' + "            <gml:upperCorner>10.0 11.0</gml:upperCorner>" + '\n' + "        </gml:Envelope>" + '\n' + "    </ogc:Overlaps>" + '\n' + "</ogc:Filter>" + '\n';
    LOGGER.log(Level.FINER, "result: {0}", result);
    LOGGER.log(Level.FINER, "expected: {0}", expResult);
    assertXmlEquals(expResult, result, "xmlns:*");
    ObjectFactory factory = new ObjectFactory();
    final BBOXType bbox = new BBOXType("propName", envelope);
    org.geotoolkit.ogc.xml.v200.FilterType filter2 = new org.geotoolkit.ogc.xml.v200.FilterType(bbox);
    sw = new StringWriter();
    marshaller.marshal(filter2, sw);
    result = sw.toString();
    expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\" xmlns:ns8=\"http://www.opengis.net/gml\">\n" + "  <fes:BBOX>\n" + "    <fes:ValueReference>propName</fes:ValueReference>\n" + "    <ns8:Envelope srsName=\"EPSG:4326\">\n" + "      <ns8:lowerCorner>10.0 11.0</ns8:lowerCorner>\n" + "      <ns8:upperCorner>10.0 11.0</ns8:upperCorner>\n" + "    </ns8:Envelope>\n" + "  </fes:BBOX>\n" + "</fes:Filter>";
    assertXmlEquals(expResult, result, "xmlns:*");
    /*--------------------------------------------*/
    /*- --------------- DEBUG --------------------*/
    /*--------------------------------------------*/
    String[] arr = new String[2];
    arr[0] = "boby";
    arr[1] = "DESC";
    SortPropertyType sp = new SortPropertyType(arr[0], SortOrderType.valueOf(arr[1]));
    SortByType sort = new SortByType(Arrays.asList(sp));
    JAXBElement<SortByType> jbSort = factory.createSortBy(sort);
    // marshaller.marshal(jbSort, System.out);
    sp = new SortPropertyType(arr[0], FilterUtilities.sortOrder(arr[1]));
    sort = new SortByType(Arrays.asList(sp));
    jbSort = factory.createSortBy(sort);
    // marshaller.marshal(jbSort, System.out);
    BBOXType filterBox = new BBOXType("boundingBox", "$test");
    org.geotoolkit.ogc.xml.v200.FilterType filter3 = new org.geotoolkit.ogc.xml.v200.FilterType(filterBox);
    sw = new StringWriter();
    marshaller.marshal(filter3, sw);
    result = sw.toString();
    expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\">\n" + "  <fes:BBOX>\n" + "    <fes:ValueReference>boundingBox</fes:ValueReference>$test</fes:BBOX>\n" + "</fes:Filter>";
    assertXmlEquals(expResult, result, "xmlns:*");
    TimeAfterType filterAfter = new TimeAfterType("boundingBox", "$test");
    org.geotoolkit.ogc.xml.v200.FilterType filter4 = new org.geotoolkit.ogc.xml.v200.FilterType(filterAfter);
    sw = new StringWriter();
    marshaller.marshal(filter4, sw);
    result = sw.toString();
    expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\">\n" + "  <fes:After>\n" + "    <fes:ValueReference>boundingBox</fes:ValueReference>$test</fes:After>\n" + "</fes:Filter>";
    assertXmlEquals(expResult, result, "xmlns:*");
    final org.geotoolkit.gml.xml.v321.ObjectFactory gmlFactory = new org.geotoolkit.gml.xml.v321.ObjectFactory();
    final org.geotoolkit.ogc.xml.v200.ObjectFactory fesFactory = new org.geotoolkit.ogc.xml.v200.ObjectFactory();
    PropertyIsBetweenType pes = new PropertyIsBetweenType();
    pes.setExpression(fesFactory.createValueReference((String) "prop"));
    final LowerBoundaryType lower = new LowerBoundaryType();
    final TimeInstantType ti = new TimeInstantType("2002");
    final LiteralType lowlit = new LiteralType(gmlFactory.createTimeInstant(ti));
    lower.setExpression(fesFactory.createLiteral(lowlit));
    pes.setLowerBoundary(lower);
    final UpperBoundaryType upper = new UpperBoundaryType();
    final TimeInstantType ti2 = new TimeInstantType("2004");
    final LiteralType upplit = new LiteralType(gmlFactory.createTimeInstant(ti2));
    upper.setExpression(fesFactory.createLiteral(upplit));
    pes.setUpperBoundary(upper);
    org.geotoolkit.ogc.xml.v200.FilterType filter5 = new org.geotoolkit.ogc.xml.v200.FilterType(pes);
    sw = new StringWriter();
    marshaller.marshal(filter5, sw);
    result = sw.toString();
    expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:gml=\"http://www.opengis.net/gml/3.2\" xmlns:fes=\"http://www.opengis.net/fes/2.0\">\n" + "  <fes:PropertyIsBetween>\n" + "    <fes:ValueReference>prop</fes:ValueReference>\n" + "    <fes:LowerBoundary>\n" + "      <fes:Literal>\n" + "        <gml:TimeInstant>\n" + "          <gml:timePosition>2002</gml:timePosition>\n" + "        </gml:TimeInstant>\n" + "      </fes:Literal>\n" + "    </fes:LowerBoundary>\n" + "    <fes:UpperBoundary>\n" + "      <fes:Literal>\n" + "        <gml:TimeInstant>\n" + "          <gml:timePosition>2004</gml:timePosition>\n" + "        </gml:TimeInstant>\n" + "      </fes:Literal>\n" + "    </fes:UpperBoundary>\n" + "  </fes:PropertyIsBetween>\n" + "</fes:Filter>";
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : OverlapsType(org.geotoolkit.ogc.xml.v110.OverlapsType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) SortByType(org.geotoolkit.ogc.xml.v110.SortByType) TimeInstantType(org.geotoolkit.gml.xml.v321.TimeInstantType) StringWriter(java.io.StringWriter) ObjectFactory(org.geotoolkit.ogc.xml.v110.ObjectFactory) SortPropertyType(org.geotoolkit.ogc.xml.v110.SortPropertyType) PropertyIsBetweenType(org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) LiteralType(org.geotoolkit.ogc.xml.v200.LiteralType) TimeAfterType(org.geotoolkit.ogc.xml.v200.TimeAfterType) UpperBoundaryType(org.geotoolkit.ogc.xml.v200.UpperBoundaryType) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) BBOXType(org.geotoolkit.ogc.xml.v200.BBOXType) LowerBoundaryType(org.geotoolkit.ogc.xml.v200.LowerBoundaryType)

Example 5 with SortPropertyType

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

the class GetRecordsRequest method get202RecordsType.

/**
 * Convert the KVP values into a GetRecordsType, validates format of fields and enumeration
 * constraints required to meet the schema requirements of the GetRecordsType. No further
 * validation is done at this point
 *
 * @return GetRecordsType representation of this key-value representation
 * @throws CswException An exception when some field cannot be converted to the equivalent
 *     GetRecordsType value
 */
public GetRecordsType get202RecordsType() throws CswException {
    GetRecordsType getRecords = new GetRecordsType();
    getRecords.setOutputSchema(getOutputSchema());
    getRecords.setRequestId(getRequestId());
    if (getMaxRecords() != null) {
        getRecords.setMaxRecords(getMaxRecords());
    }
    if (getStartPosition() != null) {
        getRecords.setStartPosition(getStartPosition());
    }
    if (getOutputFormat() != null) {
        getRecords.setOutputFormat(getOutputFormat());
    }
    if (getResponseHandler() != null) {
        getRecords.setResponseHandler(Arrays.asList(getResponseHandler()));
    }
    if (getResultType() != null) {
        try {
            getRecords.setResultType(ResultType.fromValue(getResultType()));
        } catch (IllegalArgumentException iae) {
            LOGGER.debug("Failed to find \"{}\" as a valid ResultType", LogSanitizer.sanitize(getResultType()), iae);
            throw new CswException("A CSW getRecords request ResultType must be \"hits\", \"results\", or \"validate\"");
        }
    }
    if (getDistributedSearch() != null && getDistributedSearch()) {
        DistributedSearchType disSearch = new DistributedSearchType();
        disSearch.setHopCount(getHopCount());
        getRecords.setDistributedSearch(disSearch);
    }
    QueryType query = new QueryType();
    Map<String, String> namespaces = parseNamespaces(getNamespace());
    List<QName> typeNames = typeStringToQNames(getTypeNames(), namespaces);
    query.setTypeNames(typeNames);
    if (getElementName() != null && getElementSetName() != null) {
        LOGGER.debug("CSW getRecords request received with mutually exclusive ElementName and SetElementName set");
        throw new CswException("A CSW getRecords request can only have an \"ElementName\" or an \"ElementSetName\"");
    }
    if (getElementName() != null) {
        query.setElementName(typeStringToQNames(getElementName(), namespaces));
    }
    if (getElementSetName() != null) {
        try {
            ElementSetNameType eleSetName = new ElementSetNameType();
            eleSetName.setTypeNames(typeNames);
            eleSetName.setValue(ElementSetType.fromValue(getElementSetName()));
            query.setElementSetName(eleSetName);
        } catch (IllegalArgumentException iae) {
            LOGGER.debug("Failed to find \"{}\" as a valid elementSetType", LogSanitizer.sanitize(getElementSetName()), iae);
            throw new CswException("A CSW getRecords request ElementSetType must be \"brief\", \"summary\", or \"full\"");
        }
    }
    if (getSortBy() != null) {
        SortByType sort = new SortByType();
        List<SortPropertyType> sortProps = new LinkedList<SortPropertyType>();
        String[] sortOptions = getSortBy().split(",");
        for (String sortOption : sortOptions) {
            if (sortOption.lastIndexOf(':') < 1) {
                throw new CswException("Invalid Sort Order format: " + getSortBy());
            }
            SortPropertyType sortProperty = new SortPropertyType();
            PropertyNameType propertyName = new PropertyNameType();
            String propName = StringUtils.substringBeforeLast(sortOption, ":");
            String direction = StringUtils.substringAfterLast(sortOption, ":");
            propertyName.setContent(Arrays.asList((Object) propName));
            SortOrderType sortOrder;
            if (direction.equals("A")) {
                sortOrder = SortOrderType.ASC;
            } else if (direction.equals("D")) {
                sortOrder = SortOrderType.DESC;
            } else {
                throw new CswException("Invalid Sort Order format: " + getSortBy());
            }
            sortProperty.setPropertyName(propertyName);
            sortProperty.setSortOrder(sortOrder);
            sortProps.add(sortProperty);
        }
        sort.setSortProperty(sortProps);
        query.setElementName(typeStringToQNames(getElementName(), namespaces));
        query.setSortBy(sort);
    }
    if (getConstraint() != null) {
        QueryConstraintType queryConstraint = new QueryConstraintType();
        if (getConstraintLanguage().equalsIgnoreCase(CswConstants.CONSTRAINT_LANGUAGE_CQL)) {
            queryConstraint.setCqlText(getConstraint());
        } else if (getConstraintLanguage().equalsIgnoreCase(CswConstants.CONSTRAINT_LANGUAGE_FILTER)) {
            try {
                XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
                xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
                xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
                XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(constraint));
                Unmarshaller unmarshaller = JAX_BCONTEXT.createUnmarshaller();
                @SuppressWarnings("unchecked") JAXBElement<FilterType> jaxbFilter = (JAXBElement<FilterType>) unmarshaller.unmarshal(xmlStreamReader);
                queryConstraint.setFilter(jaxbFilter.getValue());
            } catch (JAXBException e) {
                LOGGER.debug("JAXBException parsing OGC Filter:", e);
                throw new CswException("JAXBException parsing OGC Filter:" + getConstraint());
            } catch (Exception e) {
                LOGGER.debug("Unable to parse OGC Filter:", e);
                throw new CswException("Unable to parse OGC Filter:" + getConstraint());
            }
        } else {
            throw new CswException("Invalid Constraint Language defined: " + getConstraintLanguage());
        }
        query.setConstraint(queryConstraint);
    }
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(new QName(CswConstants.CSW_OUTPUT_SCHEMA), QueryType.class, query);
    getRecords.setAbstractQuery(jaxbQuery);
    return getRecords;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SortByType(net.opengis.filter.v_1_1_0.SortByType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) StringReader(java.io.StringReader) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) SortPropertyType(net.opengis.filter.v_1_1_0.SortPropertyType) DistributedSearchType(net.opengis.cat.csw.v_2_0_2.DistributedSearchType) Unmarshaller(javax.xml.bind.Unmarshaller) PropertyNameType(net.opengis.filter.v_1_1_0.PropertyNameType) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBElement(javax.xml.bind.JAXBElement) LinkedList(java.util.LinkedList) JAXBException(javax.xml.bind.JAXBException) SortOrderType(net.opengis.filter.v_1_1_0.SortOrderType) FilterType(net.opengis.filter.v_1_1_0.FilterType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) XMLInputFactory(javax.xml.stream.XMLInputFactory)

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