Search in sources :

Example 6 with ReportSession

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

the class ReportReader method readDirectory.

/**
 * Extracts all {@link ReportSession}s from a given directory.
 *
 * @param dir directory containing all log files
 *
 * @return array of old {@link ReportSession}s
 */
public List<ReportSession> readDirectory(File dir) {
    if (!dir.exists() && dir.mkdirs()) {
        // folder does not exist so there are no reports
        return new ArrayList<ReportSession>();
    }
    // create a list containing the result
    List<ReportSession> list = new ArrayList<ReportSession>();
    List<Long> ids = new ArrayList<Long>();
    // iterate through all files from the directory
    for (File f : dir.listFiles()) {
        // extract the id from filename
        long id = this.getIdentifier(f);
        // add the id
        ids.add(id);
    }
    // sort the ids
    Collections.sort(ids);
    Collections.reverse(ids);
    // and load the latest 3
    for (File f : dir.listFiles()) {
        // extract the id from filename
        long id = this.getIdentifier(f);
        boolean skip = true;
        for (int i = 0; i < 3; i++) {
            if (ids.get(i) == id) {
                skip = false;
                break;
            }
        }
        if (skip) {
            continue;
        }
        // parse the session
        ReportSession session = this.parse(f, id);
        // add it to result
        list.add(session);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession) File(java.io.File)

Example 7 with ReportSession

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

the class ReportServiceImpl method getCurrentSession.

private ReportSession getCurrentSession() {
    // check if a current session exists
    if (this.getCurrentSessionDescription() == 0) {
        this.updateCurrentSessionDescription();
    }
    long time = this.description;
    ReportSession session = reps.get(time);
    if (session == null) {
        session = new ReportSession(time);
        reps.put(time, session);
    }
    return session;
}
Also used : ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Example 8 with ReportSession

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

the class ReportServiceImpl method loadReportsOnStartup.

/**
 * @see eu.esdihumboldt.hale.ui.service.report.ReportService#loadReportsOnStartup()
 */
@Override
public void loadReportsOnStartup() {
    // folder where the reports shall be stored
    File folder = new File(Platform.getLocation().toString() + "/reports/");
    // create a ReportReader
    ReportReader rr = new ReportReader();
    // read all sessions from log folder
    List<ReportSession> list = rr.readDirectory(folder);
    // add them to internal storage
    for (ReportSession s : list) {
        this.reps.put(s.getId(), s);
    }
}
Also used : ReportReader(eu.esdihumboldt.hale.common.core.report.writer.ReportReader) File(java.io.File) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Example 9 with ReportSession

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

the class ReportServiceImpl method saveReportsOnShutdown.

/**
 * @see eu.esdihumboldt.hale.ui.service.report.ReportService#saveReportsOnShutdown()
 */
@Override
public void saveReportsOnShutdown() {
    // folder where the reports shall be stored
    File folder = new File(Platform.getLocation().toString() + "/reports/");
    if (!folder.exists() && !folder.mkdirs()) {
        // folder does not exist and we cannot create it...
        _log.error("Folder for reports does not exist and cannot be created!");
        return;
    }
    // iterate through all sessions
    for (ReportSession s : this.reps.values()) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm");
        File file = new File(folder.getPath() + "/" + df.format(new Date(s.getId())) + "-" + s.getId() + ".log");
        try {
            ReportWriter.write(file, s.getAllReports().values(), false);
        } catch (IOException e) {
            // error during saving
            _log.error("Cannot save report session.", e);
        }
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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