use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class TestGenericFeatureConverter method testMetacardCollectionToFeatureCollectionXml.
@Test
public void testMetacardCollectionToFeatureCollectionXml() {
XStream xstream = new XStream(new EnhancedStaxDriver());
xstream.setMode(XStream.NO_REFERENCES);
xstream.registerConverter(new FeatureCollectionConverterWfs20());
xstream.registerConverter(new GenericFeatureConverterWfs20());
xstream.registerConverter(new GmlGeometryConverter());
// Required the Implementing class. The interface would not work...
xstream.alias(Wfs20Constants.WFS_NAMESPACE_PREFIX + ":" + "FeatureCollection", Wfs20FeatureCollection.class);
Metacard mc = new SampleMetacard().getMetacard();
Wfs20FeatureCollection wfc = new Wfs20FeatureCollection();
wfc.getMembers().add(mc);
MetacardImpl mc2 = new SampleMetacard().getMetacard();
// Ignore the hack stuff, this was just to imitate having two different
// "MetacardTypes"
mc2.setType(new MetacardType() {
@Override
public String getName() {
return "otherType";
}
@Override
public Set<AttributeDescriptor> getAttributeDescriptors() {
return BasicTypes.BASIC_METACARD.getAttributeDescriptors();
}
@Override
public AttributeDescriptor getAttributeDescriptor(String arg0) {
return BasicTypes.BASIC_METACARD.getAttributeDescriptor(arg0);
}
});
wfc.getMembers().add(mc2);
String xml = xstream.toXML(wfc);
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class FeatureMetacardTypeTest method testFeatureMetacardTypeFindTaxonomyMetacardAttributes.
@Test
public void testFeatureMetacardTypeFindTaxonomyMetacardAttributes() {
XmlSchema schema = new XmlSchema();
XmlSchemaElement element = new XmlSchemaElement(schema, true);
element.setSchemaType(new XmlSchemaSimpleType(schema, false));
element.setSchemaTypeName(Constants.XSD_STRING);
element.setName(ELEMENT_NAME);
schema.getElements().put(new QName(ELEMENT_NAME), element);
FeatureMetacardType fmt = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs20Constants.GML_3_2_NAMESPACE);
Set<AttributeDescriptor> descriptors = initDescriptors();
for (AttributeDescriptor ad : descriptors) {
assertBasicAttributeDescriptor(fmt, ad.getName(), ad.getType());
assertFalse(fmt.getAttributeDescriptor(ad.getName()).isStored());
}
// +1 to account for one element added to schema.
assertThat(fmt.getAttributeDescriptors().size(), is(descriptors.size() + 1));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class PropertyJsonMetacardTransformer method convertToJSON.
public static Map<String, Object> convertToJSON(Metacard metacard, List<AttributeType.AttributeFormat> dontInclude) throws CatalogTransformerException {
if (metacard == null) {
throw new CatalogTransformerException("Cannot transform null metacard.");
}
Map<String, Object> rootObject = new HashMap<>();
Map<String, Object> properties = new HashMap<>();
for (AttributeDescriptor ad : metacard.getMetacardType().getAttributeDescriptors()) {
Attribute attribute = metacard.getAttribute(ad.getName());
if (attribute != null) {
Object value = convertAttribute(attribute, ad, dontInclude);
if (value != null) {
properties.put(attribute.getName(), value);
}
}
}
properties.put(METACARD_TYPE_PROPERTY_KEY, metacard.getMetacardType().getName());
if (StringUtils.isNotBlank(metacard.getSourceId())) {
properties.put(SOURCE_ID_PROPERTY, metacard.getSourceId());
}
rootObject.put("properties", properties);
return rootObject;
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class PdfInputTransformer method initializeMetacard.
private MetacardImpl initializeMetacard(String id, String contentInput) {
MetacardImpl metacard;
if (StringUtils.isNotBlank(contentInput)) {
Set<AttributeDescriptor> attributes = contentMetadataExtractors.values().stream().map(ContentMetadataExtractor::getMetacardAttributes).flatMap(Collection::stream).collect(Collectors.toSet());
metacard = new MetacardImpl(new MetacardTypeImpl(metacardType.getName(), metacardType, attributes));
for (ContentMetadataExtractor contentMetadataExtractor : contentMetadataExtractors.values()) {
contentMetadataExtractor.process(contentInput, metacard);
}
} else {
metacard = new MetacardImpl(metacardType);
}
metacard.setId(id);
metacard.setContentTypeName(MediaType.PDF.toString());
metacard.setAttribute(Media.TYPE, MediaType.PDF.toString());
metacard.setAttribute(Core.DATATYPE, DataType.DOCUMENT.toString());
return metacard;
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class Search method getType.
private Map<String, Object> getType(MetacardType metacardType) throws CatalogTransformerException {
Map<String, Object> fields = new HashMap<>();
for (AttributeDescriptor descriptor : metacardType.getAttributeDescriptors()) {
Map<String, Object> description = new HashMap<>();
description.put(ATTRIBUTE_FORMAT, descriptor.getType().getAttributeFormat().toString());
description.put(ATTRIBUTE_INDEXED, descriptor.isIndexed());
fields.put(descriptor.getName(), description);
}
return fields;
}
Aggregations