Search in sources :

Example 76 with MetacardType

use of ddf.catalog.data.MetacardType 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 77 with MetacardType

use of ddf.catalog.data.MetacardType 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)

Example 78 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestGeoJsonMetacardTransformer method testWithMultiValueAttributes.

@Test
public void testWithMultiValueAttributes() throws Exception {
    Set<AttributeDescriptor> descriptors = new HashSet(BasicTypes.BASIC_METACARD.getAttributeDescriptors());
    descriptors.add(new AttributeDescriptorImpl("multi-string", true, true, false, true, /* multivalued */
    BasicTypes.STRING_TYPE));
    MetacardType type = new MetacardTypeImpl("multi", descriptors);
    MetacardImpl metacard = new MetacardImpl(type);
    metacard.setAttribute("multi-string", (Serializable) Arrays.asList("foo", "bar"));
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    String jsonText = new String(content.getByteArray());
    JSONObject json = (JSONObject) PARSER.parse(jsonText);
    Map properties = (Map) json.get("properties");
    List<String> strings = (List<String>) properties.get("multi-string");
    assertThat(strings.get(0), is("foo"));
    assertThat(strings.get(1), is("bar"));
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) JSONObject(org.json.simple.JSONObject) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 79 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestMetacardTypeAdapter method testUnmarshalWithNullRegisteredMetacardTypes.

@Test
public void testUnmarshalWithNullRegisteredMetacardTypes() throws CatalogTransformerException {
    MetacardTypeAdapter metacardTypeAdpater = new MetacardTypeAdapter(NULL_METACARD_TYPES_LIST);
    MetacardType metacardType = metacardTypeAdpater.unmarshal(UNKNOWN_TYPE_NAME);
    assertThat(metacardType.getName(), is(BasicTypes.BASIC_METACARD.getName()));
}
Also used : MetacardTypeAdapter(ddf.catalog.transformer.xml.adapter.MetacardTypeAdapter) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 80 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestXmlResponseQueueTransformer method getMetacardTypeStub.

/**
     * @return
     */
private MetacardType getMetacardTypeStub(String name, Set<AttributeDescriptor> descriptors) {
    MetacardType type = mock(MetacardType.class);
    when(type.getName()).thenReturn(name);
    when(type.getAttributeDescriptors()).thenReturn(descriptors);
    return type;
}
Also used : MetacardType(ddf.catalog.data.MetacardType)

Aggregations

MetacardType (ddf.catalog.data.MetacardType)88 Test (org.junit.Test)57 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)41 Metacard (ddf.catalog.data.Metacard)35 ArrayList (java.util.ArrayList)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)17 HashSet (java.util.HashSet)15 Attribute (ddf.catalog.data.Attribute)12 Serializable (java.io.Serializable)10 IOException (java.io.IOException)8 Date (java.util.Date)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)7 InputStream (java.io.InputStream)7 Set (java.util.Set)7 ContentItem (ddf.catalog.content.data.ContentItem)6 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)6