branch feature/sync updated (1a9ed28 -> 140eb26)
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 1a9ed28 removed a duplicated try/catch in the sendUpdate() method new 089074f corrected update to synchronisation new f31cbed added an automatic synchronization (every min), currently synchronizes all the times of the tasks that have been modified since the last automatic sync. Sends all the times from creation date for now new 62a42e9 minor changes (comments) new 140eb26 (minor) added timezone in json output (kept forgetting it) The 4 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 140eb26887ea3b2dc066a4d80059b8e907a6a661 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:47:05 2016 +0200 (minor) added timezone in json output (kept forgetting it) commit 62a42e99d3f053d9cbb3e66579e49a2b86e5da08 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:44:41 2016 +0200 minor changes (comments) commit f31cbedbd14230f8f4e115f3ea08e6d5e7444486 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:34:13 2016 +0200 added an automatic synchronization (every min), currently synchronizes all the times of the tasks that have been modified since the last automatic sync. Sends all the times from creation date for now commit 089074f01bbcb08c074c4c1eb319f5c2cb82f88e Author: servantie <servantie.c@gmail.com> Date: Wed Jun 1 14:40:52 2016 +0200 corrected update to synchronisation Summary of changes: .../java/org/chorem/jtimer/data/TimerCore.java | 10 + .../chorem/jtimer/entities/TimerTaskHelper.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 274 +++++++++++++++++++++ .../resources/TimerTaskUpdaterView.properties | 10 +- .../resources/TimerTaskUpdaterView_fr.properties | 12 +- 5 files changed, 296 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.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 feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 089074f01bbcb08c074c4c1eb319f5c2cb82f88e Author: servantie <servantie.c@gmail.com> Date: Wed Jun 1 14:40:52 2016 +0200 corrected update to synchronisation --- .../ui/report/resources/TimerTaskUpdaterView.properties | 10 +++++----- .../ui/report/resources/TimerTaskUpdaterView_fr.properties | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties index 9546d72..ddeae17 100644 --- a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties @@ -19,7 +19,7 @@ # <http://www.gnu.org/licenses/gpl-3.0.html>. # #L% ### -updateTitle=${Application.title} - Update +updateTitle=${Application.title} - Synchronisation updateGeneral=General updateOptions=Options updateFrom=From : @@ -45,15 +45,15 @@ updateAnnotations.Action.shortDescription = Include annotations generateUpdate.Action.text = &Generate generateUpdate.Action.icon = applications-system.png -generateUpdate.Action.shortDescription = Generate update +generateUpdate.Action.shortDescription = Generate synchronisation sendUpdate.Action.text = &Send sendUpdate.Action.icon = mail-forward.png -sendUpdate.Action.shortDescription = Send update +sendUpdate.Action.shortDescription = Send synchronisation closeView.Action.text = &Close closeView.Action.icon = dialog-close.png closeView.Action.shortDescription = Close -action.updateError = Update failed, check URL ? -action.updateErrorTitle = Update error +action.updateError = Synchronisation failed, check URL ? +action.updateErrorTitle = Synchronisation error diff --git a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties index d5c7b71..908ccad 100644 --- a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties @@ -20,13 +20,13 @@ # #L% ### # update i18n -updateTitle=${Application.title} - Mise \u00E0 jour +updateTitle=${Application.title} - Synchronisation updateGeneral=G\u00E9n\u00E9ral updateOptions=Options updateFrom=De : updateTo=\u00C0 : -lastUpdateLabel=Derni\u00E8re mise \u00E0 jour : +lastUpdateLabel=Derni\u00E8re synchronisation : pickCurrentMonth.Action.text = Selectionner le mois courant @@ -45,15 +45,15 @@ isIncludingAnnotations.Action.text = Inclure les annotations generateUpdate.Action.text = &G\u00E9n\u00E9rer generateUpdate.Action.icon = applications-system.png -generateUpdate.Action.shortDescription = G\u00E9n\u00E9rer la mise \u00C0 jour +generateUpdate.Action.shortDescription = G\u00E9n\u00E9rer les données de synchronisation sendUpdate.Action.text = &Envoyer sendUpdate.Action.icon = mail-forward.png -sendUpdate.Action.shortDescription = Envoyer la mise \u00C0 jour +sendUpdate.Action.shortDescription = Envoyer les donn\u00E9es closeView.Action.text = &Fermer closeView.Action.icon = dialog-close.png closeView.Action.shortDescription = Fermer -action.updateError = Erreur de mise \u00E0 jour, v\u00E9rifier l'URL ? -action.updateErrorTitle = Erreur de mise \u00E0 jour \ No newline at end of file +action.updateError = Erreur de synchronisation, v\u00E9rifier l'URL ? +action.updateErrorTitle = Erreur de synchronisation \ No newline at end of file -- 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 f31cbedbd14230f8f4e115f3ea08e6d5e7444486 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:34:13 2016 +0200 added an automatic synchronization (every min), currently synchronizes all the times of the tasks that have been modified since the last automatic sync. Sends all the times from creation date for now --- .../java/org/chorem/jtimer/data/TimerCore.java | 10 + .../chorem/jtimer/io/TimerTaskSynchronizer.java | 262 +++++++++++++++++++++ 2 files changed, 272 insertions(+) diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index 2234d9b..f8655bd 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -38,6 +38,7 @@ 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.io.TimerTaskSynchronizer; /** * TimerCore @@ -59,6 +60,9 @@ public class TimerCore { /** saver io controller. */ protected Saver saver; + /** sync */ + protected TimerTaskSynchronizer synchronizer; + /** * Constructor. */ @@ -87,6 +91,12 @@ public class TimerCore { data.addDataEventListener(saver); } + //init sync + synchronizer = new TimerTaskSynchronizer(this); + if (synchronizer != null) { + data.addDataEventListener(synchronizer); + } + } /** diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java new file mode 100644 index 0000000..d254548 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -0,0 +1,262 @@ +package org.chorem.jtimer.io; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.data.DataEventListener; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TimerTaskHelper; + +import java.io.*; +import java.net.*; +import java.time.LocalDateTime; +import java.util.*; +import java.util.Timer; + +/** + * + * Class dealing with automated synchronization of tasks + * + * Created by servantie on 01/06/16. + */ +public class TimerTaskSynchronizer implements DataEventListener { + + /** log */ + private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); + + /** auto sync delay */ + protected int autoSyncDelay = 1000 * 60; //1min for testing purposes + + + /** timer to schedule syncs */ + protected Timer timer; + + /** timer core (to retrieve tasks) */ + protected TimerCore core; + + /** Tasks to sync */ + protected Collection<TimerTask> tasksToSync; + + + public TimerTaskSynchronizer(TimerCore core) { + + timer = new Timer(); + timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); + log.info("Starting synchronising thread"); + + this.core = core; + + + tasksToSync = Collections.synchronizedCollection(new ArrayList<>()); + } + + + public void setAutoSyncDelay(int autoSyncDelay) { + if (autoSyncDelay>0) { + this.autoSyncDelay = autoSyncDelay; + } + } + protected class UpdateTask extends java.util.TimerTask { + public void run() { + if (log.isDebugEnabled()) { + log.debug("Synchronizer wake up"); + } + synchronizeTasks(); + } + + + public void synchronizeTasks(){ + + synchronized (tasksToSync) { + Collection<TimerTask> remainingTasks = new ArrayList<>(tasksToSync); + for (TimerTask task : tasksToSync) { + //do the sync, store the result + boolean syncDone = synchronizeSingleTask(task); + if (remainingTasks.contains(task)) { + remainingTasks.remove(task); + } + log.info(" task synced : " + syncDone); + + + } + tasksToSync = remainingTasks; + } + } + + + + } + + + + /** + * Makes one synchronization for a task, without annotations by default + * + * @param task + */ + public boolean synchronizeSingleTask(TimerTask task){ + String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); + String syncURl = task.getSynchronisingURL(); + String charset = "UTF-8"; + HttpURLConnection connection = null; + URL url = null; + try { + url = new URL("http://" + syncURl); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + } + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json"); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + e.printStackTrace(); + } + byte[] postDataBytes = new byte[0]; + try { + postDataBytes = updateJsonString.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + e.printStackTrace(); + } + + //get the header fields + Map<String, List<String>> map = connection.getHeaderFields(); + boolean hasUpdated = false; + //check for positive answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; + } + } + } + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + + } + else { + log.error("Sync error, wrong URL?"); + return false; + + } + + + } + + + + + + @Override + public void addProject(TimerProject project) { + + } + + @Override + public void addTask(TimerTask task) { + } + + @Override + public void modifyProject(TimerProject project) { + + } + + @Override + public void modifyTask(TimerTask task) { + //when a task is modified, add it to the to sync list (if it isn't already there= + if(!tasksToSync.contains(task)) { + tasksToSync.add(task); + } + } + + @Override + public void deleteProject(TimerProject project) { + + } + + @Override + public void deleteTask(TimerTask task) { + if (tasksToSync.contains(task)) { + tasksToSync.remove(task); + + } + } + + @Override + public void setAnnotation(TimerTask task, Date date, String annotation) { + + } + + @Override + public void setTaskTime(TimerTask task, Date date, Long time) { + } + + @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) { + + } + + @Override + public void startTask(TimerTask task) { + } + + @Override + public void stopTask(TimerTask task) { + if(!tasksToSync.contains(task)) { + tasksToSync.add(task); + } + } + + @Override + public void dataLoaded(Collection<TimerProject> projects) { + + } + + @Override + public void modifyTaskURL(TimerTask task, String newURL) { + if(!tasksToSync.contains(task) && (!task.getSynchronisingURL().equals(null))) { + tasksToSync.add(task); + } + } + + @Override + public void modifyTaskSyncDate(TimerTask task, LocalDateTime newDate) { + + } +} -- 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 62a42e99d3f053d9cbb3e66579e49a2b86e5da08 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:44:41 2016 +0200 minor changes (comments) --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 100 ++++++++++++--------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index d254548..05e716a 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -28,7 +28,6 @@ public class TimerTaskSynchronizer implements DataEventListener { /** auto sync delay */ protected int autoSyncDelay = 1000 * 60; //1min for testing purposes - /** timer to schedule syncs */ protected Timer timer; @@ -38,7 +37,6 @@ public class TimerTaskSynchronizer implements DataEventListener { /** Tasks to sync */ protected Collection<TimerTask> tasksToSync; - public TimerTaskSynchronizer(TimerCore core) { timer = new Timer(); @@ -47,17 +45,24 @@ public class TimerTaskSynchronizer implements DataEventListener { this.core = core; - tasksToSync = Collections.synchronizedCollection(new ArrayList<>()); } - + /** + * Change the autosync delay + * @param autoSyncDelay + */ public void setAutoSyncDelay(int autoSyncDelay) { if (autoSyncDelay>0) { this.autoSyncDelay = autoSyncDelay; } } + + /** + * Inner Task class to make the automatic sync + */ protected class UpdateTask extends java.util.TimerTask { + public void run() { if (log.isDebugEnabled()) { log.debug("Synchronizer wake up"); @@ -65,7 +70,9 @@ public class TimerTaskSynchronizer implements DataEventListener { synchronizeTasks(); } - + /** + * synchronizes Tasks in remainingTasks + */ public void synchronizeTasks(){ synchronized (tasksToSync) { @@ -95,33 +102,33 @@ public class TimerTaskSynchronizer implements DataEventListener { * * @param task */ - public boolean synchronizeSingleTask(TimerTask task){ - String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); - String syncURl = task.getSynchronisingURL(); - String charset = "UTF-8"; - HttpURLConnection connection = null; - URL url = null; - try { - url = new URL("http://" + syncURl); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - e.printStackTrace(); - } - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json"); - try { - connection.setRequestMethod("POST"); - } catch (ProtocolException e) { - e.printStackTrace(); - } + public boolean synchronizeSingleTask(TimerTask task) { + String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); + String syncURl = task.getSynchronisingURL(); + String charset = "UTF-8"; + HttpURLConnection connection = null; + URL url = null; + try { + url = new URL("http://" + syncURl); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + } + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json"); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + e.printStackTrace(); + } byte[] postDataBytes = new byte[0]; try { postDataBytes = updateJsonString.toString().getBytes("UTF-8"); @@ -133,7 +140,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } catch (IOException e) { e.printStackTrace(); } - //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); boolean hasUpdated = false; @@ -148,21 +154,13 @@ public class TimerTaskSynchronizer implements DataEventListener { if (hasUpdated) { task.setLastSync(LocalDateTime.now()); return true; - } else { log.error("Sync error, wrong URL?"); return false; - } - - } - - - - @Override public void addProject(TimerProject project) { @@ -177,6 +175,10 @@ public class TimerTaskSynchronizer implements DataEventListener { } + /** + * Tasks are added to synchronization list when modified + * @param task modified task + */ @Override public void modifyTask(TimerTask task) { //when a task is modified, add it to the to sync list (if it isn't already there= @@ -189,12 +191,14 @@ public class TimerTaskSynchronizer implements DataEventListener { public void deleteProject(TimerProject project) { } - + /** + * Tasks deleted are modified from synchronization list if they exist in it + * @param task modified task + */ @Override public void deleteTask(TimerTask task) { if (tasksToSync.contains(task)) { tasksToSync.remove(task); - } } @@ -235,7 +239,10 @@ public class TimerTaskSynchronizer implements DataEventListener { @Override public void startTask(TimerTask task) { } - + /** + * Tasks are added to synchronization list when stopped + * @param task modified task + */ @Override public void stopTask(TimerTask task) { if(!tasksToSync.contains(task)) { @@ -248,6 +255,11 @@ public class TimerTaskSynchronizer implements DataEventListener { } + /** + * Tasks are added to synchronization list when the URL is updated + * + * @param task modified task + */ @Override public void modifyTaskURL(TimerTask task, String newURL) { if(!tasksToSync.contains(task) && (!task.getSynchronisingURL().equals(null))) { -- 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 140eb26887ea3b2dc066a4d80059b8e907a6a661 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:47:05 2016 +0200 (minor) added timezone in json output (kept forgetting it) --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index b786a34..8393254 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -377,7 +377,7 @@ public class TimerTaskHelper { //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); periodElement.addProperty("id", dateString); - periodElement.addProperty("startDate", dateString + "T00:00:00"); + periodElement.addProperty("startDate", dateString + "T00:00:00.000+0100"); periodElement.addProperty("duration", entry.getValue()); if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { String annotations = ""; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm