Search in sources :

Example 1 with SortPropertyType

use of net.opengis.filter.v_2_0_0.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 2 with SortPropertyType

use of net.opengis.filter.v_2_0_0.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());
    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 3 with SortPropertyType

use of net.opengis.filter.v_2_0_0.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", 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, Exception {}", 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)

Example 4 with SortPropertyType

use of net.opengis.filter.v_2_0_0.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)

Aggregations

PropertyNameType (net.opengis.filter.v_1_1_0.PropertyNameType)3 SortByType (net.opengis.filter.v_1_1_0.SortByType)3 SortPropertyType (net.opengis.filter.v_1_1_0.SortPropertyType)3 JAXBElement (javax.xml.bind.JAXBElement)2 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)2 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)2 QueryRequest (ddf.catalog.operation.QueryRequest)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 StringReader (java.io.StringReader)1 LinkedList (java.util.LinkedList)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 QName (javax.xml.namespace.QName)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 DistributedSearchType (net.opengis.cat.csw.v_2_0_2.DistributedSearchType)1 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)1 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)1 FilterType (net.opengis.filter.v_1_1_0.FilterType)1 SortOrderType (net.opengis.filter.v_1_1_0.SortOrderType)1