use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.
the class TestWfsFilterDelegate method testSequentialPropertyIsNotOfTemporalType.
private void testSequentialPropertyIsNotOfTemporalType(String methName, Object... inputParams) throws Throwable {
String mockMetacardAttribute = "myMetacardAttribute";
String mockFeatureType = "myFeatureType";
String mockFeatureProperty = "myFeatureProperty";
List<String> mockProperties = new ArrayList<>(1);
mockProperties.add(mockFeatureProperty);
when(mockFeatureMetacardType.getProperties()).thenReturn(mockProperties);
when(mockFeatureMetacardType.getName()).thenReturn(mockFeatureType);
List<String> mockTemporalProperties = Collections.emptyList();
when(mockFeatureMetacardType.getTemporalProperties()).thenReturn(mockTemporalProperties);
FeatureAttributeDescriptor mockFeatureAttributeDescriptor = mock(FeatureAttributeDescriptor.class);
when(mockFeatureAttributeDescriptor.isIndexed()).thenReturn(true);
when(mockFeatureAttributeDescriptor.getPropertyName()).thenReturn(mockFeatureProperty);
when(mockFeatureMetacardType.getAttributeDescriptor(mockFeatureProperty)).thenReturn(mockFeatureAttributeDescriptor);
MetacardMapper mockMapper = mock(MetacardMapper.class);
when(mockMapper.getFeatureProperty(mockMetacardAttribute)).thenReturn(mockFeatureProperty);
WfsFilterDelegate delegate = new WfsFilterDelegate(mockFeatureMetacardType, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, mockMapper, GeospatialUtil.LAT_LON_ORDER);
try {
// Inject the mockMetacardAttribute at the head of the array
Object[] methParams = ObjectArrays.concat(mockMetacardAttribute, inputParams);
// Generate the array of class types for the reflection call
Class<?>[] classTypes = FluentIterable.from(Arrays.asList(methParams)).transform(new Function<Object, Class>() {
@Override
public Class<?> apply(Object o) {
// Autoboxing is a small problem with reflection when trying to be too clever
return (o instanceof Long) ? long.class : o.getClass();
}
}).toArray(Class.class);
Method method = WfsFilterDelegate.class.getMethod(methName, classTypes);
method.invoke(delegate, methParams);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper 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.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.
the class WfsSource method buildFeatureFilters.
private void buildFeatureFilters(List<FeatureTypeType> featureTypes, FilterCapabilities filterCapabilities) throws SecurityServiceException {
Wfs wfs = factory.getClient();
if (filterCapabilities == null) {
return;
}
// Use local Map for metacardtype registrations and once they are populated with latest
// MetacardTypes, then do actual registration
Map<String, MetacardTypeRegistration> mcTypeRegs = new HashMap<String, MetacardTypeRegistration>();
this.featureTypeFilters.clear();
for (FeatureTypeType featureTypeType : featureTypes) {
String ftSimpleName = featureTypeType.getName().getLocalPart();
if (StringUtils.isNotBlank(forcedFeatureType) && !StringUtils.equals(forcedFeatureType, ftSimpleName)) {
continue;
}
if (mcTypeRegs.containsKey(ftSimpleName)) {
LOGGER.debug("WfsSource {}: MetacardType {} is already registered - skipping to next metacard type", getId(), ftSimpleName);
continue;
}
LOGGER.debug("ftName: {}", ftSimpleName);
try {
XmlSchema schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(featureTypeType.getName()));
if (schema == null) {
// Some WFS 2.0.0 DescribeFeatureRequests return inconsistent results when
// the `:` character is encoded in the URL, ie Prefix:SomeFeature is encoded to
// Prefix%3ASomeFeature. To avoid this issue, we will make a call without the prefix
// if the previous call does not work.
schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(new QName(featureTypeType.getName().getNamespaceURI(), featureTypeType.getName().getLocalPart(), "")));
}
if (schema != null) {
// Update local map with enough info to create actual MetacardType registrations
// later
MetacardTypeRegistration registration = createFeatureMetacardTypeRegistration(featureTypeType, ftSimpleName, schema);
mcTypeRegs.put(ftSimpleName, registration);
FeatureMetacardType featureMetacardType = registration.getFtMetacard();
lookupFeatureConverter(ftSimpleName, featureMetacardType);
MetacardMapper metacardAttributeToFeaturePropertyMapper = lookupMetacardAttributeToFeaturePropertyMapper(featureMetacardType.getFeatureType());
this.featureTypeFilters.put(featureMetacardType.getFeatureType(), new WfsFilterDelegate(featureMetacardType, filterCapabilities, registration.getSrs(), metacardAttributeToFeaturePropertyMapper, coordinateOrder));
}
} catch (WfsException | IllegalArgumentException wfse) {
LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
} catch (WebApplicationException wae) {
LOGGER.debug(handleWebApplicationException(wae), wae);
}
}
registerFeatureMetacardTypes(mcTypeRegs);
if (featureTypeFilters.isEmpty()) {
LOGGER.debug("Wfs Source {}: No Feature Type schemas validated.", getId());
}
LOGGER.debug("Wfs Source {}: Number of validated Features = {}", getId(), featureTypeFilters.size());
updateSupportedSpatialOperators(filterCapabilities.getSpatialCapabilities().getSpatialOperators());
}
use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.
the class WfsSource method mapSortByPropertyName.
/**
* If a MetacardMapper cannot be found or there is no mapping for the incomingPropertyName, return null.
* This will cause a query to be constructed without an AbstractSortingClause.
*/
private String mapSortByPropertyName(QName featureType, String incomingPropertyName) {
MetacardMapper metacardToFeaturePropertyMapper = lookupMetacardAttributeToFeaturePropertyMapper(featureType);
String mappedPropertyName = null;
if (metacardToFeaturePropertyMapper != null) {
if (StringUtils.equals(Result.TEMPORAL, incomingPropertyName) || StringUtils.equals(Metacard.EFFECTIVE, incomingPropertyName)) {
mappedPropertyName = StringUtils.isNotBlank(metacardToFeaturePropertyMapper.getSortByTemporalFeatureProperty()) ? metacardToFeaturePropertyMapper.getSortByTemporalFeatureProperty() : null;
} else if (StringUtils.equals(Result.RELEVANCE, incomingPropertyName)) {
mappedPropertyName = StringUtils.isNotBlank(metacardToFeaturePropertyMapper.getSortByRelevanceFeatureProperty()) ? metacardToFeaturePropertyMapper.getSortByRelevanceFeatureProperty() : null;
} else if (StringUtils.equals(Result.DISTANCE, incomingPropertyName)) {
mappedPropertyName = StringUtils.isNotBlank(metacardToFeaturePropertyMapper.getSortByDistanceFeatureProperty()) ? metacardToFeaturePropertyMapper.getSortByDistanceFeatureProperty() : null;
} else {
mappedPropertyName = null;
}
} else {
mappedPropertyName = null;
}
return mappedPropertyName;
}
use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.
the class WfsSource method lookupFeatureConverter.
private void lookupFeatureConverter(String ftSimpleName, FeatureMetacardType ftMetacard) {
FeatureConverter featureConverter = null;
/**
* The list of feature converter factories injected into this class is a live list. So, feature converter factories
* can be added and removed from the system while running.
*/
if (CollectionUtils.isNotEmpty(featureConverterFactories)) {
for (FeatureConverterFactory factory : featureConverterFactories) {
if (ftSimpleName.equalsIgnoreCase(factory.getFeatureType())) {
featureConverter = factory.createConverter();
break;
}
}
}
// Found a specific feature converter
if (featureConverter != null) {
LOGGER.debug("WFS Source {}: Features of type: {} will be converted using {}", getId(), ftSimpleName, featureConverter.getClass().getSimpleName());
} else {
LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftSimpleName);
// Since we have no specific converter, we will check to see if we have a mapper to do
// feature property to metacard attribute mappings.
MetacardMapper featurePropertyToMetacardAttributeMapper = lookupMetacardAttributeToFeaturePropertyMapper(ftMetacard.getFeatureType());
if (featurePropertyToMetacardAttributeMapper != null) {
featureConverter = new GenericFeatureConverterWfs20(featurePropertyToMetacardAttributeMapper);
LOGGER.debug("WFS Source {}: Created {} for feature type {} with feature property to metacard attribute mapper.", getId(), featureConverter.getClass().getSimpleName(), ftSimpleName);
} else {
featureConverter = new GenericFeatureConverterWfs20();
LOGGER.debug("WFS Source {}: Created {} for feature type {} with no feature property to metacard attribute mapper.", getId(), featureConverter.getClass().getSimpleName(), ftSimpleName);
}
}
featureConverter.setSourceId(getId());
featureConverter.setMetacardType(ftMetacard);
featureConverter.setWfsUrl(wfsUrl);
featureConverter.setCoordinateOrder(coordinateOrder);
// Add the Feature Type name as an alias for xstream
LOGGER.debug("Registering feature converter {} for feature type {}.", featureConverter.getClass().getSimpleName(), ftSimpleName);
getFeatureCollectionReader().registerConverter(featureConverter);
}
Aggregations