Search in sources :

Example 76 with AttributeDescriptor

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

the class GenericFeatureConverter method marshal.

/**
     * This method will convert a {@link Metacard} instance into xml that will validate against the
     * GML 2.1.2 AbstractFeatureType.
     *
     * @param value   the {@link Metacard} to convert
     * @param writer  the stream writer responsible for writing this xml doc
     * @param context a reference back to the Xstream marshalling context. Allows you to call
     *                "convertAnother" which will lookup other registered converters.
     */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Metacard metacard = (Metacard) value;
    // TODO when we have a reference to the MCT we can get the namespace too
    QName qname = WfsQnameBuilder.buildQName(metacard.getMetacardType().getName(), metacard.getContentTypeName());
    writer.startNode(qname.getPrefix() + ":" + qname.getLocalPart());
    // Add the "fid" attribute if we have an ID
    String fid = (String) metacard.getAttribute(Metacard.ID).getValue();
    if (fid != null) {
        writer.addAttribute(FID, fid);
    }
    if (null != metacard.getLocation()) {
        Geometry geo = XmlNode.readGeometry(metacard.getLocation());
        if (geo != null && !geo.isEmpty()) {
            XmlNode.writeEnvelope(WfsConstants.GML_PREFIX + ":" + "boundedBy", context, writer, geo.getEnvelopeInternal());
        }
    }
    Set<AttributeDescriptor> descriptors = new TreeSet<AttributeDescriptor>(new AttributeDescriptorComparator());
    descriptors.addAll(metacard.getMetacardType().getAttributeDescriptors());
    for (AttributeDescriptor attributeDescriptor : descriptors) {
        Attribute attribute = metacard.getAttribute(attributeDescriptor.getName());
        if (attribute != null) {
            writeAttributeToXml(attribute, qname, attributeDescriptor.getType().getAttributeFormat(), context, writer);
        }
    }
    writer.endNode();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QName(javax.xml.namespace.QName) TreeSet(java.util.TreeSet) AttributeDescriptorComparator(org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 77 with AttributeDescriptor

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

the class FeatureMetacardType method addDescriptors.

/**
     * we don't want to expose these in a query interface ie wfs endpoint, so we need to create new
     * attributes for each and set them to stored = false note: indexed is being used to determine
     * whether or not to query certain wfs fields so it did not seem appropriate to hide those
     * fields from the endpoint schema
     */
private void addDescriptors(Set<AttributeDescriptor> attrDescriptors) {
    for (AttributeDescriptor descriptor : attrDescriptors) {
        AttributeDescriptorImpl basicAttributeDescriptor = (AttributeDescriptorImpl) descriptor;
        AttributeDescriptor attributeDescriptor = new AttributeDescriptorImpl(basicAttributeDescriptor.getName(), false, false, basicAttributeDescriptor.isTokenized(), basicAttributeDescriptor.isMultiValued(), basicAttributeDescriptor.getType());
        descriptors.add(attributeDescriptor);
    }
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl)

Example 78 with AttributeDescriptor

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

the class AdaptedSourceResponse method getMetacard.

@XmlElement(namespace = METACARD_URI)
public List<MetacardElement> getMetacard() {
    List<MetacardElement> metacards = new ArrayList<MetacardElement>();
    for (Result r : delegate.getResults()) {
        Metacard metacard = r.getMetacard();
        if (metacard == null) {
            continue;
        }
        MetacardElement element = new MetacardElement();
        element.setId(metacard.getId());
        element.setSource(metacard.getSourceId());
        if (metacard.getMetacardType() != null) {
            String metacardTypeName = BasicTypes.BASIC_METACARD.getName();
            if (isNotBlank(metacard.getMetacardType().getName())) {
                metacardTypeName = metacard.getMetacardType().getName();
            }
            element.setType(metacardTypeName);
            AttributeAdapter attributeAdapter = new AttributeAdapter(metacard.getMetacardType());
            for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
                try {
                    element.getAttributes().add(attributeAdapter.marshal(metacard.getAttribute(descriptor.getName())));
                } catch (CatalogTransformerException e) {
                    LOGGER.info("Marshalling error with attribute", e);
                }
            }
        }
        metacards.add(element);
    }
    return metacards;
}
Also used : Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardElement(ddf.catalog.transformer.xml.binding.MetacardElement) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Result(ddf.catalog.data.Result) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 79 with AttributeDescriptor

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

the class AttributeAdapter method marshal.

@Override
public AbstractAttributeType marshal(Attribute attribute) throws CatalogTransformerException {
    if (attribute == null) {
        return null;
    }
    AbstractAttributeType element = null;
    AttributeDescriptor descriptor = metacardType.getAttributeDescriptor(attribute.getName());
    if (descriptor == null || Metacard.ID.equals(descriptor.getName()) || descriptor.getType() == null) {
        return null;
    }
    element = convertAttribute(attribute, descriptor.getType().getAttributeFormat());
    return element;
}
Also used : AbstractAttributeType(ddf.catalog.transformer.xml.binding.AbstractAttributeType) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 80 with AttributeDescriptor

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

the class TestMetacardValueResolver method testResolveType.

@Test
public void testResolveType() {
    MetacardImpl mc = new MetacardImpl();
    String expected = "feature";
    MetacardType expectedType = new MetacardTypeImpl(expected, (Set<AttributeDescriptor>) null);
    mc.setType(expectedType);
    MetacardValueResolver mvr = new MetacardValueResolver();
    Object props = mvr.resolve(mc, "properties");
    Object actual = mvr.resolve(props, "type");
    assertEquals(expected, actual);
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

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