use of ddf.catalog.data.Attribute in project ddf by codice.
the class Associated method removeEdge.
private void removeEdge(Edge edge, Map<String, Metacard> metacards, /*Mutable*/
Map<String, Metacard> changedMetacards) {
String id = edge.parent.get(Metacard.ID).toString();
Metacard target = changedMetacards.getOrDefault(id, metacards.get(id));
ArrayList<String> values = Optional.of(target).map(m -> m.getAttribute(edge.relation)).map(Attribute::getValues).map(util::getStringList).orElseGet(ArrayList::new);
values.remove(edge.child.get(Metacard.ID).toString());
target.setAttribute(new AttributeImpl(edge.relation, values));
changedMetacards.put(id, target);
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class Associated method addEdge.
private void addEdge(Edge edge, Map<String, Metacard> metacards, Map<String, Metacard> changedMetacards) {
String id = edge.parent.get(Metacard.ID).toString();
Metacard target = changedMetacards.getOrDefault(id, metacards.get(id));
ArrayList<String> values = Optional.of(target).map(m -> m.getAttribute(edge.relation)).map(Attribute::getValues).map(util::getStringList).orElseGet(ArrayList::new);
values.add(edge.child.get(Metacard.ID).toString());
target.setAttribute(new AttributeImpl(edge.relation, values));
changedMetacards.put(id, target);
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class AttributeFactoryTest method testCreateAttributeWithIllegalArgument.
@Test(expected = IllegalArgumentException.class)
public void testCreateAttributeWithIllegalArgument() throws Exception {
when(mockType.getAttributeFormat()).thenReturn(INTEGER);
Attribute attribute = attributeFactory.createAttribute(mockDescriptor, "1874xyz");
}
use of ddf.catalog.data.Attribute in project ddf by codice.
the class AttributeMetacardTransformer method transform.
@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
if (metacard == null) {
throw new CatalogTransformerException("No attribute [" + attributeName + "] found in Metacard.");
}
LOGGER.debug("Attempting transformation of [{}] with transformer [{}]", metacard, this);
Attribute attribute = metacard.getAttribute(attributeName);
if (attribute != null && attribute.getValue() != null) {
if (byte[].class.isAssignableFrom(attribute.getValue().getClass())) {
return new BinaryContentImpl(new ByteArrayInputStream((byte[]) attribute.getValue()), mimeType);
}
if (String.class.isAssignableFrom(attribute.getValue().getClass())) {
return new BinaryContentImpl(new ByteArrayInputStream(attribute.getValue().toString().getBytes(StandardCharsets.UTF_8)), mimeType);
}
}
throw new CatalogTransformerException("No attribute [" + attributeName + "] found in Metacard.");
}
use of ddf.catalog.data.Attribute 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();
}
Aggregations