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>.