Search in sources :

Example 1 with MetacardMapperImpl

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));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) MetacardMapperImpl(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 2 with MetacardMapperImpl

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);
}
Also used : MetacardMapperImpl(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl)

Example 3 with MetacardMapperImpl

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());
}
Also used : FeatureTypeType(net.opengis.wfs.v_2_0_0.FeatureTypeType) WebApplicationException(javax.ws.rs.WebApplicationException) Wfs(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MetacardMapperImpl(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Example 4 with MetacardMapperImpl

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));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) MetacardMapperImpl(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Aggregations

MetacardMapperImpl (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl)4 Query (ddf.catalog.operation.Query)2 QueryRequest (ddf.catalog.operation.QueryRequest)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 Test (org.junit.Test)2 Filter (org.opengis.filter.Filter)2 HashMap (java.util.HashMap)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 QName (javax.xml.namespace.QName)1 FeatureTypeType (net.opengis.wfs.v_2_0_0.FeatureTypeType)1 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)1 XmlSchema (org.apache.ws.commons.schema.XmlSchema)1 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)1 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)1 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)1 DescribeFeatureTypeRequest (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest)1 Wfs (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1