branch feature/sync updated (4c3886a -> 81724c1)
This is an automated email from the git hooks/post-receive script. New change to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git from 4c3886a display of lastSync new c0ee777 clean up empty methods that were not necessary new 7d0b936 documentation new 81f6802 added a boolean to track syncAtStartUp needed new a6cf316 added a yaml object to save syncInfos new 702848b changed the syncatstartup boolean to be in the SyncInfo and not in the Task new 81724c1 save of syncInfo with json instead of yaml (+ tests adapted) The 6 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 81724c16cfc5a7d15bd6283d96fa0aac9dce176f Author: servantie <servantie.c@gmail.com> Date: Tue Jul 12 14:07:47 2016 +0200 save of syncInfo with json instead of yaml (+ tests adapted) corrected some mistakes (not listening to the checkboxes properly, information wasn't saved unless some other change was made) commit 702848b51ef0a38618eaee2a49ce893f6d5c8e0e Author: servantie <servantie.c@gmail.com> Date: Mon Jul 11 12:04:33 2016 +0200 changed the syncatstartup boolean to be in the SyncInfo and not in the Task commit a6cf316d920379d6d3d2027c23d008f73b1ebb16 Author: servantie <servantie.c@gmail.com> Date: Mon Jul 11 11:14:08 2016 +0200 added a yaml object to save syncInfos commit 81f68029dfa606e0e0fd7c715cb4f7eca6bc7708 Author: servantie <servantie.c@gmail.com> Date: Fri Jul 8 11:55:11 2016 +0200 added a boolean to track syncAtStartUp needed commit 7d0b9363ca46e955fae4f4523e8b8a5ff81a7a7b Author: servantie <servantie.c@gmail.com> Date: Fri Jul 8 10:21:29 2016 +0200 documentation commit c0ee777e7d3a9508ca886b1f5afb3d630abcfc7a Author: servantie <servantie.c@gmail.com> Date: Fri Jul 8 09:51:18 2016 +0200 clean up empty methods that were not necessary Summary of changes: .../org/chorem/jtimer/data/CommonVetoable.java | 8 - .../org/chorem/jtimer/data/DataEventListener.java | 17 +- .../java/org/chorem/jtimer/data/TimerCore.java | 26 +++ .../org/chorem/jtimer/data/TimerDataManager.java | 27 ++- .../jtimer/data/VetoableDataEventListener.java | 9 - .../java/org/chorem/jtimer/entities/SyncInfo.java | 18 ++ .../java/org/chorem/jtimer/entities/TimerTask.java | 32 +++- .../chorem/jtimer/entities/TimerTaskHelper.java | 26 ++- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 75 +++++--- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 188 +++++++++------------ src/main/java/org/chorem/jtimer/ui/StatusBar.java | 3 - .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 17 +- .../jtimer/entities/TimerTaskHelperTest.java | 8 +- .../jtimer/io/GTimerIncrementalSaverTest.java | 3 +- src/test/resources/testdata/41.task.sync | 15 +- 15 files changed, 295 insertions(+), 177 deletions(-) -- 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 feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit c0ee777e7d3a9508ca886b1f5afb3d630abcfc7a Author: servantie <servantie.c@gmail.com> Date: Fri Jul 8 09:51:18 2016 +0200 clean up empty methods that were not necessary --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 71 +++------------------- 1 file changed, 8 insertions(+), 63 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index a06519a..6643199 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -1,6 +1,13 @@ package org.chorem.jtimer.io; import com.google.gson.JsonObject; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -12,18 +19,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.entities.SyncInfo; -import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.ProtocolException; -import java.net.URL; -import java.time.LocalDateTime; - /** * * Class dealing with automated synchronization of tasks @@ -197,20 +195,6 @@ public class TimerTaskSynchronizer implements DataEventListener { return upDateValue; } - @Override - public void addProject(TimerProject project) { - - } - - @Override - public void addTask(TimerTask task) { - } - - @Override - public void modifyProject(TimerProject project) { - - } - /** * Tasks are added to synchronization list when modified * @param task modified task @@ -226,10 +210,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } } - @Override - public void deleteProject(TimerProject project) { - - } /** * Tasks deleted are modified from synchronization list if they exist in it * @param task modified task @@ -241,11 +221,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } } - @Override - public void setAnnotation(TimerTask task, Date date, String annotation) { - - } - /** * When the time is modified, the task is added to the sync list * @param task task where time is changed @@ -262,36 +237,10 @@ public class TimerTaskSynchronizer implements DataEventListener { } } - @Override - public void changeClosedState(TimerTask task) { - - } - - @Override - public void preMoveTask(TimerTask task) { - - } - - @Override - public void moveTask(TimerTask task) { - - } - - @Override - public void preMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - - } - - @Override - public void postMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - - } - /** * Tasks are added to synchronization list when started * @param task started task */ - @Override public void startTask(TimerTask task) { if (!tasksToSync.contains(task)) { @@ -301,6 +250,7 @@ public class TimerTaskSynchronizer implements DataEventListener { } } } + /** * Tasks are added to synchronization list when stopped * @param task modified task @@ -315,11 +265,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } } - @Override - public void dataLoaded(Collection<TimerProject> projects) { - - } - /** * When the syncInfo is changed, add the task to sync list * @param task the task to sync -- 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 feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 7d0b9363ca46e955fae4f4523e8b8a5ff81a7a7b Author: servantie <servantie.c@gmail.com> Date: Fri Jul 8 10:21:29 2016 +0200 documentation --- src/main/java/org/chorem/jtimer/data/DataEventListener.java | 4 +++- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 8 ++++++++ src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index ea7d9e9..d62232d 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -193,7 +193,7 @@ public interface DataEventListener extends EventListener { /** * SyncInfo changed * @param task - * @param syncURL String + * @param syncURL SyncInfo */ default void changeSyncInfo(TimerTask task, SyncInfo syncURL) { @@ -201,6 +201,8 @@ public interface DataEventListener extends EventListener { /** * SyncInfo deleted + * @param task + * @param syncURL SyncInfo */ default void deleteSyncInfo(TimerTask task, SyncInfo syncURL) { diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index e893536..ca58c40 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -383,6 +383,14 @@ public class TimerTaskHelper { /** * Makes only one object for a task associated to a URL + * @param task : the task to sync + * @param url : the url to sync to + * @param startDate : the start of the period to sync + * @param endDate : the end of the period to sync + * @param withAnnotations : if true add annotations to sync + * @param timezone : the timezone + * + * @return JSonObject : the object to send */ public static JsonObject taskURLToJSONObject(TimerTask task, String url, Date startDate, Date endDate, boolean withAnnotations, String timezone) { JsonObject resultingObject = new JsonObject(); diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 6643199..b18b6d1 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -53,8 +53,8 @@ public class TimerTaskSynchronizer implements DataEventListener { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); log.info("Starting synchronizing thread"); - tasksToSync = Collections.synchronizedCollection(new ArrayList<>()); + } /** -- 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 feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 81f68029dfa606e0e0fd7c715cb4f7eca6bc7708 Author: servantie <servantie.c@gmail.com> Date: Fri Jul 8 11:55:11 2016 +0200 added a boolean to track syncAtStartUp needed --- .../org/chorem/jtimer/data/DataEventListener.java | 14 +++++++--- .../java/org/chorem/jtimer/data/TimerCore.java | 24 +++++++++++++++++ .../org/chorem/jtimer/data/TimerDataManager.java | 15 +++++++++++ .../java/org/chorem/jtimer/entities/TimerTask.java | 17 ++++++++++++ .../chorem/jtimer/io/GTimerIncrementalSaver.java | 30 +++++++++++++++++++--- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 15 +++++++++++ .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 6 ++++- 7 files changed, 113 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index d62232d..1e6dd80 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -193,18 +193,24 @@ public interface DataEventListener extends EventListener { /** * SyncInfo changed * @param task - * @param syncURL SyncInfo + * @param syncInfo SyncInfo */ - default void changeSyncInfo(TimerTask task, SyncInfo syncURL) { + default void changeSyncInfo(TimerTask task, SyncInfo syncInfo) { } /** * SyncInfo deleted * @param task - * @param syncURL SyncInfo + * @param syncInfo SyncInfo */ - default void deleteSyncInfo(TimerTask task, SyncInfo syncURL) { + default void deleteSyncInfo(TimerTask task, SyncInfo syncInfo) { + } + /** + * Task synchronized + * @param task + */ + default void synchronizeTask(TimerTask task, SyncInfo syncInfo) { } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index d29448b..286a440 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; import org.chorem.jtimer.JTimerFactory; import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.io.DataLockingException; import org.chorem.jtimer.io.Saver; import org.chorem.jtimer.io.TimerTaskSynchronizer; @@ -151,6 +152,8 @@ public class TimerCore { saver.lock(); load(); + // add the tasks that haven't been synced before to the synchronizer + addTasksToSync(); initSucceded = true; } catch (DataLockingException e) { @@ -192,6 +195,27 @@ public class TimerCore { } /** + * Add tasks that haven't been synchronized at + * the last exit to the synchronizer tasks + */ + + protected void addTasksToSync() { + log.info("adding tasks to sync"); + if (log.isDebugEnabled()) { + log.debug("Adding tasks that were not synchronized at last jTimer exit"); + } + + for (TimerTask task : data.getProjectsList()) { + if (!(task instanceof TimerProject)) { + if (task.getIsSyncAtStartUp()) { + synchronizer.addTask(task); + } + } + } + + } + + /** * Save. */ public void exit() { diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index 529a349..a740763 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -671,4 +671,19 @@ public class TimerDataManager { log.debug("SyncInfo deleted: " + info.getSyncURL()); } } + + /** + * When a task is synced + * @param task + */ + public void synchronizeTask(TimerTask task, SyncInfo syncInfo) { + task.setSyncAtStartUp(false); + + for (DataEventListener dataEventListener: dataEventListeners) { + dataEventListener.synchronizeTask(task, syncInfo); + } + if (log.isDebugEnabled()) { + log.debug("Task " + task.getName() + " synced at " + syncInfo.getSyncURL()); + } + } } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 79a90c0..a1d3707 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -94,6 +94,11 @@ public class TimerTask implements Cloneable, protected List<SyncInfo> synchronisingInfoList; /** + * Boolean to keep track of tasks not synced before jtimer exit + */ + protected boolean syncAtStartUp; + + /** * Constructor. */ public TimerTask() { @@ -376,6 +381,18 @@ public class TimerTask implements Cloneable, } /** + * Sets the sync at startup + * @param syncAtStart boolean + */ + public void setSyncAtStartUp(boolean syncAtStart) { this.syncAtStartUp = syncAtStart;} + + /** + * Get the sync at startup + * @return boolean + */ + public boolean getIsSyncAtStartUp() { return this.syncAtStartUp;} + + /** * Add task's subtask. * * Also add parent reference. diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 1db7f70..6862da3 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -604,6 +604,16 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } try (BufferedReader parseIn = new BufferedReader(new FileReader(syncTaskFile))) { + //get first line to know if the tasks has to be synced at the start + String first_line = parseIn.readLine().trim(); + if ("SyncAtStartUp : true".equals(first_line)) { + task.setSyncAtStartUp(true); + } + else { + task.setSyncAtStartUp(false); + } + log.info(task.getName() + " " + first_line); + Yaml yaml = new Yaml(); for (Object obj : yaml.loadAll(parseIn)) { if (obj instanceof SyncInfo) { @@ -1117,7 +1127,13 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // first make backup backupfile = makeBackupFile(synchronizationTaskFile); - + //add on first line if sync at startup is needed + if (task.getIsSyncAtStartUp()) { + out.write("SyncAtStartUp : true\n"); + } + else { + out.write("SyncAtStartUp : false\n"); + } //use Yaml to write it with pretty flow to make it easier to read DumperOptions dumper = new DumperOptions(); dumper.setPrettyFlow(true); @@ -1487,10 +1503,18 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, /** when a syncInfo is deleted make a save * * @param task - * @param url + * @param info + */ + @Override + public void deleteSyncInfo(TimerTask task, SyncInfo info) { + saveSynchronizationInfo(task); + } + + /** + * When a task is synced */ @Override - public void deleteSyncInfo(TimerTask task, SyncInfo url) { + public void synchronizeTask(TimerTask task, SyncInfo info) { saveSynchronizationInfo(task); } diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index b18b6d1..bcafa6d 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -141,6 +141,8 @@ public class TimerTaskSynchronizer implements DataEventListener { } Calendar cal = Calendar.getInstance(); task.setLastSync(cal.getTime(), syncURL); + //it doesn't have to be synced at startup sync it succeeded + task.setSyncAtStartUp(false); } } } @@ -206,6 +208,7 @@ public class TimerTaskSynchronizer implements DataEventListener { //add it only if the URL is not empty if ((!task.getSynchronizingInfoList().isEmpty()) && (!task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); + task.setSyncAtStartUp(true); } } } @@ -233,6 +236,7 @@ public class TimerTaskSynchronizer implements DataEventListener { //add it only if the URL is not empty if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); + task.setSyncAtStartUp(true); } } } @@ -247,6 +251,7 @@ public class TimerTaskSynchronizer implements DataEventListener { //add it only if the URL is not empty if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); + task.setSyncAtStartUp(true); } } } @@ -279,4 +284,14 @@ public class TimerTaskSynchronizer implements DataEventListener { } } } + + /** + * When the synchronization happens, set the syncAt Startup to false + * @param task the task that was synchronized + * @param info SyncInfo + */ + @Override + public void synchronizeTask(TimerTask task, SyncInfo info) { + task.setSyncAtStartUp(false); + } } diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java index c75664b..6133a76 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -305,6 +305,10 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener } + /** + * deals with item selection in the combobox + * @param itemEvent + */ @Override public void itemStateChanged(ItemEvent itemEvent) { if (itemEvent.getStateChange()== ItemEvent.SELECTED) { @@ -392,7 +396,7 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener infoBox(getResourceMap().getString("testSyncSuccessMessage"), getResourceMap().getString("testSyncSuccessTitle")); Calendar cal = Calendar.getInstance(); infoToUse.setLastSync(cal.getTime()); - core.getData().changeSyncInfo(task, infoToUse); + core.getData().synchronizeTask(task, infoToUse); } else { errorBox(getResourceMap().getString("testSyncFailureMessage"), getResourceMap().getString("testSyncFailureTitle")); -- 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 feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit a6cf316d920379d6d3d2027c23d008f73b1ebb16 Author: servantie <servantie.c@gmail.com> Date: Mon Jul 11 11:14:08 2016 +0200 added a yaml object to save syncInfos --- .../org/chorem/jtimer/data/DataEventListener.java | 13 ++-- .../java/org/chorem/jtimer/data/TimerCore.java | 22 +++--- .../org/chorem/jtimer/data/TimerDataManager.java | 13 ++-- .../chorem/jtimer/entities/TimerTaskHelper.java | 18 +++-- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 26 +++++-- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 91 ++++++++++++---------- .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 4 +- 7 files changed, 107 insertions(+), 80 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index 1e6dd80..0c42b9f 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -192,25 +192,26 @@ public interface DataEventListener extends EventListener { } /** * SyncInfo changed - * @param task + * @param task TimerTask * @param syncInfo SyncInfo */ - default void changeSyncInfo(TimerTask task, SyncInfo syncInfo) { + default void syncInfoChanged(TimerTask task, SyncInfo syncInfo) { } /** * SyncInfo deleted - * @param task + * @param task TimerTask * @param syncInfo SyncInfo */ - default void deleteSyncInfo(TimerTask task, SyncInfo syncInfo) { + default void syncInfoDeleted(TimerTask task, SyncInfo syncInfo) { } /** * Task synchronized - * @param task + * @param task TimerTask + * @param syncInfo SyncInfo */ - default void synchronizeTask(TimerTask task, SyncInfo syncInfo) { + default void taskSynchronized(TimerTask task, SyncInfo syncInfo) { } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index 286a440..fd2ea8f 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -152,8 +152,6 @@ public class TimerCore { saver.lock(); load(); - // add the tasks that haven't been synced before to the synchronizer - addTasksToSync(); initSucceded = true; } catch (DataLockingException e) { @@ -192,27 +190,29 @@ public class TimerCore { Collections.sort(projectsList); data.addAllProjects(projectsList); + + + // add the tasks that haven't been synced before to the synchronizer + for (TimerTask project : data.getProjectsList()) { + project.getSubTasks().forEach(this::addTaskToSync); + } } + /** * Add tasks that haven't been synchronized at * the last exit to the synchronizer tasks */ - protected void addTasksToSync() { - log.info("adding tasks to sync"); + protected void addTaskToSync(TimerTask task) { if (log.isDebugEnabled()) { log.debug("Adding tasks that were not synchronized at last jTimer exit"); } - for (TimerTask task : data.getProjectsList()) { - if (!(task instanceof TimerProject)) { - if (task.getIsSyncAtStartUp()) { - synchronizer.addTask(task); - } - } + if (task.getIsSyncAtStartUp()) { + synchronizer.addTask(task); } - + task.getSubTasks().forEach(this::addTaskToSync); } /** diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index a740763..bf85b24 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -22,7 +22,6 @@ package org.chorem.jtimer.data; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -643,12 +642,13 @@ public class TimerDataManager { * @param task : the task to edit * @param info : the SyncInfo that was added */ - public void changeSyncInfo(TimerTask task, SyncInfo info) { + public void syncInfoChanged(TimerTask task, SyncInfo info) { task.addSyncInfo(info); + task.setSyncAtStartUp(true); for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.changeSyncInfo(task, info); + dataEventListener.syncInfoChanged(task, info); } if (log.isDebugEnabled()) { log.debug("SyncInfo changed: " + info.getSyncURL()); @@ -665,7 +665,7 @@ public class TimerDataManager { task.removeSyncInfo(info); } for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.deleteSyncInfo(task, info); + dataEventListener.syncInfoDeleted(task, info); } if (log.isDebugEnabled()) { log.debug("SyncInfo deleted: " + info.getSyncURL()); @@ -675,12 +675,13 @@ public class TimerDataManager { /** * When a task is synced * @param task + * @param syncInfo */ - public void synchronizeTask(TimerTask task, SyncInfo syncInfo) { + public void taskSynchronized(TimerTask task, SyncInfo syncInfo) { task.setSyncAtStartUp(false); for (DataEventListener dataEventListener: dataEventListeners) { - dataEventListener.synchronizeTask(task, syncInfo); + dataEventListener.taskSynchronized(task, syncInfo); } if (log.isDebugEnabled()) { log.debug("Task " + task.getName() + " synced at " + syncInfo.getSyncURL()); diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index ca58c40..2e01103 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -431,13 +431,21 @@ public class TimerTaskHelper { /** * Makes a single object with all the times + * @param task + * @param url + * @param withAnnotations + * @param timezone + * @return a JsonObject of the task times */ public static JsonObject taskURLToJSONObject(TimerTask task, String url, boolean withAnnotations, String timezone) { - Date startDate = task.getAllDaysAndTimes().firstKey(); - Date endDate = new Date(); - //get the current day too by making endDate a day later - endDate.setTime(endDate.getTime() + 86400 * 1000L); - JsonObject resultingObject = taskURLToJSONObject(task, url, startDate, endDate, withAnnotations, timezone); + JsonObject resultingObject = new JsonObject(); + if (task.getAllDaysAndTimes().size() > 0) { + Date startDate = task.getAllDaysAndTimes().firstKey(); + Date endDate = new Date(); + //get the current day too by making endDate a day later + endDate.setTime(endDate.getTime() + 86400 * 1000L); + resultingObject = taskURLToJSONObject(task, url, startDate, endDate, withAnnotations, timezone); + } return resultingObject; } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 6862da3..7129012 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -612,8 +612,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, else { task.setSyncAtStartUp(false); } - log.info(task.getName() + " " + first_line); - + //make a yaml object for the syncInfo Yaml yaml = new Yaml(); for (Object obj : yaml.loadAll(parseIn)) { if (obj instanceof SyncInfo) { @@ -1270,10 +1269,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, return foundProjectNumber; } - @Override - public void changeSyncInfo(TimerTask task, SyncInfo syncURL) { - saveSynchronizationInfo(task); - } @Override public void deleteProject(TimerProject project) { @@ -1370,6 +1365,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // si le merge a merger les annotations par // exemple. // Potentiellement aussi lors d'un move. + task.setSyncAtStartUp(true); saveTaskAnnotation(task); saveAlerts(task); saveSynchronizationInfo(task); @@ -1452,6 +1448,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // remove task from running task and force save runningTasks.remove(task); saveTask(task); + task.setSyncAtStartUp(true); } @Override @@ -1506,16 +1503,29 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * @param info */ @Override - public void deleteSyncInfo(TimerTask task, SyncInfo info) { + public void syncInfoDeleted(TimerTask task, SyncInfo info) { saveSynchronizationInfo(task); } /** * When a task is synced + * @param task + * @param info + */ + @Override + public void taskSynchronized(TimerTask task, SyncInfo info) { + saveSynchronizationInfo(task); + } + + /** + * When a syncInfo is modified + * @param task TimerTask + * @param info */ @Override - public void synchronizeTask(TimerTask task, SyncInfo info) { + public void syncInfoChanged(TimerTask task, SyncInfo info) { saveSynchronizationInfo(task); } + } diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index bcafa6d..aa0ac6d 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -153,45 +153,48 @@ public class TimerTaskSynchronizer implements DataEventListener { * @return an int (http response code or 0 in case of a problem) */ public static int synchronizeTaskOnURL(JsonObject object) { - String updateJsonString = object.toString(); - String syncURL = object.get("URL").getAsString(); - String charset = "UTF-8"; - HttpURLConnection connection; - URL url; - byte[] postDataBytes; int upDateValue = 0; - 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); - upDateValue = connection.getResponseCode(); - } catch (MalformedURLException e) { - if (log.isErrorEnabled()) { - log.error("URL malformed : " + syncURL + " Code : " + upDateValue); - } - } catch (ProtocolException e) { - if (log.isErrorEnabled()) { - log.error("Protocol error."+ " Code : " + upDateValue); - } - } catch (UnsupportedEncodingException e) { - if (log.isErrorEnabled()) { - log.error("Problem with encoding " + syncURL + " Code : " + upDateValue); - } - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Problem with the connection " + syncURL + " Code : " + upDateValue); - } - }catch (IllegalArgumentException e) { - if (log.isErrorEnabled()) { - log.error("Port value not valid " + syncURL + " Code : " + upDateValue); + //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); + upDateValue = connection.getResponseCode(); + } catch (MalformedURLException e) { + if (log.isErrorEnabled()) { + log.error("URL malformed : " + syncURL + " Code : " + upDateValue); + } + } catch (ProtocolException e) { + if (log.isErrorEnabled()) { + log.error("Protocol error."+ " Code : " + upDateValue); + } + } catch (UnsupportedEncodingException e) { + if (log.isErrorEnabled()) { + log.error("Problem with encoding " + syncURL + " Code : " + upDateValue); + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Problem with the connection " + syncURL + " Code : " + upDateValue); + } + }catch (IllegalArgumentException e) { + if (log.isErrorEnabled()) { + log.error("Port value not valid " + syncURL + " Code : " + upDateValue); + } } } return upDateValue; @@ -214,7 +217,7 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** - * Tasks deleted are modified from synchronization list if they exist in it + * Tasks deleted are removed from synchronization list if they exist in it * @param task modified task */ @Override @@ -237,6 +240,8 @@ public class TimerTaskSynchronizer implements DataEventListener { if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); task.setSyncAtStartUp(true); + log.info(task.getName() + " " + task.getIsSyncAtStartUp()+ " time set"); + } } } @@ -267,6 +272,7 @@ public class TimerTaskSynchronizer implements DataEventListener { if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); } + task.setSyncAtStartUp(true); } } @@ -276,22 +282,23 @@ public class TimerTaskSynchronizer implements DataEventListener { * @param syncURL the url to sync on (a String) */ @Override - public void changeSyncInfo(TimerTask task, SyncInfo syncURL) { + public void syncInfoChanged(TimerTask task, SyncInfo syncURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); } } + task.setSyncAtStartUp(true); } /** - * When the synchronization happens, set the syncAt Startup to false + * When the synchronization happens, set the syncAtStartUp to false * @param task the task that was synchronized * @param info SyncInfo */ @Override - public void synchronizeTask(TimerTask task, SyncInfo info) { + public void taskSynchronized(TimerTask task, SyncInfo info) { task.setSyncAtStartUp(false); } } diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java index 6133a76..2858b29 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -296,7 +296,7 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener public void itemAdded(String urlToAdd){ if ((urlToAdd != null) && ((!task.getSynchronizingURLList().contains(urlToAdd)))) { SyncInfo infoToAdd = new SyncInfo(urlToAdd); - core.getData().changeSyncInfo(task, infoToAdd); + core.getData().syncInfoChanged(task, infoToAdd); urlComboBox.addItem(infoToAdd); if (log.isDebugEnabled()) { log.debug("New SyncInfo with URL : " + urlToAdd); @@ -396,7 +396,7 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener infoBox(getResourceMap().getString("testSyncSuccessMessage"), getResourceMap().getString("testSyncSuccessTitle")); Calendar cal = Calendar.getInstance(); infoToUse.setLastSync(cal.getTime()); - core.getData().synchronizeTask(task, infoToUse); + core.getData().taskSynchronized(task, infoToUse); } else { errorBox(getResourceMap().getString("testSyncFailureMessage"), getResourceMap().getString("testSyncFailureTitle")); -- 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 feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 702848b51ef0a38618eaee2a49ce893f6d5c8e0e Author: servantie <servantie.c@gmail.com> Date: Mon Jul 11 12:04:33 2016 +0200 changed the syncatstartup boolean to be in the SyncInfo and not in the Task --- .../java/org/chorem/jtimer/data/TimerCore.java | 8 +++--- .../org/chorem/jtimer/data/TimerDataManager.java | 4 +-- .../java/org/chorem/jtimer/entities/SyncInfo.java | 18 +++++++++++++ .../java/org/chorem/jtimer/entities/TimerTask.java | 29 ++++++++++++++------ .../chorem/jtimer/io/GTimerIncrementalSaver.java | 20 +++----------- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 31 +++++++++++++++------- 6 files changed, 70 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index fd2ea8f..21c5b8d 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -34,6 +34,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; import org.chorem.jtimer.JTimerFactory; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.io.DataLockingException; @@ -208,9 +209,10 @@ public class TimerCore { if (log.isDebugEnabled()) { log.debug("Adding tasks that were not synchronized at last jTimer exit"); } - - if (task.getIsSyncAtStartUp()) { - synchronizer.addTask(task); + for (SyncInfo sync : task.getSynchronizingInfoList()) { + if (sync.getIsToSyncAtStartUp()) { + synchronizer.addTask(task); + } } task.getSubTasks().forEach(this::addTaskToSync); } diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index bf85b24..ab4ddf0 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -645,7 +645,7 @@ public class TimerDataManager { public void syncInfoChanged(TimerTask task, SyncInfo info) { task.addSyncInfo(info); - task.setSyncAtStartUp(true); + task.setSyncAtStartUp(true, info.getSyncURL()); for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.syncInfoChanged(task, info); @@ -678,7 +678,7 @@ public class TimerDataManager { * @param syncInfo */ public void taskSynchronized(TimerTask task, SyncInfo syncInfo) { - task.setSyncAtStartUp(false); + task.setSyncAtStartUp(false, syncInfo.getSyncURL()); for (DataEventListener dataEventListener: dataEventListeners) { dataEventListener.taskSynchronized(task, syncInfo); diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java index 4b7720c..e20edbe 100644 --- a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -22,6 +22,9 @@ public class SyncInfo { /** true if annotations included */ protected boolean isWithAnnotations; + /** true if the synchronization needs to be done at next start */ + protected boolean isToSyncAtStartUp; + /** * Empty constructor (necessary for yaml) */ @@ -40,6 +43,7 @@ public class SyncInfo { this.lastSync = lastSync; this.isActiveSync = isActiveSync; this.isWithAnnotations = isWithAnnotations; + this.isToSyncAtStartUp = true; } /** @@ -52,6 +56,7 @@ public class SyncInfo { this.isActiveSync = true; this.isWithAnnotations = false; this.lastSync = new Date(0); + this.isToSyncAtStartUp = true; } /** @@ -116,6 +121,19 @@ public class SyncInfo { } /** + * Gets the isToSyncAtStartUp + * @return a boolean + */ + public boolean getIsToSyncAtStartUp() {return isToSyncAtStartUp; } + + /** + * Sets the isToSyncAtStartUp + * @param isToSyncAtStartUp a boolean + */ + public void setIsToSyncAtStartUp(boolean isToSyncAtStartUp) { this.isToSyncAtStartUp = isToSyncAtStartUp; } + + + /** * Overrides the toString() method to return the url (for combobox) */ @Override diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index a1d3707..dab5a27 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -92,12 +92,6 @@ public class TimerTask implements Cloneable, * Synchronization Info */ protected List<SyncInfo> synchronisingInfoList; - - /** - * Boolean to keep track of tasks not synced before jtimer exit - */ - protected boolean syncAtStartUp; - /** * Constructor. */ @@ -383,14 +377,33 @@ public class TimerTask implements Cloneable, /** * Sets the sync at startup * @param syncAtStart boolean + * @param url the url of the syncInfo */ - public void setSyncAtStartUp(boolean syncAtStart) { this.syncAtStartUp = syncAtStart;} + public void setSyncAtStartUp(boolean syncAtStart, String url) { + if(!synchronisingInfoList.isEmpty()) { + for (SyncInfo sync : synchronisingInfoList) { + if (sync.syncURL.equals(url)) { + sync.setIsToSyncAtStartUp(syncAtStart); + } + } + } + } /** * Get the sync at startup * @return boolean */ - public boolean getIsSyncAtStartUp() { return this.syncAtStartUp;} + public boolean getIsSyncAtStartUp(String url) { + boolean syncsAtStart = false; + if(!synchronisingInfoList.isEmpty()) { + for (SyncInfo sync : synchronisingInfoList) { + if (sync.syncURL.equals(url)) { + syncsAtStart = sync.getIsToSyncAtStartUp(); + } + } + } + return syncsAtStart; + } /** * Add task's subtask. diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 7129012..22c2680 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -604,14 +604,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } try (BufferedReader parseIn = new BufferedReader(new FileReader(syncTaskFile))) { - //get first line to know if the tasks has to be synced at the start - String first_line = parseIn.readLine().trim(); - if ("SyncAtStartUp : true".equals(first_line)) { - task.setSyncAtStartUp(true); - } - else { - task.setSyncAtStartUp(false); - } //make a yaml object for the syncInfo Yaml yaml = new Yaml(); for (Object obj : yaml.loadAll(parseIn)) { @@ -1126,13 +1118,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // first make backup backupfile = makeBackupFile(synchronizationTaskFile); - //add on first line if sync at startup is needed - if (task.getIsSyncAtStartUp()) { - out.write("SyncAtStartUp : true\n"); - } - else { - out.write("SyncAtStartUp : false\n"); - } + //use Yaml to write it with pretty flow to make it easier to read DumperOptions dumper = new DumperOptions(); dumper.setPrettyFlow(true); @@ -1365,7 +1351,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // si le merge a merger les annotations par // exemple. // Potentiellement aussi lors d'un move. - task.setSyncAtStartUp(true); saveTaskAnnotation(task); saveAlerts(task); saveSynchronizationInfo(task); @@ -1387,6 +1372,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // en cours d'execution if (!runningTasks.contains(task)) { saveTask(task); + saveSynchronizationInfo(task); } } @@ -1448,7 +1434,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // remove task from running task and force save runningTasks.remove(task); saveTask(task); - task.setSyncAtStartUp(true); + saveSynchronizationInfo(task); } @Override diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index aa0ac6d..9157890 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -142,7 +142,7 @@ public class TimerTaskSynchronizer implements DataEventListener { Calendar cal = Calendar.getInstance(); task.setLastSync(cal.getTime(), syncURL); //it doesn't have to be synced at startup sync it succeeded - task.setSyncAtStartUp(false); + task.setSyncAtStartUp(false, syncURL); } } } @@ -211,9 +211,12 @@ public class TimerTaskSynchronizer implements DataEventListener { //add it only if the URL is not empty if ((!task.getSynchronizingInfoList().isEmpty()) && (!task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); - task.setSyncAtStartUp(true); } } + //set the syncAtStartup to true for all syncInfo + for (SyncInfo info : task.getSynchronizingInfoList()) { + info.setIsToSyncAtStartUp(true); + } } /** @@ -239,11 +242,13 @@ public class TimerTaskSynchronizer implements DataEventListener { //add it only if the URL is not empty if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); - task.setSyncAtStartUp(true); - log.info(task.getName() + " " + task.getIsSyncAtStartUp()+ " time set"); } } + //set the syncAtStartup to true for all syncInfo + for (SyncInfo info : task.getSynchronizingInfoList()) { + info.setIsToSyncAtStartUp(true); + } } /** @@ -256,9 +261,12 @@ public class TimerTaskSynchronizer implements DataEventListener { //add it only if the URL is not empty if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); - task.setSyncAtStartUp(true); } } + //set the syncAtStartup to true for all syncInfo + for (SyncInfo info : task.getSynchronizingInfoList()) { + info.setIsToSyncAtStartUp(true); + } } /** @@ -272,24 +280,27 @@ public class TimerTaskSynchronizer implements DataEventListener { if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); } - task.setSyncAtStartUp(true); + } + //set the syncAtStartup to true for all syncInfo + for (SyncInfo info : task.getSynchronizingInfoList()) { + info.setIsToSyncAtStartUp(true); } } /** * When the syncInfo is changed, add the task to sync list * @param task the task to sync - * @param syncURL the url to sync on (a String) + * @param info the url to sync on (a String) */ @Override - public void syncInfoChanged(TimerTask task, SyncInfo syncURL) { + public void syncInfoChanged(TimerTask task, SyncInfo info) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); } } - task.setSyncAtStartUp(true); + task.setSyncAtStartUp(true, info.getSyncURL()); } /** @@ -299,6 +310,6 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void taskSynchronized(TimerTask task, SyncInfo info) { - task.setSyncAtStartUp(false); + task.setSyncAtStartUp(false, info.getSyncURL()); } } -- 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 feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 81724c16cfc5a7d15bd6283d96fa0aac9dce176f Author: servantie <servantie.c@gmail.com> Date: Tue Jul 12 14:07:47 2016 +0200 save of syncInfo with json instead of yaml (+ tests adapted) corrected some mistakes (not listening to the checkboxes properly, information wasn't saved unless some other change was made) --- .../org/chorem/jtimer/data/CommonVetoable.java | 8 ---- .../org/chorem/jtimer/data/TimerDataManager.java | 5 ++- .../jtimer/data/VetoableDataEventListener.java | 9 ----- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 45 ++++++++++++++-------- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 3 -- .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 9 ++++- .../jtimer/entities/TimerTaskHelperTest.java | 8 ++-- .../jtimer/io/GTimerIncrementalSaverTest.java | 3 +- src/test/resources/testdata/41.task.sync | 15 +++++--- 9 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/CommonVetoable.java b/src/main/java/org/chorem/jtimer/data/CommonVetoable.java index f74f4d3..8510936 100644 --- a/src/main/java/org/chorem/jtimer/data/CommonVetoable.java +++ b/src/main/java/org/chorem/jtimer/data/CommonVetoable.java @@ -202,12 +202,4 @@ public class CommonVetoable implements VetoableDataEventListener { // mais pas une combinaison des deux } } - - /* - * {@inheritDoc} - */ - @Override - public void checkSetTaskURL(TimerTask task, String newURL) { - - } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index ab4ddf0..fe9125b 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -645,7 +645,10 @@ public class TimerDataManager { public void syncInfoChanged(TimerTask task, SyncInfo info) { task.addSyncInfo(info); - task.setSyncAtStartUp(true, info.getSyncURL()); + //the syncInfo is added to the syncs at startup only if it is active + if (info.getIsActiveSync()) { + task.setSyncAtStartUp(true, info.getSyncURL()); + } for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.syncInfoChanged(task, info); diff --git a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java b/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java index 3c5e144..d86787c 100644 --- a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java @@ -145,13 +145,4 @@ public interface VetoableDataEventListener extends EventListener { default void checkMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { } - - /** - * Check sync URL ofr a task - * @param task task to change the url - * @param newURL the new URL - */ - default void checkSetTaskURL(TimerTask task, String newURL) { - - } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 22c2680..de3dbaf 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -6,15 +6,15 @@ * %% * 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% @@ -22,6 +22,12 @@ package org.chorem.jtimer.io; +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 java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; @@ -70,8 +76,6 @@ 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.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; /** * Charge et sauve les fichiers au format gTimer. @@ -603,12 +607,16 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, log.debug("Synchronization information found for task " + task.getName()); } try (BufferedReader parseIn = new BufferedReader(new FileReader(syncTaskFile))) { + JsonParser parser = new JsonParser(); + Gson gson = new Gson(); + JsonElement element = parser.parse(parseIn); + if (element.isJsonArray()) { + JsonArray infoArray = (JsonArray) element; + for (JsonElement obj : infoArray) { + JsonObject res = (JsonObject) obj; + SyncInfo sync = gson.fromJson(res, SyncInfo.class); + task.addSyncInfo(sync); - //make a yaml object for the syncInfo - Yaml yaml = new Yaml(); - for (Object obj : yaml.loadAll(parseIn)) { - if (obj instanceof SyncInfo) { - task.addSyncInfo((SyncInfo) obj); } } } @@ -1119,11 +1127,16 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // first make backup backupfile = makeBackupFile(synchronizationTaskFile); - //use Yaml to write it with pretty flow to make it easier to read - DumperOptions dumper = new DumperOptions(); - dumper.setPrettyFlow(true); - Yaml yaml = new Yaml(dumper); - yaml.dumpAll(task.getSynchronizingInfoList().iterator(), out); + //make a json object for the syncInfo + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + gson.newJsonWriter(out); + JsonArray infoArray = new JsonArray(); + for (SyncInfo sync : task.getSynchronizingInfoList()) { + JsonElement res= gson.toJsonTree(sync); + infoArray.add(res); + } + out.write(gson.toJson(infoArray)); + out.close(); deleteBackupFile(backupfile); } diff --git a/src/main/java/org/chorem/jtimer/ui/StatusBar.java b/src/main/java/org/chorem/jtimer/ui/StatusBar.java index 7802885..d8b82d6 100644 --- a/src/main/java/org/chorem/jtimer/ui/StatusBar.java +++ b/src/main/java/org/chorem/jtimer/ui/StatusBar.java @@ -25,16 +25,13 @@ package org.chorem.jtimer.ui; import java.awt.GridLayout; import java.util.Collection; import java.util.Date; - import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; - import org.apache.commons.lang3.time.DurationFormatUtils; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.data.TimerDataManager; -import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java index 2858b29..40fa29f 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -246,7 +246,10 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener public boolean isIncludingAnnotations() { boolean ischeckedIncludeAnnotations = checkIncludesAnnotations.isSelected(); if (urlComboBox.getSelectedItem() instanceof SyncInfo) { - task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsWithAnnotations(ischeckedIncludeAnnotations); + SyncInfo syncInfo = (SyncInfo) urlComboBox.getSelectedItem(); + task.getSynchronizingInfo(syncInfo.getSyncURL()).setIsWithAnnotations(ischeckedIncludeAnnotations); + core.getData().syncInfoChanged(task,syncInfo); + } if (log.isDebugEnabled()) { log.debug("Inclusion of annotations in sync changed"); @@ -261,7 +264,9 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener public boolean isActiveSync() { boolean isActiveSyncURL = checkIsActiveSync.isSelected(); if (urlComboBox.getSelectedItem() instanceof SyncInfo) { - task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsActiveSync(isActiveSyncURL); + SyncInfo syncInfo = (SyncInfo) urlComboBox.getSelectedItem(); + task.getSynchronizingInfo(syncInfo.getSyncURL()).setIsActiveSync(isActiveSyncURL); + core.getData().syncInfoChanged(task,syncInfo); } if (log.isDebugEnabled()) { log.debug("Activity of url changed "); diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java index abd36ea..b75f59d 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java @@ -22,15 +22,13 @@ package org.chorem.jtimer.entities; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import org.chorem.jtimer.AbstractJTimerTest; -import org.testng.Assert; -import org.testng.annotations.Test; - import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.chorem.jtimer.AbstractJTimerTest; +import org.testng.Assert; +import org.testng.annotations.Test; /** * Test related to TimerTaskHelper. diff --git a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java index 73a1724..04c6eba 100644 --- a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java +++ b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java @@ -434,8 +434,7 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { SyncInfo syncInfo = new SyncInfo("http://localhost:3000"); Assert.assertNotNull(task.getSynchronizingInfoList()); - Assert.assertEquals(task.getSynchronizingInfoList().get(0).getSyncURL(), syncInfo.getSyncURL()); - Assert.assertEquals(task.getSynchronizingInfoList().get(0).getIsActiveSync(), syncInfo.getIsActiveSync()); + Assert.assertTrue(task.getSynchronizingInfoList().contains(syncInfo)); } } diff --git a/src/test/resources/testdata/41.task.sync b/src/test/resources/testdata/41.task.sync index 16f07b8..fbb1878 100644 --- a/src/test/resources/testdata/41.task.sync +++ b/src/test/resources/testdata/41.task.sync @@ -1,6 +1,9 @@ -!!org.chorem.jtimer.entities.SyncInfo { - isActiveSync: true, - isWithAnnotations: false, - lastSync: !!timestamp '1970-01-01T00:00:00Z', - syncURL: 'http://localhost:3000' -} \ No newline at end of file +[ + { + "syncURL": "http://localhost:3000", + "lastSync": "Jan 1, 1970 1:00:00 AM", + "isActiveSync": true, + "isWithAnnotations": false, + "isToSyncAtStartUp": true + } +] \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm