use of ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator 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.validation.impl.validator.RequiredAttributesMetacardValidator in project ddf by codice.
the class ValidationParser method getMetacardValidators.
@SuppressWarnings("unchecked")
private List<MetacardValidator> getMetacardValidators(MetacardValidatorDefinition validatorDefinition) {
List<MetacardValidator> metacardValidators = new ArrayList<>();
MetacardValidator metacardValidator = null;
String validatorName = null;
Object metacardValidatorObj = validatorDefinition.arguments.get(VALIDATOR_PROPERTY);
if (metacardValidatorObj instanceof String) {
validatorName = (String) metacardValidatorObj;
}
if (validatorName != null) {
String metacardType = validatorDefinition.metacardType;
switch(validatorName) {
case REQUIRED_ATTRIBUTE_VALIDATOR_PROPERTY:
{
if (metacardType == null) {
throw new IllegalStateException("Required Attributes Validator received invalid configuration");
}
Set<String> requiredAttributes = new HashSet<>();
Object requiredAttributesObj = validatorDefinition.arguments.get(REQUIRED_ATTRIBUTES_PROPERTY);
if (requiredAttributesObj instanceof List) {
List<Object> requiredAttrObjList = (List) requiredAttributesObj;
requiredAttributes = requiredAttrObjList.stream().filter(String.class::isInstance).map(String.class::cast).collect(Collectors.toSet());
}
if (CollectionUtils.isNotEmpty(requiredAttributes)) {
metacardValidator = new RequiredAttributesMetacardValidator(metacardType, requiredAttributes);
} else {
throw new IllegalStateException("Required Attributes Validator received invalid configuration");
}
break;
}
default:
throw new IllegalStateException("Validator does not exist. (" + validatorName + ")");
}
}
if (metacardValidator != null) {
metacardValidators.add(metacardValidator);
}
return metacardValidators;
}
Aggregations