branch feature/sync updated (140eb26 -> 66dee36)
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 140eb26 (minor) added timezone in json output (kept forgetting it) new d6dd1a0 corrected the json creation to deal with times added before the task's creation date (and be able to send them, that way) corrected the url creation in the synchronization new 45ddb6e changed name of parseSyncURL to parseSyncInfo (clearer) new 83614a5 added the synchronizer to the config and started treating errors new 2c25465 removed useless tabs new aeb5909 minor typos corrected, set autosyncdelay to every two hours new 66dee36 added the timezone as option in JTimerConfig, updated json creation accordingly 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 66dee368627d529a1e70998a4995ee88ae463692 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 6 11:25:44 2016 +0200 added the timezone as option in JTimerConfig, updated json creation accordingly commit aeb5909defb6d4604b3fac481c43747ad2ffb819 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 17:24:03 2016 +0200 minor typos corrected, set autosyncdelay to every two hours commit 2c25465bad39f967534ce5b5d4ba4c8d15343578 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 16:35:15 2016 +0200 removed useless tabs commit 83614a5fb643a94ef7bb8a9d45b17158d18ab68c Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 15:19:06 2016 +0200 added the synchronizer to the config and started treating errors commit 45ddb6ed4f6a20dbfb8bb502fb5536efbdeb0c04 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 11:15:30 2016 +0200 changed name of parseSyncURL to parseSyncInfo (clearer) commit d6dd1a0314bcbb2f47f9720fcf02555518a3e85e Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 09:52:06 2016 +0200 corrected the json creation to deal with times added before the task's creation date (and be able to send them, that way) corrected the url creation in the synchronization Summary of changes: src/main/java/org/chorem/jtimer/JTimerConfig.java | 25 +++- src/main/java/org/chorem/jtimer/JTimerFactory.java | 41 ++++++ .../java/org/chorem/jtimer/data/TimerCore.java | 2 +- .../chorem/jtimer/entities/TimerTaskHelper.java | 16 +-- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 5 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 152 ++++++++++++--------- .../jtimer/ui/report/TimerTaskUpdaterView.java | 78 +++++++---- 7 files changed, 214 insertions(+), 105 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 d6dd1a0314bcbb2f47f9720fcf02555518a3e85e Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 09:52:06 2016 +0200 corrected the json creation to deal with times added before the task's creation date (and be able to send them, that way) corrected the url creation in the synchronization --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 2 +- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 8393254..7cf32c4 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -342,7 +342,7 @@ public class TimerTaskHelper { * @return result the string in JSON */ public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations) { - Date startDate = task.getCreationDate(); + Date startDate = task.getAllDaysAndTimes().firstKey(); Date endDate = new Date(); JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations); return resultingJSON; diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 05e716a..95b995d 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected int autoSyncDelay = 1000 * 60; //1min for testing purposes + protected int autoSyncDelay = 1000 * 10; //10 s for testing purposes /** timer to schedule syncs */ protected Timer timer; @@ -78,13 +78,14 @@ public class TimerTaskSynchronizer implements DataEventListener { synchronized (tasksToSync) { Collection<TimerTask> remainingTasks = new ArrayList<>(tasksToSync); for (TimerTask task : tasksToSync) { + if (log.isDebugEnabled()){ + log.debug("task " + task.getName() + " being synced."); + } //do the sync, store the result boolean syncDone = synchronizeSingleTask(task); if (remainingTasks.contains(task)) { remainingTasks.remove(task); } - log.info(" task synced : " + syncDone); - } tasksToSync = remainingTasks; @@ -109,7 +110,7 @@ public class TimerTaskSynchronizer implements DataEventListener { HttpURLConnection connection = null; URL url = null; try { - url = new URL("http://" + syncURl); + url = new URL(syncURl); } catch (MalformedURLException e) { e.printStackTrace(); } -- 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 45ddb6ed4f6a20dbfb8bb502fb5536efbdeb0c04 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 11:15:30 2016 +0200 changed name of parseSyncURL to parseSyncInfo (clearer) --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 8 ++++---- src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java | 5 ++--- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 7cf32c4..ffd7c99 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -376,9 +376,9 @@ public class TimerTaskHelper { String dateString = date.toString(); //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.000+0100"); - periodElement.addProperty("duration", entry.getValue()); + periodElement.addProperty("periodId", dateString); + periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000+0100"); + periodElement.addProperty("periodDuration", entry.getValue()); if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { String annotations = ""; for (String s : getAnnotation(task, entry.getKey())) { @@ -386,7 +386,7 @@ public class TimerTaskHelper { } //remove trailing comma annotations = annotations.substring(0, annotations.length()-1); - periodElement.addProperty("info", annotations); + periodElement.addProperty("periodInfo", annotations); } periodArray.add(periodElement); } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index faa0f5d..fdc27e0 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -71,7 +71,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.chorem.jtimer.entities.TimerTaskHelper; /** * Charge et sauve les fichiers au format gTimer. @@ -364,7 +363,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, parseAnnotations(task); parseAlerts(task); - parseSyncURL(task); + parseSyncInfo(task); } } catch (NumberFormatException e) { if (log.isWarnEnabled()) { @@ -608,7 +607,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * * @param task task to load sync info */ - protected void parseSyncURL(TimerTask task) throws IOException { + protected void parseSyncInfo(TimerTask task) throws IOException { int taskNumber = task.getNumber(); File syncTaskFile = new File(dataSaveDirectory + File.separator + taskNumber +"."+ GTIMER_TASK_EXTENSION +"."+ GTIMER_SYNC_EXTENSION); diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 95b995d..882e6af 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -83,6 +83,7 @@ public class TimerTaskSynchronizer implements DataEventListener { } //do the sync, store the result boolean syncDone = synchronizeSingleTask(task); + //for now doesn't deal with failure in the update, just task already updated if (remainingTasks.contains(task)) { remainingTasks.remove(task); } @@ -157,7 +158,7 @@ public class TimerTaskSynchronizer implements DataEventListener { return true; } else { - log.error("Sync error, wrong URL?"); + log.error("Sync error"); return false; } } -- 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 83614a5fb643a94ef7bb8a9d45b17158d18ab68c Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 15:19:06 2016 +0200 added the synchronizer to the config and started treating errors --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 18 +++++++++- src/main/java/org/chorem/jtimer/JTimerFactory.java | 38 ++++++++++++++++++++++ .../java/org/chorem/jtimer/data/TimerCore.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 36 ++++++++++---------- 4 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 76138db..499eac9 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -168,6 +168,19 @@ public class JTimerConfig { } /** + * Returns the synchronizer class + * @return + */ + public Class<?> getIOSynchronizerClass() {return appConfig.getOptionAsClass(JTimerOption.IO_SYNC_CLASS.key); + } + + /** + * Returns autosync delay in seconds + * @return auto sync delay + */ + public long getIOSyncAutoSyncDelay() { return appConfig.getOptionAsLong(JTimerOption.IO_SYNC_AUTOSYNCDELAY.key);} + + /** * Return user idle time threshold in seconds. * * @return idle time threshold @@ -279,10 +292,13 @@ 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", "org.chorem.jtimer.io.TimerTaskSynchronizer"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), UI_CLOSE_TO_SYSTRAY("jtimer.ui.closetosystray", "true"), - UI_REPORT_FIRSTDAYOFWEEK("jtimer.ui.report.firstdayofweek", "0"); + UI_REPORT_FIRSTDAYOFWEEK("jtimer.ui.report.firstdayofweek", "10"); protected String key; protected String defaultValue; diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index 021a3eb..4a100d5 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.java @@ -25,6 +25,7 @@ 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.io.TimerTaskSynchronizer; /** * JTimer config class. @@ -43,6 +44,9 @@ public class JTimerFactory { /** Saver */ protected static Saver saver; + /** Synchronizer */ + protected static TimerTaskSynchronizer synchronizer; + /** * Constructeur. */ @@ -88,4 +92,38 @@ public class JTimerFactory { return saver; } + + /** + * Get synchronizer manager + */ + public static TimerTaskSynchronizer getSynchronizer(){ + if (synchronizer == null) { + + Class<?> synchronizerClass = JTimer.config.getIOSynchronizerClass(); + + // log + if (log.isInfoEnabled()) { + log.info("Using synchronizer class : " + synchronizerClass); + log.info(" with auto synchronizer delay : " + JTimer.config.getIOSyncAutoSyncDelay()); + } + + try { + // get instance + synchronizer = (TimerTaskSynchronizer) synchronizerClass.newInstance(); + + // set delay to saver + synchronizer.setAutoSyncDelay(JTimer.config.getIOSyncAutoSyncDelay() * 1000); + + } 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 f8655bd..52e8b97 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -92,7 +92,7 @@ public class TimerCore { } //init sync - synchronizer = new TimerTaskSynchronizer(this); + synchronizer = JTimerFactory.getSynchronizer(); 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 index 882e6af..e322ab8 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,25 +26,19 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected int autoSyncDelay = 1000 * 10; //10 s for testing purposes + protected long autoSyncDelay = 1000 * 10 ; //every 2 hours, check for modifications to sync /** 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) { - + public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); log.info("Starting synchronising thread"); - this.core = core; - tasksToSync = Collections.synchronizedCollection(new ArrayList<>()); } @@ -52,7 +46,7 @@ public class TimerTaskSynchronizer implements DataEventListener { * Change the autosync delay * @param autoSyncDelay */ - public void setAutoSyncDelay(int autoSyncDelay) { + public void setAutoSyncDelay(long autoSyncDelay) { if (autoSyncDelay>0) { this.autoSyncDelay = autoSyncDelay; } @@ -84,25 +78,28 @@ public class TimerTaskSynchronizer implements DataEventListener { //do the sync, store the result boolean syncDone = synchronizeSingleTask(task); //for now doesn't deal with failure in the update, just task already updated - if (remainingTasks.contains(task)) { - remainingTasks.remove(task); + if (remainingTasks.contains(task)) { + remainingTasks.remove(task); + } + + if (syncDone) { + log.debug("Sync done"); + } + else { + log.debug("Sync failed"); } } tasksToSync = remainingTasks; } } - - - } - - /** * Makes one synchronization for a task, without annotations by default * * @param task + * @return boolean for failure of sync (maybe make it return an int for better treatment of failure) */ public boolean synchronizeSingleTask(TimerTask task) { String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); @@ -114,11 +111,15 @@ public class TimerTaskSynchronizer implements DataEventListener { url = new URL(syncURl); } catch (MalformedURLException e) { e.printStackTrace(); + //abort synchronization of this task if the url is wrong + return false; } try { connection = (HttpURLConnection) url.openConnection(); } catch (IOException e) { e.printStackTrace(); + //abort synchronization of this task if connection impossible + return false; } connection.setUseCaches(false); connection.setDoInput(true); @@ -145,9 +146,10 @@ public class TimerTaskSynchronizer implements DataEventListener { //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); boolean hasUpdated = false; - //check for positive answer from server + //check for answer from server for (Map.Entry<String, List<String>> entry : map.entrySet()) { for (String s : entry.getValue()) { + //positive answer, synchronization accepted if (s.equals("HTTP/1.1 200 OK")) { hasUpdated = true; } -- 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 2c25465bad39f967534ce5b5d4ba4c8d15343578 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 16:35:15 2016 +0200 removed useless tabs --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index e322ab8..6cabf41 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -144,25 +144,25 @@ public class TimerTaskSynchronizer implements DataEventListener { e.printStackTrace(); } //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - boolean hasUpdated = false; - //check for answer from server - for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - //positive answer, synchronization accepted - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; - } + Map<String, List<String>> map = connection.getHeaderFields(); + boolean hasUpdated = false; + //check for answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + //positive answer, synchronization accepted + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } - else { - log.error("Sync error"); - return false; - } + } + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } + else { + log.error("Sync error"); + return false; + } } @Override -- 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 aeb5909defb6d4604b3fac481c43747ad2ffb819 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 17:24:03 2016 +0200 minor typos corrected, set autosyncdelay to every two hours --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 129 +++++++++++---------- 2 files changed, 70 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 499eac9..5d52f63 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -293,7 +293,7 @@ public class JTimerConfig { IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), - IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "3600"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 6cabf41..a15f05f 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected long autoSyncDelay = 1000 * 10 ; //every 2 hours, check for modifications to sync + protected long autoSyncDelay = 1000 * 60 * 60 * 2 ; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; @@ -103,66 +103,68 @@ public class TimerTaskSynchronizer implements DataEventListener { */ public boolean synchronizeSingleTask(TimerTask task) { String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); - String syncURl = task.getSynchronisingURL(); + String syncURL = task.getSynchronisingURL(); String charset = "UTF-8"; HttpURLConnection connection = null; URL url = null; - try { - url = new URL(syncURl); - } catch (MalformedURLException e) { - e.printStackTrace(); - //abort synchronization of this task if the url is wrong - return false; - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - e.printStackTrace(); - //abort synchronization of this task if connection impossible - return false; - } - 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 answer from server - for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - //positive answer, synchronization accepted - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; + if (syncURL != null) { + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + e.printStackTrace(); + //abort synchronization of this task if the url is wrong + return false; + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + //abort synchronization of this task if connection impossible + return false; + } + 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 answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + //positive answer, synchronization accepted + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; + } } } + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } else { + log.error("Sync error"); + return false; + } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } - else { - log.error("Sync error"); - return false; - } + return false; } @Override @@ -185,9 +187,12 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void modifyTask(TimerTask task) { - //when a task is modified, add it to the to sync list (if it isn't already there= + //when a task is modified, add it to the to sync list (if it isn't already there) if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { tasksToSync.add(task); + } } } @@ -250,8 +255,10 @@ public class TimerTaskSynchronizer implements DataEventListener { @Override public void stopTask(TimerTask task) { if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { tasksToSync.add(task); - } + } } } @Override @@ -266,9 +273,11 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void modifyTaskURL(TimerTask task, String newURL) { - if(!tasksToSync.contains(task) && (!task.getSynchronisingURL().equals(null))) { - tasksToSync.add(task); - } + if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { + tasksToSync.add(task); + } } } @Override -- 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 66dee368627d529a1e70998a4995ee88ae463692 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 6 11:25:44 2016 +0200 added the timezone as option in JTimerConfig, updated json creation accordingly --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 9 ++- src/main/java/org/chorem/jtimer/JTimerFactory.java | 3 + .../chorem/jtimer/entities/TimerTaskHelper.java | 8 +-- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 21 ++++-- .../jtimer/ui/report/TimerTaskUpdaterView.java | 78 ++++++++++++++-------- 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 5d52f63..0bc8dc1 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -181,6 +181,12 @@ public class JTimerConfig { public long getIOSyncAutoSyncDelay() { return appConfig.getOptionAsLong(JTimerOption.IO_SYNC_AUTOSYNCDELAY.key);} /** + * Returns timezone for sync + * @return timezone + */ + public String getIOSyncTimeZone() { return appConfig.getOption(JTimerOption.IO_SYNC_TIMEZONE.key);} + + /** * Return user idle time threshold in seconds. * * @return idle time threshold @@ -293,7 +299,8 @@ public class JTimerConfig { IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), - IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "3600"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + IO_SYNC_TIMEZONE("jtimer.io.synchronizer.timezone", "+0600"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index 4a100d5..b0329a5 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.java @@ -114,6 +114,9 @@ public class JTimerFactory { // set delay to saver synchronizer.setAutoSyncDelay(JTimer.config.getIOSyncAutoSyncDelay() * 1000); + //set timezone to synchronizer + synchronizer.setTimezone(JTimer.config.getIOSyncTimeZone()); + } catch (InstantiationException e) { if (log.isErrorEnabled()) { log.error("Can't instanciate class : " + synchronizerClass, e); diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index ffd7c99..a640223 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -341,10 +341,10 @@ public class TimerTaskHelper { * @param task the task to make a JSON from * @return result the string in JSON */ - public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations) { + public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations, String timezone) { Date startDate = task.getAllDaysAndTimes().firstKey(); Date endDate = new Date(); - JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations); + JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations, timezone); return resultingJSON; } @@ -360,7 +360,7 @@ public class TimerTaskHelper { * @param withAnnotations true if annotations included * @return result the string in JSON */ - public static JsonObject taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations) { + public static JsonObject taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { JsonObject responseJSON = new JsonObject(); LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); @@ -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("periodId", dateString); - periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000+0100"); + periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000" + timezone); periodElement.addProperty("periodDuration", entry.getValue()); if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { String annotations = ""; diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index a15f05f..6a1f577 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected long autoSyncDelay = 1000 * 60 * 60 * 2 ; //every 2 hours, check for modifications to sync + protected long autoSyncDelay = 1000 * 10; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; @@ -34,6 +34,9 @@ public class TimerTaskSynchronizer implements DataEventListener { /** Tasks to sync */ protected Collection<TimerTask> tasksToSync; + /** Timezone */ + protected String timezone = "+0100"; + public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); @@ -53,6 +56,16 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** + * Change the timezone + * @param timezone + */ + public void setTimezone(String timezone) { + if (!timezone.isEmpty() && !timezone.equals(null)) { + this.timezone = timezone; + } + } + + /** * Inner Task class to make the automatic sync */ protected class UpdateTask extends java.util.TimerTask { @@ -102,11 +115,11 @@ public class TimerTaskSynchronizer implements DataEventListener { * @return boolean for failure of sync (maybe make it return an int for better treatment of failure) */ public boolean synchronizeSingleTask(TimerTask task) { - String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); + String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false, timezone).toString(); String syncURL = task.getSynchronisingURL(); String charset = "UTF-8"; - HttpURLConnection connection = null; - URL url = null; + HttpURLConnection connection; + URL url; if (syncURL != null) { try { url = new URL(syncURL); diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java index df85ba6..66e165c 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -82,6 +82,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener /** can update */ protected boolean canUpdate; + /** timezone */ + protected String timezone; + /** * UpdaterView constructor. * @@ -98,6 +101,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener this.core = core; this.task = task; setComponent(getMainComponent()); + //default the timezone + timezone = "+0100"; } @@ -335,7 +340,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener // make the JSON Object of information updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), - datePickerTo.getDate(), isIncludingAnnotations()); + datePickerTo.getDate(), isIncludingAnnotations(), timezone); //make it human readable Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonOutput = gson.toJson(updateJson); @@ -384,45 +389,59 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener */ @Action(enabledProperty = "updatingEnabled") public void sendUpdate() { - String syncURl = task.getSynchronisingURL(); + String syncURL = task.getSynchronisingURL(); String charset = "UTF-8"; - String query=""; - try { - query = String.format("json=%s", URLEncoder.encode(updateJson.toString(), charset)); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + if (syncURL != null) { + HttpURLConnection connection= null; + URL url = null; + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + } + + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setRequestProperty("Content-Length", "" + updateJson.toString().length()); + connection.setDoOutput(true); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json" + charset); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + e.printStackTrace(); + } + byte[] postDataBytes = new byte[0]; + try { + postDataBytes = updateJson.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + e.printStackTrace(); + } - URLConnection connection = null; - try { - connection = new URL("http://"+ syncURl).openConnection(); - } catch (IOException e) { - e.printStackTrace(); - } - connection.setDoOutput(true); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json" + charset); - - try (OutputStream output = connection.getOutputStream()) { - output.write(query.getBytes(charset)); - } 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; - } + for (String s : entry.getValue()) { + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; } } + } if (hasUpdated) { core.getData().editTaskLastSync(task, LocalDateTime.now()); - } - else { + } else { log.error("Update error, wrong URL?"); String message = getResourceMap().getString("action.updateError"); String title = getResourceMap().getString("action.updateErrorTitle"); @@ -430,6 +449,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener JOptionPane.ERROR_MESSAGE); } + } } @Override -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm