Search in sources :

Example 6 with SortByType

use of net.opengis.filter.v_1_1_0.SortByType in project ddf by codice.

the class TestWfsSource method testSortingAscendingSortingSupported.

/**
     * Verify that the SortBy is set with the mapped Feature Property and a ASC sort order.  In this case, the incoming sort property of TEMPORAL is mapped to
     * myTemporalFeatureProperty.
     * <p/>
     * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     * <ns5:GetFeature startIndex="1" count="1" service="WFS" version="2.0.0" xmlns:ns2="http://www.opengis.net/ows/1.1" xmlns="http://www.opengis.net/fes/2.0" xmlns:ns4="http://www.opengis.net/gml" xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns5="http://www.opengis.net/wfs/2.0">
     * <ns5:Query typeNames="SampleFeature0" handle="SampleFeature0">
     * <Filter>
     * <PropertyIsLike wildCard="*" singleChar="?" escapeChar="!">
     * <Literal>*</Literal>
     * <ValueReference>title</ValueReference>
     * </PropertyIsLike>
     * </Filter>
     * <SortBy>
     * <SortProperty>
     * <ValueReference>myTemporalFeatureProperty</ValueReference>
     * <SortOrder>ASC</SortOrder>
     * </SortProperty>
     * </SortBy>
     * </ns5:Query>
     * </ns5:GetFeature>
     */
@Test
public void testSortingAscendingSortingSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
    final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
    final int pageSize = 1;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
    MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
    when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
    when(mockMetacardMapper.getSortByTemporalFeatureProperty()).thenReturn(mockTemporalFeatureProperty);
    List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
    mappers.add(mockMetacardMapper);
    source.setMetacardToFeatureMapper(mappers);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    JAXBElement<?> abstractSortingClause = queryType.getAbstractSortingClause();
    SortByType sortByType = (SortByType) abstractSortingClause.getValue();
    assertThat(sortByType.getSortProperty().get(0).getValueReference(), is(mockTemporalFeatureProperty));
    assertThat(sortByType.getSortProperty().get(0).getSortOrder().name(), is(SortOrderType.ASC.value()));
}
Also used : SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) SortByType(net.opengis.filter.v_2_0_0.SortByType) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 7 with SortByType

use of net.opengis.filter.v_1_1_0.SortByType 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 SortByType

use of net.opengis.filter.v_1_1_0.SortByType in project ddf by codice.

the class AbstractCswSource method createQuery.

private JAXBElement<QueryType> createQuery(Query query, ElementSetType elementSetType, List<QName> elementNames) throws UnsupportedQueryException {
    QueryType queryType = new QueryType();
    QName queryTypeQName = null;
    try {
        if (StringUtils.isNotBlank(cswSourceConfiguration.getQueryTypeName())) {
            String[] parts = cswSourceConfiguration.getQueryTypeName().split(":");
            if (parts.length > 1) {
                queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), parts[1], parts[0]);
            } else {
                queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), cswSourceConfiguration.getQueryTypeName());
            }
        }
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Unable to parse query type QName of {}.  Defaulting to CSW Record", cswSourceConfiguration.getQueryTypeName());
    }
    if (queryTypeQName == null) {
        queryTypeQName = new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.CSW_RECORD_LOCAL_NAME, CswConstants.CSW_NAMESPACE_PREFIX);
    }
    queryType.setTypeNames(Arrays.asList(queryTypeQName));
    if (null != elementSetType) {
        queryType.setElementSetName(createElementSetName(elementSetType));
    } else if (!CollectionUtils.isEmpty(elementNames)) {
        queryType.setElementName(elementNames);
    } else {
        queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
    }
    SortByType sortBy = createSortBy(query);
    if (sortBy != null) {
        queryType.setSortBy(sortBy);
    }
    QueryConstraintType constraint = createQueryConstraint(query);
    if (null != constraint) {
        queryType.setConstraint(constraint);
    }
    ObjectFactory objectFactory = new ObjectFactory();
    return objectFactory.createQuery(queryType);
}
Also used : ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QName(javax.xml.namespace.QName) SortByType(net.opengis.filter.v_1_1_0.SortByType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType)

Aggregations

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