branch feature/sync updated (6eae5ab -> d31583a)
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 6eae5ab removed a useless toString(), removed unused imports new 5bc2777 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) new 72dbf0a changed syncURL to syncURLList, updated methods for sync accordingly new d31583a logs instead of stacktrace The 3 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 d31583af21d4f1d8ac70b0f57a74894d70613206 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 16:45:51 2016 +0200 logs instead of stacktrace commit 72dbf0a4b0b305d33f0228cd6a406c2fbdeb0086 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 15:56:18 2016 +0200 changed syncURL to syncURLList, updated methods for sync accordingly commit 5bc2777bf66d2db77071bdc2051fd8c5071790a6 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 10:00:30 2016 +0200 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) Summary of changes: .../org/chorem/jtimer/data/DataEventListener.java | 4 +- .../org/chorem/jtimer/data/TimerDataManager.java | 8 +- .../java/org/chorem/jtimer/entities/TimerTask.java | 39 +++-- .../chorem/jtimer/entities/TimerTaskHelper.java | 82 +++++----- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 18 ++- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 167 ++++++++++----------- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 2 +- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 23 +-- .../jtimer/ui/report/TimerTaskUpdaterView.java | 61 +++++--- .../chorem/jtimer/ui/systray/SystrayManager.java | 2 +- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 2 +- .../ProjectsAndTasksRunningCellRenderer.java | 2 +- 12 files changed, 232 insertions(+), 178 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 5bc2777bf66d2db77071bdc2051fd8c5071790a6 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 10:00:30 2016 +0200 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 127 ++++++++++----------- 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 425c1f4..e2e480c 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -35,6 +35,9 @@ public class TimerTaskSynchronizer implements DataEventListener { /** Timezone */ protected String timezone = "+0100"; + /** + * TimerTaskSynchronizer constructor + */ public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); @@ -58,7 +61,7 @@ public class TimerTaskSynchronizer implements DataEventListener { * @param timezone */ public void setTimezone(String timezone) { - if (!timezone.isEmpty() && !timezone.equals(null)) { + if (!timezone.isEmpty()) { this.timezone = timezone; } } @@ -68,6 +71,7 @@ public class TimerTaskSynchronizer implements DataEventListener { */ protected class UpdateTask extends java.util.TimerTask { + @Override public void run() { if (log.isDebugEnabled()) { log.debug("Synchronizer wake up"); @@ -101,7 +105,8 @@ public class TimerTaskSynchronizer implements DataEventListener { } } - tasksToSync = remainingTasks; + tasksToSync.clear(); + tasksToSync.addAll(remainingTasks); } } } @@ -118,64 +123,61 @@ public class TimerTaskSynchronizer implements DataEventListener { String charset = "UTF-8"; HttpURLConnection connection; URL url; - 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.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; - } + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + log.error("URL malformed"); + //abort synchronization of this task if the url is wrong + return false; + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + log.error("couldn't open connection"); + //abort synchronization of this task if connection impossible + return false; + } + 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"); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + log.error("Protocol error."); + } + byte[] postDataBytes = new byte[0]; + try { + postDataBytes = updateJsonString.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + log.error("Problem with encoding"); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + log.error("Problem with the Outputstream"); + } + //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 ("HTTP/1.1 200 OK".equals(s)) { + hasUpdated = true; } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } else { - log.error("Sync error"); - return false; - } } - return false; + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } else { + log.error("Sync error"); + return false; + } } @Override @@ -269,10 +271,8 @@ public class TimerTaskSynchronizer implements DataEventListener { public void stopTask(TimerTask task) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()) { - tasksToSync.add(task); - } + if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())) { + tasksToSync.add(task); } } } @@ -291,11 +291,8 @@ public class TimerTaskSynchronizer implements DataEventListener { public void modifyTaskURL(TimerTask task, String newURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()) { + if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())){ tasksToSync.add(task); - } } } } -- 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 72dbf0a4b0b305d33f0228cd6a406c2fbdeb0086 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 15:56:18 2016 +0200 changed syncURL to syncURLList, updated methods for sync accordingly --- .../org/chorem/jtimer/data/DataEventListener.java | 4 +- .../org/chorem/jtimer/data/TimerDataManager.java | 8 +-- .../java/org/chorem/jtimer/entities/TimerTask.java | 39 +++++++--- .../chorem/jtimer/entities/TimerTaskHelper.java | 82 ++++++++++++---------- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 18 +++-- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 44 ++++++------ src/main/java/org/chorem/jtimer/ui/StatusBar.java | 2 +- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 23 +++--- .../jtimer/ui/report/TimerTaskUpdaterView.java | 48 +++++++++---- .../chorem/jtimer/ui/systray/SystrayManager.java | 2 +- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 2 +- .../ProjectsAndTasksRunningCellRenderer.java | 2 +- 12 files changed, 165 insertions(+), 109 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index 0775617..10e387f 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -159,9 +159,9 @@ public interface DataEventListener extends EventListener { /** * Task url changed * @param task task with url change - * @param newURL new URl to change + * @param newURLList new URlList to change */ - void modifyTaskURL(TimerTask task, String newURL); + void modifyTaskURL(TimerTask task, List<String> newURLList); /** * Task last sync date changed diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index 2cf430a..72fab82 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -413,17 +413,17 @@ public class TimerDataManager { /** * Edit Task URL */ - public void editTaskURL(TimerTask task, String newURL) { + public void editTaskURL(TimerTask task, List<String> newURLList) { // TimerTask newTask = task.clone(); -// newTask.setSynchronisingURL(newURL); +// newTask.setSynchronisingURLList(newURL); // for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { // vetoableDataEventListener.checkSetTaskURL(task, newURL); // } - task.setSynchronisingURL(newURL); + task.setSynchronisingURLList(newURLList); // send notification for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTaskURL(task, newURL); + dataEventListener.modifyTaskURL(task, newURLList); } } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 0143445..6ef8165 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -97,7 +97,7 @@ public class TimerTask implements Cloneable, /** * URL to synchronise task */ - protected String synchronisingURL; + protected List<String> synchronisingURLList; /** * Constructor. */ @@ -107,7 +107,7 @@ public class TimerTask implements Cloneable, allDaysAnnotations = new TreeMap<>(); subTasks = new ArrayList<>(); alerts = new ArrayList<>(); - + synchronisingURLList = new ArrayList<>(); // wrong value to detect bug number = -1; } @@ -241,19 +241,40 @@ public class TimerTask implements Cloneable, public void setLastSync(LocalDateTime syncDate) { this.lastSync = syncDate; } + + /** + * Get task's sync URL List + * @return the URL List + */ + public List<String> getSynchronisingURLList() { return synchronisingURLList; } + /** - * Get task's sync URL - * @return the URL + * Returns one String containing all the URLs for sync, separated by " , " + * @return a string of URLs */ - public String getSynchronisingURL() { return synchronisingURL; } + public String getSynchronizingURLAsString() { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < synchronisingURLList.size(); ++i) { + if (i == synchronisingURLList.size()-1) { + builder.append(synchronisingURLList.get(i)); + } + else { + builder.append(synchronisingURLList.get(i)); + builder.append(" , "); + } + } + String urlListString = builder.toString(); + return urlListString; + } /** - * Sets task's sync URL - * @param synchronisingURL : the sync URL + * Sets task's sync URLList + * @param synchronisingURLList : the sync URL List */ - public void setSynchronisingURL(String synchronisingURL) { - this.synchronisingURL = synchronisingURL; + public void setSynchronisingURLList(List<String> synchronisingURLList) { + this.synchronisingURLList = synchronisingURLList; } + /** * Add task's subtask. * diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 5fbd16a..6c40ed5 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -331,18 +331,20 @@ public class TimerTaskHelper { * Returns a String in JSON format (cf schema (simplified) * with all times and annotations of a task (without subtasks) * @param task the task to make a JSON from + * @param withAnnotations true if annotations included + * @param timezone represents the timezone * @return result the string in JSON */ - public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations, String timezone) { + public static List<JsonObject> taskToJSONFormat(TimerTask task, boolean withAnnotations, String timezone) { Date startDate = task.getAllDaysAndTimes().firstKey(); Date endDate = new Date(); - JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations, timezone); + List<JsonObject> resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations, timezone); return resultingJSON; } /** - * Returns a JSONObject (cf schema (simplified) + * Returns a list of JSONObject (one for each sync URL) * with all times of a task (without subtasks) * in a given period between two dates * with annotations if enabled @@ -350,44 +352,52 @@ public class TimerTaskHelper { * @param startDate the beginning date * @param endDate the end date * @param withAnnotations true if annotations included + * @param timezone represents the timezone * @return result the string in JSON */ - 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(); - - JsonArray periodArray = new JsonArray(); - SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); - if (dates.size() != 0) { - for (SortedMap.Entry<Date, Long> entry : dates.entrySet()) { - //adding id, startDate and duration - //converting Date to LocalDate (to ease the .toString()) - //deal with timezones ? - LocalDate date = entry.getKey().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - 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("periodId", dateString); - periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000" + timezone); - periodElement.addProperty("periodDuration", entry.getValue()); - if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { - String annotations = ""; - for (String s : getAnnotation(task, entry.getKey())) { - annotations = annotations + s + ","; + public static List<JsonObject> taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { + + ArrayList<JsonObject> jsonObjectList = new ArrayList<>(); + + for (String url : task.getSynchronisingURLList()) { + + JsonObject responseJSON = new JsonObject(); + LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + JsonArray periodArray = new JsonArray(); + SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); + if (dates.size() != 0) { + for (SortedMap.Entry<Date, Long> entry : dates.entrySet()) { + //adding id, startDate and duration + //converting Date to LocalDate (to ease the .toString()) + LocalDate date = entry.getKey().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + 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("periodId", dateString); + periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000" + timezone); + periodElement.addProperty("periodDuration", entry.getValue()); + if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { + StringBuilder builder = new StringBuilder(); + for (String s : getAnnotation(task, entry.getKey())) { + builder.append(s); + builder.append(","); + } + String annotations = builder.toString(); + periodElement.addProperty("periodInfo", annotations); + } - //remove trailing comma - annotations = annotations.substring(0, annotations.length()-1); - periodElement.addProperty("periodInfo", annotations); + periodArray.add(periodElement); } - periodArray.add(periodElement); } - } - responseJSON.addProperty("URL", task.getSynchronisingURL()); - responseJSON.addProperty("startDate", startPeriodDate.toString()); - responseJSON.addProperty("endDate", endPeriodDate.toString()); - responseJSON.add("periods", periodArray ); + responseJSON.addProperty("URL", url); + responseJSON.addProperty("startDate", startPeriodDate.toString()); + responseJSON.addProperty("endDate", endPeriodDate.toString()); + responseJSON.add("periods", periodArray); - return responseJSON; + jsonObjectList.add(responseJSON); + } + return jsonObjectList; } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index fdc27e0..a5be57a 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -629,8 +629,13 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, try { - if (syncType.equals("SyncURL:")) { - task.setSynchronisingURL(syncInfo); + if (syncType.equals("SyncURLList:")) { + String[] urlArray = syncInfo.trim().split(" , "); + List<String> urlList = new ArrayList<>(); + for (String url : urlArray) { + urlList.add(url); + } + task.setSynchronisingURLList(urlList); } else if (syncType.equals("LastSync:")) { @@ -1151,7 +1156,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, File synchronisationTaskFile = new File(dataSaveDirectory + File.separator + taskNumber + "." + GTIMER_TASK_EXTENSION + "." + GTIMER_SYNC_EXTENSION); - if (task.getSynchronisingURL() != null) { + if (task.getSynchronisingURLList() != null) { File backupfile = null; try (Writer out = new OutputStreamWriter(new FileOutputStream(synchronisationTaskFile), "ISO-8859-1")) { @@ -1160,9 +1165,8 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write("Format: " + GTIMER_FILE_VERSION + "\n"); //save URL - if(!(task.getSynchronisingURL().equals("")) || task.getSynchronisingURL() !=null) { - String saveURL = task.getSynchronisingURL(); - out.write("SyncURL: " + saveURL + "\n"); + if(task.getSynchronisingURLList() !=null && !(task.getSynchronisingURLList().isEmpty())) { + out.write("SyncURLList: " + task.getSynchronizingURLAsString() + "\n"); } //save last sync (if there is one) if (task.getLastSync() !=null) { @@ -1689,7 +1693,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * {@inheritDoc} */ @Override - public void modifyTaskURL(TimerTask task, String newURL) { + public void modifyTaskURL(TimerTask task, List<String> newURL) { saveSynchronisationInfo(task); } diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index e2e480c..7f48a49 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -1,5 +1,6 @@ package org.chorem.jtimer.io; +import com.google.gson.JsonObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.DataEventListener; @@ -24,7 +25,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 * 10L; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; @@ -90,20 +91,11 @@ public class TimerTaskSynchronizer implements DataEventListener { if (log.isDebugEnabled()){ log.debug("task " + task.getName() + " being synced."); } - //do the sync, store the result - boolean syncDone = synchronizeSingleTask(task); + synchronizeSingleTask(task); //for now doesn't deal with failure in the update, just task already updated if (remainingTasks.contains(task)) { remainingTasks.remove(task); } - - if (syncDone) { - log.debug("Sync done"); - } - else { - log.debug("Sync failed"); - } - } tasksToSync.clear(); tasksToSync.addAll(remainingTasks); @@ -112,14 +104,22 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** - * Makes one synchronization for a task, without annotations by default + * Synchronizes one Task (calls to synchronizeTaskOnURL for each syncURLList element of the task) * * @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, timezone).toString(); - String syncURL = task.getSynchronisingURL(); + public void synchronizeSingleTask(TimerTask task) { + List<JsonObject> jsonObjectList = TimerTaskHelper.taskToJSONFormat(task, false, timezone); + + for (JsonObject object : jsonObjectList) { + synchronizeTaskOnURL(task, object); + } + } + + public boolean synchronizeTaskOnURL(TimerTask task, JsonObject object) { + + String updateJsonString = object.toString(); + String syncURL = object.get("URL").getAsString(); String charset = "UTF-8"; HttpURLConnection connection; URL url; @@ -203,10 +203,8 @@ public class TimerTaskSynchronizer implements DataEventListener { //when a task is modified, add it to the to sync list (if it isn't already there) if(!tasksToSync.contains(task) && (!tasksToSync.isEmpty())) { //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()){ - tasksToSync.add(task); - } + if ((task.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())){ + tasksToSync.add(task); } } } @@ -271,7 +269,7 @@ public class TimerTaskSynchronizer implements DataEventListener { public void stopTask(TimerTask task) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())) { + if ((task.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())) { tasksToSync.add(task); } } @@ -288,10 +286,10 @@ public class TimerTaskSynchronizer implements DataEventListener { * @param task modified task */ @Override - public void modifyTaskURL(TimerTask task, String newURL) { + public void modifyTaskURL(TimerTask task, List<String> newURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())){ + if ((task.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())){ tasksToSync.add(task); } } diff --git a/src/main/java/org/chorem/jtimer/ui/StatusBar.java b/src/main/java/org/chorem/jtimer/ui/StatusBar.java index 657316f..6547693 100644 --- a/src/main/java/org/chorem/jtimer/ui/StatusBar.java +++ b/src/main/java/org/chorem/jtimer/ui/StatusBar.java @@ -288,7 +288,7 @@ public class StatusBar extends JPanel implements DataEventListener { * {@inheritDoc} */ @Override - public void modifyTaskURL(TimerTask task, String newURL) { + public void modifyTaskURL(TimerTask task, List<String> newURLList) { } /* diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index b29b120..bfc8d1d 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -96,7 +96,7 @@ public class TimerTaskEditor extends DialogView { protected JTextField synchronizeURL; /** change listener on sync URl */ - protected DocumentListener URLChangeListener; + protected DocumentListener urlChangeListener; /** change listener on spinners */ protected ChangeListener spinnerListener; @@ -232,7 +232,7 @@ public class TimerTaskEditor extends DialogView { // text change listener on annotationTextArea, titleTextField and SyncURLTextField titleChangeListener = new TextChangeListener(); annotationChangeListener = new TextChangeListener(); - URLChangeListener = new TextChangeListener(); + urlChangeListener = new TextChangeListener(); panel.add(createTitlePanel(), BorderLayout.NORTH); panel.add(createJXMonthView(), BorderLayout.CENTER); @@ -255,7 +255,7 @@ public class TimerTaskEditor extends DialogView { titleText.getDocument().addDocumentListener(titleChangeListener); // task syncronizeURL and listener synchronizeURL = new JTextField("",20); - synchronizeURL.getDocument().addDocumentListener(URLChangeListener); + synchronizeURL.getDocument().addDocumentListener(urlChangeListener); //labels for title and url JLabel titleLabel = new JLabel(getResourceMap().getString("label.title.text")); JLabel URLLabel = new JLabel(getResourceMap().getString("label.syncURL.text")); @@ -575,9 +575,9 @@ public class TimerTaskEditor extends DialogView { titleText.getDocument().addDocumentListener(titleChangeListener); //URL - synchronizeURL.getDocument().removeDocumentListener(URLChangeListener); - synchronizeURL.setText(cloneTask.getSynchronisingURL()); - synchronizeURL.getDocument().addDocumentListener(URLChangeListener); + synchronizeURL.getDocument().removeDocumentListener(urlChangeListener); + synchronizeURL.setText(cloneTask.getSynchronizingURLAsString()); + synchronizeURL.getDocument().addDocumentListener(urlChangeListener); } @@ -591,7 +591,7 @@ public class TimerTaskEditor extends DialogView { isTitleChanged = true; } else if (issuer == annotationChangeListener) { isAnnotationChanged = true; - } else if (issuer == URLChangeListener) { + } else if (issuer == urlChangeListener) { isURLChanged = true; } updateTask(); @@ -633,7 +633,12 @@ public class TimerTaskEditor extends DialogView { // sync URL if (isURLChanged) { - cloneTask.setSynchronisingURL(synchronizeURL.getText()); + String[] urlArray = synchronizeURL.getText().trim().split(" , "); + List<String> urlList = new ArrayList<>(); + for (String url : urlArray) { + urlList.add(url); + } + cloneTask.setSynchronisingURLList(urlList); } dateChanged.add(getSelectedDay().getTime()); @@ -671,7 +676,7 @@ public class TimerTaskEditor extends DialogView { } // url if (isURLChanged) { - dataManager.editTaskURL(task, cloneTask.getSynchronisingURL()); + dataManager.editTaskURL(task, cloneTask.getSynchronisingURLList()); } for (Date date : dateChanged) { 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 8c980a2..f2653ab 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -73,7 +73,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener /** update output view*/ protected JTextArea updateArea; - protected JsonObject updateJson; + protected List<JsonObject> updateJson; /** task to update */ protected TimerTask task; @@ -103,6 +103,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener //default the timezone timezone = "+0100"; + updateJson = new ArrayList<>(); + } /** @@ -342,18 +344,21 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener */ @org.jdesktop.application.Action public void generateUpdate() { + //get the various objects for updates (on several urls) + updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), + datePickerTo.getDate(), isIncludingAnnotations(), timezone); + if (!updateJson.isEmpty()) { + //to make it human readable + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + StringBuilder builder = new StringBuilder(); + for (JsonObject object : updateJson) { + builder.append(gson.toJson(object)); + } + updateArea.setText(builder.toString()); - // make the JSON Object of information - updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), - datePickerTo.getDate(), isIncludingAnnotations(), timezone); - //make it human readable - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String jsonOutput = gson.toJson(updateJson); - - if (updateJson != null) { - updateArea.setText(jsonOutput); - } else { - updateArea.setText(""); + } + else { + updateArea.setText("No data"); } } @@ -390,11 +395,24 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener } /** - * send update + * goes through the Jsons to send and sends them */ @Action(enabledProperty = "updatingEnabled") public void sendUpdate() { - String syncURL = task.getSynchronisingURL(); + for (JsonObject object : updateJson) { + synchronizeTaskOnURL(task, object); + } + } + + + /** + * Sends the update of a task to one url + * @param task task to update + * @param object json of task info + */ + public void synchronizeTaskOnURL(TimerTask task, JsonObject object) { + String updateJsonString = object.toString(); + String syncURL = object.get("URL").getAsString(); String charset = "UTF-8"; if (syncURL != null) { HttpURLConnection connection= null; @@ -412,7 +430,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener connection.setUseCaches(false); connection.setDoInput(true); - connection.setRequestProperty("Content-Length", "" + updateJson.toString().length()); + connection.setRequestProperty("Content-Length", "" + updateJsonString); connection.setDoOutput(true); connection.setRequestProperty("Accept-Charset", charset); connection.setRequestProperty("Content-Type", "application/json" + charset); diff --git a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java index 3e68bd0..707ee26 100644 --- a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java +++ b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java @@ -558,7 +558,7 @@ public class SystrayManager implements ActionListener, DataEventListener, * {@inheritDoc} */ @Override - public void modifyTaskURL(TimerTask task, String newURL) { + public void modifyTaskURL(TimerTask task, List<String> newURLList) { } /* diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java index a8cd3c4..9d0c085 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java @@ -553,7 +553,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements * {@inheritDoc} */ @Override - public void modifyTaskURL(TimerTask task, String newURL) { + public void modifyTaskURL(TimerTask task, List<String> newURLList){ } /* diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java index 3586c1b..3994e9e 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java @@ -305,7 +305,7 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen * {@inheritDoc} */ @Override - public void modifyTaskURL(TimerTask task, String newURL) { + public void modifyTaskURL(TimerTask task, List<String> newURLList) { } /* -- 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 d31583af21d4f1d8ac70b0f57a74894d70613206 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 16:45:51 2016 +0200 logs instead of stacktrace --- .../org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 f2653ab..4537971 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -89,6 +89,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener * * @param application parent reference * @param core core reference + * @param task the task to update */ public TimerTaskUpdaterView(Application application, TimerCore core, TimerTask task) { @@ -420,12 +421,12 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener try { url = new URL(syncURL); } catch (MalformedURLException e) { - e.printStackTrace(); + log.error("Malformed URL"); } try { connection = (HttpURLConnection) url.openConnection(); } catch (IOException e) { - e.printStackTrace(); + log.error("Connection error"); } connection.setUseCaches(false); @@ -437,18 +438,18 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener try { connection.setRequestMethod("POST"); } catch (ProtocolException e) { - e.printStackTrace(); + log.error("Protocol Error"); } byte[] postDataBytes = new byte[0]; try { postDataBytes = updateJson.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + log.error("Unsupported Encoding"); } try { connection.getOutputStream().write(postDataBytes); } catch (IOException e) { - e.printStackTrace(); + log.error("OutputStream error"); } //get the header fields @@ -457,7 +458,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener //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")) { + if ("HTTP/1.1 200 OK".equals(s)) { hasUpdated = true; } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm