Search in sources :

Example 6 with FeatureConverter

use of org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalFeatureCollectionXmlToObject.

@Test
public void testUnmarshalFeatureCollectionXmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs20 fcConverter = new FeatureCollectionConverterWfs20();
    Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
    fcMap.put("video_data_set", converter);
    fcConverter.setFeatureConverterMap(fcMap);
    xstream.registerConverter(fcConverter);
    converter.setMetacardType(buildMetacardType());
    converter.setCoordinateOrder(GeospatialUtil.LAT_LON_ORDER);
    xstream.registerConverter(converter);
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias("FeatureCollection", Wfs20FeatureCollection.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set_collection.xml");
    Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
    assertEquals(4, wfc.getMembers().size());
    Metacard mc = wfc.getMembers().get(0);
    assertEquals(mc.getId(), "video_data_set.1");
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) HashMap(java.util.HashMap) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) Test(org.junit.Test)

Example 7 with FeatureConverter

use of org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter in project ddf by codice.

the class TestGenericFeatureConverter method testGeoServerLatLonSwappingForMultiPolygon.

@Test
public void testGeoServerLatLonSwappingForMultiPolygon() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs20 fcConverter = new FeatureCollectionConverterWfs20();
    Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
    fcMap.put("states", converter);
    fcMap.put("streams", converter);
    fcConverter.setFeatureConverterMap(fcMap);
    xstream.registerConverter(fcConverter);
    converter.setMetacardType(buildStatesMetacardType());
    converter.setCoordinateOrder(GeospatialUtil.LAT_LON_ORDER);
    xstream.registerConverter(converter);
    xstream.alias("FeatureCollection", Wfs20FeatureCollection.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/geoserver_sample_polygon.xml");
    Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
    assertEquals(1, wfc.getMembers().size());
    Metacard mc = wfc.getMembers().get(0);
    assertEquals(mc.getId(), "states.10");
    // Verifies that lat/lon was swapped to lon/lat order for the WKT conversion
    // to set the metacard's location
    assertTrue(mc.getLocation().startsWith("MULTIPOLYGON (((-89.1 36.1, -89.1 37.1, -88.1 37.1, -88.1 36.1, -89.1 36.1"));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) Test(org.junit.Test)

Example 8 with FeatureConverter

use of org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter in project ddf by codice.

the class WfsSource method buildFeatureFilters.

private void buildFeatureFilters(List<FeatureTypeType> featureTypes, List<String> supportedGeo) throws SecurityServiceException {
    // 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>();
    Wfs wfs = factory.getClient();
    for (FeatureTypeType featureTypeType : featureTypes) {
        String ftName = featureTypeType.getName().getLocalPart();
        if (StringUtils.isNotBlank(forcedFeatureType) && !StringUtils.equals(forcedFeatureType, ftName)) {
            continue;
        }
        if (mcTypeRegs.containsKey(ftName)) {
            LOGGER.debug("WfsSource {}: MetacardType {} is already registered - skipping to next metacard type", getId(), ftName);
            continue;
        }
        LOGGER.debug("ftName: {}", ftName);
        try {
            XmlSchema schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(featureTypeType.getName()));
            if ((schema != null)) {
                FeatureMetacardType ftMetacard = new FeatureMetacardType(schema, featureTypeType.getName(), nonQueryableProperties != null ? Arrays.asList(nonQueryableProperties) : new ArrayList<String>(), Wfs10Constants.GML_NAMESPACE);
                Dictionary<String, Object> props = new Hashtable<String, Object>();
                props.put(Metacard.CONTENT_TYPE, new String[] { ftName });
                LOGGER.debug("WfsSource {}: Registering MetacardType: {}", getId(), ftName);
                // Update local map with enough info to create actual MetacardType registrations
                // later
                mcTypeRegs.put(ftName, new MetacardTypeRegistration(ftMetacard, props, featureTypeType.getSRS()));
                FeatureConverter featureConverter = null;
                if (!CollectionUtils.isEmpty(featureConverterFactories)) {
                    for (FeatureConverterFactory factory : featureConverterFactories) {
                        if (ftName.equalsIgnoreCase(factory.getFeatureType())) {
                            featureConverter = factory.createConverter();
                            LOGGER.debug("WFS Source {}: Features of type: {} will be converted using {}", getId(), ftName, featureConverter.getClass().getSimpleName());
                            break;
                        }
                    }
                    if (featureConverter == null) {
                        LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftName);
                        featureConverter = new GenericFeatureConverter(featureTypeType.getSRS());
                    }
                } else {
                    LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftName);
                    featureConverter = new GenericFeatureConverter(featureTypeType.getSRS());
                }
                featureConverter.setSourceId(getId());
                featureConverter.setMetacardType(ftMetacard);
                featureConverter.setWfsUrl(wfsUrl);
                // Add the Feature Type name as an alias for xstream
                featureCollectionReader.registerConverter(featureConverter);
            }
        } catch (WfsException | IllegalArgumentException wfse) {
            LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
        } catch (WebApplicationException wae) {
            LOGGER.debug(handleWebApplicationException(wae), wae);
        }
    }
    // Unregister all MetacardType services - the DescribeFeatureTypeRequest should
    // have returned all of the most current metacard types that will now be registered.
    // As Source(s) are added/removed from this instance or to other Source(s)
    // that this instance is federated to, the list of metacard types will change.
    // This is done here vs. inside the above loop so that minimal time is spent clearing and
    // registering the MetacardTypes - the concern is that if this registration is too lengthy
    // a query could come in that is handled while the MetacardType registrations are
    // in a state of flux.
    unregisterAllMetacardTypes();
    this.featureTypeFilters.clear();
    if (!mcTypeRegs.isEmpty()) {
        Set<Entry<String, MetacardTypeRegistration>> entries = mcTypeRegs.entrySet();
        for (Map.Entry<String, MetacardTypeRegistration> entry : mcTypeRegs.entrySet()) {
            MetacardTypeRegistration mcTypeReg = entry.getValue();
            FeatureMetacardType ftMetacard = mcTypeReg.getFtMetacard();
            ServiceRegistration serviceRegistration = context.registerService(MetacardType.class.getName(), ftMetacard, mcTypeReg.getProps());
            this.metacardTypeServiceRegistrations.put(entry.getKey(), serviceRegistration);
            this.featureTypeFilters.put(ftMetacard.getFeatureType(), new WfsFilterDelegate(ftMetacard, supportedGeo, mcTypeReg.getSrs()));
        }
    }
    if (featureTypeFilters.isEmpty()) {
        LOGGER.info("Wfs Source {}: No Feature Type schemas validated. Marking source as unavailable", getId());
    }
    LOGGER.debug("Wfs Source {}: Number of validated Features = {}", getId(), featureTypeFilters.size());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) FeatureConverterFactory(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.converter.FeatureConverterFactory) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) ServiceRegistration(org.osgi.framework.ServiceRegistration) FeatureTypeType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType) Wfs(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs) Hashtable(java.util.Hashtable) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with FeatureConverter

