Search in sources :

Example 1 with GmlGeometryConverter

use of org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter 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 GenericFeatureConverter());
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias(FEATURE_TYPE, Metacard.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set_1.xml");
    try {
        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) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with GmlGeometryConverter

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

the class TestGenericFeatureConverter method testUnmarshalFeatureCollectionUnsupportedProjectionXmlToObject.

@Test
public void testUnmarshalFeatureCollectionUnsupportedProjectionXmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs10 fcConverter = new FeatureCollectionConverterWfs10();
    Map<String, FeatureConverter> fcMap = new HashMap<>();
    GenericFeatureConverter converter = new GenericFeatureConverter("CUSTOM UNSUPPORTED PROJECTION");
    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(), nullValue());
}
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 3 with GmlGeometryConverter

use of org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter 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 FeatureCollectionConverterWfs10());
    xstream.registerConverter(new GenericFeatureConverter());
    xstream.registerConverter(new GmlGeometryConverter());
    // Required the Implementing class. The interface would not work...
    xstream.alias("wfs:FeatureCollection", WfsFeatureCollection.class);
    Metacard mc = new SampleMetacard().getMetacard();
    WfsFeatureCollection wfc = new WfsFeatureCollection();
    wfc.getFeatureMembers().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.getFeatureMembers().add(mc2);
    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) 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) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) EnhancedStaxDriver(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.EnhancedStaxDriver) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection) Test(org.junit.Test)

Example 4 with GmlGeometryConverter

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

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

the class TestGenericFeatureConverter method testUnmarshalSingleFeatureXmlToObject.

@Test
//DDF-733
@Ignore
public void testUnmarshalSingleFeatureXmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    MetacardType metacardType = buildMetacardType();
    GenericFeatureConverter converter = new GenericFeatureConverter();
    converter.setMetacardType(buildMetacardType());
    converter.setSourceId(SOURCE_ID);
    xstream.registerConverter(converter);
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias(FEATURE_TYPE, MetacardImpl.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set_1.xml");
    Metacard mc = (Metacard) xstream.fromXML(is);
    assertThat(mc.getId(), is("video_data_set.2"));
    assertThat(mc.getContentTypeName(), is(FEATURE_TYPE));
    assertThat(mc.getMetacardType().getName(), is(metacardType.getName()));
    assertThat(mc.getSourceId(), is(SOURCE_ID));
    assertThat(mc.getAttribute(Core.TITLE).getValue(), is("video_data_set.2"));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + ID_ELEMENT).getValue(), is(2L));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + VERSION_ELEMENT).getValue(), is(1L));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + END_DATE_ELEMENT).getValue(), is(DatatypeConverter.parseDateTime("2005-04-07T09:54:38.983").getTime()));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + FILENAME_ELEMENT).getValue(), is("/data/test_suite/video/video/videoFile.mpg"));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + HEIGHT_ELEMENT).getValue(), is(720L));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + INDEX_ID_ELEMENT).getValue(), is("a8a55092f0afae881099637ef7746cd8d7066270d9af4cf0f52c41dab53c4005"));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + OTHER_TAGS_XML_ELEMENT).getValue(), is(getOtherTagsXml()));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + REPOSITORY_ID_ELEMENT).getValue(), is(26L));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + START_DATE_ELEMENT).getValue(), is(DatatypeConverter.parseDateTime("2005-04-07T09:53:39.000").getTime()));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + WIDTH_ELEMENT).getValue(), is(1280L));
    assertThat(mc.getAttribute(Core.LOCATION).getValue(), is(getLocation()));
    assertThat(mc.getAttribute(PROPERTY_PREFIX + GROUND_GEOM_ELEMENT).getValue(), is(mc.getLocation()));
    assertThat(mc.getEffectiveDate(), notNullValue());
    assertThat(mc.getAttribute(Core.CREATED), notNullValue());
    assertThat(mc.getAttribute(Core.MODIFIED), notNullValue());
    assertThat(mc.getContentTypeNamespace(), notNullValue());
    assertThat(mc.getContentTypeNamespace().toString(), is(WfsConstants.NAMESPACE_URN_ROOT + metacardType.getName()));
}
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) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

XStream (com.thoughtworks.xstream.XStream)10 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)10 Test (org.junit.Test)10 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)8 Metacard (ddf.catalog.data.Metacard)8 InputStream (java.io.InputStream)8 GenericFeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter)6 MetacardType (ddf.catalog.data.MetacardType)4 HashMap (java.util.HashMap)4 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)4 WfsFeatureCollection (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection)4 FeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter)4 Wfs20FeatureCollection (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection)3 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 Set (java.util.Set)2 EnhancedStaxDriver (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.EnhancedStaxDriver)2 Ignore (org.junit.Ignore)2