Search in sources :

Example 6 with GenericFeatureConverterWfs20

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.impl.GenericFeatureConverterWfs20 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 7 with GenericFeatureConverterWfs20

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.impl.GenericFeatureConverterWfs20 in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalNoMetacardTypeRegisteredInConverter.

@Test(expected = IllegalArgumentException.class)
public void testUnmarshalNoMetacardTypeRegisteredInConverter() throws Throwable {
    XStream xstream = new XStream(new WstxDriver());
    xstream.registerConverter(new GenericFeatureConverterWfs20());
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias(FEATURE_TYPE, Metacard.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set.xml");
    try {
        Wfs20FeatureCollection wfs = (Wfs20FeatureCollection) xstream.fromXML(is);
    } catch (Exception e) {
        throw e.getCause();
    }
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) Test(org.junit.Test)

Example 8 with GenericFeatureConverterWfs20

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.impl.GenericFeatureConverterWfs20 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);
}
Also used : GenericFeatureConverterWfs20(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.impl.GenericFeatureConverterWfs20) FeatureConverterFactory(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.FeatureConverterFactory) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Aggregations

XStream (com.thoughtworks.xstream.XStream)7 Wfs20FeatureCollection (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection)7 Test (org.junit.Test)7 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)6 Metacard (ddf.catalog.data.Metacard)6 InputStream (java.io.InputStream)6 FeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter)6 HashMap (java.util.HashMap)5 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)3 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)2 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 MetacardType (ddf.catalog.data.MetacardType)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 Set (java.util.Set)1 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)1 EnhancedStaxDriver (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.EnhancedStaxDriver)1 FeatureConverterFactory (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.FeatureConverterFactory)1 GenericFeatureConverterWfs20 (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.impl.GenericFeatureConverterWfs20)1