use of ddf.catalog.validation.MetacardValidator 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;
}
use of ddf.catalog.validation.MetacardValidator in project ddf by codice.
the class ValidationParser method registerMetacardValidators.
private List<Callable<Boolean>> registerMetacardValidators(Changeset changeset, List<MetacardValidatorDefinition> metacardValidatorDefinitions) {
List<Callable<Boolean>> staged = new ArrayList<>();
BundleContext context = getBundleContext();
for (MetacardValidatorDefinition metacardValidatorDefinition : metacardValidatorDefinitions) {
try {
List<MetacardValidator> metacardValidators = getMetacardValidators(metacardValidatorDefinition);
metacardValidators.forEach(metacardValidator -> staged.add(() -> {
ServiceRegistration<MetacardValidator> registration = context.registerService(MetacardValidator.class, metacardValidator, null);
changeset.metacardValidatorServices.add(registration);
return registration != null;
}));
} catch (IllegalStateException ise) {
LOGGER.error("Could not register metacard validator for definition: {}", metacardValidatorDefinition, ise);
}
}
return staged;
}
use of ddf.catalog.validation.MetacardValidator in project ddf by codice.
the class MetacardValidityMarkerPluginTest method testMetacardPassesEnforcedValidatorsNoDescribable.
@Test
public void testMetacardPassesEnforcedValidatorsNoDescribable() throws StopProcessingException, PluginExecutionException {
MetacardValidator mockValidator = getMockPassingValidatorNoDescribable();
metacardValidators.add(mockValidator);
enforcedMetacardValidators.add(mockValidator.getClass().getCanonicalName());
CreateRequest createRequest = getMockCreateRequest();
List<Metacard> createdMetacards = createRequest.getMetacards();
verifyEnforcedCreate(createRequest, createdMetacards);
UpdateRequest updateRequest = getMockUpdateRequest();
List<Metacard> updatedMetacards = getUpdatedMetacards(updateRequest);
verifyEnforcedUpdate(updateRequest, updatedMetacards);
}
use of ddf.catalog.validation.MetacardValidator in project ddf by codice.
the class MetacardValidityMarkerPluginTest method getMockFailingValidatorWithWarnings.
private MetacardValidator getMockFailingValidatorWithWarnings() throws ValidationException {
ValidationException validationException = mock(ValidationException.class);
when(validationException.getWarnings()).thenReturn(Collections.singletonList(SAMPLE_WARNING));
MetacardValidator metacardValidator = mock(MetacardValidator.class, withSettings().extraInterfaces(Describable.class));
doThrow(validationException).when(metacardValidator).validate(any(Metacard.class));
when(((Describable) metacardValidator).getId()).thenReturn(ID);
return metacardValidator;
}
use of ddf.catalog.validation.MetacardValidator in project ddf by codice.
the class MetacardValidityMarkerPluginTest method getMockEnforcedPassingValidatorWithId.
private MetacardValidator getMockEnforcedPassingValidatorWithId(String id) {
MetacardValidator metacardValidator = mock(MetacardValidator.class, withSettings().extraInterfaces(Describable.class));
when(((Describable) metacardValidator).getId()).thenReturn(id);
return metacardValidator;
}
Aggregations