use of eu.esdihumboldt.hale.ui.io.target.FileTarget in project hale by halestudio.
the class InstanceExportWizard method performValidation.
/**
* Run the configured validators on the exported instance. May be overriden
* to customize validation process.
*
* @return true if all validations were successful
*/
protected boolean performValidation() {
boolean success = true;
for (InstanceValidator validator : validators) {
// set schemas
List<? extends Locatable> schemas = getProvider().getValidationSchemas();
validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
// set service provider
validator.setServiceProvider(HaleUI.getServiceProvider());
ExportTarget<?> exportTarget = getSelectTargetPage().getExportTarget();
if (exportTarget instanceof FileTarget) {
LocatableOutputSupplier<? extends OutputStream> target = getProvider().getTarget();
List<String> fileNames = new ArrayList<>();
if (target instanceof MultiLocationOutputSupplier) {
for (URI location : ((MultiLocationOutputSupplier) target).getLocations()) {
if (!"file".equals(location.getScheme())) {
continue;
}
File targetFile = new File(location);
fileNames.add(targetFile.getAbsolutePath());
}
} else {
fileNames.add(((FileTarget<?>) exportTarget).getTargetFileName());
}
for (String fileName : fileNames) {
LocatableInputSupplier<? extends InputStream> source = new FileIOSupplier(new File(fileName));
validator.setSource(source);
validator.setContentType(getContentType());
IOReporter defReport = validator.createReporter();
// validate and execute provider
try {
// validate configuration
validator.validate();
IOReport report = execute(validator, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
if (report.isSuccess()) {
log.info(report.getSummary());
} else {
log.error(report.getSummary());
success = false;
}
}
} catch (IOProviderConfigurationException e) {
log.error(MessageFormat.format("The validator '{0}' could not be executed", validator.getClass().getCanonicalName()), e);
success = false;
}
}
} else {
log.error("No input can be provided for validation (no file target)");
success = false;
}
}
if (success) {
log.userInfo("All validations completed successfully.");
} else {
log.userError("There were validation failures. Please check the report for more details.");
}
return success;
}
Aggregations