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