use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnQuery.
@Test
public void testInjectsAttributesOnQuery() throws Exception {
final Metacard original = new MetacardImpl();
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(original), null)).getCreatedMetacards().get(0).getId();
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl("new attribute", true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final FilterFactory filterFactory = new FilterFactoryImpl();
final Filter filter = filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(id));
final QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
final QueryResponse response = framework.query(request);
final Metacard queryMetacard = response.getResults().get(0).getMetacard();
final MetacardType originalMetacardType = original.getMetacardType();
final MetacardType queryMetacardType = queryMetacard.getMetacardType();
assertThat(originalMetacardType.getName(), is(queryMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(queryMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverrides.
/**
* Tests that the framework properly passes a create request to the local provider with attribute overrides.
*/
@Test
public void testCreateStorageWithAttributeOverrides() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Serializable> propertiesMap = new HashMap<>();
HashMap<String, String> attributeMap = new HashMap<>();
attributeMap.put(Metacard.TITLE, "test");
attributeMap.put("foo", "bar");
propertiesMap.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeMap);
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
MetacardType metacardType = mock(MetacardType.class);
AttributeDescriptor stringAttributeDescriptor = new AttributeDescriptorImpl(Metacard.TITLE, true, true, true, true, new AttributeType<String>() {
private static final long serialVersionUID = 1L;
@Override
public Class<String> getBinding() {
return String.class;
}
@Override
public AttributeFormat getAttributeFormat() {
return AttributeFormat.STRING;
}
});
when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(stringAttributeDescriptor);
newCard.setType(metacardType);
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl newItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, newCard);
contentItems.add(newItem);
CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, propertiesMap));
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
for (Metacard curCard : response.getCreatedMetacards()) {
assertNotNull(curCard.getId());
// Assert valid attribute is set for the metacard
assertThat(curCard.getTitle(), is("test"));
// Assert invalid attribute is not set for the metacard
assertThat(curCard.getAttribute("foo"), nullValue());
}
// Assert That Attribute Overrides do not exist after create
assertThat(attributeMap.get(Constants.ATTRIBUTE_OVERRIDES_KEY), nullValue());
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class GenericFeatureConverterWfs20 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 "id" attribute if we have an ID
if (metacard.getAttribute(Metacard.ID).getValue() != null) {
String id = (String) metacard.getAttribute(Metacard.ID).getValue();
writer.addAttribute(ID, id);
}
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 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));
}
Aggregations