Search in sources :

Example 11 with SortByType

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

the class WfsSource method buildSortBy.

private SortByType buildSortBy(QName featureType, SortBy incomingSortBy) {
    net.opengis.filter.v_1_1_0.ObjectFactory filterObjectFactory = new net.opengis.filter.v_1_1_0.ObjectFactory();
    String propertyName = mapSortByPropertyName(featureType, incomingSortBy.getPropertyName().getPropertyName(), metacardMappers);
    if (propertyName != null) {
        SortOrder sortOrder = incomingSortBy.getSortOrder();
        SortPropertyType sortPropertyType = filterObjectFactory.createSortPropertyType();
        PropertyNameType propertyNameType = filterObjectFactory.createPropertyNameType();
        List<Serializable> props = Arrays.asList(propertyName);
        propertyNameType.setContent(props);
        sortPropertyType.setPropertyName(propertyNameType);
        if (SortOrder.ASCENDING.equals(sortOrder)) {
            sortPropertyType.setSortOrder(SortOrderType.ASC);
        } else if (SortOrder.DESCENDING.equals(sortOrder)) {
            sortPropertyType.setSortOrder(SortOrderType.DESC);
        } else {
            LOGGER.debug("Unable to build query. Unknown sort order of [{}].", sortOrder == null ? null : sortOrder.identifier());
            return null;
        }
        SortByType sortByType = filterObjectFactory.createSortByType();
        sortByType.getSortProperty().add(sortPropertyType);
        return sortByType;
    }
    return null;
}
Also used : Serializable(java.io.Serializable) SortOrder(org.opengis.filter.sort.SortOrder) SortByType(net.opengis.filter.v_1_1_0.SortByType) ObjectFactory(net.opengis.wfs.v_1_1_0.ObjectFactory) SortPropertyType(net.opengis.filter.v_1_1_0.SortPropertyType) PropertyNameType(net.opengis.filter.v_1_1_0.PropertyNameType)

Example 12 with SortByType

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

the class TestWfsSource method testSortingDescendingSortingSupported.

/**
     * Verify that the SortBy is set with the mapped Feature Property and a DESC 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>DESC</SortOrder>
     * </SortProperty>
     * </SortBy>
     * </ns5:Query>
     * </ns5:GetFeature>
     */
@Test
public void testSortingDescendingSortingSupported() 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.DESCENDING);
    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.DESC.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 13 with SortByType

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

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

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

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