use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class AtomTransformer method getGeoRssPositions.
private List<Position> getGeoRssPositions(Metacard metacard) {
List<Position> georssPositions = new ArrayList<Position>();
for (AttributeDescriptor ad : metacard.getMetacardType().getAttributeDescriptors()) {
if (ad != null && ad.getType() != null && BasicTypes.GEO_TYPE.getAttributeFormat().equals(ad.getType().getAttributeFormat())) {
Attribute geoAttribute = metacard.getAttribute(ad.getName());
if (geoAttribute == null) {
continue;
}
for (Serializable geo : geoAttribute.getValues()) {
if (geo != null) {
try {
Geometry geometry = reader.read(geo.toString());
CompositeGeometry formatter = CompositeGeometry.getCompositeGeometry(geometry);
if (null != formatter) {
georssPositions.addAll(formatter.toGeoRssPositions());
} else {
LOGGER.debug("When cycling through geometries, could not get composite geometry [{}]", geo);
}
} catch (ParseException e) {
LOGGER.info("When cycling through geometries, could not parse [{}]", geo, e);
}
}
}
}
}
return georssPositions;
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardVersionImpl method sanitizeVersionAttributes.
private static void sanitizeVersionAttributes(/*Mutable*/
Metacard source) {
Consumer<String> nullifySourceAttribute = (s) -> source.setAttribute(new AttributeImpl(s, (Serializable) null));
Sets.difference(VERSION_DESCRIPTORS, BasicTypes.BASIC_METACARD.getAttributeDescriptors()).stream().map(AttributeDescriptor::getName).forEach(nullifySourceAttribute);
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class ValidationParser method parseMetacardTypes.
private List<Callable<Boolean>> parseMetacardTypes(Changeset changeset, List<Outer.MetacardType> metacardTypes) {
List<Callable<Boolean>> staged = new ArrayList<>();
BundleContext context = getBundleContext();
for (Outer.MetacardType metacardType : metacardTypes) {
Set<AttributeDescriptor> attributeDescriptors = new HashSet<>(BasicTypes.BASIC_METACARD.getAttributeDescriptors());
Set<String> requiredAttributes = new HashSet<>();
metacardType.attributes.forEach((attributeName, attribute) -> {
AttributeDescriptor descriptor = attributeRegistry.lookup(attributeName).orElseThrow(() -> new IllegalStateException(String.format("Metacard type [%s] includes the attribute [%s], but that attribute is not in the attribute registry.", metacardType.type, attributeName)));
attributeDescriptors.add(descriptor);
if (attribute.required) {
requiredAttributes.add(attributeName);
}
});
if (!requiredAttributes.isEmpty()) {
final MetacardValidator validator = new RequiredAttributesMetacardValidator(metacardType.type, requiredAttributes);
staged.add(() -> {
ServiceRegistration<MetacardValidator> registration = context.registerService(MetacardValidator.class, validator, null);
changeset.metacardValidatorServices.add(registration);
return registration != null;
});
}
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(NAME_PROPERTY, metacardType.type);
MetacardType type = new MetacardTypeImpl(metacardType.type, attributeDescriptors);
staged.add(() -> {
ServiceRegistration<MetacardType> registration = context.registerService(MetacardType.class, type, properties);
changeset.metacardTypeServices.add(registration);
return registration != null;
});
}
return staged;
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class ReportingMetacardValidatorImpl method validateMetacard.
@Override
public Optional<MetacardValidationReport> validateMetacard(final Metacard metacard) {
Preconditions.checkArgument(metacard != null, "The metacard cannot be null.");
final Set<ValidationViolation> violations = new HashSet<>();
for (final AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
final String attributeName = descriptor.getName();
final Attribute attribute = metacard.getAttribute(attributeName);
if (attribute != null) {
for (final AttributeValidator validator : validatorRegistry.getValidators(attributeName)) {
validator.validate(attribute).ifPresent(report -> violations.addAll(report.getAttributeValidationViolations()));
}
}
}
if (violations.size() > 0) {
return getReport(violations);
}
return Optional.empty();
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class FeatureMetacardTypeTest method testFeatureMetacardTypeNonQueryGmlProperty.
@Test
public void testFeatureMetacardTypeNonQueryGmlProperty() {
XmlSchema schema = new XmlSchema();
XmlSchemaElement gmlElement = new XmlSchemaElement(schema, true);
gmlElement.setSchemaType(new XmlSchemaComplexType(schema, false));
gmlElement.setSchemaTypeName(new QName(Wfs10Constants.GML_NAMESPACE, GML));
gmlElement.setName(ELEMENT_NAME_1);
XmlSchemaElement gmlElement2 = new XmlSchemaElement(schema, true);
gmlElement2.setSchemaType(new XmlSchemaComplexType(schema, false));
gmlElement2.setSchemaTypeName(new QName(Wfs10Constants.GML_NAMESPACE, GML));
gmlElement2.setName(ELEMENT_NAME_2);
List<String> nonQueryProps = new ArrayList<String>();
nonQueryProps.add(ELEMENT_NAME_2);
FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, nonQueryProps, Wfs10Constants.GML_NAMESPACE);
assertTrue(featureMetacardType.getGmlProperties().size() == 2);
AttributeDescriptor attrDesc = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_1));
assertNotNull(attrDesc);
assertTrue(attrDesc.getType() == BasicTypes.GEO_TYPE);
assertTrue(attrDesc.isIndexed());
AttributeDescriptor attrDesc2 = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_2));
assertNotNull(attrDesc2);
assertTrue(attrDesc2.getType() == BasicTypes.GEO_TYPE);
assertFalse(attrDesc2.isIndexed());
}
Aggregations