This is an automated email from the git hooks/post-receive script. New commit to branch 1.6-database-h2 in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit f8ebac2a2a1c1535f12bcd306ee0c82cbf9ba865 Author: Eric Chatellier <chatellier@codelutin.com> Date: Fri Jun 1 15:48:09 2018 +0200 refs #142: Begin global refactoring --- pom.xml | 14 +- src/main/java/org/chorem/jtimer/JTimer.java | 191 ++---- src/main/java/org/chorem/jtimer/JTimerActions.java | 78 --- src/main/java/org/chorem/jtimer/JTimerFactory.java | 91 --- .../org/chorem/jtimer/core/ApplicationContext.java | 144 +++++ .../{JTimerConfig.java => core/Configuration.java} | 50 +- .../{data/package-info.java => core/Context.java} | 36 +- .../org/chorem/jtimer/data/CommonVetoable.java | 208 ------- .../org/chorem/jtimer/data/DataEventListener.java | 193 ------ .../chorem/jtimer/data/DataViolationException.java | 75 --- .../java/org/chorem/jtimer/data/TimerCore.java | 208 ------- .../org/chorem/jtimer/data/TimerDataManager.java | 676 --------------------- .../jtimer/data/VetoableDataEventListener.java | 148 ----- src/main/java/org/chorem/jtimer/db/Database.java | 6 +- .../java/org/chorem/jtimer/db/DbDataMigration.java | 14 +- src/main/java/org/chorem/jtimer/db/DbManager.java | 1 + .../java/org/chorem/jtimer/entities/TimerTask.java | 2 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 69 +-- src/main/java/org/chorem/jtimer/io/Saver.java | 4 +- .../org/chorem/jtimer/services/AlertService.java | 4 + .../org/chorem/jtimer/services/ReportService.java | 4 + .../org/chorem/jtimer/services/TaskService.java | 5 + .../org/chorem/jtimer/services/TimeService.java | 4 + .../java/org/chorem/jtimer/ui/NewTaskView.java | 13 +- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 27 +- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 14 +- .../org/chorem/jtimer/ui/alert/AlertEditor.java | 9 +- .../org/chorem/jtimer/ui/report/ReportView.java | 20 +- .../chorem/jtimer/ui/systray/SystrayManager.java | 17 +- .../org/chorem/jtimer/ui/tasks/IdleDialog.java | 23 +- .../chorem/jtimer/ui/tasks/RefreshTreeTask.java | 11 +- .../org/chorem/jtimer/ui/tasks/RunTaskJob.java | 10 +- .../jtimer/ui/tree/CheckBoxTreeCellComponent.java | 15 +- .../jtimer/ui/tree/CheckBoxTreeCellEditor.java | 13 +- .../jtimer/ui/tree/CheckBoxTreeCellRenderer.java | 11 +- .../org/chorem/jtimer/ui/tree/TaskTreeModel.java | 9 +- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 29 +- .../ProjectsAndTasksRunningCellRenderer.java | 17 +- .../jtimer/ui/treetable/ProjectsAndTasksTable.java | 11 +- .../ui/treetable/dnd/TimerTaskTransferHandler.java | 10 +- .../java/org/chorem/jtimer/AbstractJTimerTest.java | 361 ----------- .../java/org/chorem/jtimer/JTimerFactoryTest.java | 95 --- .../org/chorem/jtimer/data/CommonVetoableTest.java | 195 ------ .../chorem/jtimer/data/TimerDataManagerTest.java | 637 ------------------- .../org/chorem/jtimer/entities/TimerAlertTest.java | 130 ---- .../chorem/jtimer/entities/TimerProjectTest.java | 66 -- .../jtimer/entities/TimerTaskHelperTest.java | 52 -- .../org/chorem/jtimer/entities/TimerTaskTest.java | 119 ---- .../org/chorem/jtimer/io/AbstractSaverTest.java | 101 --- .../jtimer/io/GTimerIncrementalSaverTest.java | 419 ------------- .../jtimer/system/SystemInfoFactoryTest.java | 69 --- .../jtimer/ui/report/ReportGeneratorTest.java | 368 ----------- .../chorem/jtimer/ui/report/ReportUtilsTest.java | 319 ---------- .../jtimer/ui/widget/DurationEditorTest.java | 56 -- .../chorem/jtimer/utils/DailySortedMapTest.java | 538 ---------------- 55 files changed, 421 insertions(+), 5588 deletions(-) diff --git a/pom.xml b/pom.xml index 9493bad..718cd0c 100644 --- a/pom.xml +++ b/pom.xml @@ -171,16 +171,14 @@ <scope>compile</scope> </dependency> <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - <version>2.11.0</version> - <scope>runtime</scope> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.8.0-beta2</version> </dependency> <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-jcl</artifactId> - <version>2.11.0</version> - <scope>runtime</scope> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>1.3.0-alpha4</version> </dependency> <dependency> <groupId>org.freemarker</groupId> diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index cf818aa..f4283f5 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -22,12 +22,9 @@ package org.chorem.jtimer; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.DataViolationException; -import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.core.ApplicationContext; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.system.SystemInfo; @@ -46,11 +43,12 @@ import org.chorem.jtimer.ui.treetable.ProjectsAndTasksTable; import org.chorem.jtimer.ui.widget.WindowProperty2; import org.jdesktop.application.Action; import org.jdesktop.application.Application; -import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.Task; import org.jdesktop.application.TaskMonitor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.swing.ButtonGroup; import javax.swing.InputMap; @@ -79,7 +77,6 @@ import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.io.File; import java.io.IOException; import java.util.Calendar; import java.util.Date; @@ -98,14 +95,10 @@ import java.util.Timer; * Last update : $Date$ * By : $Author$ */ -public class JTimer extends SingleFrameApplication implements - TreeSelectionListener, MouseListener { +public class JTimer extends SingleFrameApplication implements TreeSelectionListener, MouseListener { /** log. */ - private static Log log = LogFactory.getLog(JTimer.class); - - /** Timer core controller. */ - protected TimerCore core; + private static Logger logger = LoggerFactory.getLogger(JTimer.class); /** Tree structure. */ protected ProjectsAndTasksTable projectsAndTasksTable; @@ -116,8 +109,8 @@ public class JTimer extends SingleFrameApplication implements /** I18n resources map. */ protected ResourceMap resourceMap; - /** Jtimer application config. */ - public static JTimerConfig config; + /** JTimer main ui context. */ + protected Context context; /** Single project selection property. */ protected boolean selectedSingleProject; @@ -154,16 +147,8 @@ public class JTimer extends SingleFrameApplication implements * * @param args args */ - public static void main(String[] args) { - - if (log.isInfoEnabled()) { - log.info("Starting " + JTimer.class.getSimpleName() + " at " + new Date()); - } - - // load configuration and run actions - loadConfiguration(args); - config.doAction(JTimerConfig.STEP_BEFORE_UI); - + public static void main(String[] args) throws IOException { + logger.info("Starting {} at {}", JTimer.class.getSimpleName(), new Date()); launch(JTimer.class, args); } @@ -180,7 +165,7 @@ public class JTimer extends SingleFrameApplication implements super.initialize(args); // init resources map - ApplicationContext ctxt = getContext(); + org.jdesktop.application.ApplicationContext ctxt = getContext(); resourceMap = ctxt.getResourceMap(); // native init @@ -190,51 +175,20 @@ public class JTimer extends SingleFrameApplication implements // fix start in iconified mode ctxt.getSessionStorage().putProperty(JFrame.class, new WindowProperty2()); - // init timercore - core = new TimerCore(); - - // Systray mgr - systrayManager = new SystrayManager(this); - core.getData().addDataEventListener(systrayManager); - - IdleDialog.init(this, core); - } - - /** - * Load configuration. - * - * @param args args to parse command line options - */ - protected static void loadConfiguration(String[] args) { - - config = new JTimerConfig(); + // init context + ApplicationContext applicationContext = new ApplicationContext(); + try { + applicationContext.init(args); + context = new Context(applicationContext); + } catch (IOException ex) { + throw new RuntimeException(ex); + } - migrateConfiguration(); - // parse after file migration - config.parse(args); - } + // Systray mgr + systrayManager = new SystrayManager(this, context); - /** - * Migrate configuration between version 1.3 and 1.4. - */ - protected static void migrateConfiguration() { - // add file migration for configuration file created before version 1.4 - File homeDir = new File(System.getProperty("user.home"), ".jtimer"); - File oldFile = new File(homeDir, "JTimer.properties"); - File newFile = new File(config.appConfig.getUserConfigDirectory(), config.appConfig.getConfigFileName()); - if (oldFile.isFile() && !newFile.isFile()) { - if (log.isInfoEnabled()) { - log.info("Migration configuration file location"); - } - try { - FileUtils.copyFile(oldFile, newFile); - } catch (IOException ex) { - if (log.isErrorEnabled()) { - log.error("Can't copy config file to new location", ex); - } - } - } + IdleDialog.init(this, context); } /** @@ -276,9 +230,9 @@ public class JTimer extends SingleFrameApplication implements panel.add(scrollPaneProjectTreeTable, BorderLayout.CENTER); // status bar bottom - StatusBar sb = new StatusBar(this, core.getData()); + StatusBar sb = new StatusBar(this, context); // status bar ui will be notified from events - core.getData().addDataEventListener(sb); + //core.getData().addDataEventListener(sb); panel.add(sb, BorderLayout.SOUTH); // taille par defaut au premier lancement de l'application @@ -295,13 +249,13 @@ public class JTimer extends SingleFrameApplication implements */ protected ProjectsAndTasksTable createTreeTable() { - projectsAndTasksTable = new ProjectsAndTasksTable(this, core); + projectsAndTasksTable = new ProjectsAndTasksTable(this, context); // name used in properties files projectsAndTasksTable.setName("projectslist"); projectsAndTasksTable.addTreeSelectionListener(this); projectsAndTasksTable.addMouseListener(this); - projectsAndTasksTable.setShowClosed(config.isShowClosed()); + // FIXME projectsAndTasksTable.setShowClosed(config.isShowClosed()); // since merge option, selection can be multiple projectsAndTasksTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); @@ -394,14 +348,14 @@ public class JTimer extends SingleFrameApplication implements // show closed JMenuItem showClosedItem = new JCheckBoxMenuItem(); showClosedItem.setAction(getAction("isShowClosed")); - showClosedItem.setSelected(config.isShowClosed()); + showClosedItem.setSelected(context.getConfig().isShowClosed()); showClosedItem.setIcon(null); menu.add(showClosedItem); // close to systray JMenuItem closeToSysItem = new JCheckBoxMenuItem(); closeToSysItem.setAction(getAction("isCloseToSystray")); - closeToSysItem.setSelected(config.isCloseToSystray()); + closeToSysItem.setSelected(context.getConfig().isCloseToSystray()); closeToSysItem.setIcon(null); menu.add(closeToSysItem); @@ -415,7 +369,7 @@ public class JTimer extends SingleFrameApplication implements int realDay = (day - 1) % 7 + 1; JRadioButtonMenuItem fdowItem = new JRadioButtonMenuItem(); fdowItem.setAction(getAction("isReportFirstDayOfWeek" + realDay)); - fdowItem.setSelected(realDay == JTimer.config.getReportFirstDayOfWeek()); + fdowItem.setSelected(realDay == context.getConfig().getReportFirstDayOfWeek()); fdowItem.setIcon(null); reportFDoW.add(fdowItem); bg.add(fdowItem); @@ -478,7 +432,7 @@ public class JTimer extends SingleFrameApplication implements protected void ready() { // init core, load list, synchronization, etc... - boolean init = core.init(); + boolean init = context.ready(); if (init) { // schedule tree refresh at midnight @@ -486,10 +440,6 @@ public class JTimer extends SingleFrameApplication implements // install icon (do it at last action) systrayManager.install(); - - // run action after ui - config.putObject(this); - config.doAction(JTimerConfig.STEP_AFTER_UI); } else { String failTitle = resourceMap.getString("startFail.title"); String failMessage = resourceMap.getString("startFail.message"); @@ -508,8 +458,8 @@ public class JTimer extends SingleFrameApplication implements */ @Override protected void shutdown() { - log.debug("Shutdown called"); - core.exit(); + logger.debug("Shutdown called"); + context.exit(); // save context // super, sauve le context des fenetres, etc... @@ -522,7 +472,7 @@ public class JTimer extends SingleFrameApplication implements protected void scheduleTreeRefresh() { // task used to refresh tree - java.util.TimerTask refreshTreeTask = new RefreshTreeTask(core); + java.util.TimerTask refreshTreeTask = new RefreshTreeTask(context); Timer timer = new Timer(); @@ -598,8 +548,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action(enabledProperty = "selectedSingleProject") public void editProject() { - TimerProject project = projectsAndTasksTable.getSelectedProjects().get( - 0); + TimerProject project = projectsAndTasksTable.getSelectedProjects().get(0); String newProjectName = (String) JOptionPane.showInputDialog(getMainFrame(), resourceMap .getString("input.editProjectMessage"), resourceMap @@ -630,7 +579,7 @@ public class JTimer extends SingleFrameApplication implements // select task to add new task TimerTask selectedTask = projectsAndTasksTable.getSelectedElements().get(0); - NewTaskView newTaskPanel = new NewTaskView(this, core, selectedTask); + NewTaskView newTaskPanel = new NewTaskView(this, context, selectedTask); show(newTaskPanel); } @@ -653,7 +602,7 @@ public class JTimer extends SingleFrameApplication implements TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); - TimerTaskEditor editor = new TimerTaskEditor(this, task, core); + TimerTaskEditor editor = new TimerTaskEditor(this, task, context); show(editor); } @@ -672,7 +621,7 @@ public class JTimer extends SingleFrameApplication implements // can't be null TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); - RunTaskJob jobToRun = new RunTaskJob(this, task, core.getData()); + RunTaskJob jobToRun = new RunTaskJob(this, task, context); core.getData().startTask(task); return jobToRun; @@ -893,7 +842,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void isReportFirstDayOfWeek1() { - config.setReportFirstDayOfWeek(1); + context.getConfig().setReportFirstDayOfWeek(1); } /** @@ -901,7 +850,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void isReportFirstDayOfWeek2() { - config.setReportFirstDayOfWeek(2); + context.getConfig().setReportFirstDayOfWeek(2); } /** @@ -909,7 +858,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void isReportFirstDayOfWeek3() { - config.setReportFirstDayOfWeek(3); + context.getConfig().setReportFirstDayOfWeek(3); } /** @@ -917,7 +866,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void isReportFirstDayOfWeek4() { - config.setReportFirstDayOfWeek(4); + context.getConfig().setReportFirstDayOfWeek(4); } /** @@ -925,7 +874,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void isReportFirstDayOfWeek5() { - config.setReportFirstDayOfWeek(5); + context.getConfig().setReportFirstDayOfWeek(5); } /** @@ -933,7 +882,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void isReportFirstDayOfWeek6() { - config.setReportFirstDayOfWeek(6); + context.getConfig().setReportFirstDayOfWeek(6); } /** @@ -941,7 +890,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void isReportFirstDayOfWeek7() { - config.setReportFirstDayOfWeek(7); + context.getConfig().setReportFirstDayOfWeek(7); } /** @@ -1087,11 +1036,9 @@ public class JTimer extends SingleFrameApplication implements @Action(enabledProperty = "selectedSingleTask") public void editAlert() { // select task to edit alert - TimerTask selectedTask = projectsAndTasksTable.getSelectedTasks() - .get(0); + TimerTask selectedTask = projectsAndTasksTable.getSelectedTasks().get(0); - AlertEditor alertEditor = new AlertEditor(this, core.getData(), - selectedTask); + AlertEditor alertEditor = new AlertEditor(this, context, selectedTask); show(alertEditor); } @@ -1100,7 +1047,7 @@ public class JTimer extends SingleFrameApplication implements */ @Action public void makeReport() { - ReportView view = new ReportView(this, core); + ReportView view = new ReportView(this, context); show(view); } @@ -1130,8 +1077,7 @@ public class JTimer extends SingleFrameApplication implements public void setSelectedSingleProject(boolean selectedSingleProject) { boolean oldValue = this.selectedSingleProject; this.selectedSingleProject = selectedSingleProject; - firePropertyChange("selectedSingleProject", oldValue, - selectedSingleProject); + firePropertyChange("selectedSingleProject", oldValue, selectedSingleProject); } /** @@ -1171,8 +1117,7 @@ public class JTimer extends SingleFrameApplication implements public void setSelectedSingleElement(boolean selectedSingleElement) { boolean oldValue = this.selectedSingleElement; this.selectedSingleElement = selectedSingleElement; - firePropertyChange("selectedSingleElement", oldValue, - selectedSingleElement); + firePropertyChange("selectedSingleElement", oldValue, selectedSingleElement); } /** @@ -1192,8 +1137,7 @@ public class JTimer extends SingleFrameApplication implements public void setSelectedSingleRunningTask(boolean selectedSingleRunningTask) { boolean oldValue = this.selectedSingleRunningTask; this.selectedSingleRunningTask = selectedSingleRunningTask; - firePropertyChange("selectedSingleRunningTask", oldValue, - selectedSingleRunningTask); + firePropertyChange("selectedSingleRunningTask", oldValue, selectedSingleRunningTask); } /** @@ -1213,8 +1157,7 @@ public class JTimer extends SingleFrameApplication implements public void setSelectedSingleStoppedTask(boolean selectedSingleStoppedTask) { boolean oldValue = this.selectedSingleStoppedTask; this.selectedSingleStoppedTask = selectedSingleStoppedTask; - firePropertyChange("selectedSingleStoppedTask", oldValue, - selectedSingleStoppedTask); + firePropertyChange("selectedSingleStoppedTask", oldValue, selectedSingleStoppedTask); } /** @@ -1234,8 +1177,7 @@ public class JTimer extends SingleFrameApplication implements public void setSelectedMultiplesProjects(boolean selectedMultiplesProjects) { boolean oldValue = this.selectedMultiplesProjects; this.selectedMultiplesProjects = selectedMultiplesProjects; - firePropertyChange("selectedMultiplesProjects", oldValue, - selectedMultiplesProjects); + firePropertyChange("selectedMultiplesProjects", oldValue, selectedMultiplesProjects); } /** @@ -1255,8 +1197,7 @@ public class JTimer extends SingleFrameApplication implements public void setSelectedMultiplesTasks(boolean selectedMultiplesTasks) { boolean oldValue = this.selectedMultiplesTasks; this.selectedMultiplesTasks = selectedMultiplesTasks; - firePropertyChange("selectedMultiplesTasks", oldValue, - selectedMultiplesTasks); + firePropertyChange("selectedMultiplesTasks", oldValue, selectedMultiplesTasks); } /** @@ -1276,8 +1217,7 @@ public class JTimer extends SingleFrameApplication implements public void setSelectedMultiplesElements(boolean selectedMultiplesElements) { boolean oldValue = this.selectedMultiplesElements; this.selectedMultiplesElements = selectedMultiplesElements; - firePropertyChange("selectedMultiplesElements", oldValue, - selectedMultiplesElements); + firePropertyChange("selectedMultiplesElements", oldValue, selectedMultiplesElements); } /** @@ -1356,12 +1296,9 @@ public class JTimer extends SingleFrameApplication implements setSelectedMultiplesTasks(projects.size() == 0); setSelectedTasks(projects.size() == 0); } else { - setSelectedSingleProject(tasks.size() == 0 - && projects.size() == 1); - setSelectedMultiplesProjects(tasks.size() == 0 - && projects.size() > 1); - setSelectedProjects(tasks.size() == 0 - && projects.size() >= 1); + setSelectedSingleProject(tasks.size() == 0 && projects.size() == 1); + setSelectedMultiplesProjects(tasks.size() == 0 && projects.size() > 1); + setSelectedProjects(tasks.size() == 0 && projects.size() >= 1); } } setSelectedSingleElement(elements.size() == 1); @@ -1416,11 +1353,7 @@ public class JTimer extends SingleFrameApplication implements @Override public void mouseClicked(MouseEvent e) { - if (log.isDebugEnabled()) { - log.debug("Mouse clicked (" + e.getClickCount() - + " clics), source = " - + e.getSource().getClass().getName()); - } + logger.debug("Mouse clicked ({} clics), source = ", e.getClickCount(), e.getSource().getClass().getName()); switch (e.getButton()) { @@ -1444,14 +1377,10 @@ public class JTimer extends SingleFrameApplication implements TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); stopTask(task); } else { - if (log.isDebugEnabled()) { - log.debug("Non selected non running task to launch"); - } + logger.debug("Non selected non running task to launch"); } } else { - if (log.isDebugEnabled()) { - log.debug("Single clic on tree, do nothing"); - } + logger.debug("Single clic on tree, do nothing"); } } break; diff --git a/src/main/java/org/chorem/jtimer/JTimerActions.java b/src/main/java/org/chorem/jtimer/JTimerActions.java deleted file mode 100644 index 095324e..0000000 --- a/src/main/java/org/chorem/jtimer/JTimerActions.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer; - -import org.chorem.jtimer.JTimerConfig.JTimerAction; -import org.nuiton.config.ApplicationConfig; -import org.nuiton.config.ApplicationConfig.Action.Step; - -/** - * JTimer actions class run from command line. - * - * @author chatellier - * @version $Revision: 2825 $ - * - * Last update : $Date: 2012-03-15 11:41:39 +0100 (jeu. 15 mars 2012) $ - * By : $Author: echatellier $ - */ -public class JTimerActions { - - protected ApplicationConfig config; - - public JTimerActions(ApplicationConfig config) { - this.config = config; - } - - @Step(JTimerConfig.STEP_BEFORE_UI) - public void help() { - displayVersion(); - System.out.println(); - for (JTimerAction a : JTimerAction.values()) { - for (int index = 0; index < a.aliases.length; index++) { - System.out.print(a.aliases[index]); - if (index != a.aliases.length - 1) { - System.out.print(", "); - } - } - System.out.println("\t" + a.description); - } - System.exit(0); - } - - @Step(JTimerConfig.STEP_BEFORE_UI) - public void version() { - displayVersion(); - System.exit(0); - } - - protected void displayVersion() { - System.out.println("jTimer " + config.getOption("application.version")); - System.out.println(config.getOption("application.website")); - } - - @Step(JTimerConfig.STEP_AFTER_UI) - public void start(String taskPath) { - JTimer ui = config.getObject(JTimer.class); - ui.startTask(taskPath); - } -} diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java deleted file mode 100644 index e66396a..0000000 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2018 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.io.Saver; - -/** - * JTimer config class. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class JTimerFactory { - - /** Logger */ - private static Log log = LogFactory.getLog(JTimerFactory.class); - - /** Saver */ - protected static Saver saver; - - /** - * Constructeur. - */ - protected JTimerFactory() { - // disable instantiation - } - - /** - * Get saver manager. - * - * @return saver manager - */ - public static Saver getFileSaver() { - - if (saver == null) { - - Class<?> saverClass = JTimer.config.getIOSaverClass(); - - // log - if (log.isInfoEnabled()) { - log.info("Using saver class : " + saverClass); - log.info(" with saver home directory : " + JTimer.config.getDataDirectory()); - log.info(" with auto save delay : " + JTimer.config.getIOSaverAutoSaveDelay()); - } - - try { - // get instance - saver = (Saver) saverClass.newInstance(); - - // set delay to saver - saver.setAutoSaveDelay(JTimer.config.getIOSaverAutoSaveDelay() * 1000); - - } catch (InstantiationException e) { - if (log.isErrorEnabled()) { - log.error("Can't instantiate class : " + saverClass, e); - } - } catch (IllegalAccessException e) { - if (log.isErrorEnabled()) { - log.error("Can't access class : " + saverClass, e); - } - } - } - - return saver; - } -} diff --git a/src/main/java/org/chorem/jtimer/core/ApplicationContext.java b/src/main/java/org/chorem/jtimer/core/ApplicationContext.java new file mode 100644 index 0000000..89784d4 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/core/ApplicationContext.java @@ -0,0 +1,144 @@ +/* + * #%L + * jTimer + * %% + * Copyright (C) 2018 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package org.chorem.jtimer.core; + +import org.apache.commons.io.FileUtils; +import org.chorem.jtimer.db.Database; +import org.chorem.jtimer.db.DbDataMigration; +import org.chorem.jtimer.db.DbManager; +import org.chorem.jtimer.db.DbMigration; +import org.chorem.jtimer.services.AlertService; +import org.chorem.jtimer.services.ReportService; +import org.chorem.jtimer.services.TaskService; +import org.chorem.jtimer.services.TimeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; + +public class ApplicationContext { + + protected static final Logger logger = LoggerFactory.getLogger(ApplicationContext.class); + + protected Configuration config; + + protected DbManager dbManager; + + protected ReportService reportService; + + protected TaskService taskService; + + protected TimeService timeService; + + protected AlertService alertService; + + public Configuration getConfig() { + return config; + } + + public void init(String[] args) throws IOException { + loadConfiguration(args); + migratePre15Directories(); + initDatabase(); + initServices(); + } + + /** + * Load configuration. + * + * @param args args to parse command line options + */ + private void loadConfiguration(String[] args) { + config = new Configuration(); + migratePre13Configuration(); + // parse after file migration + config.parse(args); + } + + /** + * Migrate configuration between version 1.3 and 1.4. + */ + protected void migratePre13Configuration() { + // add file migration for configuration file created before version 1.4 + File homeDir = new File(System.getProperty("user.home"), ".jtimer"); + File oldFile = new File(homeDir, "JTimer.properties"); + File newFile = new File(config.appConfig.getUserConfigDirectory(), config.appConfig.getConfigFileName()); + if (oldFile.isFile() && !newFile.isFile()) { + logger.info("Migration configuration file location"); + try { + FileUtils.copyFile(oldFile, newFile); + } catch (IOException ex) { + logger.error("Can't copy config file to new location", ex); + } + } + } + + + + /** + * Migrate file structure for jtimer 1.5 directories changes. + * + * @throws IOException + */ + protected void migratePre15Directories() throws IOException { + File newDataDirectory = config.getDataDirectory(); + File newBackupDirectory = config.getBackupDirectory(); + File oldBackupDirectory = config.getGtimerBackupDirectory(); + File oldDataDirectory = config.getGtimerDataDirectory(); + + // migrate data + if (!newDataDirectory.isDirectory() && oldDataDirectory.isDirectory()) { + newDataDirectory.mkdirs(); + + logger.info("Migrate data directory from {} to {}", oldDataDirectory, newDataDirectory); + + // exclude internal backup directory from recursion + FileUtils.copyDirectory(oldDataDirectory, newDataDirectory, pathName -> !pathName.equals(oldBackupDirectory)); + } + + // migrate backup + if (!newBackupDirectory.isDirectory() && oldBackupDirectory.isDirectory()) { + newBackupDirectory.mkdirs(); + + logger.info("Migrate backup directory from {} to {}", oldBackupDirectory, newBackupDirectory); + + FileUtils.copyDirectory(oldBackupDirectory, newBackupDirectory); + } + } + + protected void initDatabase() { + Database database = new Database(config); + dbManager = new DbManager(database); + DbMigration dbMigration = new DbMigration(database); + dbMigration.init(); + DbDataMigration dbDataMigration = new DbDataMigration(dbManager); + dbDataMigration.init(); + } + + protected void initServices() { + alertService = new AlertService(); + taskService = new TaskService(); + reportService = new ReportService(); + timeService = new TimeService(); + } +} diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/core/Configuration.java similarity index 83% rename from src/main/java/org/chorem/jtimer/JTimerConfig.java rename to src/main/java/org/chorem/jtimer/core/Configuration.java index a7f88ed..016fbcd 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/core/Configuration.java @@ -20,13 +20,13 @@ * #L% */ -package org.chorem.jtimer; +package org.chorem.jtimer.core; import org.apache.commons.io.FilenameUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.nuiton.config.ApplicationConfig; import org.nuiton.config.ArgumentsParserException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; import java.io.File; @@ -50,38 +50,26 @@ import java.util.TreeMap; * Last update : $Date$ * By : $Author$ */ -public class JTimerConfig { +public class Configuration { - private static final Log log = LogFactory.getLog(JTimerConfig.class); - - /** To tag action to be run before ui start. */ - protected static final int STEP_BEFORE_UI = 0; - /** To tag action to be run after ui start. */ - protected static final int STEP_AFTER_UI = 1; + private static final Logger logger = LoggerFactory.getLogger(Configuration.class); protected ApplicationConfig appConfig; - public JTimerConfig() { + public Configuration() { appConfig = new ApplicationConfig(); for (JTimerOption o : JTimerOption.values()) { if (o.defaultValue != null) { appConfig.setDefaultOption(o.key, o.defaultValue); } } - for (JTimerAction a : JTimerAction.values()) { - for (String alias : a.aliases) { - appConfig.addActionAlias(alias, a.action); - } - } } public void parse(String... args) { try { appConfig.parse(args); } catch (ArgumentsParserException ex) { - if (log.isErrorEnabled()) { - log.error("Can't parse configuration", ex); - } + logger.error("Can't parse configuration", ex); } } @@ -103,9 +91,7 @@ public class JTimerConfig { try { appConfig.doAction(step); } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't run command line actions", ex); - } + logger.error("Can't run command line actions", ex); } } @@ -237,9 +223,7 @@ public class JTimerConfig { } } } catch (DirectoryIteratorException | IOException ex) { - if (log.isErrorEnabled()) { - log.error("Can't create backup", ex); - } + logger.error("Can't create backup", ex); } } @@ -313,20 +297,4 @@ public class JTimerConfig { this.defaultValue = defaultValue; } } - - protected enum JTimerAction { - HELP("Show help", JTimerActions.class.getName() + "#help", "--help", "-h"), - VERSION("Display application version", JTimerActions.class.getName() + "#version", "--version", "-v"), - START("Start task", JTimerActions.class.getName() + "#start", "--start", "-s"); - - protected String description; - protected String action; - protected String[] aliases; - - JTimerAction(String description, String action, String... aliases) { - this.description = description; - this.action = action; - this.aliases = aliases; - } - } } diff --git a/src/main/java/org/chorem/jtimer/data/package-info.java b/src/main/java/org/chorem/jtimer/core/Context.java similarity index 53% rename from src/main/java/org/chorem/jtimer/data/package-info.java rename to src/main/java/org/chorem/jtimer/core/Context.java index b156b41..2631ec5 100644 --- a/src/main/java/org/chorem/jtimer/data/package-info.java +++ b/src/main/java/org/chorem/jtimer/core/Context.java @@ -2,24 +2,42 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin + * Copyright (C) 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -/** - * Data management classes. - */ -package org.chorem.jtimer.data; +package org.chorem.jtimer.core; + +public class Context { + + protected ApplicationContext applicationContext; + + public Context(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + public Configuration getConfig() { + return applicationContext.getConfig(); + } + + public boolean ready() { + return false; + } + + public boolean exit() { + return false; + } +} diff --git a/src/main/java/org/chorem/jtimer/data/CommonVetoable.java b/src/main/java/org/chorem/jtimer/data/CommonVetoable.java deleted file mode 100644 index c70c1e8..0000000 --- a/src/main/java/org/chorem/jtimer/data/CommonVetoable.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; - -import java.util.Collection; -import java.util.List; - -/** - * Common jtimer vetoable politics. - * - * Check that: - * - a task name doesn't appears twice in the same level. - * - creation - * - modification - * - move - */ -public class CommonVetoable implements VetoableDataEventListener { - - /** log. */ - private static Log log = LogFactory.getLog(CommonVetoable.class); - - /** - * Duplicated project violation key. - */ - protected static final String DUPLICATED_PROJECT_VIOLATION = "vetoable.common.duplicated.project.name"; - - /** - * Duplicated task violation key. - */ - protected static final String DUPLICATED_TASK_VIOLATION = "vetoable.common.duplicated.task.name"; - - /** - * Violation if try to move project into task. - */ - protected static final String MOVE_INVALID_TYPES_VIOLATION = "vetoable.common.move.invalid.types"; - - /** - * Violation if try to merge task and project. - */ - protected static final String MERGE_INVALID_TYPES_VIOLATION = "vetoable.common.merge.invalid.types"; - - /** - * Data manager. - */ - protected TimerDataManager manager; - - /** - * Constructor. - * - * @param manager data manager - */ - public CommonVetoable(TimerDataManager manager) { - this.manager = manager; - } - - /** - * Test if task name is found is tasks list. - * - * @param task task to check - * @param tasks tasks list to search into - * @return founded - */ - protected boolean isSameTaskName(TimerTask task, - List<? extends TimerTask> tasks) { - boolean found = false; - - for (TimerTask currentTask : tasks) { - if (currentTask.getName().equals(task.getName())) { - found = true; - } - } - - return found; - } - - @Override - public void checkAddProject(TimerProject project) { - - // check duplicated project name - /* - FIXME db - if (isSameTaskName(project, manager.getProjectsList())) { - if (log.isDebugEnabled()) { - log.debug("Duplicated name, checkAddProject won't pass"); - } - throw new DataViolationException("Can't add project", DUPLICATED_PROJECT_VIOLATION); - }*/ - } - - @Override - public void checkAddTask(TimerTask parent, TimerTask task) { - - // check duplicated task name - if (isSameTaskName(task, parent.getSubTasks())) { - if (log.isDebugEnabled()) { - log.debug("Duplicated name, checkAddTask won't pass"); - } - throw new DataViolationException("Can't add task", DUPLICATED_TASK_VIOLATION); - } - } - - @Override - public void checkModifyProject(TimerProject project) { - - // check duplicated project name - /*FIXME db - if (isSameTaskName(project, manager.getProjectsList())) { - if (log.isDebugEnabled()) { - log.debug("Duplicated name, checkModifyProject won't pass"); - } - throw new DataViolationException("Can't modify project", DUPLICATED_PROJECT_VIOLATION); - }*/ - } - - @Override - public void checkModifyTask(TimerTask task) { - - // check duplicated task name - if (isSameTaskName(task, task.getSubTasks())) { - if (log.isDebugEnabled()) { - log.debug("Duplicated name, checkModifyTask won't pass"); - } - throw new DataViolationException("Can't modify task", DUPLICATED_TASK_VIOLATION); - } - - } - - @Override - public void checkMoveTask(TimerTask destination, Collection<TimerTask> tasksToMove) { - - // check if destination is one task to move - // no sens - if (TimerTaskHelper.collectionContainsTask(tasksToMove, destination)) { - if (log.isDebugEnabled()) { - log.debug("Move task into himself, impossible"); - } - throw new DataViolationException("Can't move task into himself", MOVE_INVALID_TYPES_VIOLATION); - } - - for (TimerTask taskToMove : tasksToMove) { - - // can't move projects - if (taskToMove instanceof TimerProject) { - if (log.isDebugEnabled()) { - log.debug("Move project, impossible"); - } - throw new DataViolationException("Can't move project", MOVE_INVALID_TYPES_VIOLATION); - } - - // check duplicated task name - if (isSameTaskName(taskToMove, destination.getSubTasks())) { - if (log.isDebugEnabled()) { - log.debug("Duplicated name, checkMoveTask won't pass"); - } - throw new DataViolationException("Can't move task", DUPLICATED_TASK_VIOLATION); - } - } - } - - @Override - public void checkMergeTasks(TimerTask destinationTask, - List<TimerTask> otherTasks) { - - // tous les taches sont des projets - if (destinationTask instanceof TimerProject) { - for (TimerTask otherTask : otherTasks) { - if (!(otherTask instanceof TimerProject)) { - throw new DataViolationException("Can't merge task", MERGE_INVALID_TYPES_VIOLATION); - } - } - } else { - // ou toutes des taches - for (TimerTask otherTask : otherTasks) { - if (otherTask instanceof TimerProject) { - throw new DataViolationException("Can't merge task", MERGE_INVALID_TYPES_VIOLATION); - } - } - - // mais pas une combinaison des deux - } - } -} diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java deleted file mode 100644 index 30506b3..0000000 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; - -import java.util.Collection; -import java.util.Date; -import java.util.EventListener; -import java.util.List; - -/** - * Data event listener. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ By : $Author$ - */ -public interface DataEventListener extends EventListener { - - /** - * Add project event. - * - * @param project project to add - */ - default void addProject(TimerProject project) { - - } - - /** - * Add task event. - * - * @param task task to add - */ - default void addTask(TimerTask task) { - - } - - /** - * Modify project. - * - * @param project modified project - */ - default void modifyProject(TimerProject project) { - - } - - /** - * Modify task. - * - * @param task modified task - */ - default void modifyTask(TimerTask task) { - - } - - /** - * Delete project. - * - * @param project deleted project - */ - default void deleteProject(TimerProject project) { - - } - - /** - * Delete task. - * - * @param task deleted task - */ - default void deleteTask(TimerTask task) { - - } - - /** - * Add annotation. - * - * @param task task where annotation is changed - * @param date date - * @param annotation new annotation value - */ - default void setAnnotation(TimerTask task, Date date, String annotation) { - - } - - /** - * Set task time. - * - * @param task task where time is changed - * @param date date - * @param time task time - */ - default void setTaskTime(TimerTask task, Date date, Long time) { - - } - - /** - * Change task state. - * - * @param task task - */ - default void changeClosedState(TimerTask task) { - - } - - /** - * Pre move task. - * - * @param task task - */ - default void preMoveTask(TimerTask task) { - - } - - /** - * Post move task. - * - * @param task task - */ - default void moveTask(TimerTask task) { - - } - - /** - * Pre merge task. - * - * @param destinationTask task where all other task will be merged - * @param otherTasks other tasks to merge - */ - default void preMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - - } - - /** - * Post merge task. - * - * @param destinationTask task where all other task will be merged - * @param otherTasks other tasks to merge - */ - default void postMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - - } - - /** - * Start task. - * - * @param task started task - */ - default void startTask(TimerTask task) { - - } - - /** - * Stop task. - * - * @param task stopped task - */ - default void stopTask(TimerTask task) { - - } - - /** - * All data loaded. - * - * @param projects projects collection - */ - default void dataLoaded(Collection<TimerProject> projects) { - - } -} - diff --git a/src/main/java/org/chorem/jtimer/data/DataViolationException.java b/src/main/java/org/chorem/jtimer/data/DataViolationException.java deleted file mode 100644 index c7cca54..0000000 --- a/src/main/java/org/chorem/jtimer/data/DataViolationException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2009 - 2011 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -/** - * Exception thrown when a data violation is detected. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class DataViolationException extends RuntimeException { - - /** serialVersionUID. */ - private static final long serialVersionUID = 7541490706942030715L; - - /** - * Exception key message; - */ - protected String exceptionKey; - - /** - * Constructor with text message. - * - * @param message text message - * @param exceptionKey exception key - */ - public DataViolationException(String message, String exceptionKey) { - super(message); - this.exceptionKey = exceptionKey; - } - - /** - * Constructor with text message and cause. - * - * @param message text message - * @param exceptionKey exception key - * @param cause parent cause - */ - public DataViolationException(String message, String exceptionKey, Throwable cause) { - super(message, cause); - this.exceptionKey = exceptionKey; - } - - /** - * Get exception key. - * - * @return the exceptionKey - */ - public String getExceptionKey() { - return exceptionKey; - } -} diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java deleted file mode 100644 index 985536b..0000000 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2018 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.db.Database; -import org.chorem.jtimer.db.DbDataMigration; -import org.chorem.jtimer.db.DbManager; -import org.chorem.jtimer.db.DbMigration; -import org.chorem.jtimer.io.Saver; - -import java.io.File; -import java.io.IOException; - -/** - * TimerCore - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TimerCore { - - /** log. */ - private static Log log = LogFactory.getLog(TimerCore.class); - - /** Timer data. */ - protected TimerDataManager data; - - /** Database. */ - protected Database database; - protected DbManager dbManager; - - /** saver io controller. */ - protected Saver saver; - - /** - * Constructor. - */ - public TimerCore() { - - // migrate if necessary - try { - migrateDirectoryStructure(); - } catch (IOException ex) { - if (log.isErrorEnabled()) { - log.error("Can't migrate directories", ex); - } - } - - database = new Database(); - dbManager = new DbManager(database); - DbMigration dbMigration = new DbMigration(database); - dbMigration.init(); - DbDataMigration dbDataMigration = new DbDataMigration(dbManager); - dbDataMigration.init(); - - // init data - data = new TimerDataManager(dbManager); - - // add commmon vetoable - CommonVetoable commonVetoable = new CommonVetoable(data); - data.addVetoableDataEventListener(commonVetoable); - - // init saver implementation - /*saver = JTimerFactory.getFileSaver(); - if (saver != null) { - data.addVetoableDataEventListener(saver); - data.addDataEventListener(saver); - }*/ - } - - /** - * Migrate file structure for jtimer 1.5 directories changes. - * - * @throws IOException - */ - protected void migrateDirectoryStructure() throws IOException { - File newDataDirectory = JTimer.config.getDataDirectory(); - File newBackupDirectory = JTimer.config.getBackupDirectory(); - File oldBackupDirectory = JTimer.config.getGtimerBackupDirectory(); - File oldDataDirectory = JTimer.config.getGtimerDataDirectory(); - - // migrate data - if (!newDataDirectory.isDirectory() && oldDataDirectory.isDirectory()) { - newDataDirectory.mkdirs(); - - if (log.isInfoEnabled()) { - log.info("Migrate data directory from " + oldDataDirectory + " to " + newDataDirectory); - } - - // exclude internal backup directory from recursion - FileUtils.copyDirectory(oldDataDirectory, newDataDirectory, pathName -> !pathName.equals(oldBackupDirectory)); - } - - // migrate backup - if (!newBackupDirectory.isDirectory() && oldBackupDirectory.isDirectory()) { - newBackupDirectory.mkdirs(); - - if (log.isInfoEnabled()) { - log.info("Migrate backup directory from " + oldBackupDirectory + " to " + newBackupDirectory); - } - - FileUtils.copyDirectory(oldBackupDirectory, newBackupDirectory); - } - } - - /** - * Init Load and launch synchronization. - * - * @return true if init has gone successfully - **/ - public boolean init() { - - /*boolean initSucceded = false; - - // log - if (log.isInfoEnabled()) { - log.info("Init core"); - } - - try { - saver.lock(); - - load(); - - initSucceded = true; - } catch (DataLockingException e) { - // can occurs if data save directory is locked - if (log.isDebugEnabled()) { - log.error("Data can't have been loaded"); - } - } - - return initSucceded;*/ - return true; - } - - /** - * Get data. - * - * @return timer data - */ - public TimerDataManager getData() { - return data; - } - - /** - * Load project list from. - */ - protected void load() { - - // log - /*if (log.isInfoEnabled()) { - log.info("Load local data"); - } - - Collection<TimerProject> projects = saver.load(); - - // sort loaded collection - List<TimerProject> projectsList = new ArrayList<>(projects); - Collections.sort(projectsList); - - data.addAllProjects(projectsList);*/ - } - - /** - * Save. - **/ - public void exit() { - /*if (log.isInfoEnabled()) { - log.info("Exiting application"); - } - // unlock fs directory - try { - saver.unlock(); - } catch (DataLockingException e) { - if (log.isErrorEnabled()) { - log.error("Error on unlocking", e); - } - }*/ - } -} diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java deleted file mode 100644 index e73affb..0000000 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ /dev/null @@ -1,676 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.db.DbManager; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Gere les donnees. Des objets peuvent s'enregistrer pour etre notifies des - * changements de donnees. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date: 2008-06-19 10:17:31 +0200 (jeu., 19 juin 2008)$ - * By : $Author$ - */ -public class TimerDataManager { - - /** log. */ - private static Log log = LogFactory.getLog(TimerDataManager.class); - - /** Project list. * - protected List<TimerProject> projectList;*/ - - /** For change notification */ - protected Collection<DataEventListener> dataEventListeners; - - /** For change notification */ - protected Collection<VetoableDataEventListener> vetoableDataEventListeners; - - protected DbManager dbManager; - - /** - * Constructor. - */ - public TimerDataManager(DbManager dbManager) { - this.dbManager = dbManager; - - // init data list - //projectList = new ArrayList<>(); - - // init support list - dataEventListeners = new ArrayList<>(); - vetoableDataEventListeners = new ArrayList<>(); - } - - /** - * Add listener. - * - * @param listener listener - */ - public void addDataEventListener(DataEventListener listener) { - dataEventListeners.add(listener); - } - - /** - * Remove listener. - * - * @param listener listener - */ - public void removeDataEventListener(DataEventListener listener) { - dataEventListeners.remove(listener); - } - - /** - * Add vetoable listener. - * - * @param listener listener - */ - public void addVetoableDataEventListener( - VetoableDataEventListener listener) { - vetoableDataEventListeners.add(listener); - } - - /** - * Remove vetoable listener. - * - * @param listener listener - */ - public void removeVetoableDataEventListener( - VetoableDataEventListener listener) { - vetoableDataEventListeners.remove(listener); - } - - /** - * Add single project. - * - * @param project a project - */ - public void addProject(TimerProject project) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkAddProject(project); - } - - //projectList.add(project); - - // fire data event - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.addProject(project); - } - } - - /** - * Add single task. - * - * @param parent parent task - * @param task task to add - * @param taskTemplate task template to apply for subtasks - */ - public void addTask(TimerTask parent, TimerTask task, String taskTemplate) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkAddTask(parent, task); - } - - parent.addTask(task); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.addTask(task); - } - - if (taskTemplate != null) { - Object subTasks = JTimer.config.getTaskTemplates().get(taskTemplate); - createSubTasks(subTasks, task); - } - } - - /** - * Recursive method to apply tempate to current task. - * - * @param subTasks template to apply - * @param task current subtask - */ - protected void createSubTasks(Object subTasks, TimerTask task) { - if (subTasks != null && subTasks instanceof Map) { - Map<String, Object> realSubTasks = (Map<String, Object>) subTasks; - for (Map.Entry<String, Object> entry : realSubTasks.entrySet()) { - String name = entry.getKey(); - Object newSubTasks = entry.getValue(); - - TimerTask newTask = new TimerTask(name); - - // Fix creation date - newTask.setCreationDate(new Date()); - - task.addTask(newTask); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.addTask(newTask); - } - - createSubTasks(newSubTasks, newTask); - } - } - } - - /** - * Add many projects. - * - * @param projects project collection - * - public void addAllProjects(Collection<TimerProject> projects) { - if (projects != null) { - projectList.clear(); - projectList.addAll(projects); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.dataLoaded(projects); - } - } - }*/ - - /** - * Get projects list. - * - * synchronized to prevent manipulation during save. - * - * @return list of projects - */ - public List<TimerTask> getProjectsList() { - return dbManager.getTaskAndMeta(); - } - - public List<TimerTask> getSubTasks(TimerTask parent) { - return dbManager.getTaskAndMeta(parent); - } - - /** - * Change time for the given date. - * - * @param task the task to change time - * @param date date to change time - * @param value new time in ms - */ - public void changeTaskTime(TimerTask task, Date date, - long value) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkSetTaskTime(task, date, value); - } - - task.setTime(date, value); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.setTaskTime(task, date, value); - } - } - - /** - * Start task. - * - * @param task task to start - */ - public void startTask(TimerTask task) { - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.startTask(task); - } - } - - /** - * Stop task. - * - * @param task task to stop - */ - public void stopTask(TimerTask task) { - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.stopTask(task); - } - } - - /** - * Delete task. - * - * @param task task to delete - */ - public void deleteTask(TimerTask task) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkDeleteTask(task); - } - - // task deletion - task.getParent().getSubTasks().remove(task); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.deleteTask(task); - } - } - - /** - * Delete project. - * - * @param project project to delete - */ - public void deleteProject(TimerProject project) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkDeleteProject(project); - } - - //projectList.remove(project); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.deleteProject(project); - } - } - - /** - * Close project. - * - * @param project project to close - */ - public void changeProjectCloseState(TimerProject project) { - - // fire vetoable event - //Iterator<VetoableDataEventListener> itVetoableDataEventListener = vetoableDataEventListeners - // .iterator(); - //while (itVetoableDataEventListener.hasNext()) { - // itVetoableDataEventListener.next().checkChangeClosedState(project); - //} - - //// send notification - //Iterator<DataEventListener> itDataEventListener = dataEventListeners - // .iterator(); - //while (itDataEventListener.hasNext()) { - // itDataEventListener.next().preChangeClosedState(project); - //} - - //project.setClosed(!project.isClosed()); - - //// send notification - //itDataEventListener = dataEventListeners - // .iterator(); - //while (itDataEventListener.hasNext()) { - // itDataEventListener.next().postChangeClosedState(project); - //} - - changeTaskCloseState(project); - } - - /** - * Close task. - * - * @param task task to close - */ - public void changeTaskCloseState(TimerTask task) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkChangeClosedState(task); - } - - task.setClosed(!task.isClosed()); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.changeClosedState(task); - } - } - - /** - * Edit project. - * - * @param project project to edit - * @param newProjectName new project name - * - * @deprecated since 1.5.1 this is duplicated with modifyProject - */ - @Deprecated - public void editProject(TimerProject project, String newProjectName) { - - // fire vetoable event - TimerProject newProject = project.clone(); - newProject.setName(newProjectName); - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkModifyProject(newProject); - } - - project.setName(newProjectName); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyProject(project); - } - } - - /** - * Edit task. - * - * @param task task to edit - * @param newTaskName new task name - * - * @deprecated since 1.5.1 this is duplicated with modifyTask - */ - @Deprecated - public void editTask(TimerTask task, String newTaskName) { - - // fire vetoable event - TimerTask newTask = task.clone(); - newTask.setName(newTaskName); - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkModifyTask(newTask); - vetoableDataEventListener.checkChangeClosedState(newTask); - } - - task.setName(newTaskName); - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTask(task); - } - } - - /** - * Modify project. - * - * @param project project to edit - */ - public void modifyProject(TimerProject project) { - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyProject(project); - } - } - - /** - * Modify task. - * - * @param task task to edit - */ - public void modifyTask(TimerTask task) { - - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTask(task); - } - } - - /** - * Move task. - * - * @param destination task to move to - * @param tasksToMove tasks to move - */ - public void moveTask(TimerTask destination, Collection<TimerTask> tasksToMove) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkMoveTask(destination, tasksToMove); - } - - for (TimerTask taskToMove : tasksToMove) { - - // send notification (pre) - Iterator<DataEventListener> itDataEventListener = dataEventListeners - .iterator(); - while (itDataEventListener.hasNext()) { - itDataEventListener.next().preMoveTask(taskToMove); - } - - // move task - TimerTask actualParent = taskToMove.getParent(); - actualParent.getSubTasks().remove(taskToMove); - destination.addTask(taskToMove); - - // send notification (post) - itDataEventListener = dataEventListeners.iterator(); - while (itDataEventListener.hasNext()) { - itDataEventListener.next().moveTask(taskToMove); - } - } - } - - /** - * Merge tasks. - * - * @param destinationTask task where task will be merged - * @param otherTasks task to merge in first task - */ - public void mergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkMergeTasks(destinationTask, otherTasks); - } - - // send pre notification - Iterator<DataEventListener> itDataEventListener = dataEventListeners - .iterator(); - while (itDataEventListener.hasNext()) { - itDataEventListener.next().preMergeTasks(destinationTask, otherTasks); - } - - for (TimerTask otherTask : otherTasks) { - mergeTwoTasks(destinationTask, otherTask); - } - - // send post notification - itDataEventListener = dataEventListeners.iterator(); - while (itDataEventListener.hasNext()) { - itDataEventListener.next().postMergeTasks(destinationTask, otherTasks); - } - } - - /** - * Merge two task together. - * - * @param destinationTask task where task will be merged - * @param otherTask task to merge in first task - */ - protected void mergeTwoTasks(TimerTask destinationTask, TimerTask otherTask) { - - if (log.isDebugEnabled()) { - log.debug("Merging two task : " + destinationTask.getName() + " and " + otherTask.getName()); - } - - // task is modified during merge, deep clone it - - // make sub task list copy (concurrency) - Collection<TimerTask> otherTaskSubTasks = new ArrayList<>(otherTask.getSubTasks()); - for (TimerTask otherTaskSubTask : otherTaskSubTasks) { - - // first case to care about, a task with same - // same already exists in destination - TimerTask sameTaskNameTask = null; - for (TimerTask destSubTask : destinationTask.getSubTasks()) { - if (destSubTask.getName().equals(otherTaskSubTask.getName())) { - sameTaskNameTask = destSubTask; - } - } - - // no similar task found - if (sameTaskNameTask == null) { - if (log.isDebugEnabled()) { - log.debug("Moving task " + otherTaskSubTask.getName() + " to " + destinationTask.getName()); - } - // just move - moveTask(destinationTask, Collections.singleton(otherTaskSubTask)); - } else { - // task must be merged - if (log.isDebugEnabled()) { - log.debug("Sub-merging of " + sameTaskNameTask.getName() + " and " + otherTaskSubTask.getName()); - } - - // recursive merge - mergeTwoTasks(sameTaskNameTask, otherTaskSubTask); - - // TODO possible bug here, task times may not be saved - } - } - - // copy otherTask times to current task - for (Entry<Date, Long> times : otherTask.getAllDaysAndTimes().entrySet()) { - Long currentDuration = destinationTask.getTime(times.getKey()); - currentDuration += times.getValue(); - destinationTask.setTime(times.getKey(), currentDuration); - } - - // copy annotations - for (Entry<Date, String> note : otherTask.getAllDaysAnnotations().entrySet()) { - Date noteKey = note.getKey(); - while (destinationTask.getAllDaysAnnotations().containsKey(noteKey)) { - // les deux taches ont des notes au meme moments - // on ne deplace à la prochaine seconde - - if (log.isDebugEnabled()) { - log.debug("Annotation collision detected, try next second"); - } - Calendar calendar = Calendar.getInstance(); - calendar.setTime(noteKey); - calendar.add(Calendar.SECOND, 1); - noteKey = calendar.getTime(); - } - destinationTask.addAnnotation(noteKey, note.getValue()); - } - - // copy alerts - otherTask.getAlerts().forEach(destinationTask::addAlert); - - // finally otherTask still exist - // empty, but still exist - deleteTask(otherTask); - } - - /** - * Add annotation on task for specified calendar, and send event. - * - * @param task task - * @param date day of annotation - * @param annotation annotation - */ - public void addAnnotation(TimerTask task, Date date, - String annotation) { - - // fire vetoable event - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkSetAnnotation(task, date, - annotation); - } - - task.addAnnotation(date, annotation); - - // send event - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.setAnnotation(task, date, annotation); - } - } - - /** - * Notify alert modification. - * - * @param task task where alert has been modified - */ - public void modifyAlert(TimerTask task) { - - // send event - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTask(task); - } - - } - - /** - * Return the corresponding task for path. - * - * @param taskPath task path to find - * @return corresponding task for path - */ - public TimerTask getTaskForPath(String taskPath) { - - String[] paths = taskPath.split("/"); - - // make sure can't select only project - if (paths.length <= 1) { - throw new IllegalArgumentException("Can't parse argument '" + taskPath + "' as task"); - } - - return null; // FIXME findTask(projectList, paths); - } - - /** - * Find task in tasks collections. - * - * @param tasks task collection - * @param paths task path to find - * @return found task - */ - protected TimerTask findTask(Collection<? extends TimerTask> tasks, String[] paths) { - String current = paths[0]; - - TimerTask foundTask = null; - for (TimerTask subtask : tasks) { - if (subtask.getName().equals(current)) { - foundTask = subtask; - } - } - - if (foundTask != null && paths.length > 1) { - String[] subPaths = ArrayUtils.subarray(paths, 1, paths.length); - foundTask = findTask(foundTask.getSubTasks(), subPaths); - } - - return foundTask; - } -} diff --git a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java b/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java deleted file mode 100644 index 73aa04a..0000000 --- a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; - -import java.util.Collection; -import java.util.Date; -import java.util.EventListener; -import java.util.List; - -/** - * Vetoable Data event listener. - * - * @author chorlet - * @version $Revision$ - * - * Last update : $Date$ By : $Author$ - */ -public interface VetoableDataEventListener extends EventListener { - - /** - * Check add project. - * - * @param project project to add - */ - default void checkAddProject(TimerProject project) { - - } - - /** - * Check add task. - * - * @param parent parent task - * @param task task to add - */ - default void checkAddTask(TimerTask parent, TimerTask task) { - - } - - /** - * Check modify project. - * - * @param project modified project - */ - default void checkModifyProject(TimerProject project) { - - } - - /** - * Check modify task. - * - * @param task modified task - */ - default void checkModifyTask(TimerTask task) { - - } - - /** - * Check delete project. - * - * @param project deleted project - */ - default void checkDeleteProject(TimerProject project) { - - } - - /** - * Check delete task. - * - * @param task deleted task - */ - default void checkDeleteTask(TimerTask task) { - - } - - /** - * Check update task annotation. - * - * @param task task to update - * @param date day of change - * @param value new annotation - */ - default void checkSetAnnotation(TimerTask task, Date date, String value) { - - } - - /** - * Check update task time. - * - * @param task task to update - * @param date day of change - * @param value new time in seconds - */ - default void checkSetTaskTime(TimerTask task, Date date, Long value) { - - } - - /** - * Check change task state. - * - * @param task task - */ - default void checkChangeClosedState(TimerTask task) { - - } - - /** - * Check move task. - * - * @param destination task to move to - * @param tasksToMove tasks to move - */ - default void checkMoveTask(TimerTask destination, Collection<TimerTask> tasksToMove) { - - } - - /** - * Check merge task. - * - * @param destinationTask task result of merge - * @param otherTasks other task to merge - */ - default void checkMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - - } -} diff --git a/src/main/java/org/chorem/jtimer/db/Database.java b/src/main/java/org/chorem/jtimer/db/Database.java index ebe6c62..243f829 100644 --- a/src/main/java/org/chorem/jtimer/db/Database.java +++ b/src/main/java/org/chorem/jtimer/db/Database.java @@ -21,8 +21,7 @@ */ package org.chorem.jtimer.db; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.JTimerConfig; +import org.chorem.jtimer.core.Configuration; import java.sql.Connection; import java.sql.DriverManager; @@ -34,8 +33,7 @@ public class Database { protected String connectionUsername; protected String connectionPassword; - public Database() { - JTimerConfig config = JTimer.config; + public Database(Configuration config) { connectionUrl = String.format("jdbc:h2:%s/jtimer", config.getDatabaseDirectory()); connectionUsername = "sa"; diff --git a/src/main/java/org/chorem/jtimer/db/DbDataMigration.java b/src/main/java/org/chorem/jtimer/db/DbDataMigration.java index 8c8b876..fe055c1 100644 --- a/src/main/java/org/chorem/jtimer/db/DbDataMigration.java +++ b/src/main/java/org/chorem/jtimer/db/DbDataMigration.java @@ -21,18 +21,18 @@ */ package org.chorem.jtimer.db; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimerFactory; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.io.Saver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Collection; public class DbDataMigration { - private static Log log = LogFactory.getLog(DbDataMigration.class); + private static Logger logger = LoggerFactory.getLogger(DbDataMigration.class); protected DbManager dbm; @@ -48,18 +48,14 @@ public class DbDataMigration { } protected void performDataMigration() { - if (log.isInfoEnabled()) { - log.info("Performing data migration"); - } + logger.info("Performing data migration"); Saver fileSaver = JTimerFactory.getFileSaver(); Collection<TimerProject> projects = fileSaver.load(); projects.forEach(this::migrateTask); } protected void migrateTask(TimerTask timerTask) { - if (log.isDebugEnabled()) { - log.debug("migration task " + timerTask.getName()); - } + logger.debug("migration task " + timerTask.getName()); dbm.createTask(timerTask); dbm.updateTask(timerTask); timerTask.getSubTasks().forEach(this::migrateTask); diff --git a/src/main/java/org/chorem/jtimer/db/DbManager.java b/src/main/java/org/chorem/jtimer/db/DbManager.java index 4190e16..5b49671 100644 --- a/src/main/java/org/chorem/jtimer/db/DbManager.java +++ b/src/main/java/org/chorem/jtimer/db/DbManager.java @@ -95,6 +95,7 @@ public class DbManager { task.setName(resultSet.getString(2)); task.setCreationDate(JTimerUtils.toDate(resultSet.getObject(3, LocalDateTime.class))); task.setSubTasksCount(resultSet.getLong("subtasks")); + task.setParent(parent); tasks.add(task); } } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index d2f53d4..8557816 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -210,7 +210,7 @@ public class TimerTask implements Cloneable, Comparable<TimerTask>, Serializable * * @param parent the parent to set */ - protected void setParent(TimerTask parent) { + public void setParent(TimerTask parent) { // will cause an infinite loop if (parent == this) { throw new IllegalArgumentException("Parent can't be current task"); diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 1ad0420..4c545a8 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2016 CodeLutin + * Copyright (C) 2007 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,8 +25,6 @@ package org.chorem.jtimer.io; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerAlert.Type; import org.chorem.jtimer.entities.TimerProject; @@ -86,8 +84,7 @@ import java.util.zip.ZipOutputStream; * Last update : $Date$ * By : $Author$ */ -public class GTimerIncrementalSaver extends AbstractSaver implements Saver, - DataEventListener { +public class GTimerIncrementalSaver extends AbstractSaver implements Saver { /** log. */ private static Log log = LogFactory.getLog(GTimerIncrementalSaver.class); @@ -228,7 +225,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, autoSaveTimer.cancel(); // save running tasks - saveRunningTasks(); + //saveRunningTasks(); // clear task list runningTasks.clear(); @@ -1121,8 +1118,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } - @Override - public void addProject(TimerProject project) { + /*public void addProject(TimerProject project) { // searching for good project number int projectNumber = getUnusedNumber("." + GTIMER_PROJECT_EXTENSION); @@ -1137,10 +1133,9 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // loop on subtasks to set correct task number (only on add) project.getSubTasks().forEach(this::addTask); - } + }*/ - @Override - public void addTask(TimerTask task) { + /*public void addTask(TimerTask task) { // searching for good task number int taskNumber = getUnusedNumber("." + GTIMER_TASK_EXTENSION); @@ -1155,7 +1150,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // loop on subtasks to set correct task number (only on add) task.getSubTasks().forEach(this::addTask); - } + }*/ /** * Explore directory and find a non used number for project. @@ -1181,22 +1176,20 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, return foundProjectNumber; } - @Override - public void deleteProject(TimerProject project) { + /*public void deleteProject(TimerProject project) { deleteTaskOrProject(project, GTIMER_PROJECT_EXTENSION); } - @Override public void deleteTask(TimerTask task) { deleteTaskOrProject(task, GTIMER_TASK_EXTENSION); } - /** + /* * Delete associated file or project files on disk. * * @param taskOrProject task or project to delete file * @param extension extension without . - */ + * protected void deleteTaskOrProject(TimerTask taskOrProject, String extension) { // and then manage current file @@ -1247,14 +1240,12 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, + fileToDelete.getAbsolutePath()); } } - } + }*/ - @Override - public void modifyProject(TimerProject project) { + /*public void modifyProject(TimerProject project) { saveProject(project); } - @Override public void modifyTask(TimerTask task) { // ne sauve la tache que si elle n'est pas @@ -1275,14 +1266,12 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // save format du to composed task name // subtasks have to be resaved task.getSubTasks().forEach(this::modifyTask); - } + }*/ - @Override - public void setAnnotation(TimerTask task, Date date, String annotation) { + /*public void setAnnotation(TimerTask task, Date date, String annotation) { saveTaskAnnotation(task); } - @Override public void setTaskTime(TimerTask task, Date date, Long time) { // ne sauve la tache que si elle n'est pas // en cours d'execution @@ -1291,7 +1280,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } - @Override public void changeClosedState(TimerTask task) { if (task instanceof TimerProject) { saveProject((TimerProject) task); @@ -1302,10 +1290,9 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, saveTask(task); } } - } + }*/ - @Override - public void moveTask(TimerTask task) { + /*public void moveTask(TimerTask task) { if (log.isDebugEnabled()) { log.debug("postMoveTask event received"); @@ -1314,7 +1301,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, modifyTask(task); } - @Override public void postMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { // destination task need to be updated modifyTask(destinationTask); @@ -1326,10 +1312,9 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // better if deleted here // but deleted by another event // some otherTasks subtasks must be deleted too - } + }*/ - @Override - public void startTask(TimerTask task) { + /*public void startTask(TimerTask task) { if (log.isDebugEnabled()) { log.debug("startTask event received"); @@ -1339,7 +1324,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } - @Override public void stopTask(TimerTask task) { if (log.isDebugEnabled()) { @@ -1349,42 +1333,39 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // remove task from running task and force save runningTasks.remove(task); saveTask(task); - } + }*/ - @Override public void run() { if (log.isDebugEnabled()) { log.debug("Saver wake up"); } - saveRunningTasks(); + //saveRunningTasks(); } - /** + /* * Save runing tasks and their synchronization info - */ + * protected void saveRunningTasks() { synchronized (runningTasks) { runningTasks.forEach(this::saveTask); } } - @Override public void checkAddProject(TimerProject project) { checkName(project); } - @Override public void checkAddTask(TimerTask parent, TimerTask task) { checkName(task); } - /** + /* * Check task name. * * @param task task to check - */ + * protected void checkName(TimerTask task) { String name = task.getName(); @@ -1395,5 +1376,5 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, if (name.contains(GTIMER_SUBTASK_SEPARATOR)) { throw new DataViolationException("Can't add task", "vetoable.saver.invalid.characters"); } - } + }*/ } diff --git a/src/main/java/org/chorem/jtimer/io/Saver.java b/src/main/java/org/chorem/jtimer/io/Saver.java index 29d13b4..48690ee 100644 --- a/src/main/java/org/chorem/jtimer/io/Saver.java +++ b/src/main/java/org/chorem/jtimer/io/Saver.java @@ -22,8 +22,6 @@ package org.chorem.jtimer.io; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.VetoableDataEventListener; import org.chorem.jtimer.entities.TimerProject; import java.util.Collection; @@ -37,7 +35,7 @@ import java.util.Collection; * Last update : $Date$ * By : $Author$ */ -public interface Saver extends DataEventListener, VetoableDataEventListener { +public interface Saver { /** * Set auto save delay (in milliseconds). diff --git a/src/main/java/org/chorem/jtimer/services/AlertService.java b/src/main/java/org/chorem/jtimer/services/AlertService.java new file mode 100644 index 0000000..25d8b48 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/services/AlertService.java @@ -0,0 +1,4 @@ +package org.chorem.jtimer.services; + +public class AlertService { +} diff --git a/src/main/java/org/chorem/jtimer/services/ReportService.java b/src/main/java/org/chorem/jtimer/services/ReportService.java new file mode 100644 index 0000000..2159f47 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/services/ReportService.java @@ -0,0 +1,4 @@ +package org.chorem.jtimer.services; + +public class ReportService { +} diff --git a/src/main/java/org/chorem/jtimer/services/TaskService.java b/src/main/java/org/chorem/jtimer/services/TaskService.java new file mode 100644 index 0000000..2211371 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/services/TaskService.java @@ -0,0 +1,5 @@ +package org.chorem.jtimer.services; + +public class TaskService { + +} diff --git a/src/main/java/org/chorem/jtimer/services/TimeService.java b/src/main/java/org/chorem/jtimer/services/TimeService.java new file mode 100644 index 0000000..217ae4d --- /dev/null +++ b/src/main/java/org/chorem/jtimer/services/TimeService.java @@ -0,0 +1,4 @@ +package org.chorem.jtimer.services; + +public class TimeService { +} diff --git a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java index d8e4e12..42e8cff 100644 --- a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java +++ b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2016 CodeLutin + * Copyright (C) 2016 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -23,8 +23,7 @@ package org.chorem.jtimer.ui; import org.apache.commons.lang3.StringUtils; import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.data.DataViolationException; -import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.ui.widget.DialogView; import org.jdesktop.application.Action; @@ -59,17 +58,17 @@ import java.util.Set; public class NewTaskView extends DialogView { protected JTimer parent; - protected TimerCore core; + protected Context context; protected ActionMap actionMap; protected TimerTask selectedTask; protected JTextField newTaskField; protected JComboBox<String> newTaskTemplateBox; - public NewTaskView(JTimer parent, TimerCore core, TimerTask selectedTask) { + public NewTaskView(JTimer parent, Context context, TimerTask selectedTask) { super(parent.getMainFrame(), parent); this.parent = parent; - this.core = core; + this.context = context; this.selectedTask = selectedTask; actionMap = parent.getContext().getActionMap(this); @@ -99,7 +98,7 @@ public class NewTaskView extends DialogView { GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 0, 5), 0, 0)); // Task template - Map<String, Object> templates = JTimer.config.getTaskTemplates(); + Map<String, Object> templates = context.getConfig().getTaskTemplates(); newTaskTemplateBox = new JComboBox<>(); if (templates != null && !templates.isEmpty()) { diff --git a/src/main/java/org/chorem/jtimer/ui/StatusBar.java b/src/main/java/org/chorem/jtimer/ui/StatusBar.java index 86cdda2..48a3bad 100644 --- a/src/main/java/org/chorem/jtimer/ui/StatusBar.java +++ b/src/main/java/org/chorem/jtimer/ui/StatusBar.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2016 CodeLutin + * Copyright (C) 2007 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,10 +22,7 @@ package org.chorem.jtimer.ui; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.TimerDataManager; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.core.Context; import org.jdesktop.application.Application; import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceManager; @@ -36,8 +33,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import java.awt.GridLayout; -import java.util.Collection; -import java.util.Date; /** * StatusBar. @@ -48,7 +43,7 @@ import java.util.Date; * Last update : $Date: 2008-06-17 10:50:40 +0200 (mar., 17 juin 2008) * $ By : $Author$ */ -public class StatusBar extends JPanel implements DataEventListener { +public class StatusBar extends JPanel { /** VersionUID */ private static final long serialVersionUID = -1283108564414026297L; @@ -57,7 +52,7 @@ public class StatusBar extends JPanel implements DataEventListener { protected ResourceMap resourceMap; /** DataManager */ - protected TimerDataManager dataManager; + protected Context context; /** Message label */ protected JLabel lblMessage; @@ -74,9 +69,9 @@ public class StatusBar extends JPanel implements DataEventListener { * Constucteur. * * @param application parent application - * @param dataManager data manager + * @param context context */ - public StatusBar(Application application, TimerDataManager dataManager) { + public StatusBar(Application application, Context context) { // set layout super(new GridLayout()); @@ -97,7 +92,7 @@ public class StatusBar extends JPanel implements DataEventListener { add(lblTime); // save tdm - this.dataManager = dataManager; + this.context = context; } /** @@ -115,7 +110,7 @@ public class StatusBar extends JPanel implements DataEventListener { .formatDuration(duration, "HH:mm:ss")));*/ } - @Override + /*@Override public void addProject(TimerProject project) { // can happen for synchronized project updateTodayTime(); @@ -165,12 +160,12 @@ public class StatusBar extends JPanel implements DataEventListener { startStopTask(task, false); } - /** + /* * Start and stop task common code. * * @param task task * @param start start(true) or stop (false) - */ + * protected void startStopTask(TimerTask task, boolean start) { // increment or decrement task @@ -192,5 +187,5 @@ public class StatusBar extends JPanel implements DataEventListener { } } lblMessage.setText(message); - } + }*/ } diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 1b1e34f..f88947a 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -25,6 +25,7 @@ package org.chorem.jtimer.ui; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.data.TimerDataManager; @@ -103,10 +104,8 @@ public class TimerTaskEditor extends DialogView { protected TimerTask task; /** task to edit */ protected TimerTask cloneTask; - /** timer core */ - protected TimerCore core; - /** task manager */ - protected TimerDataManager dataManager; + /** ui context */ + protected Context context; protected boolean dataChanged; /** did the modified the title ? */ @@ -136,9 +135,9 @@ public class TimerTaskEditor extends DialogView { * * @param parent * @param task - * @param core + * @param context */ - public TimerTaskEditor(JTimer parent, TimerTask task, TimerCore core) { + public TimerTaskEditor(JTimer parent, TimerTask task, Context context) { super(parent.getMainFrame(), parent); this.parent = parent; @@ -154,8 +153,7 @@ public class TimerTaskEditor extends DialogView { this.task = task; cloneTask = task.clone(); - this.core = core; - dataManager = core.getData(); + this.context = context; // init resources map //ApplicationContext ctxt = parent.getContext(); diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java index da03f5e..9cfa98f 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java @@ -22,6 +22,7 @@ package org.chorem.jtimer.ui.alert; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.TimerDataManager; import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerAlert.Type; @@ -64,7 +65,7 @@ public class AlertEditor extends FrameView implements ListSelectionListener { protected List<TimerAlert> alerts; /** Manager to commit alert modification. */ - protected TimerDataManager timerDataManager; + protected Context context; /** Table to display alerts .*/ protected JTable alertTable; @@ -80,12 +81,12 @@ public class AlertEditor extends FrameView implements ListSelectionListener { * * @param application parent * @param task task - * @param timerDataManager + * @param context */ - public AlertEditor(Application application, TimerDataManager timerDataManager, TimerTask task) { + public AlertEditor(Application application, Context context, TimerTask task) { super(application); this.task = task; - this.timerDataManager = timerDataManager; + this.context = context; // build a new editing list for alerts alerts = task.getAlerts().stream().map(TimerAlert::clone).collect(Collectors.toList()); diff --git a/src/main/java/org/chorem/jtimer/ui/report/ReportView.java b/src/main/java/org/chorem/jtimer/ui/report/ReportView.java index d5370cb..6418c89 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/ReportView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/ReportView.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2008 - 2016 CodeLutin + * Copyright (C) 2008 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -24,7 +24,7 @@ package org.chorem.jtimer.ui.report; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; @@ -89,7 +89,7 @@ public class ReportView extends FrameView implements DocumentListener { protected static Log log = LogFactory.getLog(ReportView.class); /** Timer core. */ - protected TimerCore core; + protected Context context; /** Unselected task set. */ protected Set<TimerTask> uncheckedTaskSet; @@ -136,9 +136,9 @@ public class ReportView extends FrameView implements DocumentListener { * Reposts constructor. * * @param application parent reference - * @param core core reference + * @param context context */ - public ReportView(Application application, TimerCore core) { + public ReportView(Application application, Context context) { super(application); @@ -147,7 +147,7 @@ public class ReportView extends FrameView implements DocumentListener { getFrame().setName("reportFrame"); getFrame().setTitle(getResourceMap().getString("reportTitle")); - this.core = core; + this.context = context; this.uncheckedTaskSet = new HashSet<>(); // set title @@ -266,9 +266,9 @@ public class ReportView extends FrameView implements DocumentListener { projectsTree = new JTree(); projectsTree.setRootVisible(true); projectsTree.setEditable(true); - projectsTree.setModel(new TaskTreeModel(core, getResourceMap().getString("reportProjectsList") + " :")); - projectsTree.setCellEditor(new CheckBoxTreeCellEditor(core, projectsTree, uncheckedTaskSet)); - projectsTree.setCellRenderer(new CheckBoxTreeCellRenderer(core, projectsTree, uncheckedTaskSet)); + projectsTree.setModel(new TaskTreeModel(context, getResourceMap().getString("reportProjectsList") + " :")); + projectsTree.setCellEditor(new CheckBoxTreeCellEditor(context, projectsTree, uncheckedTaskSet)); + projectsTree.setCellRenderer(new CheckBoxTreeCellRenderer(context, projectsTree, uncheckedTaskSet)); JScrollPane jspTable = new JScrollPane(projectsTree); panelProjects.add(jspTable, new GridBagConstraints(0, 1, 1, 1, 1, 1, @@ -339,7 +339,7 @@ public class ReportView extends FrameView implements DocumentListener { protected void fillPickerDates(int delay) { // init dates Calendar calendarBegin = Calendar.getInstance(); - int firstDayOfWeek = JTimer.config.getReportFirstDayOfWeek(); + int firstDayOfWeek = context.getConfig().getReportFirstDayOfWeek(); if (firstDayOfWeek <= 0 || firstDayOfWeek > 7) { firstDayOfWeek = calendarBegin.getFirstDayOfWeek(); } diff --git a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java index b6f0eb0..d78263b 100644 --- a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java +++ b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java @@ -25,6 +25,7 @@ package org.chorem.jtimer.ui.systray; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.ui.widget.JPopupTrayIcon; @@ -55,8 +56,7 @@ import java.awt.event.WindowListener; * Last update : $Date$ * By : $Author$ */ -public class SystrayManager extends WindowAdapter implements ActionListener, DataEventListener, - MouseListener, Runnable { +public class SystrayManager extends WindowAdapter implements ActionListener, MouseListener, Runnable { /** Log. */ private static Log log = LogFactory.getLog(SystrayManager.class); @@ -64,6 +64,9 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat /** Parent reference. */ protected JTimer parent; + /** Context. */ + protected Context context; + /** I18n resources map. */ protected ResourceMap resourceMap; @@ -95,9 +98,11 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat * Default constructor. * * @param parent parent + * @param context context */ - public SystrayManager(JTimer parent) { + public SystrayManager(JTimer parent, Context context) { this.parent = parent; + this.context = context; // init resources map ApplicationContext ctxt = parent.getContext(); @@ -190,7 +195,7 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat } } - @Override + /*@Override public void startTask(TimerTask task) { startStopTask(task, true); } @@ -198,7 +203,7 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat @Override public void stopTask(TimerTask task) { startStopTask(task, false); - } + }*/ /** * Common code for start or stop task. @@ -350,7 +355,7 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat public void windowClosing(WindowEvent e) { // tray available only if trayIcon != null - if (trayIcon != null && JTimer.config.isCloseToSystray()) { + if (trayIcon != null && context.getConfig().isCloseToSystray()) { // hide window (without exiting) parent.hide(); showItem.setText(resourceMap.getString("showMenuText")); diff --git a/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java b/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java index 82624ea..846fce8 100644 --- a/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java +++ b/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java @@ -25,14 +25,13 @@ package org.chorem.jtimer.ui.tasks; import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.ui.tree.ProjectsAndTasksTree; import org.chorem.jtimer.ui.tree.TaskTreeModel; import org.chorem.jtimer.ui.treetable.ProjectsAndTasksCellRenderer; import org.jdesktop.application.Action; -import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceManager; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; @@ -105,8 +104,8 @@ public class IdleDialog extends JDialog { /** Parent application. */ protected SingleFrameApplication application; - /** Timer core. */ - protected TimerCore core; + /** Application context. */ + protected Context context; /** I18N resource map. */ protected ResourceMap resourceMap; @@ -147,13 +146,13 @@ public class IdleDialog extends JDialog { * Protected to force use of show static method. * * @param application parent application - * @param core timer core + * @param context context */ - protected IdleDialog(SingleFrameApplication application, TimerCore core) { + protected IdleDialog(SingleFrameApplication application, Context context) { // don't make reference on other parent // windows, cause idle to unlock some task // if parent window is hidden by systray - this.core = core; + this.context = context; // init resources map this.application = application; @@ -193,7 +192,7 @@ public class IdleDialog extends JDialog { GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(10, 5, 10, 10), 0, 0)); // label - JLabel idleLabel = new JLabel(resourceMap.getString("idleMessage", JTimer.config.getIdleTime() / 60)); + JLabel idleLabel = new JLabel(resourceMap.getString("idleMessage", context.getConfig().getIdleTime() / 60)); mainComponent.add(idleLabel, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 3), 0, 0)); @@ -284,7 +283,7 @@ public class IdleDialog extends JDialog { projectsTree = new ProjectsAndTasksTree(); projectsTree.setRootVisible(false); projectsTree.setShowsRootHandles(true); - projectsTree.setModel(new TaskTreeModel(core, null)); + projectsTree.setModel(new TaskTreeModel(context, null)); projectsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); projectsTree.setCellRenderer(new ProjectsAndTasksCellRenderer()); projectsTree.addTreeSelectionListener(e -> { @@ -323,10 +322,10 @@ public class IdleDialog extends JDialog { * Init dialog idleDialog instance. * * @param parent parent reference - * @param core core reference + * @param context context */ - public static void init(SingleFrameApplication parent, TimerCore core) { - idleDialog = new IdleDialog(parent, core); + public static void init(SingleFrameApplication parent, Context context) { + idleDialog = new IdleDialog(parent, context); } /** diff --git a/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java b/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java index 2e4f49b..915e5da 100644 --- a/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java +++ b/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java @@ -24,8 +24,7 @@ package org.chorem.jtimer.ui.tasks; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.data.TimerDataManager; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerTask; import java.util.Date; @@ -46,15 +45,15 @@ public class RefreshTreeTask extends java.util.TimerTask { private static Log log = LogFactory.getLog(RefreshTreeTask.class); /** Data manager */ - protected TimerDataManager dataManager; + protected Context context; /** * Constructor with core. * - * @param core core + * @param context context */ - public RefreshTreeTask(TimerCore core) { - dataManager = core.getData(); + public RefreshTreeTask(Context context) { + this.context = context; } /* diff --git a/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java b/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java index 7aed6ef..1ce4bee 100644 --- a/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java +++ b/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java @@ -27,6 +27,7 @@ import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.TimerDataManager; import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerAlert.Type; @@ -69,7 +70,7 @@ public class RunTaskJob extends Task<Void, Void> { protected TimerTask managedTask; /** Data manager. */ - protected TimerDataManager dataManager; + protected Context context; /** System information (idle...). */ protected SystemInfo systemInfo; @@ -92,8 +93,7 @@ public class RunTaskJob extends Task<Void, Void> { * @param managedTask task * @param dataManager data */ - public RunTaskJob(JTimer parentApp, TimerTask managedTask, - TimerDataManager dataManager) { + public RunTaskJob(JTimer parentApp, TimerTask managedTask, Context context) { super(parentApp); this.parentApp = parentApp; @@ -102,7 +102,7 @@ public class RunTaskJob extends Task<Void, Void> { // save vars this.managedTask = managedTask; - this.dataManager = dataManager; + this.context = context; // must be init here, checkAlreadyThrownAlerts is called multiples times alreadyThrownAlerts = new HashSet<>(); @@ -164,7 +164,7 @@ public class RunTaskJob extends Task<Void, Void> { lastUserActivity = new AtomicLong(System.currentTimeMillis()); // get idle time - long configIdleTime = JTimer.config.getIdleTime() * 1000; + long configIdleTime = context.getConfig().getIdleTime() * 1000; boolean dontWantToStop = true; while (dontWantToStop) { diff --git a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java index 2bdbb8e..e4b2c82 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2009 - 2016 CodeLutin + * Copyright (C) 2009 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,7 +22,7 @@ package org.chorem.jtimer.ui.tree; -import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerTask; import javax.swing.JCheckBox; @@ -46,7 +46,7 @@ public abstract class CheckBoxTreeCellComponent extends JCheckBox { private static final long serialVersionUID = 2497464481840318274L; /** Timer core. */ - protected TimerCore core; + protected Context context; /** Parent tree. */ protected JTree parentTree; @@ -57,12 +57,12 @@ public abstract class CheckBoxTreeCellComponent extends JCheckBox { /** * Constructor. * - * @param core core reference + * @param context context * @param parentTree tree reference * @param uncheckedTaskList common unselected tasks list */ - protected CheckBoxTreeCellComponent(TimerCore core, JTree parentTree, Set<TimerTask> uncheckedTaskList) { - this.core = core; + protected CheckBoxTreeCellComponent(Context context, JTree parentTree, Set<TimerTask> uncheckedTaskList) { + this.context = context; this.parentTree = parentTree; this.uncheckedTaskSet = uncheckedTaskList; } @@ -78,8 +78,7 @@ public abstract class CheckBoxTreeCellComponent extends JCheckBox { * @param row row * @return check box component */ - protected Component getCheckBoxComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, - int row) { + protected Component getCheckBoxComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) { // if this is a task if (value instanceof TimerTask) { diff --git a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java index 4c7cb72..fd14ad8 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2009 - 2016 CodeLutin + * Copyright (C) 2009 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -24,7 +24,7 @@ package org.chorem.jtimer.ui.tree; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerTask; import javax.swing.JCheckBox; @@ -50,8 +50,7 @@ import java.util.Set; * Last update : $Date$ * By : $Author$ */ -public class CheckBoxTreeCellEditor extends CheckBoxTreeCellComponent implements - TreeCellEditor, ItemListener { +public class CheckBoxTreeCellEditor extends CheckBoxTreeCellComponent implements TreeCellEditor, ItemListener { /** serialVersionUID */ private static final long serialVersionUID = 2497464481840318274L; @@ -65,12 +64,12 @@ public class CheckBoxTreeCellEditor extends CheckBoxTreeCellComponent implements /** * Constructor. * - * @param core core + * @param context context * @param parentTree tree * @param uncheckedTaskList common unselected tasks list */ - public CheckBoxTreeCellEditor(TimerCore core, JTree parentTree, Set<TimerTask> uncheckedTaskList) { - super(core, parentTree, uncheckedTaskList); + public CheckBoxTreeCellEditor(Context context, JTree parentTree, Set<TimerTask> uncheckedTaskList) { + super(context, parentTree, uncheckedTaskList); addItemListener(this); cellEditorListeners = new ArrayList<>(); diff --git a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java index dcddacb..175cc9c 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2009 - 2011 CodeLutin + * Copyright (C) 2009 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,7 +22,7 @@ package org.chorem.jtimer.ui.tree; -import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerTask; import javax.swing.JTree; @@ -48,13 +48,12 @@ public class CheckBoxTreeCellRenderer extends CheckBoxTreeCellComponent /** * Constructor. * - * @param core core + * @param context context * @param parentTree tree * @param uncheckedTaskList common unselected tasks list */ - public CheckBoxTreeCellRenderer(TimerCore core, JTree parentTree, - Set<TimerTask> uncheckedTaskList) { - super(core, parentTree, uncheckedTaskList); + public CheckBoxTreeCellRenderer(Context context, JTree parentTree, Set<TimerTask> uncheckedTaskList) { + super(context, parentTree, uncheckedTaskList); } @Override diff --git a/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java b/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java index b520477..811b1ce 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java @@ -24,6 +24,7 @@ package org.chorem.jtimer.ui.tree; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; @@ -53,7 +54,7 @@ public class TaskTreeModel implements TreeModel { protected TreeModelSupport modelSupport; /** Timer core. */ - protected TimerCore core; + protected Context context; /** Tree model root. */ protected TimerTask root; @@ -64,11 +65,11 @@ public class TaskTreeModel implements TreeModel { /** * Constructor. * - * @param core core + * @param context context * @param rootName root node name */ - public TaskTreeModel(TimerCore core, String rootName) { - this.core = core; + public TaskTreeModel(Context context, String rootName) { + this.context = context; root = new TimerTask(rootName); modelSupport = new TreeModelSupport(this); } diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java index c4edbef..6a60cf1 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2016 CodeLutin + * Copyright (C) 2007 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,19 +25,13 @@ package org.chorem.jtimer.ui.treetable; import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.data.TimerDataManager; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.jdesktop.swingx.treetable.AbstractTreeTableModel; -import javax.swing.SwingUtilities; -import javax.swing.table.TableColumn; import javax.swing.tree.TreePath; import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -66,8 +60,7 @@ import java.util.Map; * Last update : $Date: 2008-06-13 11:05:57 +0200 (ven., 13 juin 2008) * $ By : $Author$ */ -public class ProjectsAndTasksModel extends AbstractTreeTableModel implements - DataEventListener { +public class ProjectsAndTasksModel extends AbstractTreeTableModel { /** log */ private static Log log = LogFactory.getLog(ProjectsAndTasksModel.class); @@ -83,7 +76,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements protected ProjectsAndTasksTable projectsAndTaskTable; /** Data. */ - protected TimerDataManager dataManager; + protected Context context; /** Tree column identifiers. */ protected List<String> columnIdentifiers; @@ -95,16 +88,16 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements * Constructor. * * @param projectsAndTaskTable table - * @param core timer core + * @param context context * @param columnIdentifiers column identifiers */ - public ProjectsAndTasksModel(ProjectsAndTasksTable projectsAndTaskTable, TimerCore core, + public ProjectsAndTasksModel(ProjectsAndTasksTable projectsAndTaskTable, Context context, List<String> columnIdentifiers) { super(new TimerProject("root")); // remember this.projectsAndTaskTable = projectsAndTaskTable; - this.dataManager = core.getData(); + this.context = context; this.columnIdentifiers = columnIdentifiers; taskNameCache = new HashMap<>(); @@ -333,7 +326,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements return updated; } - @Override + /*@Override public void addProject(TimerProject project) { notifyTaskChanged(project, OPERATION_ADD); } @@ -390,7 +383,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements @Override public void setTaskTime(TimerTask task, Date date, Long time) { notifyTaskChanged(task, OPERATION_MODIFY); - } + }*/ /*@Override public void changeClosedState(TimerTask task) { @@ -426,7 +419,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements //dataLoaded(null); } - @Override + /*@Override public void moveTask(TimerTask task) { notifyTaskChanged(task, OPERATION_ADD); } @@ -443,5 +436,5 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements for (TimerTask otherTask : otherTasks) { notifyTaskChanged(otherTask, OPERATION_DELETE); } - } + }*/ } diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java index c099566..9128caa 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2016 CodeLutin + * Copyright (C) 2007 - 2018 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -24,8 +24,7 @@ package org.chorem.jtimer.ui.treetable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.entities.TimerTask; import org.jdesktop.swingx.JXTreeTable; @@ -52,7 +51,7 @@ import java.util.Set; * Last update : $Date$ * By : $Author$ */ -public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRenderer implements DataEventListener { +public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRenderer { /** serialVersionUID. */ private static final long serialVersionUID = 1383276150996517529L; @@ -76,9 +75,9 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen * Constructor. * * @param treeTable Tree table reference for image observer - * @param core TimerCore + * @param context context */ - public ProjectsAndTasksRunningCellRenderer(JXTreeTable treeTable, TimerCore core) { + public ProjectsAndTasksRunningCellRenderer(JXTreeTable treeTable, Context context) { this.treeTable = treeTable; // init @@ -91,7 +90,7 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen runningIcon.setImageObserver(nodeObserver); // be notified on events - core.getData().addDataEventListener(this); + //core.getData().addDataEventListener(this); } @Override @@ -147,7 +146,7 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen } } - @Override + /*@Override public void startTask(TimerTask task) { if (log.isDebugEnabled()) { @@ -167,5 +166,5 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen // remember don't running task runningTasks.remove(task); - } + }*/ } diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java index aabb82d..4f2dc37 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java @@ -22,6 +22,7 @@ package org.chorem.jtimer.ui.treetable; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; @@ -73,7 +74,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { * @param application application * @param core timer core */ - public ProjectsAndTasksTable(Application application, TimerCore core) { + public ProjectsAndTasksTable(Application application, Context context) { // start with init i18n of table column name ApplicationContext ctxt = application.getContext(); @@ -86,10 +87,10 @@ public class ProjectsAndTasksTable extends JXTreeTable { columnIdentifiers.add(resourceMap.getString("totalTimeColumnName")); // set model - treeTableModel = new ProjectsAndTasksModel(this, core, columnIdentifiers); + treeTableModel = new ProjectsAndTasksModel(this, context, columnIdentifiers); // set renderer - treeCellRenderer = new ProjectsAndTasksRunningCellRenderer(this, core); + treeCellRenderer = new ProjectsAndTasksRunningCellRenderer(this, context); setTreeCellRenderer(treeCellRenderer); setTreeTableModel(treeTableModel); @@ -99,11 +100,11 @@ public class ProjectsAndTasksTable extends JXTreeTable { setBackground(Color.WHITE); //treeTableModel.setSortColumn("Projects & Tasks"); - core.getData().addDataEventListener(treeTableModel); + //core.getData().addDataEventListener(treeTableModel); // enable drag n drop setDragEnabled(true); - setTransferHandler(new TimerTaskTransferHandler(application, core.getData())); + setTransferHandler(new TimerTaskTransferHandler(application, context)); { // add action to collapse (left arrow) selected node Action action = new AbstractAction("collapseSelectedNode") { diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java b/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java index b057972..e79e1a3 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java @@ -25,6 +25,7 @@ package org.chorem.jtimer.ui.treetable.dnd; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.core.Context; import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.data.TimerDataManager; import org.chorem.jtimer.entities.TimerTask; @@ -65,17 +66,16 @@ public class TimerTaskTransferHandler extends TransferHandler { protected ResourceMap resourceMap; /** Data manager. */ - protected TimerDataManager dataManager; + protected Context context; /** * Constructor. * * @param application - * @param dataManager data manager + * @param context context */ - public TimerTaskTransferHandler(Application application, - TimerDataManager dataManager) { - this.dataManager = dataManager; + public TimerTaskTransferHandler(Application application, Context context) { + this.context = context; // init resources map ApplicationContext ctxt = application.getContext(); diff --git a/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java b/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java deleted file mode 100644 index 15df5b0..0000000 --- a/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java +++ /dev/null @@ -1,361 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.filefilter.HiddenFileFilter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.io.Saver; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Collection; -import java.util.List; -import java.util.Locale; -import java.util.Properties; - -/** - * Surcharge la factory du code principal. - * - * Redefinie les propriétés de test. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public abstract class AbstractJTimerTest { - - /** Class log */ - private static Log log = LogFactory.getLog(AbstractJTimerTest.class); - - /** Saver instance on specific test directory. */ - protected Saver testSaver; - - /** Test directory. */ - protected File testDataDirectory; - - /** - * Return specific temp dir. - * - * @return system temp dir - */ - public static String getTempDirPath() { - String tempdir = System.getProperty("java.io.tmpdir"); - - if (!(tempdir.endsWith("/") || tempdir.endsWith("\\"))) { - tempdir += File.separator; - } - - return tempdir; - } - - /** - * Redefinit les proprietes utilisées pour les tests. - * - * @throws IOException - */ - protected void initDataDirectory() throws IOException { - - JTimer.config = new JTimerConfig(); - - URL testConfigFile = AbstractJTimerTest.class.getResource("/jtimertest.properties"); - Properties props = new Properties(JTimer.config.appConfig.getOptions()); - props.load(testConfigFile.openStream()); - - // overload system wide options - testDataDirectory = new File(getTempDirPath(), String.valueOf(System.currentTimeMillis())); - props.put("jtimer.home.directory", testDataDirectory.getAbsolutePath()); - props.put("jtimer.io.saver.directory", testDataDirectory.getParent() + File.separator + ".gtimer"); - - JTimer.config.appConfig.setOptions(props); // not call parse in test - - if (log.isDebugEnabled()) { - log.debug("Copy resource test directory to " - + testDataDirectory.getAbsolutePath()); - } - - // HiddenFileFilter.VISIBLE is used to not - // copy .svn folders - FileUtils.copyDirectory(new File("src/test/resources/testdata"), - new File(testDataDirectory, "data"), HiddenFileFilter.VISIBLE); - - // force null, to force new instance - JTimerFactory.saver = null; - testSaver = JTimerFactory.getFileSaver(); - - } - - /** - * Delete data directory defined in saver. - * - * @throws IOException - */ - protected void deleteDataDirectory() throws IOException { - if (log.isDebugEnabled()) { - log.debug("Removing test directory"); - } - - FileUtils.deleteDirectory(testDataDirectory); - } - - /** - * Before each test, set up test data directory. - * - * @throws IOException - */ - @BeforeMethod - public void beforeTest() throws IOException { - if (log.isDebugEnabled()) { - log.debug("Set up test"); - } - - // jtimer code use default system locale - // test are coded in en_US - Locale.setDefault(Locale.US); - - initDataDirectory(); - } - - /** - * After each test, remove test data directory. - * - * @throws IOException - */ - @AfterMethod - public void afterTest() throws IOException { - if (log.isDebugEnabled()) { - log.debug("Clean after test"); - } - deleteDataDirectory(); - testSaver = null; - } - - /** - * Get A specific task with is path in tree. - * - * @param tasks tasks list to search into - * @param path path to search - * @return found task, or <tt>null</tt> if not found - */ - public static TimerTask findTask(Collection<? extends TimerTask> tasks, - String path) { - - String[] paths = path.split("/"); - String current = paths[0]; - - TimerTask foundTask = null; - for (TimerTask subtask : tasks) { - if (subtask.getName().equals(current)) { - foundTask = subtask; - } - } - - if (foundTask != null && paths.length > 1) { - // +1 == / - String newPath = path.substring(current.length() + 1); - foundTask = findTask(foundTask.getSubTasks(), newPath); - - } - - return foundTask; - } - - /** - * Get a specific project in project list. - * - * @param projects projects list - * @param path path to search - * @return found project, or <tt>null</tt> if not found - */ - public static TimerProject findProject(Collection<TimerProject> projects, - String path) { - - TimerProject foundProject = null; - for (TimerProject project : projects) { - if (project.getName().equals(path)) { - foundProject = project; - } - } - - return foundProject; - } - - /** - * Get A specific task with is path in tree. - * - * @param tasks tasks list to search into - * @param path path to search - * @return found task, or <tt>null</tt> if not found - */ - public static TimerTask findTask(List<TimerTask> tasks, String path) { - - String[] paths = path.split("/"); - String current = paths[0]; - - TimerTask foundTask = null; - for (TimerTask subtaskAndCount : tasks) { - if (subtaskAndCount.getName().equals(current)) { - foundTask = subtaskAndCount; - } - } - - if (foundTask != null && paths.length > 1) { - // +1 == / - String newPath = path.substring(current.length() + 1); - // FIXME db foundTask = findTask(foundTask.getSubTasks(), newPath); - - } - - return foundTask; - } - - /** - * Get a specific project in project list. - * - * @param projects projects list - * @param path path to search - * @return found project, or <tt>null</tt> if not found - */ - public static TimerTask findProject(List<TimerTask> projects, String path) { - - TimerProject foundProject = null; - for (TimerTask projectAndCount : projects) { - if (projectAndCount.getName().equals(path)) { - foundProject = (TimerProject)projectAndCount; - } - } - - return foundProject; - } - - /** - * Get projects subTasksCount. - * - * @param projects projects collection - * @return project subTasksCount - */ - protected static int getProjectsCount(Collection<TimerProject> projects) { - return projects.size(); - } - - /** - * Get task subTasksCount. - * - * @param projects projects collection - * @return task subTasksCount - */ - protected static int getTasksCount(Collection<TimerProject> projects) { - int tasksCount = 0; - - for (TimerProject project : projects) { - tasksCount += getRecursiveTasksCount(project.getSubTasks()); - } - return tasksCount; - } - - /** - * Get task subTasksCount. - * - * @param tasks tasks collection - * @return task subTasksCount - */ - protected static int getRecursiveTasksCount(Collection<TimerTask> tasks) { - int tasksCount = 0; - - for (TimerTask task : tasks) { - tasksCount++; // subTasksCount me - tasksCount += getRecursiveTasksCount(task.getSubTasks()); - } - return tasksCount; - } - - /** - * Get annotations subTasksCount. - * - * @param projects projects collection - * @return annotations subTasksCount - */ - protected static int getAnnotationsCount(Collection<TimerProject> projects) { - int annotationsCount = 0; - - for (TimerProject project : projects) { - annotationsCount += getRecursiveAnnotationsCount(project.getSubTasks()); - } - return annotationsCount; - } - - /** - * Get annotations subTasksCount. - * - * @param tasks tasks collection - * @return annotations subTasksCount - */ - protected static int getRecursiveAnnotationsCount(Collection<TimerTask> tasks) { - int annotationsCount = 0; - - for (TimerTask task : tasks) { - annotationsCount += task.getAllDaysAnnotations().size(); - annotationsCount += getRecursiveAnnotationsCount(task.getSubTasks()); - } - return annotationsCount; - } - - /** - * Get alert subTasksCount. - * - * @param projects projects collection - * @return annotations subTasksCount - */ - protected static int getAlertsCount(Collection<TimerProject> projects) { - int annotationsCount = 0; - - for (TimerProject project : projects) { - annotationsCount += getRecursiveAlertsCount(project.getSubTasks()); - } - return annotationsCount; - } - - /** - * Get alert subTasksCount. - * - * @param tasks tasks collection - * @return annotations subTasksCount - */ - protected static int getRecursiveAlertsCount(Collection<TimerTask> tasks) { - int annotationsCount = 0; - - for (TimerTask task : tasks) { - annotationsCount += task.getAlerts().size(); - annotationsCount += getRecursiveAlertsCount(task.getSubTasks()); - } - return annotationsCount; - } -} diff --git a/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java b/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java deleted file mode 100644 index 9f8e8d6..0000000 --- a/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.io.GTimerIncrementalSaver; -import org.chorem.jtimer.io.Saver; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.Map; - -/** - * Test for JTimerFactory. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class JTimerFactoryTest extends AbstractJTimerTest { - - /** Class log */ - private static Log log = LogFactory.getLog(JTimerFactoryTest.class); - - /** - * Verifie que les options par default sont bien chargées. - */ - @Test - public void testInitConfiguration() { - - if (log.isInfoEnabled()) { - log.info("Test property loading " + JTimerFactoryTest.class); - } - - Assert.assertEquals(JTimer.config.getIdleTime(), 299); - - Assert.assertEquals(JTimer.config.getIOSaverClass(), GTimerIncrementalSaver.class); - // Temp dir is dynamic - //Assert.assertEquals(AbstractJTimerTest.getTempDirPath() + "/testngdata", - // JTimer.config.getIOSaverDirectory()); - Assert.assertEquals(JTimer.config.getIOSaverAutoSaveDelay(), 199); - - } - - /** - * Test json parsing of config property. - */ - @Test - public void testJsonTaskTemplates() { - Map<String, Object> templates = JTimer.config.getTaskTemplates(); - Map<String, Object> p1Tpl = (Map<String, Object>) templates.get("project1"); - Assert.assertNotNull(p1Tpl); - Map<String, Object> p2Tpl = (Map<String, Object>) templates.get("project2"); - Assert.assertNotNull(p2Tpl); - Object p3Tpl = templates.get("project3"); - Assert.assertNull(p3Tpl); - - Assert.assertEquals(p1Tpl.size(), 5); - Assert.assertEquals(p2Tpl.size(), 3); - } - - /** - * Test que le saver de fichier s'est bien initialise. - */ - @Test - public void getFileSaverTest() { - Saver saver = JTimerFactory.getFileSaver(); - - Assert.assertNotNull(saver); - } - -} diff --git a/src/test/java/org/chorem/jtimer/data/CommonVetoableTest.java b/src/test/java/org/chorem/jtimer/data/CommonVetoableTest.java deleted file mode 100644 index 10069b7..0000000 --- a/src/test/java/org/chorem/jtimer/data/CommonVetoableTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2009 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; - -/** - * Test that all forbidden operation by {@link CommonVetoable} throws - * excepted exception. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class CommonVetoableTest extends AbstractJTimerTest { - - /** - * Test create with already existing name. - */ - @Test(expectedExceptions = DataViolationException.class) - public void testAddProject() { - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - - // add new project - TimerProject project = new TimerProject("jTimer"); - project.setCreationDate(new Date()); - dataManager.addProject(project); - } - - /** - * Test create task with already existing name. - */ - @Test(expectedExceptions = DataViolationException.class) - public void testAddTask() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "IsisFish/UserInterface"); - - // add a new task - TimerTask newTask = new TimerTask("Debug"); - newTask.setCreationDate(new Date()); - dataManager.addTask(task1, newTask, null); - } - - /** - * Test single task move, trying to move projects into tasks. - */ - @Test(expectedExceptions = DataViolationException.class) - public void testMoveTask() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findProject(projectsBefore, "Topia"); - TimerTask task2 = findTask(projectsBefore, "jTimer/Add workspace support"); - - Assert.assertNotNull(task1); - Assert.assertNotNull(task2); - - // move task - dataManager.moveTask(task2, Collections.singleton(task1)); - } - - /** - * Test single task move, into another task where name already exists. - */ - @Test(expectedExceptions = DataViolationException.class) - public void testMoveTask2() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "Chorem/Add webservice"); - TimerTask task2 = findTask(projectsBefore, "jTimer"); - - Assert.assertNotNull(task1); - Assert.assertNotNull(task2); - - // rename tank before move - // (task jTimer/Add workspace support exists !) - dataManager.editTask(task1, "Add workspace support"); - - // move task - dataManager.moveTask(task2, Collections.singleton(task1)); - } - - /** - * Test multiples tasks move move into one task to move. - */ - @Test(expectedExceptions = DataViolationException.class) - public void testMoveMultiplesTasks() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "jTimer/Add workspace support"); - TimerTask task2 = findTask(projectsBefore, "jTimer/Interact with chorem services"); - TimerTask task3 = findTask(projectsBefore, "jTimer/Refactoring"); - TimerTask task4 = findTask(projectsBefore, "jTimer/Unit tests"); - - Assert.assertNotNull(task1); - Assert.assertNotNull(task2); - Assert.assertNotNull(task3); - Assert.assertNotNull(task4); - - Collection<TimerTask> tasksToMove = new HashSet<>(); - tasksToMove.add(task1); - tasksToMove.add(task2); - tasksToMove.add(task3); - tasksToMove.add(task4); - - // move task 3 in task1 : forbidden - dataManager.moveTask(task1, tasksToMove); - - } - - /** - * Merge two projects and tasks. - */ - @Test(expectedExceptions = DataViolationException.class) - public void testMergeTasks() { - // first load all - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "Chorem"); - TimerTask task2 = findTask(projectsBefore, "jTimer/Unit tests/UI tests"); - - // merge tasks - dataManager.mergeTasks(task2, Collections.singletonList(task1)); - } -} diff --git a/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java b/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java deleted file mode 100644 index f308738..0000000 --- a/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java +++ /dev/null @@ -1,637 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2009 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.data; - -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.entities.TimerAlert; -import org.chorem.jtimer.entities.TimerAlert.Type; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; - -/** - * Test class for TimerDataManager. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TimerDataManagerTest extends AbstractJTimerTest { - - /** - * Test create project. - */ - @Test - public void testAddProject() { - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask project1 = findProject(projectsBefore, "Test project"); - - Assert.assertNull(project1); - Assert.assertEquals(projectsBefore.size(), 6); - - // add new project - TimerProject project = new TimerProject("Test project"); - project.setCreationDate(new Date()); - dataManager.addProject(project); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask project1a = findProject(projectsAfter, "Test project"); - - Assert.assertNotNull(project1a); - Assert.assertEquals(projectsBefore.size(), 7); - } - - /** - * Test edit project. - */ - @Test - public void testEditProject() { - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask project1 = findProject(projectsBefore, "jTimer"); - - Assert.assertNotNull(project1); - Assert.assertEquals(project1.getSubTasks().size(), 4); - - // edit project - dataManager.editProject((TimerProject)project1, "Edit Name"); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - - TimerTask project1a = findProject(projectsBefore, "Edit Name"); - Assert.assertNull(findProject(projectsAfter, "jTimer")); - Assert.assertNotNull(project1a); - Assert.assertEquals(project1a.getSubTasks().size(), 4); - } - - /** - * Test delete project. - */ - @Test - public void testDeleteProject() { - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask project1 = findProject(projectsBefore, "jTimer"); - - Assert.assertNotNull(project1); - Assert.assertEquals(projectsBefore.size(), 6); - - // delete project - dataManager.deleteProject((TimerProject)project1); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - - Assert.assertNull(findProject(projectsAfter, "jTimer")); - Assert.assertEquals(projectsAfter.size(), 5); - } - - /** - * Test create task. - */ - @Test - public void testAddTask() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "IsisFish/UserInterface"); - - Assert.assertNotNull(task1); - Assert.assertEquals(task1.getSubTasks().size(), 2); - - // add a new task - TimerTask newTask = new TimerTask("new task"); - newTask.setCreationDate(new Date()); - dataManager.addTask(task1, newTask, null); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "IsisFish/UserInterface"); - TimerTask task2a = findTask(projectsAfter, "IsisFish/UserInterface/new task"); - - Assert.assertNotNull(task1a); - Assert.assertEquals(task1a.getSubTasks().size(), 3); - Assert.assertNotNull(task2a); - } - - /** - * Test edit task. - */ - @Test - public void testEditTask() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "IsisFish/UserInterface"); - - Assert.assertNotNull(task1); - Assert.assertEquals(task1.getSubTasks().size(), 2); - - // edit task name - dataManager.editTask(task1, "UI"); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "IsisFish/UI"); - TimerTask task2a = findTask(projectsAfter, "IsisFish/UI/Debug"); - - Assert.assertNotNull(task1a); - Assert.assertEquals(task1a.getSubTasks().size(), 2); - Assert.assertNotNull(task2a); - } - - /** - * Test edit task. - */ - @Test - public void testDeleteTask() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask project1 = findProject(projectsBefore, "IsisFish"); - TimerTask task1 = findTask(projectsBefore, "IsisFish/UserInterface"); - - Assert.assertNotNull(project1); - Assert.assertEquals(project1.getSubTasks().size(), 3); - Assert.assertNotNull(task1); - - // delete task - dataManager.deleteTask(task1); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask project1a = findProject(projectsAfter, "IsisFish"); - TimerTask task1a = findTask(projectsAfter, "IsisFish/UserInterface"); - - Assert.assertNotNull(project1a); - Assert.assertEquals(project1a.getSubTasks().size(), 2); - Assert.assertNull(task1a); - } - - /** - * Test single task move. - */ - @Test - public void testMoveTask() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "Topia"); - TimerTask task2 = findTask(projectsBefore, "jTimer/Add workspace support"); - TimerTask task3 = findTask(projectsBefore, "Topia/Add workspace support"); - - Assert.assertNotNull(task1); - Assert.assertNotNull(task2); - Assert.assertNull(task3); - - // move task 3 in jTimer/3 - dataManager.moveTask(task1, Collections.singleton(task2)); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "Topia"); - TimerTask task2a = findTask(projectsAfter, "jTimer/Add workspace support"); - TimerTask task3a = findTask(projectsAfter, "Topia/Add workspace support"); - - Assert.assertNotNull(task1a); - Assert.assertNull(task2a); - Assert.assertNotNull(task3a); - } - - /** - * Test multiples tasks move. - */ - @Test - public void testMoveMultiplesTasks() { - - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask project1 = findProject(projectsBefore, "Chorem"); - TimerTask task1 = findTask(projectsBefore, "jTimer/Add workspace support"); - TimerTask task2 = findTask(projectsBefore, "jTimer/Interact with chorem services"); - TimerTask task3 = findTask(projectsBefore, "jTimer/Refactoring"); - TimerTask task4 = findTask(projectsBefore, "jTimer/Unit tests"); - - Assert.assertNotNull(project1); - Assert.assertNotNull(task1); - Assert.assertNotNull(task2); - Assert.assertNotNull(task3); - Assert.assertNotNull(task4); - - Collection<TimerTask> tasksToMove = new HashSet<>(); - tasksToMove.add(task1); - tasksToMove.add(task2); - tasksToMove.add(task3); - tasksToMove.add(task4); - - // move task 3 in jTimer/3 - dataManager.moveTask(project1, tasksToMove); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "Chorem/Add workspace support"); - TimerTask task2a = findTask(projectsAfter, "Chorem/Interact with chorem services"); - TimerTask task3a = findTask(projectsAfter, "Chorem/Refactoring"); - TimerTask task4a = findTask(projectsAfter, "Chorem/Unit tests"); - TimerTask project1a = findProject(projectsBefore, "jTimer"); - - Assert.assertNotNull(task1a); - Assert.assertNotNull(task2a); - Assert.assertNotNull(task3a); - Assert.assertNotNull(task4a); - Assert.assertEquals(0, project1a.getSubTasks().size()); - } - - /* - * Merge two project together. - * - * Can't merge 2 projects. - * - public void testMergeProjects() { - // first load all - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerProject> projectsBefore = dataManager.getProjectsList(); - TimerProject project1 = findProject(projectsBefore, "Topia"); - TimerProject project2 = findProject(projectsBefore, "jTimer"); - - Assert.assertNotNull(project1); - Assert.assertNotNull(project2); - Assert.assertEquals(project1.getSubTasks().size(), 3); - Assert.assertEquals(project2.getSubTasks().size(), 4); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(project1), 62005); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(project2), 160280); - - // merge projects - dataManager.mergeProjects(project1, Collections.singletonList(project2)); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerProject> projectsAfter = dataManager.getProjectsList(); - TimerProject project1a = findProject(projectsAfter, "Topia"); - TimerProject project2a = findProject(projectsAfter, "jTimer"); - - Assert.assertNotNull(project1a); - Assert.assertNull(project2a); - Assert.assertEquals(project1.getSubTasks().size(), 7); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(project1), 62005 + 160280); - }*/ - - /** - * Merge two tasks together. - */ - @Test - public void testMergeTasks() { - // first load all - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "jTimer/Refactoring"); - TimerTask task2 = findTask(projectsBefore, "jTimer/Unit tests/UI tests"); - TimerTask task3 = findTask(projectsBefore, "jTimer/Unit tests"); - - Assert.assertNotNull(task1); - Assert.assertNotNull(task2); - Assert.assertEquals(task1.getSubTasks().size(), 2); - Assert.assertEquals(getRecursiveAnnotationsCount(Collections.singleton(task1)), 5); - Assert.assertEquals(task2.getSubTasks().size(), 2); - Assert.assertEquals(getRecursiveAnnotationsCount(Collections.singleton(task2)), 2); - Assert.assertEquals(task3.getSubTasks().size(), 4); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task1), 55035000); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task2), 65602000); - - // merge tasks - dataManager.mergeTasks(task1, Collections.singletonList(task2)); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "jTimer/Refactoring"); - TimerTask task2a = findTask(projectsAfter, "jTimer/Unit tests/UI tests"); - TimerTask task3a = findTask(projectsAfter, "jTimer/Unit tests"); - - Assert.assertNotNull(task1a); - Assert.assertNull(task2a); - Assert.assertNotNull(task3a); - Assert.assertEquals(task1a.getSubTasks().size(), 4); - Assert.assertEquals(getRecursiveAnnotationsCount(Collections.singleton(task1a)), 5 + 2); - Assert.assertEquals(task3a.getSubTasks().size(), 3); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task1a), 55035000 + 65602000); - } - - /** - * Merge two tasks together. - * - * In both task subtask, there is a name conflict (same subtask name). - */ - @Test - public void testMergeTasksWithConflict() { - // first load all - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "jTimer/Refactoring"); - Assert.assertNotNull(task1); - - // add THE conflict task name - TimerTask tTreeTests = new TimerTask("Tree tests"); - tTreeTests.setCreationDate(new Date()); - tTreeTests.setTime(new Date(), 200000L); - dataManager.addTask(task1, tTreeTests, null); - - Assert.assertEquals(task1.getSubTasks().size(), 3); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task1), 55035000 + 200000); - - TimerTask task2 = findTask(projectsBefore, "jTimer/Unit tests/UI tests"); - Assert.assertEquals(task2.getSubTasks().size(), 2); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task2), 65602000); - - // merge tasks - dataManager.mergeTasks(task1, Collections.singletonList(task2)); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "jTimer/Refactoring"); - TimerTask task2a = findTask(projectsAfter, "jTimer/Unit tests/UI tests"); - - Assert.assertNotNull(task1a); - Assert.assertNull(task2a); - // 4 = conflict resolved - Assert.assertEquals(task1a.getSubTasks().size(), 4); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task1a), - 55035000 + 65602000 + 200000); - } - - /** - * Test add alert. - * - * Alert reloading was buggy when multiple alert types were defined. - * (i.e. two alert type REACH_DAILY_TIME) - */ - @Test - public void testAddAlert() { - // first load all - // and make a move operation - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "jTimer/Refactoring"); - - Assert.assertNotNull(task1); - Assert.assertEquals(getRecursiveAlertsCount(Collections - .singleton(task1)), 0); - - // add new project - TimerAlert alert1 = new TimerAlert(TimerAlert.Type.REACH_DAILY_TIME, 3600000); - TimerAlert alert2 = new TimerAlert(TimerAlert.Type.REACH_DAILY_TIME, 7200000); - TimerAlert alert3 = new TimerAlert(TimerAlert.Type.REACH_TOTAL_TIME, 10800000); - task1.addAlert(alert1); - task1.addAlert(alert2); - task1.addAlert(alert3); - dataManager.modifyAlert(task1); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "jTimer/Refactoring"); - - Assert.assertNotNull(task1a); - Assert.assertEquals(getRecursiveAlertsCount(Collections - .singleton(task1a)), 3); - - // test correct alert loading - boolean alert1found = false; - boolean alert2found = false; - boolean alert3found = false; - for (TimerAlert alert : task1a.getAlerts()) { - if (alert.getType().equals(Type.REACH_DAILY_TIME) && alert.getDuration() == 3600000) { - alert1found = true; - } - if (alert.getType().equals(Type.REACH_DAILY_TIME) && alert.getDuration() == 7200000) { - alert2found = true; - } - if (alert.getType().equals(Type.REACH_TOTAL_TIME) && alert.getDuration() == 10800000) { - alert3found = true; - } - } - Assert.assertTrue(alert1found, "Missing first alert"); - Assert.assertTrue(alert2found, "Missing second alert"); - Assert.assertTrue(alert3found, "Missing third alert"); - } - - /** - * Merge two tasks (tests alerts merge). - */ - @Test - public void testMergeTasksWithAlerts() { - // first load all - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - List<TimerTask> projectsBefore = dataManager.getProjectsList(); - TimerTask task1 = findTask(projectsBefore, "IsisFish/Storage"); - TimerTask task2 = findTask(projectsBefore, "IsisFish/Support"); - TimerTask task3 = findTask(projectsBefore, "IsisFish/UserInterface"); - - Assert.assertNotNull(task1); - Assert.assertNotNull(task2); - Assert.assertNotNull(task3); - Assert.assertEquals(getRecursiveAlertsCount(Collections.singleton(task1)), 1); - Assert.assertEquals(getRecursiveAlertsCount(Collections.singleton(task2)), 0); - Assert.assertEquals(getRecursiveAlertsCount(Collections.singleton(task3)), 3); - - // merge tasks - List<TimerTask> othersTask = new ArrayList<>(); - othersTask.add(task1); - othersTask.add(task3); - dataManager.mergeTasks(task2, othersTask); - core.exit(); - - // second reload - // and test reloaded data - //core.init(); - core.load(); - List<TimerTask> projectsAfter = dataManager.getProjectsList(); - TimerTask task1a = findTask(projectsAfter, "IsisFish/Storage"); - TimerTask task2a = findTask(projectsAfter, "IsisFish/Support"); - TimerTask task3a = findTask(projectsAfter, "IsisFish/UserInterface"); - - Assert.assertNull(task1a); - Assert.assertNotNull(task2a); - Assert.assertNull(task3a); - Assert.assertEquals(getRecursiveAlertsCount(Collections.singleton(task2)), 4); - } - - /** - * Test to find task by path. - */ - @Test - public void testGetTaskForPath() { - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - - TimerTask task = dataManager.getTaskForPath("jTimer/Unit tests/UI tests"); - Assert.assertEquals(task.getName(), "UI tests"); - task = dataManager.getTaskForPath("jTimer/Unit tests/fake"); - Assert.assertNull(task); - } - - /** - * Test to find task by path. - */ - @Test(expectedExceptions = IllegalArgumentException.class) - public void testGetTaskForPathProject() { - TimerCore core = new TimerCore(); - TimerDataManager dataManager = core.getData(); - - //core.init(); - core.load(); - - TimerTask task = dataManager.getTaskForPath("jTimer"); - Assert.assertNotNull(task); - } -} diff --git a/src/test/java/org/chorem/jtimer/entities/TimerAlertTest.java b/src/test/java/org/chorem/jtimer/entities/TimerAlertTest.java deleted file mode 100644 index f0e35d9..0000000 --- a/src/test/java/org/chorem/jtimer/entities/TimerAlertTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.entities; - -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.entities.TimerAlert.Type; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Test class for TimerAlert. - * - * @author chatellier - * @version $Revision: 2607 $ - * - * Last update : $Date: 2009-06-18 17:19:19 +0200 (jeu. 18 juin 2009) $ - * By : $Author: echatellier $ - */ -public class TimerAlertTest extends AbstractJTimerTest { - - /** - * Test alert duration. - */ - @Test - public void testAlertData() { - - TimerAlert alert = new TimerAlert(Type.REACH_DAILY_TIME, 8); - - Assert.assertEquals(alert.getDuration(), 8); - Assert.assertEquals(alert.getType(), Type.REACH_DAILY_TIME); - } - - /** - * Test task clone(); - */ - @Test - public void testClone() { - - TimerAlert alert = new TimerAlert(Type.REACH_DAILY_TIME, 8); - TimerAlert alertClone = alert.clone(); - - Assert.assertEquals(alertClone.getDuration(), 8); - Assert.assertEquals(alertClone.getType(), Type.REACH_DAILY_TIME); - - // not origin modification - alertClone.setDuration(16); - Assert.assertEquals(alert.getDuration(), 8); - } - - /** - * Test equals. - */ - @Test - public void testEquals() { - - TimerAlert alert = new TimerAlert(Type.REACH_DAILY_TIME, 8); - TimerAlert alert2 = new TimerAlert(Type.REACH_TOTAL_TIME, 8); - - Assert.assertFalse(alert.equals(alert2)); - alert.setType(Type.REACH_TOTAL_TIME); - Assert.assertEquals(alert, alert2); - } - - /** - * Test equals with null values. - */ - @Test - public void testEqualsNull() { - - Assert.assertEquals(new TimerAlert(), new TimerAlert()); - - TimerAlert alert1 = new TimerAlert(); - alert1.setDuration(1); - Assert.assertFalse(alert1.equals(new TimerAlert())); - } - - /** - * Test list content (hash code implementation). - */ - @Test - public void testAlertList() { - List<TimerAlert> alertList = new ArrayList<>(); - alertList.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); - alertList.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); - alertList.add(new TimerAlert(Type.REACH_DAILY_TIME, 7)); - - Assert.assertEquals(alertList.size(), 3); - Assert.assertTrue(alertList.contains(new TimerAlert(Type.REACH_DAILY_TIME, 7))); - } - - /** - * Some tests on alert type. - */ - @Test - public void testAlertSet() { - Set<TimerAlert> alertSet = new HashSet<>(); - alertSet.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); - alertSet.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); - alertSet.add(new TimerAlert(Type.REACH_DAILY_TIME, 7)); - - // 2 => due to hashcode - Assert.assertEquals(alertSet.size(), 2); - Assert.assertTrue(alertSet.contains(new TimerAlert(Type.REACH_DAILY_TIME, 7))); - } -} diff --git a/src/test/java/org/chorem/jtimer/entities/TimerProjectTest.java b/src/test/java/org/chorem/jtimer/entities/TimerProjectTest.java deleted file mode 100644 index 134668e..0000000 --- a/src/test/java/org/chorem/jtimer/entities/TimerProjectTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2011 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.entities; - -import org.chorem.jtimer.AbstractJTimerTest; -import org.testng.Assert; -import org.testng.annotations.Test; - -/** - * Test class for TimerProject. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TimerProjectTest extends AbstractJTimerTest { - - /** - * Test project name. - */ - @Test - public void testProjectName() { - - TimerProject project = new TimerProject(); - project.setName("test"); - - Assert.assertEquals("test", project.getName()); - } - - /** - * Test project clone() - */ - @Test - public void testClone() { - - TimerProject project = new TimerProject(); - project.setName("name1"); - - TimerProject project2 = project.clone(); - - Assert.assertEquals("name1", project2.getName()); - Assert.assertEquals(project, project2); - } -} diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java deleted file mode 100644 index a0f835e..0000000 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package org.chorem.jtimer.entities; - -import org.chorem.jtimer.AbstractJTimerTest; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.List; - -/** - * Test related to TimerTaskHelper. - */ -public class TimerTaskHelperTest extends AbstractJTimerTest { - - /** - * Test get path from parent. - */ - @Test - public void getPathFromParentTest() { - TimerProject project = new TimerProject(); - TimerTask task1 = new TimerTask(); - TimerTask task2 = new TimerTask(); - - project.addTask(task1); - task1.addTask(task2); - - List<TimerTask> components = TimerTaskHelper.getPathFromParent(task2); - Assert.assertEquals(components.get(0), project); - Assert.assertEquals(components.get(1), task1); - Assert.assertEquals(components.get(2), task2); - } -} diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java deleted file mode 100644 index 3cf070d..0000000 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.entities; - -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.utils.DailySortedMap; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.Date; - -/** - * Test class for TimerTask. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class TimerTaskTest extends AbstractJTimerTest { - - /** - * Test project name. - */ - @Test - public void testTaskName() { - - TimerTask task = new TimerTask(); - task.setName("test"); - - Assert.assertEquals("test", task.getName()); - } - - /** - * Test task clone(); - */ - @Test - public void testCloneDailyMap() { - - TimerTask task = new TimerTask(); - task.setName("test"); - - TimerTask clonedTask = task.clone(); - - Assert.assertTrue(clonedTask.allDaysTimes instanceof DailySortedMap<?>, "Clone put invalid type for map"); - Assert.assertFalse(clonedTask.allDaysAnnotations instanceof DailySortedMap<?>, "Clone put invalid type for map"); - } - - /** - * Test task subtasks. - */ - @Test - public void testSubtasks() { - - TimerTask task = new TimerTask(); - task.setName("test"); - - TimerTask subtask = new TimerTask(); - subtask.setName("subtest"); - subtask.setCreationDate(new Date()); - task.addTask(subtask); - - TimerTask clonedTask = task.clone(); - - // subtask copied - Assert.assertEquals(1, clonedTask.getSubTasks().size()); - - // subtask modification - Assert.assertEquals("subtest", clonedTask.getSubTasks().get(0).getName()); - - // clone removal, not modify first - clonedTask.getSubTasks().clear(); - Assert.assertEquals(0, clonedTask.getSubTasks().size()); - Assert.assertEquals(1, task.getSubTasks().size()); - } - - /** - * Test that clone is a soft clone (excepted for lists). - */ - @Test - public void testCloneLists() { - TimerTask task = new TimerTask(); - task.setName("test"); - - TimerTask clonedTask = task.clone(); - - task.setClosed(true); - task.addTask(new TimerTask()); - task.setName("new name"); - - Assert.assertEquals(task.getName(), "new name"); - Assert.assertEquals(clonedTask.getName(), "test"); - Assert.assertTrue(task.isClosed()); - Assert.assertFalse(clonedTask.isClosed()); - Assert.assertEquals(task.getSubTasks().size(), 1); - Assert.assertEquals(clonedTask.getSubTasks().size(), 0); - } -} diff --git a/src/test/java/org/chorem/jtimer/io/AbstractSaverTest.java b/src/test/java/org/chorem/jtimer/io/AbstractSaverTest.java deleted file mode 100644 index d1516dc..0000000 --- a/src/test/java/org/chorem/jtimer/io/AbstractSaverTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.io; - -import org.apache.commons.io.FileUtils; -import org.chorem.jtimer.AbstractJTimerTest; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -/** - * Test for AbstractSaver. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class AbstractSaverTest extends AbstractJTimerTest { - - /** - * Test that backup create a backup file. - * - * @throws IOException - */ - @Test - public void makeBackupFileTest() throws IOException { - File file = File.createTempFile("test", ".test"); - - File backupFile = BackupUtils.makeBackupFile(file); - - Assert.assertNotNull(backupFile); - Assert.assertTrue(backupFile.isFile()); - } - - /** - * Test that restore restore backup file. - * - * @throws IOException - */ - @Test - public void restoreBackupFileTest() throws IOException { - File file = File.createTempFile("test", ".test"); - FileUtils.writeStringToFile(file, "oldcontent", StandardCharsets.UTF_8); - - File backupFile = BackupUtils.makeBackupFile(file); - - Assert.assertNotNull(backupFile); - Assert.assertTrue(backupFile.isFile()); - - FileUtils.writeStringToFile(file, "newcontent", StandardCharsets.UTF_8); - Assert.assertEquals(FileUtils.readFileToString(file, StandardCharsets.UTF_8), "newcontent"); - Assert.assertEquals(FileUtils.readFileToString(backupFile, StandardCharsets.UTF_8), "oldcontent"); - - boolean result = BackupUtils.restoreBackupFile(backupFile); - Assert.assertTrue(result); - - Assert.assertFalse(backupFile.isFile()); - Assert.assertEquals(FileUtils.readFileToString(file, StandardCharsets.UTF_8), "oldcontent"); - } - - /** - * Test that delete really delete file. - * - * @throws IOException - */ - @Test - public void deleteBackupFile() throws IOException { - File file = File.createTempFile("test", ".test"); - - File backupFile = BackupUtils.makeBackupFile(file); - - BackupUtils.deleteBackupFile(backupFile); - - Assert.assertFalse(backupFile.isFile()); - } -} diff --git a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java deleted file mode 100644 index a964a1d..0000000 --- a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java +++ /dev/null @@ -1,419 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.io; - -import org.apache.commons.io.FileUtils; -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.entities.TimerAlert; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - -/** - * Test for JTimerFactory. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class GTimerIncrementalSaverTest extends AbstractJTimerTest { - - /** - * Test que saveDirectory a une valeur attendue. - */ - @Test - public void saveDirectoryTest() { - - Assert.assertTrue(testSaver instanceof GTimerIncrementalSaver); - - } - - /** - * Test que saveDirectory a une valeur attendue. - */ - @Test - public void autoSaveDelayTest() { - - Assert.assertTrue(testSaver instanceof GTimerIncrementalSaver); - - Assert.assertEquals(((GTimerIncrementalSaver) testSaver).autoSaveDelay, 199000); - - } - - /** - * Test data loading. - * - * Test that 5 projects are loaded (39 tasks, etc...) - */ - @Test - public void loadTest() { - - /*try { - //FIXME saver.lock();*/ - - Collection<TimerProject> projects = testSaver.load(); - - Assert.assertNotNull(projects); - Assert.assertEquals(getProjectsCount(projects), 6); - Assert.assertEquals(getTasksCount(projects), 41); - Assert.assertEquals(getAnnotationsCount(projects), 9); - Assert.assertEquals(getAlertsCount(projects), 6); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("loadTest error", e); - } - Assert.fail(); - }*/ - } - - /** - * Test project loading. - * - * @throws IOException - */ - @Test - public void getProjectFromFileTest() throws IOException { - - /*try { - FIXME saver.lock();*/ - - GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - - String projectFilePath = gsaver.dataSaveDirectory + "/1.project"; - - TimerProject project = gsaver.getProjectFromFile(new File( - projectFilePath)); - - Assert.assertNotNull(project); - Assert.assertEquals("Topia", project.getName()); - // not done by this method - //Assert.assertEquals(1, project.getNumber()); - Assert.assertTrue(project.isClosed()); - - Date expectedDate = new Date(); - expectedDate.setTime(2147483647 * 1000L); - Assert.assertEquals(expectedDate, project.getCreationDate()); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test task loading. - * - * Test: - * name - * times - * parent - * - * @throws IOException - */ - @Test - public void parseTaskFromFileTest() throws IOException { - - /*try { - //FIXME saver.lock();*/ - - GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - - String taskFilePath = gsaver.dataSaveDirectory + "/1.task"; - - // parent projects map - TimerProject parentProject = new TimerProject(); - parentProject.setName("Test"); - parentProject.setNumber(1); - Map<String, TimerProject> mapNumberProject = new HashMap<>(); - mapNumberProject.put(String.valueOf(parentProject.getNumber()), - parentProject); - - // out map for post parsing - SortedMap<TimerTask, TimerProject> taskToManage = new TreeMap<>(); - - TimerTask task = gsaver.parseTaskFromFile(mapNumberProject, - new File(taskFilePath), taskToManage); - - Assert.assertNotNull(task); - Assert.assertEquals("Add service layer", task.getName()); - // not done by this method - // Assert.assertEquals(1, task.getNumber()); - Assert.assertEquals(false, task.isClosed()); - // not done by this method - //Assert.assertEquals(parentProject, task.getParent()); - - Date expectedDate = new Date(); - expectedDate.setTime(2147483647 * 1000L); - Assert.assertEquals(expectedDate, task.getCreationDate()); - - long totalTime = 0; - for (Long time : task.getAllDaysAndTimes().values()) { - totalTime += time; - } - Assert.assertEquals(totalTime, 11391000); - - // test 20080909 9000 - - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, 2008); - calendar.set(Calendar.MONTH, 8); - calendar.set(Calendar.DAY_OF_MONTH, 9); - Assert.assertEquals(task.getTime(calendar.getTime()), 9000000); - - // 20080922 13 - calendar.set(Calendar.YEAR, 2008); - calendar.set(Calendar.MONTH, 8); - calendar.set(Calendar.DAY_OF_MONTH, 22); - Assert.assertEquals(task.getTime(calendar.getTime()), 13000); - - // 20080930 2332 - calendar.set(Calendar.YEAR, 2008); - calendar.set(Calendar.MONTH, 8); - calendar.set(Calendar.DAY_OF_MONTH, 30); - Assert.assertEquals(task.getTime(calendar.getTime()), 2332000); - - // 20081011 46 - calendar.set(Calendar.YEAR, 2008); - calendar.set(Calendar.MONTH, 9); - calendar.set(Calendar.DAY_OF_MONTH, 11); - Assert.assertEquals(task.getTime(calendar.getTime()), 46000); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test annotation loading. - * - * @throws IOException - */ - @Test - public void parseAnnotationsTest() throws IOException { - - /*try { - //FIXME saver.lock();*/ - - GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - - // task to get annotation - TimerTask task = new TimerTask(); - task.setNumber(13); - - gsaver.parseAnnotations(task); - - Assert.assertNotNull(task.getAllDaysAnnotations()); - Assert.assertEquals(2, task.getAllDaysAnnotations().size()); - - // first ann - Date date = new Date(); - date.setTime(1228950001 * 1000L); - Assert.assertEquals(date, task.getAllDaysAnnotations() - .firstKey()); - Assert.assertEquals("Very hard work", task.getAllDaysAnnotations().get( - task.getAllDaysAnnotations().firstKey())); - - // second ann - date = new Date(); - date.setTime(1228950002 * 1000L); - Assert.assertEquals(date, task.getAllDaysAnnotations() - .lastKey()); - Assert.assertEquals("Not easy work", task.getAllDaysAnnotations().get( - task.getAllDaysAnnotations().lastKey())); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("parseAnnotations error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test alert loading. - * - * @throws IOException - */ - @Test - public void parseAlertsTest() throws IOException { - - /*try { - //FIXME saver.lock();*/ - - GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - - // task to get annotation - TimerTask task = new TimerTask(); - task.setNumber(18); - - gsaver.parseAlerts(task); - - Assert.assertNotNull(task.getAlerts()); - Assert.assertEquals(task.getAlerts().size(), 2); - - // first alert - Assert.assertEquals(task.getAlerts().get(0).getType(), TimerAlert.Type.REACH_DAILY_TIME); - Assert.assertEquals(task.getAlerts().get(0).getDuration(), 3600000); - - // second alert - Assert.assertEquals(task.getAlerts().get(1).getType(), TimerAlert.Type.REACH_TOTAL_TIME); - Assert.assertEquals(task.getAlerts().get(1).getDuration(), 25000000); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("parseAnnotations error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test que les taches sans projets parent (autorisé par gtimer) sont bien - * chargé par jtimer dans un projet nommé "No project". - * - * @throws IOException - */ - @Test - public void defaultProjectTest() throws IOException { - /*try { - //FIXME testSaver.lock();*/ - - GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - - // task to get annotation - Collection<TimerProject> projects = gsaver.load(); - - TimerProject project1 = findProject(projects, "No project"); - Assert.assertNotNull(project1); - - TimerTask task1 = findTask(projects, "No project/Test no parent project"); - Assert.assertNotNull(task1); - Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task1), 9644000); - - /*FIXME testSaver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("parseAnnotations error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test que les lignes avec 0 ne sont pas chargées dans les fichiers de temps. - * - * @throws IOException - */ - @Test - public void dontLoadZeroTimeTest() throws IOException { - /*try { - //FIXME testSaver.lock();*/ - - GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - - // task to get annotation - Collection<TimerProject> projects = gsaver.load(); - - TimerTask task1 = findTask(projects, "Chorem/Add webservice"); - Assert.assertNotNull(task1); - Assert.assertEquals(task1.getAllDaysAndTimes().size(), 3); - - /*FIXME testSaver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("parseAnnotations error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test que les lignes avec 0 ne sont pas enregistrées dans les fichiers de temps. - * - * @throws IOException - */ - @Test - public void dontSaveZeroTimeTest() throws IOException { - /*try { - //FIXME testSaver.lock();*/ - - GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - - // task to get annotation - Collection<TimerProject> projects = gsaver.load(); - - TimerProject project = findProject(projects, "Chorem"); - TimerTask task = new TimerTask("test"); - task.setCreationDate(new Date()); - - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, 2016); - calendar.set(Calendar.MONTH, 5); - calendar.set(Calendar.DAY_OF_MONTH, 26); - - task.setTime(new Date(), 0L); - task.setNumber(99); - project.addTask(task); - gsaver.saveTask(task); - - String taskFileName = gsaver.dataSaveDirectory + File.separator + task.getNumber() + "." + GTimerIncrementalSaver.GTIMER_TASK_EXTENSION; - File taskFile = new File(taskFileName); - List<String> lines = FileUtils.readLines(taskFile, StandardCharsets.UTF_8); - Assert.assertTrue(lines.stream().noneMatch(line -> line.startsWith("2016"))); - - /*FIXME testSaver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("parseAnnotations error", e); - Assert.fail(); - } - }*/ - } -} diff --git a/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java b/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java deleted file mode 100644 index 40302e7..0000000 --- a/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2009 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.system; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.ui.report.ReportGeneratorTest; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.Optional; - -/** - * Test for SystemInfoFactory. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class SystemInfoFactoryTest extends AbstractJTimerTest { - - /** log. */ - private static Log log = LogFactory.getLog(ReportGeneratorTest.class); - - /** - * Test to get system info. - * - * Could return a valid system info, on linux - * windows, or fail if none is available. - */ - @Test - public void getSystemInfoTest() { - try { - Optional<SystemInfo> systemInfo = SystemInfoFactory.getSystemInfo(); - if (systemInfo.isPresent()) { - Assert.assertTrue(systemInfo.get().getIdleTime() >= 0, "Idle time must be positive"); - } - } catch (UnsatisfiedLinkError e) { - // can happen on system where libX11 is available - // libXss is not (on xvfb x server for example) - if (log.isWarnEnabled()) { - log.warn("Can't initialize native system libraries", e); - } - } - } -} diff --git a/src/test/java/org/chorem/jtimer/ui/report/ReportGeneratorTest.java b/src/test/java/org/chorem/jtimer/ui/report/ReportGeneratorTest.java deleted file mode 100644 index 624561f..0000000 --- a/src/test/java/org/chorem/jtimer/ui/report/ReportGeneratorTest.java +++ /dev/null @@ -1,368 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ui.report; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.entities.TimerProject; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.text.DateFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -/** - * Test for ReportGenerator class. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class ReportGeneratorTest extends AbstractJTimerTest { - - /** Class log */ - private static Log log = LogFactory.getLog(ReportGeneratorTest.class); - - protected static DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); - - /** - * Test report generation. - * - * @throws ParseException - */ - @Test - public void getReportTextDaily() throws ParseException { - - /*try { - FIXME saver.lock();*/ - - Date d1 = df.parse("January 1, 2008"); - Date d2 = df.parse("December 31, 2008"); - List<TimerProject> projects = new ArrayList<>(); - projects.addAll(testSaver.load()); - ReportGenerator generator = new ReportGenerator(); - String content = generator.getReportText(ReportGenerator.Type.BY_DAY_REPORT, - projects, d1, d2, false, false, false, false); - - if (log.isDebugEnabled()) { - log.debug("Daily report = " + content); - } - - Assert.assertNotNull(content); - Assert.assertFalse(content.indexOf("IsisFish") > 0); - Assert.assertFalse(content.indexOf("jRST") > 0); - Assert.assertTrue(content.indexOf("Topia") > 0); - - // no present task - Assert.assertFalse(content.indexOf("Add webservice") > 0); - Assert.assertFalse(content.indexOf("Add workspace support") > 0); - - // present task - Assert.assertTrue(content.indexOf("Add service layer") > 0); - Assert.assertTrue(content.indexOf("Calendar to date") > 0); - Assert.assertTrue(content.indexOf("Tree tests") > 0); - - // no annotations - Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); - Assert.assertFalse(content.indexOf("Not easy work") > 0); - Assert.assertFalse(content.indexOf("Reports tests") > 0); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test report generation with annotation time. - * - * @throws ParseException - */ - @Test - public void getReportTextDailyAnnotationTime() throws ParseException { - - /*try { - FIXME saver.lock();*/ - - Date d1 = df.parse("November 1, 2008"); - Date d2 = df.parse("March 31, 2009"); - List<TimerProject> projects = new ArrayList<>(); - projects.addAll(testSaver.load()); - ReportGenerator generator = new ReportGenerator(); - String content = generator.getReportText(ReportGenerator.Type.BY_DAY_REPORT, - projects, d1, d2, false, true, true, false); - - if (log.isDebugEnabled()) { - log.debug("Daily report = " + content); - } - - Assert.assertNotNull(content); - - // with annotations and time (* is important in test) - Assert.assertTrue(content.indexOf("* 2:10 PM : Test task and subtask time") > 0); - Assert.assertTrue(content.indexOf("* 12:00 AM : Not easy work") > 0); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test report generation. - * - * @throws ParseException - */ - @Test - public void getReportTextWeekly() throws ParseException { - - /*try { - FIXME saver.lock();*/ - - Date d1 = df.parse("November 1, 2008"); - Date d2 = df.parse("March 31, 2009"); - List<TimerProject> projects = new ArrayList<>(); - projects.addAll(testSaver.load()); - ReportGenerator generator = new ReportGenerator(); - String content = generator.getReportText(ReportGenerator.Type.BY_WEEK_REPORT, - projects, d1, d2, true, true, false, false); - - if (log.isDebugEnabled()) { - log.debug("Weekly report = " + content); - } - - Assert.assertNotNull(content); - Assert.assertTrue(content.indexOf("jTimer") > 0); - Assert.assertTrue(content.indexOf("Topia") > 0); - - // no present task - Assert.assertFalse(content.indexOf("Add service layer") > 0); - - // present task - Assert.assertTrue(content.indexOf("Add webservice") > 0); - Assert.assertTrue(content.indexOf("Add workspace support") > 0); - - // with annotations - Assert.assertTrue(content.indexOf("* Test task and subtask time") > 0); - Assert.assertTrue(content.indexOf("* Not easy work") > 0); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test report generation with annotation time. - * - * @throws ParseException - */ - @Test - public void getReportTextMonthlyAnnotationTime() throws ParseException { - - /*try { - FIXME saver.lock();*/ - - Date d1 = df.parse("November 1, 2008"); - Date d2 = df.parse("March 31, 2009"); - List<TimerProject> projects = new ArrayList<>(); - projects.addAll(testSaver.load()); - ReportGenerator generator = new ReportGenerator(); - String content = generator.getReportText(ReportGenerator.Type.BY_MONTH_REPORT, - projects, d1, d2, true, true, true, false); - - if (log.isDebugEnabled()) { - log.debug("Monthly report = " + content); - } - - Assert.assertNotNull(content); - - // no annotations - Assert.assertTrue(content.indexOf("* 2/3/09 2:10 PM : Test task and subtask time") > 0); - Assert.assertTrue(content.indexOf("* 12/11/08 12:00 AM : Not easy work") > 0); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test report generation. - * @throws ParseException - */ - @Test - public void getReportTextMonthly() throws ParseException { - - /*try { - FIXME saver.lock();*/ - - Date d1 = df.parse("November 1, 2008"); - Date d2 = df.parse("March 31, 2009"); - List<TimerProject> projects = new ArrayList<>(); - projects.addAll(testSaver.load()); - ReportGenerator generator = new ReportGenerator(); - String content = generator.getReportText(ReportGenerator.Type.BY_MONTH_REPORT, - projects, d1, d2, true, false, false, false); - - if (log.isDebugEnabled()) { - log.debug("Monthly report = " + content); - } - - Assert.assertNotNull(content); - Assert.assertTrue(content.indexOf("Chorem") > 0); - Assert.assertTrue(content.indexOf("Topia") > 0); - - // no present task - Assert.assertFalse(content.indexOf("Add service layer") > 0); - - // present task - Assert.assertTrue(content.indexOf("Add webservice") > 0); - Assert.assertTrue(content.indexOf("Add workspace support") > 0); - - // no annotations - Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); - Assert.assertFalse(content.indexOf("Not easy work") > 0); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test report generation. - * @throws ParseException - */ - @Test - public void getReportTextYearly() throws ParseException { - - /*try { - FIXME saver.lock();*/ - - Date d1 = df.parse("January 1, 2008"); - Date d2 = df.parse("December 31, 2008"); - List<TimerProject> projects = new ArrayList<>(); - projects.addAll(testSaver.load()); - ReportGenerator generator = new ReportGenerator(); - String content = generator.getReportText(ReportGenerator.Type.BY_YEAR_REPORT, - projects, d1, d2, false, false, false, false); - - if (log.isDebugEnabled()) { - log.debug("Yearly report = " + content); - } - - Assert.assertNotNull(content); - Assert.assertFalse(content.indexOf("Chorem") > 0); - Assert.assertTrue(content.indexOf("Topia") > 0); - - // no present task - Assert.assertFalse(content.indexOf("Add webservice") > 0); - Assert.assertFalse(content.indexOf("Add workspace support") > 0); - - // present task - Assert.assertTrue(content.indexOf("Add service layer") > 0); - Assert.assertTrue(content.indexOf("Calendar to date") > 0); - - // no annotations - Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); - Assert.assertFalse(content.indexOf("Not easy work") > 0); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } - - /** - * Test report generation. - * @throws ParseException - */ - @Test - public void getReportTextByProject() throws ParseException { - - /*try { - FIXME saver.lock();*/ - - Date d1 = df.parse("January 1, 2008"); - Date d2 = df.parse("December 31, 2008"); - List<TimerProject> projects = new ArrayList<>(); - projects.addAll(testSaver.load()); - ReportGenerator generator = new ReportGenerator(); - String content = generator.getReportText(ReportGenerator.Type.BY_PROJECT_REPORT, - projects, d1, d2, true, true, false, false); - - if (log.isDebugEnabled()) { - log.debug("Project report = " + content); - } - - Assert.assertNotNull(content); - Assert.assertFalse(content.indexOf("Chorem") > 0); - Assert.assertTrue(content.indexOf("Topia") > 0); - - // no present task - Assert.assertFalse(content.indexOf("Add webservice") > 0); - Assert.assertFalse(content.indexOf("Add workspace support") > 0); - - // present task - Assert.assertTrue(content.indexOf("Add service layer") > 0); - Assert.assertTrue(content.indexOf("Calendar to date") > 0); - - // test annotations - Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); - Assert.assertTrue(content.indexOf("* Not easy work") > 0); - - /*FIXME saver.unlock(); - } catch (DataLockingException e) { - if(log.isErrorEnabled()) { - log.error("getProjectFromFileTest error", e); - Assert.fail(); - } - }*/ - } -} diff --git a/src/test/java/org/chorem/jtimer/ui/report/ReportUtilsTest.java b/src/test/java/org/chorem/jtimer/ui/report/ReportUtilsTest.java deleted file mode 100644 index b7ccf1d..0000000 --- a/src/test/java/org/chorem/jtimer/ui/report/ReportUtilsTest.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ui.report; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.AbstractJTimerTest; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.text.DateFormat; -import java.text.ParseException; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -/** - * Test for ReportUtils class. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class ReportUtilsTest extends AbstractJTimerTest { - - /** Class log */ - private static Log log = LogFactory.getLog(ReportUtilsTest.class); - - protected static DateFormat df; - - /** - * Init date format instance. - */ - @BeforeClass - public static void init() { - df = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH); - } - - /** - * Get date list, between to date (1 day interval). - * - * Test qu'il y a bien 46 jours entre date102008 et date112008. - * - * @throws ParseException - */ - @Test - public void testGetDailyDates() throws ParseException { - - Date date102008 = df.parse("vendredi 10 octobre 2008"); - Date date112008 = df.parse("lundi 24 novembre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> daylyDates = utils.getDailyDates(date102008, date112008); - - Assert.assertNotNull(daylyDates); - Assert.assertEquals(46, daylyDates.size()); - Assert.assertEquals(date102008, daylyDates.get(0)); - Assert.assertEquals(date112008, daylyDates.get(daylyDates.size() - 1)); - } - - /** - * Get date list, between to date (1 day interval). - * - * @throws ParseException - */ - @Test - public void testGetDailyDates2() throws ParseException { - - Date date1 = df.parse("lundi 6 octobre 2008"); - Date date2 = df.parse("mardi 7 octobre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> daylyDates = utils.getDailyDates(date1, date2); - - Assert.assertNotNull(daylyDates); - Assert.assertEquals(2, daylyDates.size()); - Assert.assertEquals(date1, daylyDates.get(0)); - Assert.assertEquals(date2, daylyDates.get(daylyDates.size() - 1)); - } - - /** - * Get date list, between to date (1 day interval). - * - * @throws ParseException - */ - @Test - public void testGetDailyDates3() throws ParseException { - - Date date1 = df.parse("vendredi 10 octobre 2008"); - Date date2 = df.parse("lundi 13 octobre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> daylyDates = utils.getDailyDates(date1, date2); - - Assert.assertNotNull(daylyDates); - Assert.assertEquals(4, daylyDates.size()); - Assert.assertEquals(date1, daylyDates.get(0)); - Assert.assertEquals(date2, daylyDates.get(daylyDates.size() - 1)); - } - - /** - * Get date list, between to date (1 week interval). - * - * Test qu'il y a bien 46 jours entre date102008 et date112008. - * @throws ParseException - */ - @Test - public void testGetWeeklyDates() throws ParseException { - - Date date102008 = df.parse("vendredi 10 octobre 2008"); - Date date112008 = df.parse("lundi 24 novembre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> weeklyDates = utils.getWeeklyDates(date102008, date112008); - - Assert.assertNotNull(weeklyDates); - Assert.assertEquals(8, weeklyDates.size()); - Assert.assertEquals(date102008, weeklyDates.get(0)); - //Assert.assertEquals(date112008, weeklyDates.get(weeklyDates.size()-1)); - } - - /** - * Get date list, between to date (1 week interval). - * @throws ParseException - */ - @Test - public void testGetWeeklyDates2() throws ParseException { - - Date date1 = df.parse("lundi 6 octobre 2008"); - Date date2 = df.parse("vendredi 10 octobre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> weeklyDates = utils.getWeeklyDates(date1, date2); - - Assert.assertNotNull(weeklyDates); - Assert.assertEquals(1, weeklyDates.size()); - Assert.assertEquals(date1, weeklyDates.get(0)); - //Assert.assertEquals(date2, weeklyDates.get(weeklyDates.size()-1)); - } - - /** - * Get date list, between to date (1 week interval). - * @throws ParseException - */ - @Test - public void testGetWeeklyDates3() throws ParseException { - - Date date1 = df.parse("vendredi 10 octobre 2008"); - Date date2 = df.parse("lundi 13 octobre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> weeklyDates = utils.getWeeklyDates(date1, date2); - - Assert.assertNotNull(weeklyDates); - Assert.assertEquals(2, weeklyDates.size()); - Assert.assertEquals(date1, weeklyDates.get(0)); - Assert.assertEquals(date2, weeklyDates.get(weeklyDates.size() - 1)); - } - - /** - * Get date list, between to date (1 month interval). - * - * 16 mois. - * @throws ParseException - */ - @Test - public void testGetMonthlyDates() throws ParseException { - - Date date1 = df.parse("lundi 24 novembre 2008"); - Date date2 = df.parse("mercredi 17 mars 2010"); - - ReportUtils utils = new ReportUtils(); - - List<Date> monthlyDates = utils.getMonthlyDates(date1, date2); - - Assert.assertNotNull(monthlyDates); - Assert.assertEquals(17, monthlyDates.size()); - Assert.assertEquals(date1, monthlyDates.get(0)); - //Assert.assertEquals(date2, monthlyDates.get(monthlyDates.size()-1)); - - } - - /** - * Get date list, between to date (1 month interval). - * @throws ParseException - */ - @Test - public void testGetMonthlyDates2() throws ParseException { - - Date date1 = df.parse("lundi 3 novembre 2008"); - Date date2 = df.parse("mardi 4 novembre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> monthlyDates = utils.getMonthlyDates(date1, date2); - - Assert.assertNotNull(monthlyDates); - Assert.assertEquals(1, monthlyDates.size()); - Assert.assertEquals(date1, monthlyDates.get(0)); - //Assert.assertEquals(date2, monthlyDates.get(monthlyDates.size()-1)); - - } - - /** - * Get date list, between to date (1 month interval). - * @throws ParseException - */ - @Test - public void testGetMonthlyDates4() throws ParseException { - - Date date1 = df.parse("lundi 27 octobre 2008"); - Date date2 = df.parse("lundi 10 novembre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> monthlyDates = utils.getMonthlyDates(date1, date2); - - Assert.assertNotNull(monthlyDates); - Assert.assertEquals(2, monthlyDates.size()); - Assert.assertEquals(date1, monthlyDates.get(0)); - Assert.assertEquals(date2, monthlyDates.get(monthlyDates.size() - 1)); - - } - - /** - * Get date list, between to date (1 year interval). - * @throws ParseException - */ - @Test - public void testGetYearlyDates() throws ParseException { - - Date date112008 = df.parse("lundi 24 novembre 2008"); - Date date032010 = df.parse("mercredi 17 mars 2010"); - - ReportUtils utils = new ReportUtils(); - - List<Date> yearlyDates = utils.getYearlyDates(date112008, date032010); - - log.debug(yearlyDates); - - Assert.assertNotNull(yearlyDates); - Assert.assertEquals(3, yearlyDates.size()); - Assert.assertEquals(date112008, yearlyDates.get(0)); - //Assert.assertEquals(date032010, yearlyDates.get(yearlyDates.size()-1)); - } - - /** - * Get date list, between to date (1 year interval). - * @throws ParseException - */ - @Test - public void testGetYearlyDates2() throws ParseException { - - Date date1 = df.parse("lundi 24 novembre 2008"); - Date date2 = df.parse("vendredi 28 novembre 2008"); - - ReportUtils utils = new ReportUtils(); - - List<Date> yearlyDates = utils.getYearlyDates(date1, date2); - - log.debug(yearlyDates); - - Assert.assertNotNull(yearlyDates); - Assert.assertEquals(1, yearlyDates.size()); - Assert.assertEquals(date1, yearlyDates.get(0)); - //Assert.assertEquals(date2, yearlyDates.get(yearlyDates.size()-1)); - } - - /** - * Get date list, between to date (1 year interval). - * @throws ParseException - */ - @Test - public void testGetYearlyDates3() throws ParseException { - - Date date1 = df.parse("lundi 24 novembre 2008"); - Date date2 = df.parse("lundi 5 janvier 2009"); - - ReportUtils utils = new ReportUtils(); - - List<Date> yearlyDates = utils.getYearlyDates(date1, date2); - - log.debug(yearlyDates); - - Assert.assertNotNull(yearlyDates); - Assert.assertEquals(2, yearlyDates.size()); - Assert.assertEquals(date1, yearlyDates.get(0)); - //Assert.assertEquals(date2, yearlyDates.get(yearlyDates.size()-1)); - } -} diff --git a/src/test/java/org/chorem/jtimer/ui/widget/DurationEditorTest.java b/src/test/java/org/chorem/jtimer/ui/widget/DurationEditorTest.java deleted file mode 100644 index f907488..0000000 --- a/src/test/java/org/chorem/jtimer/ui/widget/DurationEditorTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2009 - 2011 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ui.widget; - -import javax.swing.JFrame; - -/** - * Duration editor test class. - * - * @author chatellier - * @version $Revision: 1.0 $ - * - * Last update : $Date: 2 juil. 2009 $ - * By : $Author: chatellier $ - */ -public class DurationEditorTest { - - /** - * Show duration editor test. - * - * TODO add ui test framework - */ - public void showDurationEditorTest() { - JFrame f = new JFrame(); - f.add(new DurationEditor()); - f.pack(); - f.setVisible(true); - - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } -} diff --git a/src/test/java/org/chorem/jtimer/utils/DailySortedMapTest.java b/src/test/java/org/chorem/jtimer/utils/DailySortedMapTest.java deleted file mode 100644 index bf59506..0000000 --- a/src/test/java/org/chorem/jtimer/utils/DailySortedMapTest.java +++ /dev/null @@ -1,538 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.utils; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.text.DateFormat; -import java.text.ParseException; -import java.util.Date; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedMap; -import java.util.TreeMap; - -/** - * Test for DailySortedMap class. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class DailySortedMapTest { - - protected static DateFormat df; - - /** - * Init date format instance. - */ - @BeforeClass - public static void init() { - df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); - } - - /** - * Test le contructeur par defaut. - */ - @Test - public void testConstructor() { - DailySortedMap<Long> map = new DailySortedMap<>(); - Assert.assertNotNull(map); - } - - /** - * Test le constructeur avec comparateur. - * @throws ParseException - */ - @Test - public void testConsctuctorComparator() throws ParseException { - - DailySortedMap<Long> map = new DailySortedMap<>(Date::compareTo); - - Date d1 = df.parse("December 30, 2008"); - Date d2 = df.parse("December 29, 2008"); - - map.put(d1, 1l); - map.put(d2, 2l); - map.put(d1, 3l); - - Assert.assertNotNull(map); - Assert.assertEquals(map.size(), 2); - Assert.assertEquals(map.firstEntry().getValue().longValue(), 2l); - Assert.assertEquals(map.lastEntry().getValue().longValue(), 3l); - } - - /** - * Test du constructeur avec une sorted map. - * @throws ParseException - */ - @Test - public void testConstructorMap() throws ParseException { - Date d1 = df.parse("December 30, 2008, 12:00:00 GMT"); - Date d2 = df.parse("December 30, 2008, 13:00:00 GMT"); - Date d3 = df.parse("December 31, 2008, 12:00:00 GMT"); - Date d4 = df.parse("December 31, 2008, 13:00:00 GMT"); - - SortedMap<Date, Long> map = new TreeMap<>(); - map.put(d1, 1l); - map.put(d2, 2l); - map.put(d3, 3l); - map.put(d4, 4l); - - // d2 erase d1, and d4 erase d3 - DailySortedMap<Long> newMap = new DailySortedMap<>(map); - Assert.assertEquals(newMap.size(), 2); - Assert.assertEquals(newMap.firstEntry().getValue().longValue(), 2l); - Assert.assertEquals(newMap.lastEntry().getValue().longValue(), 4l); - } - - /** - * Test du constructeur avec une map. - * @throws ParseException - */ - @Test - public void testConstructorSortedMap() throws ParseException { - Date d1 = df.parse("December 30, 2008, 12:00:00 GMT"); - Date d2 = df.parse("December 30, 2008, 13:00:00 GMT"); - Date d3 = df.parse("December 31, 2008, 12:00:00 GMT"); - Date d4 = df.parse("December 31, 2008, 13:00:00 GMT"); - - Map<Date, Long> map = new HashMap<>(); - map.put(d1, 1l); - map.put(d2, 2l); - map.put(d3, 3l); - map.put(d4, 4l); - - // d2 erase d1, and d4 erase d3 - DailySortedMap<Long> newMap = new DailySortedMap<>(map); - Assert.assertEquals(newMap.size(), 2); - Assert.assertEquals(newMap.firstEntry().getValue().longValue(), 2l); - Assert.assertEquals(newMap.lastEntry().getValue().longValue(), 4l); - } - - /** - * Test ceilingEntry. - * @throws ParseException - */ - @Test - public void ceilingEntryTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Entry<Date, Long> entry = map.ceilingEntry(d2); - - Assert.assertEquals(entry.getKey(), d3); - Assert.assertEquals(entry.getValue().longValue(), 13l); - } - - /** - * Test ceilingKey. - * @throws ParseException - */ - @Test - public void ceilingKeyTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Date d = map.ceilingKey(d2); - - Assert.assertEquals(d, d3); - } - - /** - * Test containsKey. - * @throws ParseException - */ - @Test - public void containsKeyTest() throws ParseException { - Date d1 = df.parse("December 30, 2008, 12:00:00 GMT"); - - DailySortedMap<Long> map = new DailySortedMap<>(); - map.put(d1, 1l); - - Assert.assertTrue(map.containsKey(d1)); - - Date d2 = df.parse("December 31, 2008, 12:00:00 GMT"); - Assert.assertFalse(map.containsKey(d2)); - - Date d3 = df.parse("December 30, 2008, 18:48:00 GMT"); - Assert.assertTrue(map.containsKey(d3)); - - // non date object - Assert.assertFalse(map.containsKey("test false")); - } - - /** - * Test floorEntry. - * @throws ParseException - */ - @Test - public void floorEntryTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Entry<Date, Long> entry = map.floorEntry(d2); - - Assert.assertEquals(entry.getKey(), d1); - Assert.assertEquals(entry.getValue().longValue(), 3l); - } - - /** - * Test floorKey. - * @throws ParseException - */ - @Test - public void floorKeyTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Date d = map.floorKey(d2); - - Assert.assertEquals(d, d1); - } - - /** - * Test get(). - * @throws ParseException - */ - @Test - public void getTest() throws ParseException { - Date d1 = df.parse("December 30, 2008, 12:00:00 GMT"); - Date d2 = df.parse("December 31, 2008, 12:00:00 GMT"); - - DailySortedMap<Long> map = new DailySortedMap<>(); - map.put(d1, 1l); - map.put(d2, 2l); - - Assert.assertEquals(1l, map.get(d1).longValue()); - Assert.assertEquals(2l, map.get(d2).longValue()); - - Date d3 = df.parse("December 29, 2008, 12:00:00 GMT"); - Assert.assertNull(map.get(d3)); - - Date d4 = df.parse("December 30, 2008, 18:48:00 GMT"); - Assert.assertEquals(map.get(d4).longValue(), 1l); - - // non date object - Assert.assertNull(map.get("test false")); - } - - /** - * Test headMap. - * @throws ParseException - */ - @Test - public void headMapTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d2, 34l); - map.put(d3, 13l); - - SortedMap<Date, Long> newMap = map.headMap(df.parse("June 12, 2009, 18:44:59 GMT")); - - Assert.assertEquals(newMap.size(), 1); - } - - /** - * Test headMap. - * @throws ParseException - */ - @Test - public void headMapBooleanTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d2, 34l); - map.put(d3, 13l); - - SortedMap<Date, Long> newMap = map.headMap(df.parse("June 12, 2009, 18:44:59 GMT"), true); - - Assert.assertEquals(newMap.size(), 2); - } - - /** - * Test higherEntry. - * @throws ParseException - */ - @Test - public void higherEntryTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Entry<Date, Long> entry = map.higherEntry(df.parse("June 12, 2009, 18:44:59 GMT")); - - Assert.assertEquals(entry.getKey(), d3); - Assert.assertEquals(entry.getValue().longValue(), 13l); - } - - /** - * Test higherKey. - * @throws ParseException - */ - @Test - public void higherKeyTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Date d = map.higherKey(df.parse("June 12, 2009, 18:44:59 GMT")); - - Assert.assertEquals(d, d3); - } - - /** - * Test lowerEntry. - * @throws ParseException - */ - @Test - public void lowerEntryTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Entry<Date, Long> entry = map.lowerEntry(df.parse("June 12, 2009, 18:44:59 GMT")); - - Assert.assertEquals(entry.getKey(), d1); - Assert.assertEquals(entry.getValue().longValue(), 3l); - } - - /** - * Test lowerKey. - * @throws ParseException - */ - @Test - public void lowerKeyTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d3, 13l); - - Date d = map.lowerKey(df.parse("June 12, 2009, 18:44:59 GMT")); - - Assert.assertEquals(d, d1); - } - - /** - * Test put(). - * @throws ParseException - */ - @Test - public void putTest() throws ParseException { - Date d1 = df.parse("December 30, 2008, 12:00:00 GMT"); - Date d2 = df.parse("December 30, 2008, 14:00:00 GMT"); - Date d3 = df.parse("December 31, 2008, 12:00:00 GMT"); - Date d4 = df.parse("December 31, 2008, 18:48:00 GMT"); - Date d5 = df.parse("December 31, 2008, 00:00:00 GMT"); - - DailySortedMap<Long> map = new DailySortedMap<>(); - map.put(d1, 1l); - map.put(d2, 2l); - Assert.assertEquals(map.size(), 1); - Assert.assertEquals(map.get(d1).longValue(), 2l); - - map.put(d3, 3l); - Assert.assertEquals(map.size(), 2); - Assert.assertEquals(map.get(d3).longValue(), 3l); - - map.put(d4, 4l); - Assert.assertEquals(map.size(), 2); - Assert.assertEquals(map.get(d3).longValue(), 4l); - - map.put(d5, 5l); - Assert.assertEquals(map.size(), 2); - Assert.assertEquals(map.get(d3).longValue(), 5l); - } - - /** - * Test putAll(). - * @throws ParseException - */ - @Test - public void putAllTest() throws ParseException { - - Date d1 = df.parse("December 30, 2008, 12:00:00 GMT"); - Date d2 = df.parse("December 30, 2008, 14:00:00 GMT"); - Date d3 = df.parse("December 31, 2008, 12:00:00 GMT"); - Date d4 = df.parse("December 31, 2008, 18:48:00 GMT"); - Date d5 = df.parse("December 31, 2008, 00:00:00 GMT"); - - Map<Date, Long> map = new HashMap<>(); - map.put(d1, 1l); - map.put(d2, 2l); - map.put(d3, 3l); - map.put(d4, 4l); - map.put(d5, 5l); - Assert.assertEquals(2, map.size()); - - DailySortedMap<Long> newMap = new DailySortedMap<>(); - newMap.putAll(map); - Assert.assertEquals(newMap.size(), 2); - Assert.assertEquals(newMap.get(d1).longValue(), 2l); - Assert.assertEquals(newMap.get(d3).longValue(), 5l); - } - - /** - * Test subMap. - * @throws ParseException - */ - @Test - public void subMapTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d2, 3l); - map.put(d3, 13l); - - SortedMap<Date, Long> newMap = map.subMap(df.parse("May 1, 2009, 11:02:33 GMT"), - df.parse("October 11, 2009, 18:44:59 GMT")); - - Assert.assertEquals(newMap.size(), 2); - } - - /** - * Test subMap. - * @throws ParseException - */ - @Test - public void subMapBooleanTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d2, 3l); - map.put(d3, 13l); - - SortedMap<Date, Long> newMap = map.subMap(df.parse("May 09, 2009, 15:45:00 GMT"), true, - df.parse("December 07, 2009, 17:56:12 GMT"), false); - - Assert.assertEquals(newMap.size(), 2); - } - - /** - * Test tailMap. - * @throws ParseException - */ - @Test - public void tailMapTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d2, 3l); - map.put(d3, 13l); - - SortedMap<Date, Long> newMap = map.tailMap(df.parse("July 15, 2009, 15:10:00 GMT")); - - Assert.assertEquals(newMap.size(), 1); - } - - /** - * Test tailMap. - * @throws ParseException - */ - @Test - public void tailMapBooleanTest() throws ParseException { - DailySortedMap<Long> map = new DailySortedMap<>(); - - Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); - Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); - Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - - map.put(d1, 3l); - map.put(d2, 3l); - map.put(d3, 13l); - - SortedMap<Date, Long> newMap = map.tailMap(df.parse("December 07, 2009, 13:58:00 GMT"), false); - - Assert.assertEquals(newMap.size(), 0); - } -} -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.