use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class EndpointUtil method getMetacardMap.
public Map<String, Object> getMetacardMap(Metacard metacard) {
Set<AttributeDescriptor> attributeDescriptors = metacard.getMetacardType().getAttributeDescriptors();
Map<String, Object> result = new HashMap<>();
for (AttributeDescriptor descriptor : attributeDescriptors) {
if (metacard.getAttribute(descriptor.getName()) == null) {
if (descriptor.isMultiValued()) {
result.put(descriptor.getName(), Collections.emptyList());
} else {
result.put(descriptor.getName(), null);
}
continue;
}
if (Metacard.THUMBNAIL.equals(descriptor.getName())) {
if (metacard.getThumbnail() != null) {
result.put(descriptor.getName(), Base64.getEncoder().encodeToString(metacard.getThumbnail()));
} else {
result.put(descriptor.getName(), null);
}
continue;
}
if (descriptor.getType().getAttributeFormat().equals(AttributeType.AttributeFormat.DATE)) {
Attribute attribute = metacard.getAttribute(descriptor.getName());
if (descriptor.isMultiValued()) {
result.put(descriptor.getName(), attribute.getValues().stream().map(this::parseDate).collect(Collectors.toList()));
} else {
result.put(descriptor.getName(), parseDate(attribute.getValue()));
}
}
if (descriptor.isMultiValued()) {
result.put(descriptor.getName(), metacard.getAttribute(descriptor.getName()).getValues());
} else {
result.put(descriptor.getName(), metacard.getAttribute(descriptor.getName()).getValue());
}
}
return result;
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class ValidationParser method parseAttributeTypes.
private List<Callable<Boolean>> parseAttributeTypes(Changeset changeset, Map<String, Outer.AttributeType> attributeTypes) {
List<Callable<Boolean>> staged = new ArrayList<>();
for (Map.Entry<String, Outer.AttributeType> entry : attributeTypes.entrySet()) {
final AttributeDescriptor descriptor = new AttributeDescriptorImpl(entry.getKey(), entry.getValue().indexed, entry.getValue().stored, entry.getValue().tokenized, entry.getValue().multivalued, BasicTypes.getAttributeType(entry.getValue().type));
staged.add(() -> {
attributeRegistry.register(descriptor);
changeset.attributes.add(descriptor);
return true;
});
}
return staged;
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class FeatureMetacardTypeTest method assertBasicAttributeDescriptor.
private void assertBasicAttributeDescriptor(FeatureMetacardType featureMetacardType, String propertyName, AttributeType type) {
AttributeDescriptor attrDesc = featureMetacardType.getAttributeDescriptor(propertyName);
assertNotNull(attrDesc);
assertTrue(attrDesc.getType() == type);
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class FeatureMetacardTypeTest method testFeatureMetacardTypeStringNonQueryProperty.
@Test
public void testFeatureMetacardTypeStringNonQueryProperty() {
XmlSchema schema = new XmlSchema();
XmlSchemaElement stringElement = new XmlSchemaElement(schema, true);
stringElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
stringElement.setSchemaTypeName(Constants.XSD_STRING);
stringElement.setName(ELEMENT_NAME_1);
XmlSchemaElement stringElement2 = new XmlSchemaElement(schema, true);
stringElement2.setSchemaType(new XmlSchemaSimpleType(schema, false));
stringElement2.setSchemaTypeName(Constants.XSD_STRING);
stringElement2.setName(ELEMENT_NAME_2);
List<String> nonQueryProps = new ArrayList<String>();
nonQueryProps.add(ELEMENT_NAME_1);
FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, nonQueryProps, Wfs10Constants.GML_NAMESPACE);
assertTrue(featureMetacardType.getTextualProperties().size() == 2);
AttributeDescriptor attrDesc = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_1));
assertNotNull(attrDesc);
assertFalse(attrDesc.isIndexed());
AttributeDescriptor attrDesc2 = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_2));
assertNotNull(attrDesc2);
assertTrue(attrDesc2.isIndexed());
}
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, Wfs10Constants.GML_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