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;
}
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());
}
}
}
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();
}
}
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;
}
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;
}
Aggregations