Search in sources :

Example 56 with AttributeDescriptor

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

the class MetacardTypeRegistryTest method setupMetacardTypeRegistry.

@BeforeClass
public static void setupMetacardTypeRegistry() throws Exception {
    mtr = MetacardTypeRegistryImpl.getInstance();
    qmtAttributes = new HashSet<AttributeDescriptor>();
    AttributeDescriptor ad1 = new AttributeDescriptorImpl(GEO_ATTRIBUTE_DESCRIPTOR_NAME, true, true, false, false, BasicTypes.GEO_TYPE);
    qmtAttributes.add(ad1);
    AttributeDescriptor ad2 = new AttributeDescriptorImpl(METADATA_ATTRIBUTE_DESCRIPTOR_NAME, true, true, false, false, BasicTypes.XML_TYPE);
    qmtAttributes.add(ad2);
    QualifiedMetacardTypeImpl qmt1 = new QualifiedMetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAMESPACE_1, QUALIFIED_METACARD_TYPE_NAME_1, qmtAttributes);
    mtr.register(qmt1);
    QualifiedMetacardTypeImpl qmt2 = new QualifiedMetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAMESPACE_1, QUALIFIED_METACARD_TYPE_NAME_2, qmtAttributes);
    mtr.register(qmt2);
    QualifiedMetacardTypeImpl qmt3 = new QualifiedMetacardTypeImpl(QualifiedMetacardType.DEFAULT_METACARD_TYPE_NAMESPACE, QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    mtr.register(qmt3);
}
Also used : QualifiedMetacardTypeImpl(ddf.catalog.data.impl.QualifiedMetacardTypeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) BeforeClass(org.junit.BeforeClass)

Example 57 with AttributeDescriptor

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

the class CswMarshallHelper method writeBoundingBox.

static void writeBoundingBox(HierarchicalStreamWriter writer, MarshallingContext context, Metacard metacard) {
    Set<AttributeDescriptor> attrDescs = metacard.getMetacardType().getAttributeDescriptors();
    List<Geometry> geometries = new LinkedList<>();
    for (AttributeDescriptor ad : attrDescs) {
        if (ad.getType() != null && AttributeType.AttributeFormat.GEOMETRY.equals(ad.getType().getAttributeFormat())) {
            Attribute attr = metacard.getAttribute(ad.getName());
            if (attr != null) {
                if (ad.isMultiValued()) {
                    for (Serializable value : attr.getValues()) {
                        geometries.add(XmlNode.readGeometry((String) value));
                    }
                } else {
                    geometries.add(XmlNode.readGeometry((String) attr.getValue()));
                }
            }
        }
    }
    Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), new GeometryFactory());
    Envelope bounds = allGeometry.getEnvelopeInternal();
    if (!bounds.isNull()) {
        String bbox = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_BOUNDING_BOX;
        String lower = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_LOWER_CORNER;
        String upper = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_UPPER_CORNER;
        writer.startNode(bbox);
        writer.addAttribute(CswConstants.CRS, CswConstants.SRS_URL);
        writer.startNode(lower);
        writer.setValue(bounds.getMinX() + " " + bounds.getMinY());
        writer.endNode();
        writer.startNode(upper);
        writer.setValue(bounds.getMaxX() + " " + bounds.getMaxY());
        writer.endNode();
        writer.endNode();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Serializable(java.io.Serializable) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Envelope(com.vividsolutions.jts.geom.Envelope) LinkedList(java.util.LinkedList)

Example 58 with AttributeDescriptor

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

the class CswMarshallHelper method writeFields.

static void writeFields(HierarchicalStreamWriter writer, MarshallingContext context, MetacardImpl metacard, List<QName> fieldsToWrite) {
    for (QName qName : fieldsToWrite) {
        if (qName != null && !qName.equals(CswConstants.OWS_BOUNDING_BOX_QNAME)) {
            String attrName = DefaultCswRecordMap.getDefaultCswRecordMap().getDefaultMetacardFieldFor(qName);
            AttributeDescriptor ad = metacard.getMetacardType().getAttributeDescriptor(attrName);
            /*  Backwards Compatibility */
            if (ad == null) {
                ad = BasicTypes.BASIC_METACARD.getAttributeDescriptor(attrName);
            }
            writeAttribute(writer, context, metacard, ad, qName);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 59 with AttributeDescriptor

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

the class CqlResult method metacardToMap.

private Map<String, Object> metacardToMap(Result result) {
    Map<String, Object> geoJson = null;
    MetacardImpl resultMetacard = new MetacardImpl(result.getMetacard(), result.getMetacard().getMetacardType());
    try {
        for (AttributeDescriptor descriptor : resultMetacard.getMetacardType().getAttributeDescriptors()) {
            switch(descriptor.getType().getAttributeFormat()) {
                case BINARY:
                case XML:
                case OBJECT:
                    resultMetacard.setAttribute(descriptor.getName(), null);
                default:
                    break;
            }
        }
        geoJson = PropertyJsonMetacardTransformer.convertToJSON(resultMetacard, ImmutableList.of(AttributeType.AttributeFormat.BINARY, AttributeType.AttributeFormat.XML, AttributeType.AttributeFormat.OBJECT));
        addCachedDate(resultMetacard, geoJson);
    } catch (CatalogTransformerException e) {
        LOGGER.debug("Unable to convert metacard to GeoJSON", e);
    }
    return geoJson;
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 60 with AttributeDescriptor

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

the class TestXmlResponseQueueTransformer method givenMetacardTypeName.

private SourceResponse givenMetacardTypeName(String metacardTypeName) {
    MetacardType type = getMetacardTypeStub(metacardTypeName, new HashSet<AttributeDescriptor>());
    Metacard metacard = new MetacardImpl(type);
    SourceResponse response = new SourceResponseImpl(null, Arrays.asList((Result) new ResultImpl(metacard)));
    return response;
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

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