use of org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalFeatureCollectionXmlToObject.

@Test
public void testUnmarshalFeatureCollectionXmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs10 fcConverter = new FeatureCollectionConverterWfs10();
    Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
    GenericFeatureConverter converter = new GenericFeatureConverter();
    fcMap.put("video_data_set", converter);
    fcConverter.setFeatureConverterMap(fcMap);
    xstream.registerConverter(fcConverter);
    converter.setMetacardType(buildMetacardType());
    xstream.registerConverter(converter);
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias("FeatureCollection", WfsFeatureCollection.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set_collection.xml");
    WfsFeatureCollection wfc = (WfsFeatureCollection) xstream.fromXML(is);
    assertThat(wfc.getFeatureMembers(), hasSize(4));
    Metacard mc = wfc.getFeatureMembers().get(0);
    assertThat(mc.getId(), is("video_data_set.1"));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) HashMap(java.util.HashMap) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) Test(org.junit.Test)

Example 10 with FeatureConverter

use of org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalFeatureCollectionNonWGS84XmlToObject.

@Test
public void testUnmarshalFeatureCollectionNonWGS84XmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs10 fcConverter = new FeatureCollectionConverterWfs10();
    Map<String, FeatureConverter> fcMap = new HashMap<>();
    GenericFeatureConverter converter = new GenericFeatureConverter("EPSG:26713");
    fcMap.put("video_data_set", converter);
    fcConverter.setFeatureConverterMap(fcMap);
    xstream.registerConverter(fcConverter);
    converter.setMetacardType(buildMetacardType());
    xstream.registerConverter(converter);
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias("FeatureCollection", WfsFeatureCollection.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set_2.xml");
    WfsFeatureCollection wfc = (WfsFeatureCollection) xstream.fromXML(is);
    assertThat(wfc.getFeatureMembers(), hasSize(1));
    Metacard mc = wfc.getFeatureMembers().get(0);
    assertThat(mc.getId(), is("video_data_set.1"));
    assertThat(mc.getLocation(), is("MULTILINESTRING ((-103.85275410013904 44.48520433037816, -103.85142707963864 44.48544013668279))"));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) HashMap(java.util.HashMap) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) Test(org.junit.Test)

Aggregations

FeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter)10 HashMap (java.util.HashMap)9 XStream (com.thoughtworks.xstream.XStream)8 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)8 Metacard (ddf.catalog.data.Metacard)8 InputStream (java.io.InputStream)8 Test (org.junit.Test)8 Wfs20FeatureCollection (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection)5 GenericFeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter)4 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)4 WfsFeatureCollection (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection)3 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)2 MetacardType (ddf.catalog.data.MetacardType)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 FeatureTypeType (ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType)1 XmlSchema (org.apache.ws.commons.schema.XmlSchema)1