19 package org.turro.timetracker;
22 import java.io.IOException;
23 import java.util.Arrays;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import org.turro.action.IMailSender;
30 import org.turro.action.MailSenders;
31 import org.turro.auth.Authentication;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.db.ElephantPU;
34 import org.turro.elephant.entities.db.TimeTrackerType;
35 import org.turro.entities.Entities;
36 import org.turro.i18n.I_;
37 import org.turro.jpa.Dao;
38 import org.turro.jpa.export.ExportAsStream;
39 import org.turro.message.MessageQueue;
40 import org.turro.plugin.contacts.IContact;
41 import org.turro.sql.SqlClause;
42 import org.turro.time.Time;
57 .send(
I_.
get(
"Export time tracker"),
I_.
get(
"Export time tracker"));
60 private static void timeTrackerToExcel(
IMailSender sender) {
61 Map<String, String> cache =
new HashMap<>();
62 List<String> l = Arrays.asList(
new String[] {
71 Dao dao =
new ElephantPU();
72 ExportAsStream eq =
new ExportAsStream(dao, l,
73 SqlClause.select(
"tt.entityPath, tt.trackedPath, tt.timeTrack, tt.trackType, tt.hours, tt.validated")
74 .from(
"TimeTracker tt")
75 .where().greaterOrEqual(
"timeTrack", Time.now().addYears(-1).getDate())
76 .orderBy(
"tt.entityPath, tt.trackedPath, tt.timeTrack"));
77 eq.fieldReplacement((col, obj) -> {
78 if(col == 0 || col == 1) {
79 if(cache.containsKey((String) obj)) {
80 obj = cache.get((String) obj);
82 String name = Entities.getController(obj).getName();
83 cache.put((String) obj, name);
87 obj = ((TimeTrackerType) obj).toString();
91 File result = File.createTempFile(
"report",
"_TimeTracker.xls");
92 eq.generateExcel(result);
95 }
catch (IOException ex) {
96 Logger.getLogger(TimeTrackerExporter.class.getName()).log(Level.SEVERE,
null, ex);
static IMailSender getHeavy()
static IContact getIContact()
static String get(String msg)
static void pushMessage(IContact contact, String msg)
static void exportTimeTracker()
IMailSender onFinish(Consumer command)
IMailSender addAttachment(File file)