Search in sources :

Example 1 with Wfs20FeatureCollection

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalMultiQueryFeatureCollectionXmlToObjectWithMetacardMapper.

/*
     * This test will check is the MetacardMapper maps the feature value of 'states.STATE_NAME' to the metacard property 'title'.
     */
@Test
public void testUnmarshalMultiQueryFeatureCollectionXmlToObjectWithMetacardMapper() {
    //Create Metacard Mapper
    String featureProp = "ext.states.STATE_NAME";
    String metacardAttr = "title";
    MetacardMapper metacardMapper = mock(MetacardMapper.class);
    when(metacardMapper.getMetacardAttribute(featureProp)).thenReturn(metacardAttr);
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs20 fcConverter = new FeatureCollectionConverterWfs20();
    Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20(metacardMapper);
    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.xml");
    Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
    assertEquals(7, wfc.getMembers().size());
    Metacard mc = wfc.getMembers().get(0);
    assertEquals(mc.getTitle(), "Missouri");
    // 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.104965 36.953869, -89.129585 36.86644, -89.166496 36.843422000000004,"));
}
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) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) Test(org.junit.Test)

Example 2 with Wfs20FeatureCollection

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalMultiQueryFeatureCollectionXmlToObject.

@Test
public void testUnmarshalMultiQueryFeatureCollectionXmlToObject() {
    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.xml");
    Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
    assertEquals(7, 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.104965 36.953869, -89.129585 36.86644, -89.166496 36.843422000000004,"));
}
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 3 with Wfs20FeatureCollection

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection in project ddf by codice.

the class TestGenericFeatureConverter method testMetacardCollectionToFeatureCollectionXml.

@Test
public void testMetacardCollectionToFeatureCollectionXml() {
    XStream xstream = new XStream(new EnhancedStaxDriver());
    xstream.setMode(XStream.NO_REFERENCES);
    xstream.registerConverter(new FeatureCollectionConverterWfs20());
    xstream.registerConverter(new GenericFeatureConverterWfs20());
    xstream.registerConverter(new GmlGeometryConverter());
    // Required the Implementing class. The interface would not work...
    xstream.alias(Wfs20Constants.WFS_NAMESPACE_PREFIX + ":" + "FeatureCollection", Wfs20FeatureCollection.class);
    Metacard mc = new SampleMetacard().getMetacard();
    Wfs20FeatureCollection wfc = new Wfs20FeatureCollection();
    wfc.getMembers().add(mc);
    MetacardImpl mc2 = new SampleMetacard().getMetacard();
    // Ignore the hack stuff, this was just to imitate having two different
    // "MetacardTypes"
    mc2.setType(new MetacardType() {

        @Override
        public String getName() {
            return "otherType";
        }

        @Override
        public Set<AttributeDescriptor> getAttributeDescriptors() {
            return BasicTypes.BASIC_METACARD.getAttributeDescriptors();
        }

        @Override
        public AttributeDescriptor getAttributeDescriptor(String arg0) {
            return BasicTypes.BASIC_METACARD.getAttributeDescriptor(arg0);
        }
    });
    wfc.getMembers().add(mc2);
    String xml = xstream.toXML(wfc);
}
Also used : Set(java.util.Set) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) XStream(com.thoughtworks.xstream.XStream) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Metacard(ddf.catalog.data.Metacard) EnhancedStaxDriver(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.EnhancedStaxDriver) Test(org.junit.Test)

Example 4 with Wfs20FeatureCollection

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection in project ddf by codice.

the class TestGenericFeatureConverter method testGeoServerLatLonSwappingForPoint.

@Test
public void testGeoServerLatLonSwappingForPoint() {
    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_point.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("POINT (-123.26 49.41)"));
}
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 5 with Wfs20FeatureCollection

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection 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)

Aggregations

Wfs20FeatureCollection (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection)11 Metacard (ddf.catalog.data.Metacard)8 XStream (com.thoughtworks.xstream.XStream)7 Test (org.junit.Test)7 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)6 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)5 FeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter)5 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 JAXBException (javax.xml.bind.JAXBException)2 XStreamException (com.thoughtworks.xstream.XStreamException)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 MetacardType (ddf.catalog.data.MetacardType)1 Result (ddf.catalog.data.Result)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 Query (ddf.catalog.operation.Query)1 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)1