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;
}
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;
}
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);
}
}
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);
}
}
}
Aggregations