use of ddf.catalog.validation.AttributeValidator 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.validation.AttributeValidator in project ddf by codice.
the class Validator method validateAttribute.
public AttributeValidationResponse validateAttribute(String attribute, String value) {
Set<AttributeValidator> validators = attributeValidatorRegistry.stream().map(avr -> avr.getValidators(attribute)).reduce((left, right) -> {
left.addAll(right);
return left;
}).orElse(new HashSet<>());
Set<String> suggestedValues = new HashSet<>();
Set<ValidationViolation> violations = new HashSet<>();
for (AttributeValidator validator : validators) {
Optional<AttributeValidationReport> validationReport = validator.validate(new AttributeImpl(attribute, value));
if (validationReport.isPresent()) {
AttributeValidationReport report = validationReport.get();
if (!report.getSuggestedValues().isEmpty()) {
suggestedValues = report.getSuggestedValues();
}
violations.addAll(report.getAttributeValidationViolations());
}
}
return new AttributeValidationResponse(violations, suggestedValues);
}
Aggregations