Search in sources :

Example 46 with Attribute

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

the class GmdConverter method buildPaths.

@Override
protected XstreamPathValueTracker buildPaths(MetacardImpl metacard) {
    XstreamPathValueTracker pathValueTracker = new XstreamPathValueTracker();
    pathValueTracker.add(new Path("/MD_Metadata/@xmlns"), GmdConstants.GMD_NAMESPACE);
    pathValueTracker.add(new Path("/MD_Metadata/@xmlns:" + GmdConstants.GCO_PREFIX), GmdConstants.GCO_NAMESPACE);
    pathValueTracker.add(new Path("/MD_Metadata/@xmlns:" + CswConstants.GML_NAMESPACE_PREFIX), CswConstants.GML_SCHEMA);
    pathValueTracker.add(new Path(GmdConstants.FILE_IDENTIFIER_PATH), metacard.getId());
    Attribute language = metacard.getAttribute(Core.LANGUAGE);
    if (language != null) {
        addListAttributeToXml(metacard, pathValueTracker, GmdConstants.METADATA_LANGUAGE_PATH, Core.LANGUAGE);
    } else {
        pathValueTracker.add(new Path(GmdConstants.METADATA_LANGUAGE_PATH), Locale.ENGLISH.getISO3Language());
    }
    pathValueTracker.add(new Path(GmdConstants.CODE_LIST_VALUE_PATH), StringUtils.defaultIfEmpty(metacard.getContentTypeName(), DataType.DATASET.toString()));
    pathValueTracker.add(new Path(GmdConstants.CODE_LIST_PATH), GmdConstants.METACARD_URI);
    addStringAttributeToXml(metacard, pathValueTracker, GmdConstants.CODE_LIST_VALUE_PATH, Core.DATATYPE, Metacard.CONTENT_TYPE);
    pathValueTracker.add(new Path(GmdConstants.CODE_LIST_PATH), GmdConstants.METACARD_URI);
    addListAttributeToXml(metacard, pathValueTracker, GmdConstants.CONTACT_ORGANISATION_PATH, Contact.POINT_OF_CONTACT_NAME);
    addListAttributeToXml(metacard, pathValueTracker, GmdConstants.CONTACT_EMAIL_PATH, Contact.POINT_OF_CONTACT_EMAIL);
    addListAttributeToXml(metacard, pathValueTracker, GmdConstants.CONTACT_PHONE_PATH, Contact.POINT_OF_CONTACT_PHONE);
    addListAttributeToXml(metacard, pathValueTracker, GmdConstants.CONTACT_ADDRESS_DELIVERY_POINT_PATH, Contact.POINT_OF_CONTACT_ADDRESS);
    addDateAttributeToXml(metacard, pathValueTracker, GmdConstants.DATE_TIME_STAMP_PATH, Core.METACARD_MODIFIED);
    addCRSInformation(metacard, pathValueTracker);
    addIdentificationInfo(metacard, pathValueTracker);
    addDistributionInfo(metacard, pathValueTracker);
    return pathValueTracker;
}
Also used : Path(com.thoughtworks.xstream.io.path.Path) Attribute(ddf.catalog.data.Attribute)

Example 47 with Attribute

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

the class GmdConverter method addDateAttributeToXml.

private void addDateAttributeToXml(Metacard metacard, XstreamPathValueTracker pathValueTracker, String path, String metcardAttributeName) {
    Attribute attribute = metacard.getAttribute(metcardAttributeName);
    if (attribute != null) {
        Serializable serializable = attribute.getValue();
        if (serializable instanceof Date) {
            GregorianCalendar modifiedCal = new GregorianCalendar();
            modifiedCal.setTime((Date) serializable);
            modifiedCal.setTimeZone(UTC_TIME_ZONE);
            pathValueTracker.add(new Path(path), XSD_FACTORY.newXMLGregorianCalendar(modifiedCal).toXMLFormat());
        }
    }
}
Also used : Path(com.thoughtworks.xstream.io.path.Path) Serializable(java.io.Serializable) Attribute(ddf.catalog.data.Attribute) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 48 with Attribute

use of ddf.catalog.data.Attribute 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 49 with Attribute

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

the class AttributeMetacardFormatter method doFormat.

@Override
protected String doFormat(String template, WorkspaceMetacardImpl workspaceMetacard, Long hitCount) {
    int iterationCount = 0;
    String tmp = template;
    Matcher m = PATTERN.matcher(tmp);
    while (m.matches() && (++iterationCount < MAX_ITERATIONS)) {
        String attributeName = m.group(CAPTURE_GROUP);
        String replacement = defaultReplacement;
        Attribute attribute = workspaceMetacard.getAttribute(attributeName);
        if (attribute != null) {
            List<Serializable> serializables = attribute.getValues();
            if (serializables != null) {
                replacement = StringUtils.join(serializables, LIST_SEPARATOR);
            }
        }
        tmp = tmp.replace(PREFIX + attributeName + SUFFIX, replacement);
        m = PATTERN.matcher(tmp);
    }
    return tmp;
}
Also used : Serializable(java.io.Serializable) Matcher(java.util.regex.Matcher) Attribute(ddf.catalog.data.Attribute)

Example 50 with Attribute

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

the class ZipCompression method getAllMetacardContent.

private Map<String, Resource> getAllMetacardContent(Metacard metacard) {
    Map<String, Resource> resourceMap = new HashMap<>();
    Attribute attribute = metacard.getAttribute(Metacard.DERIVED_RESOURCE_URI);
    if (attribute != null) {
        List<Serializable> serializables = attribute.getValues();
        serializables.forEach(serializable -> {
            String fragment = ZipDecompression.CONTENT + File.separator;
            URI uri = null;
            try {
                uri = new URI((String) serializable);
                String derivedResourceFragment = uri.getFragment();
                if (ContentItem.CONTENT_SCHEME.equals(uri.getScheme()) && StringUtils.isNotBlank(derivedResourceFragment)) {
                    fragment += derivedResourceFragment + File.separator;
                    Resource resource = getResource(metacard);
                    if (resource != null) {
                        resourceMap.put(fragment + uri.getSchemeSpecificPart() + "-" + resource.getName(), resource);
                    }
                }
            } catch (URISyntaxException e) {
                LOGGER.debug("Invalid Derived Resource URI Syntax for metacard : {}", metacard.getId(), e);
            }
        });
    }
    URI resourceUri = metacard.getResourceURI();
    Resource resource = getResource(metacard);
    if (resource != null) {
        resourceMap.put(ZipDecompression.CONTENT + File.separator + resourceUri.getSchemeSpecificPart() + "-" + resource.getName(), resource);
    }
    return resourceMap;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) Resource(ddf.catalog.resource.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

Attribute (ddf.catalog.data.Attribute)103 Metacard (ddf.catalog.data.Metacard)39 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)30 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)29 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)26 Serializable (java.io.Serializable)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 HashMap (java.util.HashMap)15 Result (ddf.catalog.data.Result)14 List (java.util.List)14 MetacardType (ddf.catalog.data.MetacardType)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 Date (java.util.Date)11 Map (java.util.Map)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)8 Set (java.util.Set)8 Filter (org.opengis.filter.Filter)8 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)7