Search in sources :

Example 96 with AttributeDescriptor

use of ddf.catalog.data.AttributeDescriptor 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 97 with AttributeDescriptor

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

the class FeatureMetacardTypeTest method testFeatureMetacardTypeFindTaxonomyMetacardAttributes.

@Test
public void testFeatureMetacardTypeFindTaxonomyMetacardAttributes() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement element = new XmlSchemaElement(schema, true);
    element.setSchemaType(new XmlSchemaSimpleType(schema, false));
    element.setSchemaTypeName(Constants.XSD_STRING);
    element.setName(ELEMENT_NAME);
    schema.getElements().put(new QName(ELEMENT_NAME), element);
    FeatureMetacardType fmt = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs20Constants.GML_3_2_NAMESPACE);
    Set<AttributeDescriptor> descriptors = initDescriptors();
    for (AttributeDescriptor ad : descriptors) {
        assertBasicAttributeDescriptor(fmt, ad.getName(), ad.getType());
        assertFalse(fmt.getAttributeDescriptor(ad.getName()).isStored());
    }
    // +1 to account for one element added to schema.
    assertThat(fmt.getAttributeDescriptors().size(), is(descriptors.size() + 1));
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Example 98 with AttributeDescriptor

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

the class PropertyJsonMetacardTransformer method convertToJSON.

public static Map<String, Object> convertToJSON(Metacard metacard, List<AttributeType.AttributeFormat> dontInclude) throws CatalogTransformerException {
    if (metacard == null) {
        throw new CatalogTransformerException("Cannot transform null metacard.");
    }
    Map<String, Object> rootObject = new HashMap<>();
    Map<String, Object> properties = new HashMap<>();
    for (AttributeDescriptor ad : metacard.getMetacardType().getAttributeDescriptors()) {
        Attribute attribute = metacard.getAttribute(ad.getName());
        if (attribute != null) {
            Object value = convertAttribute(attribute, ad, dontInclude);
            if (value != null) {
                properties.put(attribute.getName(), value);
            }
        }
    }
    properties.put(METACARD_TYPE_PROPERTY_KEY, metacard.getMetacardType().getName());
    if (StringUtils.isNotBlank(metacard.getSourceId())) {
        properties.put(SOURCE_ID_PROPERTY, metacard.getSourceId());
    }
    rootObject.put("properties", properties);
    return rootObject;
}
Also used : HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException)

Example 99 with AttributeDescriptor

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

the class PdfInputTransformer method initializeMetacard.

private MetacardImpl initializeMetacard(String id, String contentInput) {
    MetacardImpl metacard;
    if (StringUtils.isNotBlank(contentInput)) {
        Set<AttributeDescriptor> attributes = contentMetadataExtractors.values().stream().map(ContentMetadataExtractor::getMetacardAttributes).flatMap(Collection::stream).collect(Collectors.toSet());
        metacard = new MetacardImpl(new MetacardTypeImpl(metacardType.getName(), metacardType, attributes));
        for (ContentMetadataExtractor contentMetadataExtractor : contentMetadataExtractors.values()) {
            contentMetadataExtractor.process(contentInput, metacard);
        }
    } else {
        metacard = new MetacardImpl(metacardType);
    }
    metacard.setId(id);
    metacard.setContentTypeName(MediaType.PDF.toString());
    metacard.setAttribute(Media.TYPE, MediaType.PDF.toString());
    metacard.setAttribute(Core.DATATYPE, DataType.DOCUMENT.toString());
    return metacard;
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ContentMetadataExtractor(ddf.catalog.content.operation.ContentMetadataExtractor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 100 with AttributeDescriptor

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

the class Search method getType.

private Map<String, Object> getType(MetacardType metacardType) throws CatalogTransformerException {
    Map<String, Object> fields = new HashMap<>();
    for (AttributeDescriptor descriptor : metacardType.getAttributeDescriptors()) {
        Map<String, Object> description = new HashMap<>();
        description.put(ATTRIBUTE_FORMAT, descriptor.getType().getAttributeFormat().toString());
        description.put(ATTRIBUTE_INDEXED, descriptor.isIndexed());
        fields.put(descriptor.getName(), description);
    }
    return fields;
}
Also used : HashMap(java.util.HashMap) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Aggregations

AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)111 Test (org.junit.Test)51 MetacardType (ddf.catalog.data.MetacardType)40 Metacard (ddf.catalog.data.Metacard)38 HashSet (java.util.HashSet)29 Attribute (ddf.catalog.data.Attribute)26 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)24 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)24 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)24 ArrayList (java.util.ArrayList)23 Serializable (java.io.Serializable)16 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)9 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)7 IOException (java.io.IOException)7 Date (java.util.Date)7 List (java.util.List)7 QName (javax.xml.namespace.QName)7