use of eu.esdihumboldt.hale.io.validation.service.ValidatorConfigurationService in project hale by halestudio.
the class ProjectValidator method execute.
/**
* @see eu.esdihumboldt.hale.common.core.io.impl.AbstractIOProvider#execute(eu.esdihumboldt.hale.common.core.io.ProgressIndicator,
* eu.esdihumboldt.hale.common.core.io.report.IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
ValidatorConfigurationService service = getServiceProvider().getService(ValidatorConfigurationService.class);
if (service == null) {
reporter.setSuccess(false);
throw new RuntimeException("Unable to find validator configurations");
}
Collection<IOProviderDescriptor> validators = new ArrayList<>();
validators.addAll(HaleIO.getProviderFactories(ConfigurableInstanceValidator.class));
List<ValidatorConfiguration> configurations = service.getConfigurations();
progress.begin("Performing project validation", configurations.size());
reporter.setSuccess(true);
SubtaskProgressIndicator subProgress = new SubtaskProgressIndicator(progress);
int i = 0;
for (ValidatorConfiguration configuration : configurations) {
for (IOProviderDescriptor validatorFactory : HaleIO.filterFactoriesByConfigurationType(validators, configuration.getContentType())) {
try {
// Assert that the validator can validate the exported
// content type, skip otherwise
boolean compatible = validatorFactory.getSupportedTypes().stream().anyMatch(type -> getContentType().isKindOf(type));
if (!compatible) {
reporter.info(new IOMessageImpl(MessageFormat.format("Validator \"{0}\" skipped: cannot validate exported content type \"{1}\"", validatorFactory.getIdentifier(), getContentType().getId()), null));
continue;
}
ConfigurableInstanceValidator validator = (ConfigurableInstanceValidator) validatorFactory.createExtensionObject();
subProgress.begin(MessageFormat.format("Executing project validator ({0}/{1})", ++i, configurations.size()), ProgressIndicator.UNKNOWN);
validator.setSchemas(getSchemas());
validator.setSource(getSource());
validator.setContentType(getContentType());
validator.setServiceProvider(getServiceProvider());
validator.configure(configuration);
validator.validate();
IOReport result = validator.execute(null);
if (result != null) {
reporter.importMessages(result);
if (!result.isSuccess()) {
reporter.setSuccess(false);
}
}
} catch (Exception e) {
reporter.error(new IOMessageImpl("Error running project validator", e));
reporter.setSuccess(false);
}
subProgress.end();
progress.advance(1);
}
}
progress.end();
return reporter;
}
use of eu.esdihumboldt.hale.io.validation.service.ValidatorConfigurationService in project hale by halestudio.
the class ValidatorConfigurationImportAdvisor method handleResults.
/**
* @see IOAdvisor#handleResults(IOProvider)
*/
@Override
public void handleResults(ValidatorConfigurationReader provider) {
ValidatorConfiguration configuration = provider.getConfiguration();
ValidatorConfigurationService service = getService(ValidatorConfigurationService.class);
if (service != null) {
service.addConfiguration(provider.getResourceIdentifier(), configuration);
} else {
log.warn(MessageFormat.format("Implementation for service interface {0} could not be found!", ValidatorConfigurationService.class.getCanonicalName()));
}
super.handleResults(provider);
}
Aggregations