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;
}
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()));
}
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()));
}
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;
}
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);
}
Aggregations