use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl in project ddf by codice.
the class WfsSourceTest method testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties.
@Test
public void testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties() throws Exception {
final MetacardMapperImpl metacardMapper = new MetacardMapperImpl();
metacardMapper.setFeatureType("SampleFeature0");
metacardMapper.setTitleMapping("orderperson");
metacardMapper.setResourceUriMapping("orderdog");
metacardMappers.add(metacardMapper);
mapSchemaToFeatures(TWO_TEXT_PROPERTY_SCHEMA, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
final Filter filter = builder.allOf(builder.attribute(Core.TITLE).is().equalTo().text("something"), builder.attribute(Core.RESOURCE_URI).is().equalTo().text("anything"));
final Query query = new QueryImpl(filter);
final QueryRequest queryRequest = new QueryRequestImpl(query);
source.query(queryRequest);
final ArgumentCaptor<ExtendedGetFeatureType> getFeatureCaptor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
verify(mockWfs, times(2)).getFeature(getFeatureCaptor.capture());
ExtendedGetFeatureType getFeatureType = getFeatureCaptor.getAllValues().get(1);
final String getFeatureXml = marshal(getFeatureType);
assertThat(getFeatureXml, hasXPath("/wfs:GetFeature/wfs:Query/ogc:Filter/ogc:And/ogc:PropertyIsEqualTo[ogc:PropertyName='orderperson' and ogc:Literal='something']").withNamespaceContext(NAMESPACE_CONTEXT));
assertThat(getFeatureXml, hasXPath("/wfs:GetFeature/wfs:Query/ogc:Filter/ogc:And/ogc:PropertyIsEqualTo[ogc:PropertyName='orderdog' and ogc:Literal='anything']").withNamespaceContext(NAMESPACE_CONTEXT));
}
use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl in project ddf by codice.
the class WfsSourceTest method setupMapper.
private void setupMapper(String temporalSortProperty, String relevanceSortProperty, String distanceSortProperty) {
final MetacardMapperImpl metacardMapper = new MetacardMapperImpl();
metacardMapper.setSortByTemporalFeatureProperty(temporalSortProperty);
metacardMapper.setSortByDistanceFeatureProperty(distanceSortProperty);
metacardMapper.setSortByRelevanceFeatureProperty(relevanceSortProperty);
metacardMapper.setFeatureType("SampleFeature0");
metacardMappers.add(metacardMapper);
}
use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl in project ddf by codice.
the class WfsSource method buildFeatureFilters.
private void buildFeatureFilters(List<FeatureTypeType> featureTypes, FilterCapabilities filterCapabilities) {
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<>();
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(), metacardToFeatureMappers);
if (metacardAttributeToFeaturePropertyMapper == null) {
LOGGER.debug("Unable to find a metacard mapper for featureType {} - using a default implementation", featureMetacardType.getFeatureType());
metacardAttributeToFeaturePropertyMapper = new MetacardMapperImpl();
}
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.impl.MetacardMapperImpl in project ddf by codice.
the class WfsSourceTest method testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties.
@Test
public void testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties() throws Exception {
final MetacardMapperImpl metacardMapper = new MetacardMapperImpl();
metacardMapper.setFeatureType("{http://example.com}SampleFeature0");
metacardMapper.setResourceUriMapping("title");
metacardMappers.add(metacardMapper);
final WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 1, false, false, 1);
final Filter filter = builder.attribute(Core.RESOURCE_URI).is().equalTo().text("anything");
final Query query = new QueryImpl(filter);
final QueryRequest queryRequest = new QueryRequestImpl(query);
source.query(queryRequest);
final ArgumentCaptor<GetFeatureType> getFeatureCaptor = ArgumentCaptor.forClass(GetFeatureType.class);
verify(mockWfs).getFeature(getFeatureCaptor.capture());
final GetFeatureType getFeatureType = getFeatureCaptor.getValue();
final String getFeatureXml = marshal(getFeatureType);
assertThat(getFeatureXml, hasXPath("/wfs:GetFeature/wfs:Query/ogc:Filter/ogc:PropertyIsEqualTo[ogc:ValueReference='title' and ogc:Literal='anything']").withNamespaceContext(NAMESPACE_CONTEXT));
}
Aggregations