Search in sources :

Example 1 with ReportSession

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

the class ReportServiceImpl method loadReport.

/**
 * @see eu.esdihumboldt.hale.ui.service.report.ReportService#loadReport(java.io.File)
 */
@Override
public void loadReport(File file) throws org.eclipse.jface.bindings.keys.ParseException {
    // create a ReportReader
    ReportReader rr = new ReportReader();
    // read all sessions from log folder
    ReportSession s = rr.readFile(file);
    if (s == null) {
        throw new org.eclipse.jface.bindings.keys.ParseException("Log could not be read.");
    }
    // add them to internal storage
    this.reps.put(s.getId(), s);
}
Also used : ReportReader(eu.esdihumboldt.hale.common.core.report.writer.ReportReader) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Example 2 with ReportSession

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

the class ReportServiceImpl method addReport.

/**
 * @see ReportService#addReport(Report)
 */
@SuppressWarnings("unchecked")
@Override
public <M extends Message, R extends Report<M>> void addReport(R report) {
    ReportSession session = this.getCurrentSession();
    session.addReport(report);
    // open ReportList
    openView();
    // notify listeners
    notifyReportAdded(report.getClass(), report.getMessageType(), report);
}
Also used : ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Example 3 with ReportSession

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

the class ReportList method createViewControl.

/**
 * Create contents of the view part.
 *
 * @param parent parent element
 */
@Override
public void createViewControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    TreeColumnLayout layout = new TreeColumnLayout();
    composite.setLayout(layout);
    {
        _treeViewer = new TreeViewer(composite, SWT.BORDER);
        final Tree tree = _treeViewer.getTree();
        tree.setHeaderVisible(false);
        tree.setLinesVisible(false);
        // create column for reports
        TreeViewerColumn col1 = new TreeViewerColumn(_treeViewer, SWT.NONE);
        // add the label provider
        col1.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelProvider()));
        // and layout
        layout.setColumnData(col1.getColumn(), new ColumnWeightData(3));
        // create column for reports
        TreeViewerColumn col2 = new TreeViewerColumn(_treeViewer, SWT.NONE);
        // add the label provider
        col2.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelDateProvider()));
        // create column for reports
        layout.setColumnData(col2.getColumn(), new ColumnWeightData(1));
        new ReportListMenu(getSite(), _treeViewer);
    }
    createActions();
    initializeToolBar();
    initializeMenu();
    // set label provider
    // _treeViewer.setLabelProvider(new ReportListLabelProvider());
    // set content provider
    _treeViewer.setContentProvider(new ReportListContentProvider());
    // disable this if it uses too much memory
    // but should maintain the list much faster
    _treeViewer.setUseHashlookup(true);
    // order the sessions from latest to oldest
    _treeViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof ReportSession && e2 instanceof ReportSession) {
                long first = ((ReportSession) e1).getId();
                long second = ((ReportSession) e2).getId();
                if (first > second) {
                    return -1;
                } else if (first < second) {
                    return 1;
                } else {
                    return 0;
                }
            } else if (e1 instanceof Report<?> && e2 instanceof Report<?>) {
                Report<?> first = (Report<?>) e1;
                Report<?> second = (Report<?>) e2;
                if (first.getStartTime() == null && second.getStartTime() == null) {
                    return 0;
                } else if (first.getStartTime() == null) {
                    return 1;
                } else if (second.getStartTime() == null) {
                    return -1;
                } else if (first.getStartTime().getTime() > second.getStartTime().getTime()) {
                    return -1;
                } else if (first.getStartTime().getTime() < second.getStartTime().getTime()) {
                    return 1;
                } else {
                    return 0;
                }
            }
            return 0;
        }
    });
    // set selection provider
    getSite().setSelectionProvider(_treeViewer);
    _treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            OpenPropertiesHandler.unpinAndOpenPropertiesView(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
        }
    });
    // load all added reports
    this.loadReports();
}
Also used : TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Report(eu.esdihumboldt.hale.common.core.report.Report) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Tree(org.eclipse.swt.widgets.Tree) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Example 4 with ReportSession

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

the class ReportReader method parse.

/**
 * Parse a file and creates a {@link ReportSession}.
 *
 * @param file file to parse
 * @param id identifier for {@link ReportSession}
 *
 * @return the {@link ReportSession}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private ReportSession parse(File file, long id) {
    // create the new session
    ReportSession session = new ReportSession(id);
    // get content
    StringBuilder sw = new StringBuilder();
    BufferedReader reader = null;
    String nl = System.getProperty("line.separator");
    try {
        // try to get a BufferedReader from FileReader
        reader = new BufferedReader(new FileReader(file));
        String temp;
        Report lastReport = null;
        String messageType = "";
        // read all data
        while (reader.ready()) {
            temp = reader.readLine();
            if (temp == null || temp.isEmpty()) {
                continue;
            }
            // check if the line starts with a marker
            if (temp.startsWith("!")) {
                // we found a new marker, time to parse previous lines
                Report r = rf.parse(sw.toString());
                if (!sw.toString().isEmpty() && !messageType.isEmpty()) {
                    Message m = mf.parse(sw.toString());
                    if (m != null) {
                        ReportLog<Message> repLog = (ReportLog<Message>) lastReport;
                        // add the message to the corresponding report
                        if (messageType.equals("!ERROR")) {
                            repLog.error(m);
                        } else if (messageType.equals("!WARN")) {
                            repLog.warn(m);
                        } else if (messageType.equals("!INFO")) {
                            repLog.info(m);
                        }
                        // reset message type
                        messageType = "";
                    }
                } else if (r != null) {
                    // new report
                    lastReport = r;
                    session.addReport(lastReport);
                }
                // check if the new line is a marker for messages
                if (temp.startsWith("!ERROR")) {
                    messageType = temp;
                    temp = "";
                } else if (temp.startsWith("!WARN")) {
                    messageType = temp;
                    temp = "";
                } else if (temp.startsWith("!INFO")) {
                    messageType = temp;
                    temp = "";
                }
                // then flush sw
                sw = new StringBuilder();
                // and add the new line
                sw.append(temp + nl);
            } else {
                sw.append(temp + nl);
            }
        }
        // close reader
        reader.close();
    } catch (Exception e) {
        _log.error("Error while parsing a log file.", e);
    }
    return session;
}
Also used : ReportLog(eu.esdihumboldt.hale.common.core.report.ReportLog) Message(eu.esdihumboldt.hale.common.core.report.Message) Report(eu.esdihumboldt.hale.common.core.report.Report) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Example 5 with ReportSession

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

the class ReportReader method readFile.

/**
 * Creates a {@link ReportSession} from a report log file.
 *
 * @param file the file to parse
 *
 * @return {@link ReportSession} from the file
 */
public ReportSession readFile(File file) {
    if (file.exists()) {
        // extract the id from filename
        long id = this.getIdentifier(file);
        // parse the session
        ReportSession session = this.parse(file, id);
        return session;
    }
    return null;
}
Also used : ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Aggregations

ReportSession (eu.esdihumboldt.hale.common.core.report.ReportSession)9 File (java.io.File)3 Report (eu.esdihumboldt.hale.common.core.report.Report)2 ReportReader (eu.esdihumboldt.hale.common.core.report.writer.ReportReader)2 Message (eu.esdihumboldt.hale.common.core.report.Message)1 ReportLog (eu.esdihumboldt.hale.common.core.report.ReportLog)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TreeColumnViewerLabelProvider (org.eclipse.jface.viewers.TreeColumnViewerLabelProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 Viewer (org.eclipse.jface.viewers.Viewer)1