branch develop updated (5ad75f1 -> 43b02e0)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git from 5ad75f1 Fix website new 43b02e0 Remove timebundle code from master (refactored in branch) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 43b02e091361065e1e751c32e3318cd068c13c3f Author: Eric Chatellier <chatellier@codelutin.com> Date: Mon May 28 10:02:36 2018 +0200 Remove timebundle code from master (refactored in branch) Summary of changes: src/main/java/org/chorem/jtimer/JTimer.java | 27 +-- src/main/java/org/chorem/jtimer/JTimerConfig.java | 10 - src/main/java/org/chorem/jtimer/JTimerFactory.java | 38 +--- .../java/org/chorem/jtimer/data/TimerCore.java | 18 +- .../java/org/chorem/jtimer/entities/TimerSync.java | 151 ------------- .../java/org/chorem/jtimer/entities/TimerTask.java | 21 +- .../jtimer/plugin/timebundle/TimeBundleHelper.java | 136 ------------ .../jtimer/plugin/timebundle/TimeBundleSaver.java | 219 ------------------ .../plugin/timebundle/TimeBundleSynchronizer.java | 171 -------------- .../plugin/timebundle/TimeBundleVetoable.java | 56 ----- .../plugin/timebundle/TimerSyncCellRenderer.java | 46 ---- .../jtimer/plugin/timebundle/TimerSyncEditor.java | 245 --------------------- .../plugin/timebundle/TimerSyncTableModel.java | 203 ----------------- src/main/resources/log4j2.xml | 3 +- .../resources/TimerSyncEditor.properties | 46 ---- .../resources/TimerSyncEditor_fr.properties | 47 ---- .../org/chorem/jtimer/resources/JTimer.properties | 5 - .../chorem/jtimer/resources/JTimer_fr.properties | 4 - src/site/rst/timebundle.rst | 30 --- src/site/site.xml | 1 - .../java/org/chorem/jtimer/AbstractJTimerTest.java | 2 - .../plugin/timebundle/TimeBundleHelperTest.java | 87 -------- .../plugin/timebundle/TimeBundleSaverTest.java | 66 ------ 23 files changed, 5 insertions(+), 1627 deletions(-) delete mode 100644 src/main/java/org/chorem/jtimer/entities/TimerSync.java delete mode 100644 src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java delete mode 100644 src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java delete mode 100644 src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSynchronizer.java delete mode 100644 src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java delete mode 100644 src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncCellRenderer.java delete mode 100644 src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java delete mode 100644 src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java delete mode 100644 src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor.properties delete mode 100644 src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor_fr.properties delete mode 100644 src/site/rst/timebundle.rst delete mode 100644 src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java delete mode 100644 src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaverTest.java -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 43b02e091361065e1e751c32e3318cd068c13c3f Author: Eric Chatellier <chatellier@codelutin.com> Date: Mon May 28 10:02:36 2018 +0200 Remove timebundle code from master (refactored in branch) --- src/main/java/org/chorem/jtimer/JTimer.java | 27 +-- src/main/java/org/chorem/jtimer/JTimerConfig.java | 10 - src/main/java/org/chorem/jtimer/JTimerFactory.java | 38 +--- .../java/org/chorem/jtimer/data/TimerCore.java | 18 +- .../java/org/chorem/jtimer/entities/TimerSync.java | 151 ------------- .../java/org/chorem/jtimer/entities/TimerTask.java | 21 +- .../jtimer/plugin/timebundle/TimeBundleHelper.java | 136 ------------ .../jtimer/plugin/timebundle/TimeBundleSaver.java | 219 ------------------ .../plugin/timebundle/TimeBundleSynchronizer.java | 171 -------------- .../plugin/timebundle/TimeBundleVetoable.java | 56 ----- .../plugin/timebundle/TimerSyncCellRenderer.java | 46 ---- .../jtimer/plugin/timebundle/TimerSyncEditor.java | 245 --------------------- .../plugin/timebundle/TimerSyncTableModel.java | 203 ----------------- src/main/resources/log4j2.xml | 3 +- .../resources/TimerSyncEditor.properties | 46 ---- .../resources/TimerSyncEditor_fr.properties | 47 ---- .../org/chorem/jtimer/resources/JTimer.properties | 5 - .../chorem/jtimer/resources/JTimer_fr.properties | 4 - src/site/rst/timebundle.rst | 30 --- src/site/site.xml | 1 - .../java/org/chorem/jtimer/AbstractJTimerTest.java | 2 - .../plugin/timebundle/TimeBundleHelperTest.java | 87 -------- .../plugin/timebundle/TimeBundleSaverTest.java | 66 ------ 23 files changed, 5 insertions(+), 1627 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index f711d12..ab54d3e 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.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 @@ -31,7 +31,6 @@ import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.plugin.timebundle.TimerSyncEditor; import org.chorem.jtimer.system.SystemInfo; import org.chorem.jtimer.system.SystemInfoFactory; import org.chorem.jtimer.ui.HelpFrame; @@ -366,9 +365,6 @@ public class JTimer extends SingleFrameApplication implements String[] projectMenuActionNames = {"newProject", "editProject", "closeProject", "deleteProject", "---", "quit"}; - if (JTimerFactory.getSynchronizer() != null) { - projectMenuActionNames = ArrayUtils.add(projectMenuActionNames, 2, "editSync"); - } menuBar.add(createMenu("projectMenu", projectMenuActionNames)); String[] taskMenuActionNames = {"newTask", "editTask", "closeTask", @@ -376,9 +372,6 @@ public class JTimer extends SingleFrameApplication implements "addAnnotation", "editAlert", "increment1Task", "increment5Task", "increment30Task", "decrement1Task", "decrement5Task", "decrement30Task", "setToZero", "mergeTasks"}; - if (JTimerFactory.getSynchronizer() != null) { - taskMenuActionNames = ArrayUtils.add(taskMenuActionNames, 2, "editSync"); - } menuBar.add(createMenu("taskMenu", taskMenuActionNames)); String[] reportMenuActionNames = {"makeReport"}; @@ -668,18 +661,6 @@ public class JTimer extends SingleFrameApplication implements show(editor); } - /** - * Update task. - * Enabled when a task is selected - */ - @Action(enabledProperty = "selectedSingleElement") - public void editSync() { - TimerTask task = projectsAndTasksTable.getSelectedElements().get(0); - - TimerSyncEditor updater = new TimerSyncEditor(this, core, task); - show(updater); - } - /** * Start selected task in tree. * @@ -1498,9 +1479,6 @@ public class JTimer extends SingleFrameApplication implements if (isSelectedSingleProject()) { actionNames = new String[]{"newTask", "---", "newProject", "editProject", "closeProject", "deleteProject"}; - if (JTimerFactory.getSynchronizer() != null) { - actionNames = ArrayUtils.add(actionNames, 4, "editSync"); - } } if (isSelectedSingleTask()) { @@ -1509,9 +1487,6 @@ public class JTimer extends SingleFrameApplication implements "---", "addAnnotation", "editAlert", "increment1Task", "increment5Task", "increment30Task", "decrement1Task", "decrement5Task", "decrement30Task", "setToZero"}; - if (JTimerFactory.getSynchronizer() != null) { - actionNames = ArrayUtils.add(actionNames, 4, "editSync"); - } } if (isSelectedMultiplesTasks()) { diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index bc1f2c2..50db0ab 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -177,14 +177,6 @@ public class JTimerConfig { return appConfig.getOptionAsLong(JTimerOption.IO_SAVER_AUTOSAVEDELAY.key); } - /** - * Returns the synchronizer class - * @return - */ - public Class<?> getIOSynchronizerClass() { - return appConfig.getOptionAsClass(JTimerOption.IO_SYNC_CLASS.key); - } - /** * Return user idle time threshold in seconds. * @@ -297,8 +289,6 @@ public class JTimerConfig { GTIMER_BACKUP_DIRECTORY("jtimer.io.backup.directory", "${jtimer.io.saver.directory}/backups"), IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), - IO_SYNC_CLASS("jtimer.io.synchronizer.class", null), - UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), UI_CLOSE_TO_SYSTRAY("jtimer.ui.closetosystray", "true"), diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index dc2953e..e66396a 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.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,7 +25,6 @@ package org.chorem.jtimer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.io.Saver; -import org.chorem.jtimer.plugin.timebundle.TimeBundleSynchronizer; /** * JTimer config class. @@ -44,9 +43,6 @@ public class JTimerFactory { /** Saver */ protected static Saver saver; - /** Synchronizer */ - protected static TimeBundleSynchronizer synchronizer; - /** * Constructeur. */ @@ -92,36 +88,4 @@ public class JTimerFactory { return saver; } - - /** - * Get synchronizer manager - */ - public static TimeBundleSynchronizer getSynchronizer() { - if (synchronizer == null) { - - Class<?> synchronizerClass = JTimer.config.getIOSynchronizerClass(); - - if (synchronizerClass != null) { - // log - if (log.isInfoEnabled()) { - log.info("Using synchronizer class : " + synchronizerClass); - } - - try { - // get instance - synchronizer = (TimeBundleSynchronizer) synchronizerClass.newInstance(); - - } catch (InstantiationException e) { - if (log.isErrorEnabled()) { - log.error("Can't instanciate class : " + synchronizerClass, e); - } - } catch (IllegalAccessException e) { - if (log.isErrorEnabled()) { - log.error("Can't access class : " + synchronizerClass, e); - } - } - } - } - return synchronizer; - } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index ae4a4cc..b63347d 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.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 @@ -30,9 +30,6 @@ import org.chorem.jtimer.JTimerFactory; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.io.DataLockingException; import org.chorem.jtimer.io.Saver; -import org.chorem.jtimer.plugin.timebundle.TimeBundleSaver; -import org.chorem.jtimer.plugin.timebundle.TimeBundleSynchronizer; -import org.chorem.jtimer.plugin.timebundle.TimeBundleVetoable; import java.io.File; import java.io.IOException; @@ -61,9 +58,6 @@ public class TimerCore { /** saver io controller. */ protected Saver saver; - /** sync */ - protected TimeBundleSynchronizer synchronizer; - /** * Constructor. */ @@ -91,16 +85,6 @@ public class TimerCore { data.addVetoableDataEventListener(saver); data.addDataEventListener(saver); } - - //init sync - synchronizer = JTimerFactory.getSynchronizer(); - if (synchronizer != null) { - TimeBundleSaver saver = new TimeBundleSaver(); - data.addVetoableDataEventListener(new TimeBundleVetoable()); - data.addDataEventListener(saver); - data.addDataEventListener(synchronizer); - synchronizer.setSaver(saver); - } } /** diff --git a/src/main/java/org/chorem/jtimer/entities/TimerSync.java b/src/main/java/org/chorem/jtimer/entities/TimerSync.java deleted file mode 100644 index dfd15a9..0000000 --- a/src/main/java/org/chorem/jtimer/entities/TimerSync.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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 java.util.Date; - -/** - * Class to structure synchronization info. - */ -public class TimerSync { - - /** - * the url to synchronize on - */ - protected String url; - - /** - * the last time the synchronization happened successfully - */ - protected Date lastSync; - - /** - * true if the synchronization is active - */ - protected boolean active; - - /** - * true if annotations included - */ - protected boolean withAnnotations; - - /** - * constructor with all parameters - * - * @param url the url to sync to - * @param lastSync the last time it was synced successfully - * @param active if true, will sync auto - * @param withAnnotations if true, will add annotations - */ - public TimerSync(String url, Date lastSync, boolean active, boolean withAnnotations) { - this.url = url; - this.lastSync = lastSync; - this.active = active; - this.withAnnotations = withAnnotations; - } - - /** - * Constructor with just the url, at creation the sync is considered active by default, - * and annotations are not sent by default - * - * @param url the url to sync to - */ - public TimerSync(String url) { - this(url, new Date(0), true, false); - } - - /** - * Returns the time of the last sync - * - * @return LocalDateTime - */ - public Date getLastSync() { - return lastSync; - } - - /** - * Returns a boolean if sync should send to this url - * - * @return a boolean - */ - public boolean isActive() { - return active; - } - - /** - * Sets the setActive boolean - * - * @param active boolean - */ - public void setActive(boolean active) { - this.active = active; - } - - /** - * Returns a boolean for the inclusion of annotations - * in the sync - * - * @return a boolean - */ - public boolean isWithAnnotations() { - return withAnnotations; - } - - /** - * Sets the withAnnotations boolean - * - * @param withAnnotations boolean - */ - public void setWithAnnotations(boolean withAnnotations) { - this.withAnnotations = withAnnotations; - } - - /** - * Set the url - * - * @param url String - */ - public void setUrl(String url) { - this.url = url; - } - - /** - * Get the url - * - * @return String - */ - public String getUrl() { - return url; - } - - /** - * Set Sync time - * - * @param syncTime Date - */ - public void setLastSync(Date syncTime) { - lastSync = syncTime; - } - -} - diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 19175ea..11dab70 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.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 @@ -88,11 +88,6 @@ public class TimerTask implements Cloneable, */ protected List<TimerAlert> alerts; - /** - * Synchronization Info - */ - protected List<TimerSync> syncs; - /** * Constructor. */ @@ -102,7 +97,6 @@ public class TimerTask implements Cloneable, allDaysAnnotations = new TreeMap<>(); subTasks = new ArrayList<>(); alerts = new ArrayList<>(); - syncs = new ArrayList<>(); // wrong value to detect bug number = -1; } @@ -321,18 +315,6 @@ public class TimerTask implements Cloneable, this.alerts = alerts; } - public void addSync(TimerSync sync) { - syncs.add(sync); - } - - public List<TimerSync> getSyncs() { - return syncs; - } - - public void setSyncs(List<TimerSync> syncs) { - this.syncs = syncs; - } - @Override public String toString() { return name + subTasks.toString(); @@ -375,7 +357,6 @@ public class TimerTask implements Cloneable, task.allDaysTimes = new DailySortedMap<>(allDaysTimes); task.allDaysAnnotations = new TreeMap<>(allDaysAnnotations); task.subTasks = new ArrayList<>(subTasks); - task.syncs = new ArrayList<>(syncs); } catch (CloneNotSupportedException e) { throw new RuntimeException("Can't clone", e); } diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java deleted file mode 100644 index b8baaaf..0000000 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java +++ /dev/null @@ -1,136 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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.plugin.timebundle; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.apache.commons.lang3.time.DateFormatUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.SortedMap; - -/** - * Helper for time bundle. - */ -public class TimeBundleHelper { - - protected static final String DATE_MIDNIGHT_PATTERN = "yyyy-MM-dd'T'00:00:00XXX"; - - /** - * Returns all the subtasks of a task (including the subtaks of subtasks). - * - * @param task - * @return a List<TimerTask> - */ - public static List<TimerTask> getAllSubTasks(TimerTask task) { - List<TimerTask> subTasksList = new ArrayList<>(); - if (task.getSubTasks() != null) { - for (TimerTask subTask : task.getSubTasks()) { - subTasksList.add(subTask); - subTasksList.addAll(getAllSubTasks(subTask)); - } - } - return subTasksList; - } - - /** - * makes a JSONObject corresponding to one sync with all the times since lastSync. - * - * @param task - * @param sync - * @return - */ - public static JsonObject taskToJsonObject(TimerTask task, TimerSync sync) { - JsonObject resultingObject = new JsonObject(); - JsonArray periodArray = new JsonArray(); - Date startDate = sync.getLastSync(); - Date endDate = DateUtils.ceiling(new Date(), Calendar.DAY_OF_MONTH); - String startPeriodString = DateFormatUtils.format(startDate, DATE_MIDNIGHT_PATTERN); - String endPeriodString = DateFormatUtils.format(endDate, DATE_MIDNIGHT_PATTERN); - - //get the times of the task - periodArray.addAll(getTimesAsJsonArray(task, startDate, endDate, sync.isWithAnnotations())); - //if there are subtasks, get the times of the subtasks that have no syncInfo - if (!task.getSubTasks().isEmpty()) { - for (TimerTask subtask : getAllSubTasks(task)) { - if (subtask.getSyncs().isEmpty()) { - periodArray.addAll(getTimesAsJsonArray(subtask, startDate, endDate, sync.isWithAnnotations())); - } - } - } - resultingObject.addProperty("URL", sync.getUrl()); - resultingObject.addProperty("startDate", startPeriodString); - resultingObject.addProperty("endDate", endPeriodString); - resultingObject.add("periods", periodArray); - - return resultingObject; - - } - - /*** - * Returns a JsonArray of all the times of a task, according to format - * the id is made of the date of the time and the id of the task (as in the number given - * by jTimer) - * id, startdate, duration, info (if annotations is true) - * - * @param task - * @param startDate - * @param endDate - * @param withAnnotations - * @return a JsonArray of the periods - */ - public static JsonArray getTimesAsJsonArray(TimerTask task, Date startDate, Date endDate, boolean withAnnotations) { - JsonArray periodArray = new JsonArray(); - SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); - for (SortedMap.Entry<Date, Long> entry : dates.entrySet()) { - //adding id, startDate and duration - String dateString = DateFormatUtils.format(entry.getKey(), DATE_MIDNIGHT_PATTERN); - //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format - String idString = DateFormatUtils.format(entry.getKey(), "yyyy-MM-dd"); - JsonObject periodElement = new JsonObject(); - periodElement.addProperty("id", idString + "_" + task.getNumber()); - periodElement.addProperty("startDate", dateString); - //TimerTaskHelper.getTotalTime(task, entry.getKey()) to get the total time of the task and all the subtasks - //entry.getValue() to get only the time of the task divided by 1000 (jtimer stores milliseconds) - periodElement.addProperty("duration", entry.getValue() / 1000); - if (withAnnotations && !(TimerTaskHelper.getAnnotation(task, entry.getKey()).isEmpty())) { - StringBuilder annotationBuilder = new StringBuilder(); - for (String s : TimerTaskHelper.getAnnotation(task, entry.getKey())) { - annotationBuilder.append(s); - annotationBuilder.append(","); - } - periodElement.addProperty("info", annotationBuilder.toString()); - } - periodArray.add(periodElement); - } - return periodArray; - - } - -} diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java deleted file mode 100644 index f2f0fa4..0000000 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java +++ /dev/null @@ -1,219 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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.plugin.timebundle; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -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.entities.TimerProject; -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.io.BackupUtils; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.Collection; -import java.util.List; - -/** - * Saver to handle sync related info. - */ -public class TimeBundleSaver implements DataEventListener { - - private static Log log = LogFactory.getLog(TimeBundleSaver.class); - - protected static final String JTIMER_SYNC_DIRECTORY = "timebundle"; - - protected static final String JTIMER_PROJECT_EXTENSION = ".project.sync"; - - protected static final String JTIMER_TASK_EXTENSION = ".task.sync"; - - protected File syncDataDirectory; - - public TimeBundleSaver() { - syncDataDirectory = new File(JTimer.config.getHomeDirectory(), JTIMER_SYNC_DIRECTORY); - syncDataDirectory.mkdirs(); - } - - @Override - public void dataLoaded(Collection<TimerProject> projects) { - projects.forEach(this::addProjectSync); - } - - @Override - public void modifyProject(TimerProject project) { - saveProjectSync(project); - } - - @Override - public void modifyTask(TimerTask task) { - saveTaskSync(task); - } - - @Override - public void addProject(TimerProject project) { - saveProjectSync(project); - } - - @Override - public void addTask(TimerTask task) { - saveTaskSync(task); - } - - @Override - public void deleteProject(TimerProject project) { - int projectNumber = project.getNumber(); - File projectSyncFile = new File(syncDataDirectory, projectNumber + JTIMER_PROJECT_EXTENSION); - if (projectSyncFile.exists()) { - projectSyncFile.delete(); - if (log.isDebugEnabled()) { - log.debug("Synchronization file deleted for " + project.getName()); - } - } - } - - @Override - public void deleteTask(TimerTask task) { - int taskNumber = task.getNumber(); - File taskSyncFile = new File(syncDataDirectory, taskNumber + JTIMER_TASK_EXTENSION); - if (taskSyncFile.exists()) { - taskSyncFile.delete(); - if (log.isDebugEnabled()) { - log.debug("Synchronization file deleted for " + task.getName()); - } - } - } - - protected void addProjectSync(TimerProject timerProject) { - int projectNumber = timerProject.getNumber(); - File projectSyncFile = new File(syncDataDirectory, projectNumber + JTIMER_PROJECT_EXTENSION); - parseFileSync(timerProject, projectSyncFile); - timerProject.getSubTasks().forEach(this::addTaskSync); - } - - protected void addTaskSync(TimerTask timerTask) { - int taskNumber = timerTask.getNumber(); - File taskSyncFile = new File(syncDataDirectory, taskNumber + JTIMER_TASK_EXTENSION); - parseFileSync(timerTask, taskSyncFile); - timerTask.getSubTasks().forEach(this::addTaskSync); - } - - protected void parseFileSync(TimerTask projectOrTask, File syncFile) { - if (syncFile.exists()) { - if (log.isDebugEnabled()) { - log.debug("Add sync for project " + projectOrTask.getName()); - } - - try (Reader parseIn = new BufferedReader(new FileReader(syncFile))) { - JsonParser parser = new JsonParser(); - Gson gson = new Gson(); - JsonElement element = parser.parse(parseIn); - JsonArray infoArray = (JsonArray) element; - for (JsonElement obj : infoArray) { - JsonObject res = (JsonObject) obj; - TimerSync sync = gson.fromJson(res, TimerSync.class); - projectOrTask.addSync(sync); - } - } catch (IOException ex) { - if (log.isErrorEnabled()) { - log.error("Can't parse sync file", ex); - } - } - } else if (log.isTraceEnabled()) { - log.trace("Sync not found for " + projectOrTask.getName()); - } - } - - protected void saveProjectSync(TimerProject timerProject) { - int projectNumber = timerProject.getNumber(); - File projectSyncFile = new File(syncDataDirectory, projectNumber + JTIMER_PROJECT_EXTENSION); - saveFileSync(timerProject, projectSyncFile); - } - - protected void saveTaskSync(TimerTask timerTask) { - int taskNumber = timerTask.getNumber(); - File taskSyncFile = new File(syncDataDirectory, taskNumber + JTIMER_TASK_EXTENSION); - saveFileSync(timerTask, taskSyncFile); - } - - protected void saveFileSync(TimerTask task, File taskSyncFile) { - - if (task.getSyncs() == null || task.getSyncs().isEmpty()) { - taskSyncFile.delete(); - - } else { - File backupfile = null; - - try (Writer out = new OutputStreamWriter(new FileOutputStream(taskSyncFile), "ISO-8859-1")) { - - // first make backup - backupfile = BackupUtils.makeBackupFile(taskSyncFile); - - //make a json object for the syncInfo - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - out.write(gson.toJson(task.getSyncs())); - - out.close(); - BackupUtils.deleteBackupFile(backupfile); - if (log.isDebugEnabled()) { - log.debug("Saving sync on task : " + task.getName()); - } - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.debug("Can't save task synchronization information", e); - } - - // can be null if backup throws the exception - if (backupfile != null) { - BackupUtils.restoreBackupFile(backupfile); - } - } - } - } - - @Override - public void postMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - otherTasks.forEach(task -> { - task.getSyncs().forEach(sync -> { - boolean urlExists = destinationTask.getSyncs().stream() - .anyMatch(timerSync -> timerSync.getUrl().equals(sync.getUrl())); - if (!urlExists) { - destinationTask.getSyncs().add(sync); - } - }); - }); - modifyTask(destinationTask); - } -} diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSynchronizer.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSynchronizer.java deleted file mode 100644 index e42f59c..0000000 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSynchronizer.java +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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.plugin.timebundle; - -import com.google.gson.JsonObject; -import org.apache.commons.lang3.time.DateUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerSync; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Collection; -import java.util.Date; -import java.util.Timer; -import java.util.TimerTask; - -/** - * Synchronizer background task. - */ -public class TimeBundleSynchronizer extends TimerTask implements DataEventListener { - - /** log */ - private static Log log = LogFactory.getLog(TimeBundleSynchronizer.class); - - /** timer to schedule syncs */ - protected Timer timer; - - protected Collection<TimerProject> projects; - - protected TimeBundleSaver saver; - - /** - * TimeBundleSynchronizer constructor - */ - public TimeBundleSynchronizer() { - log.info("Starting synchronizer"); - timer = new Timer(); - } - - @Override - public void dataLoaded(Collection<TimerProject> projects) { - this.projects = projects; - timer.schedule(this, 0, 60 * 60 * 1000); - } - - @Override - public void run() { - projects.forEach(this::synchronizerTask); - } - - protected void synchronizerTask(org.chorem.jtimer.entities.TimerTask timerTask) { - synchronizerProjectOrTask(timerTask); - timerTask.getSubTasks().forEach(this::synchronizerTask); - } - - protected void synchronizerProjectOrTask(org.chorem.jtimer.entities.TimerTask timerTask) { - timerTask.getSyncs().forEach(timerSync -> { - if (!DateUtils.isSameDay(new Date(), timerSync.getLastSync())) { - if (log.isDebugEnabled()) { - log.debug("Synchronizing task " + timerTask.getName() + "..."); - } - - JsonObject syncObject = TimeBundleHelper.taskToJsonObject(timerTask, timerSync); - boolean resultOk = synchronizeTaskOnURL(syncObject); - if (resultOk) { - timerSync.setLastSync(new Date()); - if (timerTask instanceof TimerProject) { - saver.modifyProject(TimerProject.class.cast(timerTask)); - } else { - saver.modifyTask(timerTask); - } - } - } - }); - } - - /** - * Sends one synchronization (one JSON object) - * @param object the object to sync - * @return an int (http response code or 0 in case of a problem) - */ - protected boolean synchronizeTaskOnURL(JsonObject object) { - boolean result = false; - // if it's an empty object, no synchronization is possible - if (!object.equals(new JsonObject())) { - String updateJsonString = object.toString(); - String syncURL = object.get("URL").getAsString(); - String charset = "UTF-8"; - HttpURLConnection connection; - URL url; - byte[] postDataBytes; - try { - url = new URL(syncURL); - connection = (HttpURLConnection) url.openConnection(); - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", Integer.toString(updateJsonString.length())); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setRequestMethod("POST"); - postDataBytes = updateJsonString.getBytes(charset); - connection.getOutputStream().write(postDataBytes); - int upDateValue = connection.getResponseCode(); - if (upDateValue >= 200 && upDateValue < 300) { - result = true; - } - } catch (IOException ex) { - if (log.isErrorEnabled()) { - log.error("Problem with the connection " + syncURL, ex); - } - } - } - return result; - } - - /** - * When tasktime is modified, if it's before the last sync, - * the task is synchronized - */ - @Override - public void setTaskTime(org.chorem.jtimer.entities.TimerTask task, Date date, Long time) { - //check if it isn't the current day, to avoid sync every second - if (!DateUtils.isSameDay(new Date(), date)) { - if (!task.getSyncs().isEmpty()) { - for (TimerSync timerSync : task.getSyncs()) { - if (!DateUtils.isSameDay(date, timerSync.getLastSync())) { - timerSync.setLastSync(date); - } - } - } - - if (task.getParent() != null) { - setTaskTime(task.getParent(), date, time); - } - } - } - - /** - * Set saver. - * @param saver - * @deprecated since 1.5.1 this is ugly, need a proper centralized way to save a task modified by current class - */ - @Deprecated - public void setSaver(TimeBundleSaver saver) { - this.saver = saver; - } -} diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java deleted file mode 100644 index b911ed8..0000000 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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.plugin.timebundle; - -import org.chorem.jtimer.data.DataViolationException; -import org.chorem.jtimer.data.VetoableDataEventListener; -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerTask; - -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Vetoable for forbidden action on synchronized tasks. - */ -public class TimeBundleVetoable implements VetoableDataEventListener { - - /** - * Merge project violation key. - */ - protected static final String INVALID_SYNC_LIST_VIOLATION = "vetoable.timebundle.invalid.sync.list"; - - @Override - public void checkMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - Set<String> allUrls = otherTasks.stream() - .flatMap(t -> t.getSyncs().stream()) - .map(TimerSync::getUrl) - .collect(Collectors.toSet()); - Set<String> destUrls = destinationTask.getSyncs().stream() - .map(TimerSync::getUrl) - .collect(Collectors.toSet()); - if (!allUrls.equals(destUrls)) { - throw new DataViolationException("Can't merge tasks", INVALID_SYNC_LIST_VIOLATION); - } - } -} diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncCellRenderer.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncCellRenderer.java deleted file mode 100644 index a9e124c..0000000 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncCellRenderer.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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.plugin.timebundle; - -import javax.swing.table.DefaultTableCellRenderer; -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * Renderer for last sync date column. - */ -public class TimerSyncCellRenderer extends DefaultTableCellRenderer { - - private Date dateValue; - private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); - private String valueToString = ""; - - @Override - public void setValue(Object value) { - if ((value != null)) { - dateValue = (Date) value; - valueToString = dateFormat.format(dateValue); - value = valueToString; - super.setValue(value); - } - } -} diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java deleted file mode 100644 index 5740577..0000000 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java +++ /dev/null @@ -1,245 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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.plugin.timebundle; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerTask; -import org.jdesktop.application.Application; -import org.jdesktop.application.FrameView; - -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.table.TableColumnModel; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** - * UI to modify Synchronization Info of a task. - */ -public class TimerSyncEditor extends FrameView implements ActionListener { - - /** - * Class logger - */ - protected static Log log = LogFactory.getLog(TimerSyncEditor.class); - - /** - * Timer core. - */ - protected TimerCore core; - - /** - * button to add a URL - */ - protected JButton addButton; - - /** - * button to delete a URL - */ - protected JButton deleteButton; - - /** - * button to test a url - */ - protected JButton testSyncUrlButton; - - /** - * JTable of URLs - */ - protected JTable urlJTable; - - /** - * task to update - */ - protected TimerTask task; - - /** - * timezone - */ - protected String timezone; - - /** - * UpdaterView constructor. - * - * @param application parent reference - * @param core core reference - * @param task the task to update - */ - public TimerSyncEditor(Application application, TimerCore core, TimerTask task) { - - super(application); - // modify frame name - getFrame().setName("syncFrame"); - getFrame().setTitle(getResourceMap().getString("syncTitle")); - - this.core = core; - this.task = task; - timezone = "+01:00"; - - setComponent(getMainComponent()); - } - - /** - * Get main view component. - * - * @return main component - */ - protected JComponent getMainComponent() { - - JPanel configComponent = new JPanel(); - configComponent.setLayout(new BorderLayout(5, 5)); - - JPanel urlPanel = new JPanel(); - urlPanel.setLayout(new BorderLayout(5, 5)); - - urlJTable = new JTable(new TimerSyncTableModel(this, task)); - //try to have coherent width of columns - TableColumnModel tableColModel = urlJTable.getColumnModel(); - tableColModel.getColumn(0).setPreferredWidth(200); - tableColModel.getColumn(1).setPreferredWidth(40); - tableColModel.getColumn(2).setPreferredWidth(60); - tableColModel.getColumn(3).setPreferredWidth(200); - - //render the date properly - tableColModel.getColumn(3).setCellRenderer(new TimerSyncCellRenderer()); - - JScrollPane scrollTablePane = new JScrollPane(urlJTable); - configComponent.add(scrollTablePane, BorderLayout.CENTER); - - //panel to hold the buttons - JPanel buttonsPane = new JPanel(new BorderLayout()); - JPanel buttonPane = new JPanel(); - buttonPane.setAlignmentX(Component.CENTER_ALIGNMENT); - - addButton = new JButton(getResourceMap().getString("addButton")); - addButton.addActionListener(this); - addButton.setActionCommand("addURL"); - - deleteButton = new JButton(getResourceMap().getString("deleteButton")); - deleteButton.addActionListener(this); - deleteButton.setActionCommand("deleteURL"); - - testSyncUrlButton = new JButton(getResourceMap().getString("testSyncButton")); - testSyncUrlButton.addActionListener(this); - testSyncUrlButton.setActionCommand("testURL"); - - buttonPane.add(addButton); - buttonPane.add(testSyncUrlButton); - buttonPane.add(deleteButton); - // button to close - JButton closeButton = new JButton(); - closeButton.setAction(getContext().getActionMap(this).get("closeView")); - - //adding components to the main one - buttonsPane.add(buttonPane, BorderLayout.CENTER); - buttonsPane.add(closeButton, BorderLayout.SOUTH); - configComponent.add(buttonsPane, BorderLayout.SOUTH); - - // color fix on linux ? - configComponent.setBackground(urlPanel.getBackground()); - // set minimum size to prevent "packed size" (too big) - configComponent.setMinimumSize(new Dimension(200, 200)); - - return configComponent; - } - - /** - * Close action. - */ - @org.jdesktop.application.Action - public void closeView() { - TimerSyncTableModel model = (TimerSyncTableModel) urlJTable.getModel(); - task.setSyncs(model.getTimerSyncList()); - if (task instanceof TimerProject) { - core.getData().modifyProject(TimerProject.class.cast(task)); - } else { - core.getData().modifyTask(task); - } - getApplication().hide(this); - } - - /** - * Method to display an error message - * - * @param errorMessage the message to display - * @param titleBar the title of the frame - */ - public static void errorBox(String errorMessage, String titleBar) { - JOptionPane.showMessageDialog(null, errorMessage, titleBar, JOptionPane.ERROR_MESSAGE); - } - - /** - * Method to display an info message - * - * @param infoMessage the message to display - * @param titleBar the title of the frame - */ - public static void infoBox(String infoMessage, String titleBar) { - JOptionPane.showMessageDialog(null, infoMessage, titleBar, JOptionPane.INFORMATION_MESSAGE); - } - - @Override - public void actionPerformed(ActionEvent actionEvent) { - - String actionCommand = actionEvent.getActionCommand(); - TimerSyncTableModel model = (TimerSyncTableModel) urlJTable.getModel(); - - if ("addURL".equals(actionCommand)) { - model.add(new TimerSync("")); - } else if ("deleteURL".equals(actionCommand)) { - TimerSync timerSync = model.getValueAt(urlJTable.getSelectedRow()); - model.remove(timerSync); - } - /*else if ("testURL".equals(actionCommand)) { - //if the test button has been clicked, test the sync on the URL and returns a message to the user - //tests only if the info exists - if (task.getSynchronizingInfoList().contains(infoToUse)) { - JsonObject testObject = TimerTaskHelper.taskToJsonObject(task, infoToUse, timezone); - int responseCode = TimerTaskSynchronizer.synchronizeTaskOnURL(testObject); - - if (responseCode > 199 && responseCode < 300) { - infoBox(getResourceMap().getString("testSyncSuccessMessage"), getResourceMap().getString("testSyncSuccessTitle")); - Calendar cal = Calendar.getInstance(); - infoToUse.setLastSync(cal.getTime()); - core.getData().syncInfoChanged(task, infoToUse); - } else { - errorBox(getResourceMap().getString("testSyncFailureMessage"), getResourceMap().getString("testSyncFailureTitle")); - } - - if (log.isDebugEnabled()) { - log.debug("Response code : " + responseCode); - } - } - } */ - } -} diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java deleted file mode 100644 index d38f80a..0000000 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java +++ /dev/null @@ -1,203 +0,0 @@ -/*- - * #%L - * jTimer - * %% - * Copyright (C) 2016 CodeLutin, Charlène Servantie - * %% - * 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.plugin.timebundle; - -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerTask; -import org.jdesktop.application.View; - -import javax.swing.table.AbstractTableModel; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * Class to deal with the syncs in a table. - */ -public class TimerSyncTableModel extends AbstractTableModel { - - /** the syncInfo list. */ - protected List<TimerSync> timerSyncList; - - /** headers of the columns. */ - protected String[] columnHeaders; - - public TimerSyncTableModel(View view, TimerTask task) { - timerSyncList = new ArrayList<>(task.getSyncs()); - columnHeaders = new String[]{ - view.getResourceMap().getString("syncURLHeader"), - view.getResourceMap().getString("activeHeader"), - view.getResourceMap().getString("withAnnotationsHeader"), - view.getResourceMap().getString("lastSyncHeader") - }; - } - - /** - * Gets the column headers - * - * @param col the column - * @return a string for the header - */ - @Override - public String getColumnName(int col) { - return columnHeaders[col]; - } - - - @Override - public int getRowCount() { - return timerSyncList.size(); - } - - /** - * returns the column number (url, activity, annotations and last sync, so 4) - */ - @Override - public int getColumnCount() { - return columnHeaders.length; - } - - /** - * Returns the value at rowIndex, columnIndex - * column 0 is url String, column 1 is activity boolean, - * column 2 is annotations boolean, column 3 is lastSync Date - * - * @param rowIndex - * @param columnIndex - * @return an Object - */ - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - Object value = ""; - TimerSync timerSync = timerSyncList.get(rowIndex); - switch (columnIndex) { - case 0: - value = timerSync.getUrl(); - break; - case 1: - value = timerSync.isActive(); - break; - case 2: - value = timerSync.isWithAnnotations(); - break; - case 3: - value = timerSync.getLastSync(); - break; - } - return value; - } - - /** - * When the data is changed - * - * @param value an object -a string- - * @param rowIndex the row selected - * @param columnIndex the column modified - */ - @Override - public void setValueAt(Object value, int rowIndex, int columnIndex) { - TimerSync timerSync = timerSyncList.get(rowIndex); - // if the url changes - switch (columnIndex) { - case 0: - timerSync.setUrl((String) value); - break; - case 1: - timerSync.setActive((Boolean) value); - break; - case 2: - timerSync.setWithAnnotations((Boolean) value); - break; - } - } - - /** - * To mark the url and checkbox cells as editable but not the date - * - * @param rowIndex - * @param columnIndex - * @return - */ - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - // the sync date is not editable - return columnIndex < 3; - } - - /** - * Returns the class of objects in the columns - * - * @param columnIndex - * @return the class - */ - - @Override - public Class<?> getColumnClass(int columnIndex) { - Class<?> result; - switch (columnIndex) { - case 0: - result = String.class; - break; - case 1: - case 2: - result = Boolean.class; - break; - case 3: - result = Date.class; - break; - default: - result = Object.class; - break; - } - - return result; - } - - /** - * Adds a syncInfo - * - * @param sync - */ - public void add(TimerSync sync) { - timerSyncList.add(sync); - fireTableRowsInserted(timerSyncList.indexOf(sync), timerSyncList.indexOf(sync)); - } - - /** - * removes a syncInfo - * - * @param sync - */ - public void remove(TimerSync sync) { - int index = timerSyncList.indexOf(sync); - timerSyncList.remove(sync); - fireTableRowsDeleted(index, index); - } - - public TimerSync getValueAt(int selectedRow) { - return timerSyncList.get(selectedRow); - } - - public List<TimerSync> getTimerSyncList() { - return timerSyncList; - } -} diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 1f9a53b..2b970c9 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -3,7 +3,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 @@ -30,7 +30,6 @@ <Loggers> <Logger name="org.chorem.jtimer" level="info"/> - <Logger name="org.chorem.jtimer.plugin.timebundle" level="debug"/> <Root level="warn"> <AppenderRef ref="Console"/> diff --git a/src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor.properties b/src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor.properties deleted file mode 100644 index 48ae0cc..0000000 --- a/src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor.properties +++ /dev/null @@ -1,46 +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% -### -syncTitle=${Application.title} - Edition of Synchronization Info - -updateAnnotations.Action.text = Include annotations -updateAnnotations.Action.shortDescription = Include annotations - -closeView.Action.text = &Close -closeView.Action.icon = dialog-close.png -closeView.Action.shortDescription = Close - -deleteButton = Delete URL -deleteErrorMessage = No URL to delete -deleteErrorTitle = Deletion error - -addButton = Add URL - -testSyncButton = Test URL -testSyncSuccessMessage = Synchronization test successful ! -testSyncSuccessTitle = Successful test -testSyncFailureMessage = Test failed to synchronize, check the URL ? -testSyncFailureTitle = Synchronization test failure - -syncURLHeader = URL -activeHeader = is Active -withAnnotationsHeader = Annotations -lastSyncHeader = Last Synchronization \ No newline at end of file diff --git a/src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor_fr.properties b/src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor_fr.properties deleted file mode 100644 index 906ecf8..0000000 --- a/src/main/resources/org/chorem/jtimer/plugin/timebundle/resources/TimerSyncEditor_fr.properties +++ /dev/null @@ -1,47 +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% -### -# update i18n -syncTitle=${Application.title} - Edition de la Synchronisation - - -closeView.Action.text = &Fermer -closeView.Action.icon = dialog-close.png -closeView.Action.shortDescription = Fermer - -deleteButton = Supprimer l'URL -deleteErrorMessage = Aucune URL \u00E0 supprimer -deleteErrorTitle = Erreur de suppression - -addButton = Ajouter une URL - -testSyncButton = Tester l'URL -testSyncSuccessMessage = Test r\u00E9ussi, URL de synchronisation valide ! -testSyncSuccessTitle = Test r\u00E9ussi -testSyncFailureMessage = Test \u00E9chou\u00E9, v\u00E9rifier l'URL ? -testSyncFailureTitle = Echec du test de synchronisation - -active.Action.text = Synchronisation Active - -syncURLHeader = URL -isActiveHeader = Active -isWithAnnotationsHeader = Annotations -lastSyncHeader = Derni\u00E8re synchronisation \ No newline at end of file diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties index 9441720..4d92c8e 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties @@ -62,10 +62,6 @@ editTask.Action.text = &Edit Task editTask.Action.accelerator = F2 editTask.Action.shortDescription = Edit task -editSync.Action.text = &Edit Synchronization -editSync.Action.accelerator = F5 -editSync.Action.shortDescription = Edit Synchronization - closeTask.Action.text = &Open/Close Task closeTask.Action.accelerator = control O closeTask.Action.shortDescription = Open or close task @@ -186,7 +182,6 @@ vetoable.common.merge.invalid.types=Can't merge project and task ! vetoable.common.move.invalid.types=Can't move project ! vetoable.saver.empty.name=Empty task name ! vetoable.saver.invalid.characters=Task name contains invalid characters ! -vetoable.timebundle.invalid.sync.list=Can't merge tasks with non matching sync urls ! # Start fail i18n startFail.title=Error diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties index 938eb07..e4563ca 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties @@ -41,9 +41,6 @@ newTask.Action.shortDescription = Cr\u00E9ation d'une nouvelle t\u00E2che editTask.Action.text = \u00C9dition de la t\u00E2ch&e editTask.Action.shortDescription = \u00C9dition de la t\u00E2che -editSync.Action.text = &\u00C9dition de la synchronisation -editSync.Action.shortDescription = Edition de la synchronisation - closeTask.Action.text = &Ouvrir/Fermer la t\u00E2che closeTask.Action.shortDescription = Ouvrir ou fermer la t\u00E2che @@ -150,7 +147,6 @@ vetoable.common.merge.invalid.types=Impossible de fusionner un projet et une t\u vetoable.common.move.invalid.types=Impossible de d\u00E9placer un projet ! vetoable.saver.empty.name=Le nom est vide ! vetoable.saver.invalid.characters=Le nom contient des caract\u00E8res invalide ! -vetoable.timebundle.invalid.sync.list=Impossible de fusionner des t\u00E2ches n'ayant pas les m\u00EAmes adresses de synchronisation ! # Start fail i18n startFail.title=Erreur diff --git a/src/site/rst/timebundle.rst b/src/site/rst/timebundle.rst deleted file mode 100644 index 386d032..0000000 --- a/src/site/rst/timebundle.rst +++ /dev/null @@ -1,30 +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% -.. - - -Time bundle -=========== - -Synchronization with time bundle is currently under developpement and disabled by default. - -To enable it, modify configuration with following line:: - - jtimer.io.synchronizer.class=org.chorem.jtimer.plugin.timebundle.TimeBundleSynchronizer diff --git a/src/site/site.xml b/src/site/site.xml index 3dd5e3e..245a748 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -80,7 +80,6 @@ <item name="Swing framework" href="devel/saf.html"/> <item name="File format" href="devel/fileformat.html"/> </item> - <item name="Time bundle" href="timebundle.html"/> </menu> <menu ref="reports"/> diff --git a/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java b/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java index c731bc7..5e56ded 100644 --- a/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java +++ b/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java @@ -105,8 +105,6 @@ public abstract class AbstractJTimerTest { // copy .svn folders FileUtils.copyDirectory(new File("src/test/resources/testdata"), new File(testDataDirectory, "data"), HiddenFileFilter.VISIBLE); - FileUtils.copyDirectory(new File("src/test/resources/testsync"), - new File(testDataDirectory, "timebundle"), HiddenFileFilter.VISIBLE); // force null, to force new instance JTimerFactory.saver = null; diff --git a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java b/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java deleted file mode 100644 index 5fcbe84..0000000 --- a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java +++ /dev/null @@ -1,87 +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.plugin.timebundle; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.apache.commons.lang3.time.DateFormatUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerTask; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.Calendar; -import java.util.Date; - -/** - * Test related to TimeBundleHelper. - */ -public class TimeBundleHelperTest extends AbstractJTimerTest { - - /** - * Test json production - */ - @Test - public void taskToJSONFormatTest() { - TimerTask task = new TimerTask(); - task.setNumber(42); - task.setName("JsonBuilder Test"); - TimerSync sync = new TimerSync("http://localhost:3000"); - task.addSync(sync); - //set the creation date at same date as first timing date (to fit test object) - task.setCreationDate(new Date(1451602800000L)); - sync.setLastSync(new Date(1451602800000L)); - //date : 2016-01-18 - task.setTime(new Date(1453071600000L), 452000L); - //date : 2016-05-12 - task.setTime(new Date(1463004000000L), 4533000L); - - - //create json object - JsonObject objectToHave = new JsonObject(); - JsonArray periodArray = new JsonArray(); - JsonObject periodElement1 = new JsonObject(); - periodElement1.addProperty("id", "2016-01-18_42"); - periodElement1.addProperty("startDate", "2016-01-18T00:00:00+01:00"); - periodElement1.addProperty("duration", 452); - periodArray.add(periodElement1); - JsonObject periodElement2 = new JsonObject(); - periodElement2.addProperty("id", "2016-05-12_42"); - periodElement2.addProperty("startDate", "2016-05-12T00:00:00+02:00"); - periodElement2.addProperty("duration", 4533); - periodArray.add(periodElement2); - - objectToHave.addProperty("URL", "http://localhost:3000"); - objectToHave.addProperty("startDate", "2016-01-01T00:00:00+01:00"); - Date endDate = DateUtils.ceiling(new Date(), Calendar.DAY_OF_MONTH); - String endPeriodString = DateFormatUtils.format(endDate, TimeBundleHelper.DATE_MIDNIGHT_PATTERN); - - objectToHave.addProperty("endDate", endPeriodString); - objectToHave.add("periods", periodArray); - - //make a list of json objects from the task - JsonObject jsonObject = TimeBundleHelper.taskToJsonObject(task, sync); - Assert.assertEquals(jsonObject, objectToHave); - } -} diff --git a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaverTest.java b/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaverTest.java deleted file mode 100644 index 06708ec..0000000 --- a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaverTest.java +++ /dev/null @@ -1,66 +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.plugin.timebundle; - -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.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.util.Collections; - -/** - * Test class for TimeBundleSaver. - */ -public class TimeBundleSaverTest extends AbstractJTimerTest { - - protected TimeBundleSaver saver; - - @BeforeMethod - @Override - public void beforeTest() throws IOException { - super.beforeTest(); - saver = new TimeBundleSaver(); - } - - /** - * Test that synchronization Info is properly parsed - * @throws IOException - */ - @Test - public void parseSyncInfoTest() throws IOException { - - TimerTask task = new TimerTask(); - task.setNumber(41); - TimerProject project = new TimerProject(); - project.setNumber(1); - project.addTask(task); - saver.dataLoaded(Collections.singletonList(project)); - - Assert.assertNotNull(task.getSyncs()); - Assert.assertEquals(task.getSyncs().get(0).getUrl(), "http://localhost:3000"); - - } -} -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm