use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class ProjectParser method execute.
/**
* @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin(Messages.ProjectParser_0, ProgressIndicator.UNKNOWN);
try {
File file;
try {
file = new File(getSource().getLocation());
} catch (IllegalArgumentException e) {
file = null;
}
String basePath = (file == null) ? (new File(".").getAbsolutePath()) : (FilenameUtils.getFullPath(file.getAbsolutePath()));
// Unmarshal the project file
JAXBContext jc;
JAXBElement<HaleProject> root;
try {
jc = JAXBContext.newInstance(PROJECT_CONTEXT, ObjectFactory.class.getClassLoader());
Unmarshaller u = jc.createUnmarshaller();
u.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
root = u.unmarshal(new StreamSource(getSource().getInput()), HaleProject.class);
} catch (JAXBException e) {
reporter.error(new IOMessageImpl("Unmarshalling the HaleProject from the given resource failed: {0}", e, -1, -1, getSource().getLocation()));
reporter.setSuccess(false);
return reporter;
}
project = new Project();
projectFiles = new HashMap<String, ProjectFile>();
report = reporter;
HaleProject haleProject = root.getValue();
// populate project and project files
loadProject(haleProject);
loadSchemas(haleProject, basePath);
loadAlignment(haleProject, basePath);
loadStyle(haleProject, basePath);
loadInstances(haleProject, basePath);
loadTasks(haleProject, basePath);
loadConfig(haleProject);
report = null;
reporter.setSuccess(true);
return reporter;
} finally {
progress.end();
}
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class SchematronInstanceValidator method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
URI schematronLoc = getSchematronLocation();
if (schematronLoc == null) {
throw new IOProviderConfigurationException("Providing a schematron file is required");
}
progress.begin("Performing Schematron validation", ProgressIndicator.UNKNOWN);
final InputStream sourceInput = this.getSource().getInput();
if (sourceInput == null) {
throw new RuntimeException("No input for Schematron validator");
}
final Source xmlSource = new StreamSource(sourceInput);
final DefaultInputSupplier schematronInputSupplier = new DefaultInputSupplier(schematronLoc);
final InputStream schematronInput = schematronInputSupplier.getInput();
if (schematronInput == null) {
throw new RuntimeException("No rules input for Schematron validator");
}
final Source schematronSource = new StreamSource(schematronInput);
try {
final SchematronValidator validator = new SchematronValidator(schematronSource);
final Result result = validator.validate(xmlSource, /* svrlReport */
true);
final StringWriter reportWriter = new StringWriter();
SchematronUtils.convertValidatorResult(result, reportWriter);
reporter.setSuccess(!validator.ruleViolationsDetected());
if (validator.ruleViolationsDetected()) {
SchematronReportParser parser = new SchematronReportParser(reportWriter.toString());
parser.reportFailedAssertions(reporter);
}
} catch (Exception e) {
reporter.error(new IOMessageImpl("Error running schematron validation", e));
reporter.setSuccess(false);
} finally {
schematronInput.close();
progress.end();
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl 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.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class PartitioningWFSWriter method execute.
@Override
protected IOReport execute(final ProgressIndicator progress, final IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Upload to WFS-T", IProgressMonitor.UNKNOWN);
try {
progress.setCurrentTask("Partitioning data");
// create the partitioner
InstanceCollectionPartitioner partitioner = StreamGmlWriter.getPartitioner(this, reporter);
// partition the graph
int threshold = getParameter(PARAM_INSTANCES_THRESHOLD).as(Integer.class, DEFAULT_INSTANCES_THRESHOLD);
try (ResourceIterator<InstanceCollection> parts = partitioner.partition(getInstances(), threshold, reporter)) {
if (partitioner.requiresImmediateConsumption()) {
// handle all parts right here, one after another
int partCount = 0;
boolean failed = false;
if (parts.hasNext()) {
while (parts.hasNext() && !progress.isCanceled()) {
partCount++;
SubtaskProgressIndicator partitionProgress = new SubtaskProgressIndicator(progress);
partitionProgress.begin("Assembling part " + partCount, ProgressIndicator.UNKNOWN);
InstanceCollection part = parts.next();
partitionProgress.end();
progress.setCurrentTask("Upload part " + partCount + ((part.hasSize()) ? (" (" + part.size() + " instances)") : ("")));
IOReport report = uploadInstances(part, reporter, new SubtaskProgressIndicator(progress));
if (!report.isSuccess()) {
failed = true;
reporter.error("Upload of part {0} - {1}", partCount, report.getSummary());
} else {
reporter.info("Upload of part {0} - {1}", partCount, report.getSummary());
}
}
reporter.setSuccess(!failed && reporter.getErrors().isEmpty());
if (!reporter.isSuccess()) {
reporter.setSummary("Errors during upload to WFS-T, please see the report.");
} else {
reporter.setSummary("Successfully uploaded data via WFS-T");
}
} else {
reporter.setSuccess(false);
reporter.setSummary("Partitioning yielded no instances to upload");
}
} else {
// can start requests with separate thread (potentially
// threads, but tests with WFSes show that this usually is
// too much to handle for the service)
int partCount = 0;
final AtomicBoolean failed = new AtomicBoolean();
if (parts.hasNext()) {
ExecutorService requestThread = Executors.newSingleThreadExecutor();
while (parts.hasNext() && !progress.isCanceled()) {
partCount++;
SubtaskProgressIndicator partitionProgress = new SubtaskProgressIndicator(// only used for first
progress);
// partitioning
if (partCount == 1)
partitionProgress.begin("Assembling part " + partCount, ProgressIndicator.UNKNOWN);
// not
final InstanceCollection part = parts.next();
// safe
if (partCount == 1)
partitionProgress.end();
progress.setCurrentTask("Upload part " + partCount + ((part.hasSize()) ? (" (" + part.size() + " instances)") : ("")));
final int currentPart = partCount;
requestThread.submit(new Runnable() {
@Override
public void run() {
try {
IOReport report = uploadInstances(part, reporter, new SubtaskProgressIndicator(progress));
if (!report.isSuccess()) {
failed.set(true);
reporter.error(new IOMessageImpl("Upload of part " + currentPart + " - " + report.getSummary(), null));
} else {
reporter.info(new IOMessageImpl("Upload of part " + currentPart + " - " + report.getSummary(), null));
}
} catch (Exception e) {
failed.set(true);
reporter.error(new IOMessageImpl("Upload of part " + currentPart + " failed", e));
}
}
});
}
// wait for requests completion
requestThread.shutdown();
if (!requestThread.awaitTermination(24, TimeUnit.HOURS)) {
reporter.error(new IOMessageImpl("Timeout reached waiting for completion of WFS requests", null));
}
reporter.setSuccess(!failed.get() && reporter.getErrors().isEmpty());
if (!reporter.isSuccess()) {
reporter.setSummary("Errors during upload to WFS-T, please see the report.");
} else {
reporter.setSummary("Successfully uploaded data via WFS-T");
}
} else {
reporter.setSuccess(false);
reporter.setSummary("Partitioning yielded no instances to upload");
}
}
}
} catch (Exception e) {
reporter.error(new IOMessageImpl("Error during attempt to upload to WFS-T", e));
reporter.setSuccess(false);
} finally {
progress.end();
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class XLSInstanceReader method createInstanceCollection.
/**
* create instances, see
* {@link CSVInstanceReader#execute(ProgressIndicator, IOReporter)}
*
* @param row the current row
* @param reporter the reporter of the writer
* @param solveNestedProperties true, if schema should not be flat <b>(not
* implemented yet)</b>
*/
@SuppressWarnings("javadoc")
private void createInstanceCollection(List<String> row, IOReporter reporter) {
MutableInstance instance = new DefaultInstance(type, null);
// int propertyIndex = 0;
for (int index = 0; index < propAr.length; index++) {
String part = null;
if (index < row.size())
part = row.get(index);
if (part != null) {
PropertyDefinition property = propAr[index];
if (part.isEmpty()) {
// FIXME make this configurable
part = null;
}
Object value = part;
if (value != null) {
Binding binding = property.getPropertyType().getConstraint(Binding.class);
try {
if (!binding.getBinding().equals(String.class)) {
ConversionService conversionService = HalePlatform.getService(ConversionService.class);
if (conversionService.canConvert(String.class, binding.getBinding())) {
value = conversionService.convert(part, binding.getBinding());
} else {
throw new IllegalStateException("Conversion not possible!");
}
}
} catch (Exception e) {
reporter.error(new IOMessageImpl("Cannot convert property value to {0}", e, line, -1, binding.getBinding().getSimpleName()));
}
instance.addProperty(property.getName(), value);
}
// propertyIndex++;
}
}
instances.add(instance);
}
Aggregations