use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class ExportJob method run.
/**
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
IOReporter defaultReporter = writer.createReporter();
defaultReporter.setSuccess(false);
IOReport report = defaultReporter;
try {
ATransaction trans = log.begin(defaultReporter.getTaskName());
try {
IOReport result = writer.execute(new ProgressMonitorIndicator(monitor));
if (result != null) {
report = result;
} else {
defaultReporter.setSuccess(true);
}
} catch (Throwable e) {
defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
} finally {
trans.end();
}
} catch (Throwable e) {
defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
}
if (monitor.isCanceled()) {
reset();
return Status.CANCEL_STATUS;
}
// add report to report service
reportHandler.publishReport(report);
// show message to user
if (report.isSuccess()) {
// no message, we rely on the report being
// shown/processed
// let advisor handle results
advisor.handleResults(writer);
reset();
return Status.OK_STATUS;
} else {
reset();
log.error(report.getSummary());
return new Status(Status.ERROR, "eu.esdihumboldt.hale.common.headless", report.getSummary(), null);
}
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class ValidationJob method run.
/**
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
boolean successful = true;
for (InstanceValidator validator : this.validators) {
IOReporter defaultReporter = validator.createReporter();
defaultReporter.setSuccess(false);
IOReport report = defaultReporter;
try {
ATransaction trans = log.begin(defaultReporter.getTaskName());
try {
if (writer != null) {
// set validation schemas (may have been determined only
// during writer execution)
// set schemas
List<? extends Locatable> schemas = writer.getValidationSchemas();
validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
}
validator.setServiceProvider(serviceProvider);
IOReport result = validator.execute(new ProgressMonitorIndicator(monitor));
if (result != null) {
report = result;
} else {
defaultReporter.setSuccess(true);
}
} catch (Throwable e) {
defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
} finally {
trans.end();
}
} catch (Throwable e) {
defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
}
if (monitor.isCanceled()) {
reset();
return Status.CANCEL_STATUS;
}
// add report to report service
reportHandler.publishReport(report);
// show message to user
if (report.isSuccess()) {
// info message
log.info(report.getSummary());
} else {
// error message
log.error(report.getSummary());
successful = false;
}
}
reset();
if (successful) {
log.userInfo("All validations completed successfully.");
return Status.OK_STATUS;
} else {
log.userError("There were validation failures. Please check the reports for details.");
return ERROR_STATUS;
}
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class AbstractGeoInstanceWriter method convertGeometry.
/**
* Convert the given geometry to the target CRS, if possible (and a target
* CRS is set).
*
* @param geom the geometry to convert
* @param sourceCrs the source CRS
* @param report the reporter
* @return a pair of geometry and CRS definition, either the converted
* geometry and the target CRS or the given geometry and the source
* CRS
*/
protected Pair<Geometry, CRSDefinition> convertGeometry(Geometry geom, CRSDefinition sourceCrs, IOReporter report) {
if (getTargetCRS() != null && getTargetCRS().getCRS() != null) {
if (sourceCrs != null && sourceCrs.getCRS() != null) {
try {
// TODO cache mathtransforms?
MathTransform transform = CRS.findMathTransform(sourceCrs.getCRS(), getTargetCRS().getCRS());
Geometry targetGeometry = JTS.transform(geom, transform);
return new Pair<>(targetGeometry, getTargetCRS());
} catch (Exception e) {
if (report != null) {
report.error(new IOMessageImpl("Could not convert geometry to target CRS", e));
}
// return original geometry
return new Pair<>(geom, sourceCrs);
}
} else {
// valid source CRS was passed
if (report != null) {
report.error(new IOMessageImpl("Could not convert geometry to target CRS: No source CRS provided", null));
}
return new Pair<>(geom, sourceCrs);
}
} else {
// return original geometry
return new Pair<>(geom, sourceCrs);
}
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class SkosCodeListReader method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Loading SKOS code list", ProgressIndicator.UNKNOWN);
try {
this.language = getLangauge();
URI loc = getSource().getLocation();
InputStream in = getSource().getInput();
codelist = new SkosCodeList(in, loc, this.language);
progress.setCurrentTask("Code list loaded.");
reporter.setSuccess(true);
} catch (Exception ex) {
reporter.error(new IOMessageImpl("Error in loading skos code list", ex));
reporter.setSuccess(false);
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class INSPIRECodeListReader method parse.
private boolean parse(Document doc, URI location, IOReporter reporter) throws Exception {
XPath xpath = XPathFactory.newInstance().newXPath();
boolean directlyReferenced = location != null && location.toString().toLowerCase().endsWith(".xml");
String description = null;
String namespace = null;
namespace = (String) xpath.evaluate("codelist/@id", doc, XPathConstants.STRING);
if (namespace == null) {
reporter.error(new IOMessageImpl("No id attribute present in INSPIRE codelist.", null));
return false;
}
// use the last part of the id as name
String name = namespace;
int idxSlash = name.indexOf('/');
if (idxSlash >= 0 && idxSlash + 1 < name.length()) {
name = name.substring(idxSlash);
}
if (directlyReferenced) {
// if directly referenced use the label as name
// (for backwards compatibility)
NodeList labels = (NodeList) xpath.evaluate("codelist/label", doc, XPathConstants.NODESET);
if (labels.getLength() > 0) {
name = labels.item(0).getTextContent();
}
}
NodeList definitions = (NodeList) xpath.evaluate("codelist/definition", doc, XPathConstants.NODESET);
if (definitions.getLength() > 0)
description = definitions.item(0).getTextContent();
// XXX ignore descriptions for now
// also ignore status, extensibility, register, applicationschema and
// theme
// don't use the name as identifier, as it is language dependent!
INSPIRECodeList codelist = new INSPIRECodeList(namespace, name, description, location);
NodeList entries = (NodeList) xpath.evaluate("codelist/containeditems/value", doc, XPathConstants.NODESET);
for (int i = 0; i < entries.getLength(); i++) addEntry(entries.item(i), codelist, xpath, reporter);
this.codelist = codelist;
return true;
}
Aggregations