Search in sources :

Example 36 with IOMessageImpl

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);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) ATransaction(de.fhg.igd.slf4jplus.ATransaction) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 37 with IOMessageImpl

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;
    }
}
Also used : InstanceValidator(eu.esdihumboldt.hale.common.instance.io.InstanceValidator) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) ATransaction(de.fhg.igd.slf4jplus.ATransaction) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 38 with IOMessageImpl

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);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) MathTransform(org.opengis.referencing.operation.MathTransform) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Pair(eu.esdihumboldt.util.Pair)

Example 39 with IOMessageImpl

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;
}
Also used : InputStream(java.io.InputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) URI(java.net.URI) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 40 with IOMessageImpl

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;
}
Also used : XPath(javax.xml.xpath.XPath) NodeList(org.w3c.dom.NodeList) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)

Aggregations

IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)85 IOException (java.io.IOException)43 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)33 QName (javax.xml.namespace.QName)20 URI (java.net.URI)15 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 InputStream (java.io.InputStream)13 File (java.io.File)12 HashMap (java.util.HashMap)11 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)9 FileOutputStream (java.io.FileOutputStream)9 ArrayList (java.util.ArrayList)9 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)8 OutputStream (java.io.OutputStream)8 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)7 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)7 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)6 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)4 Value (eu.esdihumboldt.hale.common.core.io.Value)4