Search in sources :

Example 6 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class ReportWriter method write.

/**
 * Writes all {@link Report}s to a {@link File}.
 *
 * @param file target file
 * @param reports reports to be saved
 * @param append if the reports should be appended to the file instead of
 *            overwriting it
 *
 * @return true on success
 *
 * @throws IOException if IO fails
 */
public static boolean write(File file, Collection<Report<?>> reports, boolean append) throws IOException {
    // check if the file exists
    if (!file.exists()) {
        // and create the file
        if (!file.createNewFile()) {
            _log.error("Logfile could not be created!");
            return false;
        }
        // make it writable
        file.setWritable(true);
    }
    // check if it's writable
    if (!file.canWrite()) {
        _log.error("Report could not be saved. No write permission!");
        return false;
    }
    // create PrintStream
    PrintStream p = new PrintStream(new BufferedOutputStream(new FileOutputStream(file, append)));
    try {
        // get an instance of ReportFactory
        ReportFactory rf = ReportFactory.getInstance();
        MessageFactory mf = MessageFactory.getInstance();
        // iterate through all reports
        for (Report<?> r : reports) {
            // write them to the file
            p.print(rf.asString(r));
            for (Message m : r.getErrors()) {
                p.println("!ERROR");
                p.print(mf.asString(m));
            }
            for (Message m : r.getWarnings()) {
                p.println("!WARN");
                p.print(mf.asString(m));
            }
            for (Message m : r.getInfos()) {
                p.println("!INFO");
                p.print(mf.asString(m));
            }
        }
        // new line at end of file to allow appending
        p.println();
        p.flush();
    } finally {
        // close stream
        p.close();
    }
    return true;
}
Also used : PrintStream(java.io.PrintStream) MessageFactory(eu.esdihumboldt.hale.common.core.report.MessageFactory) Message(eu.esdihumboldt.hale.common.core.report.Message) FileOutputStream(java.io.FileOutputStream) ReportFactory(eu.esdihumboldt.hale.common.core.report.ReportFactory) BufferedOutputStream(java.io.BufferedOutputStream)

Example 7 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class ProjectHandler method onSuccess.

@Override
protected void onSuccess(EnvironmentManager context, String projectId, File projectFile, Project project, ReportFile reportFile) {
    super.onSuccess(context, projectId, projectFile, project, reportFile);
    if (isEnabled()) {
        // load transformation environment if not yet done
        if (transformationEnvironment == null) {
            try {
                transformationEnvironment = new ProjectTransformationEnvironment(projectId, new FileIOSupplier(projectFile), reportFile);
                // check alignment
                if (transformationEnvironment.getAlignment() == null) {
                    throw new IllegalStateException("Alignment missing or failed to load");
                }
                if (transformationEnvironment.getAlignment().getActiveTypeCells().isEmpty()) {
                    throw new IllegalStateException("Alignment contains no active type relations");
                }
            } catch (Exception e) {
                log.error("Could not load transformation environment for project " + projectId, e);
                status = Status.BROKEN;
                transformationEnvironment = null;
                context.removeEnvironment(projectId);
                // log the exception as report
                Reporter<Message> report = new DefaultReporter<Message>("Load project transformation environment", ProjectIO.ACTION_LOAD_PROJECT, Message.class, false);
                report.error(new MessageImpl(e.getMessage(), e));
                reportFile.publishReport(report);
            }
        } else {
        // XXX somehow check if project was changed?
        }
        if (transformationEnvironment != null) {
            context.addEnvironment(transformationEnvironment);
            status = Status.ACTIVE;
        }
    } else {
        // clear transformation environment
        status = Status.INACTIVE;
        transformationEnvironment = null;
        context.removeEnvironment(projectId);
    }
}
Also used : Message(eu.esdihumboldt.hale.common.core.report.Message) Reporter(eu.esdihumboldt.hale.common.core.report.Reporter) DefaultReporter(eu.esdihumboldt.hale.common.core.report.impl.DefaultReporter) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) ProjectTransformationEnvironment(eu.esdihumboldt.hale.common.headless.impl.ProjectTransformationEnvironment) MessageImpl(eu.esdihumboldt.hale.common.core.report.impl.MessageImpl) IOException(java.io.IOException)

Example 8 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class DefinitionInstanceLabelProvider method getToolTipText.

/**
 * @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
 */
@Override
public String getToolTipText(Object element) {
    if (element instanceof EntityDefinition) {
        InstanceValidationReport report = validator.validate(instance);
        Collection<InstanceValidationMessage> warnings = report.getWarnings();
        if (warnings.isEmpty())
            return null;
        StringBuilder toolTip = new StringBuilder();
        for (Message m : warnings) toolTip.append(m.getFormattedMessage()).append('\n');
        return toolTip.substring(0, toolTip.length() - 1);
    } else
        return null;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Message(eu.esdihumboldt.hale.common.core.report.Message) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)

Example 9 with Message

use of eu.esdihumboldt.hale.common.core.report.Message in project hale by halestudio.

the class DefaultReportDetailsPage method setInput.

@Override
public void setInput(Collection<? extends Message> messages, MessageType type) {
    this.messageType = type;
    if (more > 0) {
        Collection<Message> messageList = new ArrayList<>(messages);
        String message;
        switch(messageType) {
            case Error:
                message = MessageFormat.format("{0} more errors that are not listed", more);
                break;
            case Warning:
                message = MessageFormat.format("{0} more warnings that are not listed", more);
                break;
            case Information:
            default:
                message = MessageFormat.format("{0} more messages that are not listed", more);
        }
        messageList.add(new MessageImpl(message, null));
        treeViewer.setInput(messageList);
    } else {
        treeViewer.setInput(messages);
    }
}
Also used : Message(eu.esdihumboldt.hale.common.core.report.Message) ArrayList(java.util.ArrayList) MessageImpl(eu.esdihumboldt.hale.common.core.report.impl.MessageImpl)

Aggregations

Message (eu.esdihumboldt.hale.common.core.report.Message)9 InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)3 MessageImpl (eu.esdihumboldt.hale.common.core.report.impl.MessageImpl)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 ArrayList (java.util.ArrayList)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1 MessageFactory (eu.esdihumboldt.hale.common.core.report.MessageFactory)1 Report (eu.esdihumboldt.hale.common.core.report.Report)1 ReportFactory (eu.esdihumboldt.hale.common.core.report.ReportFactory)1 ReportLog (eu.esdihumboldt.hale.common.core.report.ReportLog)1 ReportSession (eu.esdihumboldt.hale.common.core.report.ReportSession)1 Reporter (eu.esdihumboldt.hale.common.core.report.Reporter)1 DefaultReporter (eu.esdihumboldt.hale.common.core.report.impl.DefaultReporter)1 ProjectTransformationEnvironment (eu.esdihumboldt.hale.common.headless.impl.ProjectTransformationEnvironment)1 DefaultInstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage)1 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 MessageType (eu.esdihumboldt.hale.ui.views.report.properties.details.extension.CustomReportDetailsPage.MessageType)1