branch feature/sync updated (2ba81c9 -> 90cb72f)
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 2ba81c9 corrected sent time (was sending milliseconds instead of seconds) new 4253a46 simplified code receiving new 5dbad0a major change: List<SyncInfo> added to TimerTask to store synchronization info new 30d6c44 checking for response codes and sending error messages to user (if needed) new bb81588 showing last sync associated with url picked in combobox new 995179e added a method to remove a sync URL, added more return codes. new 90cb72f removed the changes in the task editor (url no longer changed here) 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 90cb72f279bb0c71657d89dd37e07cc15e9d8f61 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 17 11:34:00 2016 +0200 removed the changes in the task editor (url no longer changed here) commit 995179ea6c8d16765f49647cbab066614ef29de1 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 17 10:38:34 2016 +0200 added a method to remove a sync URL, added more return codes. commit bb815883028a0be60dc9689979e1fbd0092f75be Author: servantie <servantie.c@gmail.com> Date: Thu Jun 16 15:02:07 2016 +0200 showing last sync associated with url picked in combobox commit 30d6c44aa473105a6392a4336219c6eb159169b3 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 16 10:38:10 2016 +0200 checking for response codes and sending error messages to user (if needed) commit 5dbad0a39dc4a82f59e0b140ec00afed0ddcdc2b Author: servantie <servantie.c@gmail.com> Date: Tue Jun 14 12:00:08 2016 +0200 major change: List<SyncInfo> added to TimerTask to store synchronization info updated parsing/saving methods to adapt to SyncInfo commit 4253a462cc740d328e147ebe8896944305cce47c Author: servantie <servantie.c@gmail.com> Date: Tue Jun 14 11:43:38 2016 +0200 simplified code receiving Summary of changes: .../org/chorem/jtimer/data/DataEventListener.java | 15 +-- .../org/chorem/jtimer/data/TimerDataManager.java | 37 ++---- .../java/org/chorem/jtimer/entities/SyncInfo.java | 85 +++++++++++++ .../java/org/chorem/jtimer/entities/TimerTask.java | 128 +++++++++++++++---- .../chorem/jtimer/entities/TimerTaskHelper.java | 70 ++++++----- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 115 ++++++++--------- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 43 +++---- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 20 +-- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 86 +------------ .../jtimer/ui/report/TimerTaskUpdaterView.java | 138 +++++++++++++-------- .../chorem/jtimer/ui/systray/SystrayManager.java | 20 +-- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 20 +-- .../ProjectsAndTasksRunningCellRenderer.java | 20 +-- .../resources/TimerTaskUpdaterView.properties | 12 +- .../resources/TimerTaskUpdaterView_fr.properties | 10 +- 15 files changed, 441 insertions(+), 378 deletions(-) create mode 100644 src/main/java/org/chorem/jtimer/entities/SyncInfo.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 4253a462cc740d328e147ebe8896944305cce47c Author: servantie <servantie.c@gmail.com> Date: Tue Jun 14 11:43:38 2016 +0200 simplified code receiving --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 17 +++++---------- .../jtimer/ui/report/TimerTaskUpdaterView.java | 24 ++++++++-------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 557a96a..03b25c5 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -152,19 +152,12 @@ public class TimerTaskSynchronizer implements DataEventListener { connection.setRequestMethod("POST"); postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); - //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - //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)) { + int code = connection.getResponseCode(); + if (code == 200) { hasUpdated = true; - } - else { - log.info("Error" + s); - } - } + } + else { + log.info("Error"); } } catch (MalformedURLException e) { log.error("URL malformed"); 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 24b697f..2bdd40a 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -462,21 +462,15 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, connection.setRequestMethod("POST"); postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); - //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - //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.startsWith("HTTP/1.1 2")){ - log.info("OK git" + s); - hasUpdated = true; - } - else if ("HTTP/1.1 400 Bad Request".equals(s)) { - log.info("Bad Request (400)"); - } - log.info(s); - } + int code = connection.getResponseCode(); + if (code == 200) { + hasUpdated = true; + } + else if (code == 400) { + log.error("Bad Request"); + } + else { + log.info("Error"); } connection.disconnect(); } catch (MalformedURLException e) { -- 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 5dbad0a39dc4a82f59e0b140ec00afed0ddcdc2b Author: servantie <servantie.c@gmail.com> Date: Tue Jun 14 12:00:08 2016 +0200 major change: List<SyncInfo> added to TimerTask to store synchronization info updated parsing/saving methods to adapt to SyncInfo --- .../org/chorem/jtimer/data/DataEventListener.java | 15 +-- .../org/chorem/jtimer/data/TimerDataManager.java | 37 ++----- .../java/org/chorem/jtimer/entities/SyncInfo.java | 85 +++++++++++++++ .../java/org/chorem/jtimer/entities/TimerTask.java | 112 +++++++++++++++----- .../chorem/jtimer/entities/TimerTaskHelper.java | 70 +++++++------ .../chorem/jtimer/io/GTimerIncrementalSaver.java | 115 +++++++++++---------- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 23 ++--- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 20 +--- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 53 +--------- .../jtimer/ui/report/TimerTaskUpdaterView.java | 34 +++--- .../chorem/jtimer/ui/systray/SystrayManager.java | 20 +--- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 20 +--- .../ProjectsAndTasksRunningCellRenderer.java | 20 +--- 13 files changed, 326 insertions(+), 298 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index 10e387f..cead109 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -22,7 +22,6 @@ package org.chorem.jtimer.data; -import java.time.LocalDateTime; import java.util.*; import org.chorem.jtimer.entities.TimerProject; @@ -157,17 +156,11 @@ public interface DataEventListener extends EventListener { void dataLoaded(Collection<TimerProject> projects); /** - * Task url changed - * @param task task with url change - * @param newURLList new URlList to change + * SyncInfo changed + * @param task + * @param syncURL String */ - void modifyTaskURL(TimerTask task, List<String> newURLList); + void changeSyncInfo(TimerTask task, String syncURL); - /** - * Task last sync date changed - * @param task task with date change - * @param newDate new synchronisation date - */ - void modifyTaskSyncDate(TimerTask task, LocalDateTime newDate); } diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index 72fab82..09c6c83 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -410,32 +410,6 @@ public class TimerDataManager { } } - /** - * Edit Task URL - */ - public void editTaskURL(TimerTask task, List<String> newURLList) { - -// TimerTask newTask = task.clone(); -// newTask.setSynchronisingURLList(newURL); -// for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { -// vetoableDataEventListener.checkSetTaskURL(task, newURL); -// } - task.setSynchronisingURLList(newURLList); - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTaskURL(task, newURLList); - } - } - - /** - * Edit Task last synchronisation date - */ - public void editTaskLastSync(TimerTask task, LocalDateTime newDate) { - task.setLastSync(newDate); - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTaskSyncDate(task, newDate); - } - } /** * Move task. @@ -666,4 +640,15 @@ public class TimerDataManager { return foundTask; } + + /** + * Edit Synchronisation Information + */ + public void changeSyncInfo(TimerTask task, String url) { + task.addSyncInfo(url, LocalDateTime.MIN, true); + + for (DataEventListener dataEventListener : dataEventListeners) { + dataEventListener.changeSyncInfo(task, url); + } + } } diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java new file mode 100644 index 0000000..d5d9e00 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -0,0 +1,85 @@ +package org.chorem.jtimer.entities; + + + +import java.time.LocalDateTime; + +/** + * Class to structure synchronization info + * Created by servantie on 13/06/16. + */ +public class SyncInfo { + String syncURL; + LocalDateTime lastSync; + boolean isActiveSync; + + /** + * constructor with all parameters + * @param syncURL the url to sync to + * @param lastSync the last time it was synced successfully + * @param isActiveSync if true, will sync auto + */ + public SyncInfo(String syncURL, LocalDateTime lastSync, boolean isActiveSync) { + this.syncURL = syncURL; + this.lastSync = lastSync; + this.isActiveSync = isActiveSync; + } + + /** + * Constructor with just the url, at creation the sync is considered active by default + * @param syncURL the url to sync to + */ + public SyncInfo(String syncURL) { + this.syncURL = syncURL; + this.isActiveSync = true; + } + + /** + * Returns the time of the last sync + * @return LocalDateTime + */ + public LocalDateTime getLastSync() { + return lastSync; + } + + /** + * Returns a boolean if sync should send to this url + * @return boolean + */ + public boolean getActiveSync() { + return isActiveSync; + } + + /** + * Sets the isActiveSync boolean + * @param isActive boolean + */ + public void setActiveSync(boolean isActive) { + isActiveSync = isActive; + } + + /** + * Set the syncURL + * @param syncURL String + */ + public void setSyncURL(String syncURL) { + this.syncURL = syncURL; + } + + /** + * Get the syncURL + * @return String + */ + public String getSyncURL() { + return syncURL; + } + + /** + * Set Sync time + * @param syncTime LocalDateTime + */ + public void setLastSync(LocalDateTime syncTime) { + lastSync = syncTime; + } +} + diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 35ff460..67d0293 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -95,9 +95,10 @@ public class TimerTask implements Cloneable, protected LocalDateTime lastSync; /** - * URL to synchronise task + * Synchronisation Info */ - protected List<String> synchronisingURLList; + protected List<SyncInfo> synchronisingInfoList; + /** * Constructor. */ @@ -107,7 +108,7 @@ public class TimerTask implements Cloneable, allDaysAnnotations = new TreeMap<>(); subTasks = new ArrayList<>(); alerts = new ArrayList<>(); - synchronisingURLList = new ArrayList<>(); + synchronisingInfoList = new ArrayList<>(); // wrong value to detect bug number = -1; } @@ -229,24 +230,59 @@ public class TimerTask implements Cloneable, } /** - * Get task's last sync + * Get task's last sync time associated to the url + * If there is no last sync, will return a very far past time + * @param urlString the url to get the last sync from * @return the date of the sync */ - public LocalDateTime getLastSync() { return lastSync; } + public LocalDateTime getLastSync(String urlString) { + //to avoid null, a default time to return if errors + LocalDateTime resultTime = LocalDateTime.MIN; + if (!synchronisingInfoList.isEmpty()) { + for(SyncInfo sync : synchronisingInfoList) { + if (urlString.equals(sync.getSyncURL())) { + resultTime = sync.lastSync; + } + } + } + return resultTime; + } /** - * Sets task's last sync + * Sets task's last sync time on one url + * (if the url doesn't exist in the task's sync info, adds it) * @param syncDate : date of the sync - */ - public void setLastSync(LocalDateTime syncDate) { - this.lastSync = syncDate; + * @param syncURL : the url that has a change of syncdate + */ + public void setLastSync(LocalDateTime syncDate, String syncURL) { + boolean urlinList = false; + if(!synchronisingInfoList.isEmpty()) { + for (SyncInfo sync : synchronisingInfoList) { + if (sync.syncURL.equals(syncURL)) { + sync.setLastSync(syncDate); + urlinList = true; + } + } + } + if (!urlinList) { + synchronisingInfoList.add(new SyncInfo(syncURL, syncDate, true)); + } } /** * Get task's sync URL List + * returns an empty list if there is no info * @return the URL List */ - public List<String> getSynchronisingURLList() { return synchronisingURLList; } + public List<String> getSynchronizingURLList() { + List<String> resutList = new ArrayList<>(); + if (!synchronisingInfoList.isEmpty()) { + for (SyncInfo sync : synchronisingInfoList) { + resutList.add(sync.getSyncURL()); + } + } + return resutList; + } /** * Returns one String containing all the URLs for sync, separated by " , " @@ -254,12 +290,12 @@ public class TimerTask implements Cloneable, */ 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)); + for (int i = 0; i < synchronisingInfoList.size(); ++i) { + if (i == synchronisingInfoList.size()-1) { + builder.append(synchronisingInfoList.get(i).getSyncURL()); } else { - builder.append(synchronisingURLList.get(i)); + builder.append(synchronisingInfoList.get(i).getSyncURL()); builder.append(" , "); } } @@ -268,25 +304,53 @@ public class TimerTask implements Cloneable, } /** - * Sets task's sync URLList - * @param synchronisingURLList : the sync URL List - */ - public void setSynchronisingURLList(List<String> synchronisingURLList) { - this.synchronisingURLList = synchronisingURLList; - } - - /** * Add one URL to the task's syncURLList * @param urlToAdd : the url to add */ public void addURLToSyncList(String urlToAdd) { //no need to have redundant elements - if (!synchronisingURLList.contains(urlToAdd)) { - synchronisingURLList.add(urlToAdd); + if (!getSynchronizingURLAsString().contains(urlToAdd)) { + synchronisingInfoList.add(new SyncInfo(urlToAdd)); } } /** + * Adds a new synchronization info if the url isn't already present + * @param url a string + * @param time a LocalDateTime + * @param isActive a boolean for activity (true to sync auto) + */ + public void addSyncInfo(String url, LocalDateTime time, boolean isActive) { + if (!getSynchronizingURLList().contains(url)) { + synchronisingInfoList.add(new SyncInfo(url, time, isActive)); + } + } + + /** + * Returns all the synchronization info + * @return a list of TimerTask.SyncInfo + */ + public List<SyncInfo> getSynchronizingInfoList() { + return synchronisingInfoList; + } + + + /** + * Returns the sync info matching a url + * @param urlString + */ + public SyncInfo getSynchronizingInfo(String urlString) { + for (SyncInfo sync : synchronisingInfoList) { + if (sync.getSyncURL().equals(urlString)) { + return sync; + } + } + SyncInfo errorInfo = new SyncInfo("error"); + return errorInfo; + + } + + /** * Add task's subtask. * * Also add parent reference. diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 4dbf343..5f77e03 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -359,44 +359,46 @@ public class TimerTaskHelper { 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("id", dateString); - periodElement.addProperty("startDate", dateString + "T00:00:00" + timezone); - periodElement.addProperty("duration", entry.getValue()/1000); - 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("info", annotations); + for (String url : task.getSynchronizingURLList()) { + boolean isActive = task.getSynchronizingInfo(url).getActiveSync(); + if (isActive) { + 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("id", dateString); + periodElement.addProperty("startDate", dateString + "T00:00:00" + timezone); + periodElement.addProperty("duration", entry.getValue()/1000); + 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("info", annotations); + } + periodArray.add(periodElement); } - periodArray.add(periodElement); } - } - responseJSON.addProperty("URL", url); - responseJSON.addProperty("startDate", startPeriodDate.toString() + "T00:00:00" + timezone); - responseJSON.addProperty("endDate", endPeriodDate.toString() + "T00:00:00" + timezone); - responseJSON.add("periods", periodArray); + responseJSON.addProperty("URL", url); + responseJSON.addProperty("startDate", startPeriodDate.toString() + "T00:00:00" + timezone); + responseJSON.addProperty("endDate", endPeriodDate.toString() + "T00:00:00" + timezone); + responseJSON.add("periods", periodArray); - jsonObjectList.add(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 a5be57a..aaf83d4 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -43,7 +43,6 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -67,6 +66,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.data.DataViolationException; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerAlert.Type; import org.chorem.jtimer.entities.TimerProject; @@ -618,51 +618,52 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, try (BufferedReader parseIn = new BufferedReader(new FileReader(syncTaskFile))) { - // first line : "format: 1.2" + //format line String line = parseIn.readLine(); while ((line = parseIn.readLine()) != null) { line = line.trim(); - if ((!line.isEmpty()) && (line.contains(" "))) { - String syncType = line.substring(0, line.indexOf(' ')); - String syncInfo = line.substring(line.indexOf(' ') +1, line.length()); - - - try { - 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:")) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"); - LocalDateTime date = LocalDateTime.parse(syncInfo, formatter); - task.setLastSync(date); + if ((!line.isEmpty())) { + String[] urlArray = line.split(" "); + //if there is no lastSyncTime + if (urlArray.length == 2) { + if ("true".equals(urlArray[1])) { + task.addSyncInfo(urlArray[0], LocalDateTime.MIN, true); } else { - if (log.isWarnEnabled()) { - log.warn("Unknown synchronisation type " + syncType); - } - } - }catch (DateTimeParseException e) { - if (log.isErrorEnabled()) { - log.error("Can't parse " + syncInfo - + " as synchronisation date"); + task.addSyncInfo(urlArray[0], LocalDateTime.MIN, false); } } - + //else if there is lastSyncTime + else if (urlArray.length == 3) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"); + LocalDateTime date = LocalDateTime.parse(urlArray[2], formatter); + if ("true".equals(urlArray[1])) { + task.addSyncInfo(urlArray[0], date, true); + } else { + task.addSyncInfo(urlArray[0], date, false); + } + } + } + else { + if (log.isWarnEnabled()) { + log.warn("Unknown synchronization type " + line); + } } + } + + } + } + else { + if (log.isDebugEnabled()) { + log.debug("Synchronisation information not found for task " + task.getName()); } } - } + /** * Find task alert and load it. * @@ -1149,14 +1150,12 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * @param task task to save annotation */ protected void saveSynchronisationInfo(TimerTask task) { - - int taskNumber = task.getNumber(); File synchronisationTaskFile = new File(dataSaveDirectory + File.separator + taskNumber + "." + GTIMER_TASK_EXTENSION + "." + GTIMER_SYNC_EXTENSION); - if (task.getSynchronisingURLList() != null) { + if ((task.getSynchronizingURLList() != null) || (!task.getSynchronizingURLList().isEmpty())) { File backupfile = null; try (Writer out = new OutputStreamWriter(new FileOutputStream(synchronisationTaskFile), "ISO-8859-1")) { @@ -1164,16 +1163,27 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, backupfile = makeBackupFile(synchronisationTaskFile); out.write("Format: " + GTIMER_FILE_VERSION + "\n"); - //save URL - if(task.getSynchronisingURLList() !=null && !(task.getSynchronisingURLList().isEmpty())) { - out.write("SyncURLList: " + task.getSynchronizingURLAsString() + "\n"); - } - //save last sync (if there is one) - if (task.getLastSync() !=null) { - String saveLastSync = task.getLastSync().toString(); - out.write("LastSync: " + saveLastSync + "\n"); + //start Sync Save + out.write("SyncInfo:\n"); + //loop across SyncInfo + for (SyncInfo sync : task.getSynchronizingInfoList()) { + //write url + out.write(sync.getSyncURL() + " "); + //write isActive + if (sync.getActiveSync()) { + out.write("true "); + } + else { + out.write("false "); + } + //write lastsync + if (sync.getLastSync().isAfter(LocalDateTime.MIN)) { + out.write(sync.getLastSync().toString() + "\n"); + } + else { + out.write("\n"); + } } - deleteBackupFile(backupfile); } catch (IOException e) { if (log.isErrorEnabled()) { @@ -1323,6 +1333,11 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // do nothing } + @Override + public void changeSyncInfo(TimerTask task, String syncURL) { + saveSynchronisationInfo(task); + } + /* * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) */ @@ -1432,6 +1447,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // Potentiellement aussi lors d'un move. saveTaskAnnotation(task); saveAlerts(task); + saveSynchronisationInfo(task); // fix a bug with the gtimer subtask // save format du to composed task name @@ -1689,18 +1705,5 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, List<TimerTask> otherTasks) { } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskURL(TimerTask task, List<String> newURL) { - saveSynchronisationInfo(task); - } - - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskSyncDate(TimerTask task, LocalDateTime newDate) { 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 03b25c5..b4fb1a1 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -116,7 +116,7 @@ public class TimerTaskSynchronizer implements DataEventListener { //sync successful -> change the last sync time if (successfulSync) { log.debug("Sync successful on " + object.get("URL").getAsString()); - task.setLastSync(LocalDateTime.now()); + task.setLastSync(LocalDateTime.now(), object.get("URL").getAsString()); } //-> do not change last sync time else { @@ -158,6 +158,7 @@ public class TimerTaskSynchronizer implements DataEventListener { } else { log.info("Error"); + } } catch (MalformedURLException e) { log.error("URL malformed"); @@ -194,7 +195,7 @@ 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.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())){ + if ((!task.getSynchronizingInfoList().isEmpty()) && (!task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); } } @@ -260,7 +261,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.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())) { + if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { tasksToSync.add(task); } } @@ -271,23 +272,13 @@ 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, List<String> newURL) { + public void changeSyncInfo(TimerTask task, String syncURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if ((task.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())){ - tasksToSync.add(task); + if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { + tasksToSync.add(task); } } } - - @Override - public void modifyTaskSyncDate(TimerTask task, LocalDateTime newDate) { - - } } diff --git a/src/main/java/org/chorem/jtimer/ui/StatusBar.java b/src/main/java/org/chorem/jtimer/ui/StatusBar.java index 6547693..407a3dc 100644 --- a/src/main/java/org/chorem/jtimer/ui/StatusBar.java +++ b/src/main/java/org/chorem/jtimer/ui/StatusBar.java @@ -23,7 +23,6 @@ package org.chorem.jtimer.ui; import java.awt.GridLayout; -import java.time.LocalDateTime; import java.util.Collection; import java.util.Date; import java.util.List; @@ -148,6 +147,11 @@ public class StatusBar extends JPanel implements DataEventListener { modifyTask(null); } + @Override + public void changeSyncInfo(TimerTask task, String syncURL) { + + } + /* * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) */ @@ -284,18 +288,4 @@ public class StatusBar extends JPanel implements DataEventListener { List<TimerTask> otherTasks) { } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskURL(TimerTask task, List<String> newURLList) { - - } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskSyncDate(TimerTask task, LocalDateTime newDate) { - - } } diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index bfc8d1d..95ee592 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -92,12 +92,6 @@ public class TimerTaskEditor extends DialogView { /** annotation textarea */ protected JTextArea annotationText; - /** task sync URL */ - protected JTextField synchronizeURL; - - /** change listener on sync URl */ - protected DocumentListener urlChangeListener; - /** change listener on spinners */ protected ChangeListener spinnerListener; @@ -121,9 +115,6 @@ public class TimerTaskEditor extends DialogView { /** did the modified annotation ? */ protected boolean isAnnotationChanged; - /** was the url modified ?*/ - protected boolean isURLChanged; - /** * days modified: You can modify any number of days before you apply changes, * this set keep track of days modified (for time, annotations or title). @@ -232,7 +223,6 @@ public class TimerTaskEditor extends DialogView { // text change listener on annotationTextArea, titleTextField and SyncURLTextField titleChangeListener = new TextChangeListener(); annotationChangeListener = new TextChangeListener(); - urlChangeListener = new TextChangeListener(); panel.add(createTitlePanel(), BorderLayout.NORTH); panel.add(createJXMonthView(), BorderLayout.CENTER); @@ -253,34 +243,18 @@ public class TimerTaskEditor extends DialogView { // task title and listener titleText = new JTextField("", 20); // prevent too long task names titleText.getDocument().addDocumentListener(titleChangeListener); - // task syncronizeURL and listener - synchronizeURL = new JTextField("",20); - 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")); panel.add(titleLabel); panel.add(titleText); - panel.add(synchronizeURL); - panel.add(URLLabel); - - JLabel largerLabel = titleLabel.getText().length() < URLLabel.getText().length() ? URLLabel : titleLabel; layout.putConstraint(SpringLayout.NORTH, titleLabel, 2, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.WEST, titleLabel, 2, SpringLayout.WEST, panel); layout.putConstraint(SpringLayout.NORTH, titleText, 2, SpringLayout.NORTH, panel); - layout.putConstraint(SpringLayout.WEST, titleText, 2, SpringLayout.EAST, largerLabel); + layout.putConstraint(SpringLayout.WEST, titleText, 2, SpringLayout.EAST, panel); - layout.putConstraint(SpringLayout.NORTH, URLLabel, 2, SpringLayout.SOUTH, titleText); - layout.putConstraint(SpringLayout.WEST, URLLabel, 2, SpringLayout.WEST, largerLabel); - - layout.putConstraint(SpringLayout.NORTH, synchronizeURL, 2, SpringLayout.SOUTH, titleText); - layout.putConstraint(SpringLayout.WEST, synchronizeURL, 2, SpringLayout.EAST, largerLabel); - - layout.putConstraint(SpringLayout.SOUTH, panel, 2, SpringLayout.SOUTH, synchronizeURL); - layout.putConstraint(SpringLayout.EAST, panel, 2, SpringLayout.EAST, synchronizeURL); return panel; @@ -573,12 +547,6 @@ public class TimerTaskEditor extends DialogView { titleText.setText(cloneTask.getName()); titleText.setCaretPosition(0); titleText.getDocument().addDocumentListener(titleChangeListener); - - //URL - synchronizeURL.getDocument().removeDocumentListener(urlChangeListener); - synchronizeURL.setText(cloneTask.getSynchronizingURLAsString()); - synchronizeURL.getDocument().addDocumentListener(urlChangeListener); - } /** @@ -591,10 +559,8 @@ public class TimerTaskEditor extends DialogView { isTitleChanged = true; } else if (issuer == annotationChangeListener) { isAnnotationChanged = true; - } else if (issuer == urlChangeListener) { - isURLChanged = true; + updateTask(); } - updateTask(); } /** @@ -631,16 +597,6 @@ public class TimerTaskEditor extends DialogView { cloneTask.setName(titleText.getText()); } - // sync URL - if (isURLChanged) { - 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()); setDataChanged(true); @@ -674,11 +630,6 @@ public class TimerTaskEditor extends DialogView { if (isTitleChanged) { dataManager.editTask(task, cloneTask.getName()); } - // url - if (isURLChanged) { - dataManager.editTaskURL(task, cloneTask.getSynchronisingURLList()); - } - for (Date date : dateChanged) { if (log.isDebugEnabled()) { log.debug("Applying changes on: " + date); 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 2bdd40a..91bd5fe 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -42,8 +42,6 @@ import javax.swing.event.DocumentListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.*; @@ -80,9 +78,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** task in json format (1/synchronizing url) */ protected List<JsonObject> updateJson; - /** list of URLs to sync to */ - protected List<String> urlSyncList; - /** ComboBox of URLs */ protected JComboBox<String> urlComboBox; @@ -111,7 +106,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, this.core = core; this.task = task; timezone = "+01:00"; - urlSyncList = task.getSynchronisingURLList(); setComponent(getMainComponent()); @@ -197,16 +191,16 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); //display the lastSyncDate - JLabel lastSyncDate = new JLabel(getResourceMap().getString("lastUpdateLabel")); +// JLabel lastSyncDate = new JLabel(getResourceMap().getString("lastUpdateLabel")); //if there has been an update before, display its date - LocalDateTime lastSyncTime = task.getLastSync(); - if (lastSyncTime != null) { - JLabel lastUpdate = new JLabel(lastSyncTime.toString()); - panelOption.add(lastSyncDate, new GridBagConstraints(1, 2, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 1, 1), 0, 0)); - panelOption.add(lastUpdate, new GridBagConstraints(2, 2, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); - } +// LocalDateTime lastSyncTime = task.getLastSync(); +// if (lastSyncTime != null) { +// JLabel lastUpdate = new JLabel(lastSyncTime.toString()); +// panelOption.add(lastSyncDate, new GridBagConstraints(1, 2, 1, 1, 0, 0, +// GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 1, 1), 0, 0)); +// panelOption.add(lastUpdate, new GridBagConstraints(2, 2, 1, 1, 0, 0, +// GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); +// } //display the various urls to sync to in a combobox to choose which one will be updated JLabel urlcomboBoxLabel = new JLabel(getResourceMap().getString("urlComboLabel")); @@ -215,7 +209,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, urlComboBox.setEditable(true); urlComboBox.addActionListener(this); //add the urls to the combobox - for (String url : urlSyncList) { + for (String url : task.getSynchronizingURLList()) { urlComboBox.addItem(url); } panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1,3,1,1,0,0, @@ -483,7 +477,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, log.error("Problem with the connection"); } if (hasUpdated) { - core.getData().editTaskLastSync(task, LocalDateTime.now()); + task.setLastSync(LocalDateTime.now(),syncURL); } else { String message = getResourceMap().getString("action.updateError"); String title = getResourceMap().getString("action.updateErrorTitle"); @@ -534,13 +528,13 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, */ public void itemAdded(){ String urlToAdd = (String) urlComboBox.getSelectedItem(); - if ((!urlToAdd.isEmpty()) && (!urlSyncList.contains(urlToAdd))) { + if ((!urlToAdd.isEmpty()) && (!task.getSynchronizingURLList().contains(urlToAdd))) { urlComboBox.addItem(urlToAdd); - task.addURLToSyncList(urlToAdd); + task.addSyncInfo(urlToAdd, LocalDateTime.MIN, true); + core.getData().changeSyncInfo(task, urlToAdd); } } - @Override public void actionPerformed(ActionEvent actionEvent) { itemAdded(); 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 707ee26..c89e455 100644 --- a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java +++ b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java @@ -32,7 +32,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; -import java.time.LocalDateTime; import java.util.Collection; import java.util.Date; import java.util.List; @@ -222,6 +221,11 @@ public class SystrayManager implements ActionListener, DataEventListener, } + @Override + public void changeSyncInfo(TimerTask task, String syncURL) { + + } + /* * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) */ @@ -554,18 +558,4 @@ public class SystrayManager implements ActionListener, DataEventListener, public void windowOpened(WindowEvent e) { } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskURL(TimerTask task, List<String> newURLList) { - - } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskSyncDate(TimerTask task, LocalDateTime newDate) { - - } } 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 9d0c085..918d5dd 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java @@ -22,7 +22,6 @@ package org.chorem.jtimer.ui.treetable; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -410,6 +409,11 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements }); } + @Override + public void changeSyncInfo(TimerTask task, String syncURL) { + + } + /* * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) */ @@ -549,18 +553,4 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements public void preMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskURL(TimerTask task, List<String> newURLList){ - - } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskSyncDate(TimerTask task, LocalDateTime newDate) { - - } } 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 3994e9e..a3b756c 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java @@ -27,7 +27,6 @@ import java.awt.Image; import java.awt.Rectangle; import java.awt.image.ImageObserver; import java.net.URL; -import java.time.LocalDateTime; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -184,6 +183,11 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen } + @Override + public void changeSyncInfo(TimerTask task, String syncURL) { + + } + /* * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) */ @@ -301,18 +305,4 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen public void setAnnotation(TimerTask task, Date date, String annotation) { } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskURL(TimerTask task, List<String> newURLList) { - - } - /* - * {@inheritDoc} - */ - @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 30d6c44aa473105a6392a4336219c6eb159169b3 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 16 10:38:10 2016 +0200 checking for response codes and sending error messages to user (if needed) --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 1 - .../jtimer/ui/report/TimerTaskUpdaterView.java | 45 +++++++++++++++------- .../resources/TimerTaskUpdaterView.properties | 7 +++- .../resources/TimerTaskUpdaterView_fr.properties | 9 ++++- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index b4fb1a1..0fececb 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -158,7 +158,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } else { log.info("Error"); - } } catch (MalformedURLException e) { log.error("URL malformed"); 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 91bd5fe..263ded8 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -444,6 +444,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, URL url; byte[] postDataBytes; boolean hasUpdated = false; + String message = ""; + String title = getResourceMap().getString("action.updateErrorTitle"); try { url = new URL(syncURL); connection = (HttpURLConnection) url.openConnection(); @@ -457,31 +459,45 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); int code = connection.getResponseCode(); - if (code == 200) { + if ((code == 200) || (code == 2001) || (code == 202)) { hasUpdated = true; } else if (code == 400) { - log.error("Bad Request"); + log.debug("Bad Request"); + message = getResourceMap().getString("action.update400"); + } + else if (code == 404) { + log.debug("Not Found"); + message = getResourceMap().getString("action.update404"); + } + else if (code == 500) { + log.debug("Server Error"); + message = getResourceMap().getString("action.update500"); } else { - log.info("Error"); + log.debug("Error"); + message = getResourceMap().getString("action.updateError"); } connection.disconnect(); + } catch (MalformedURLException e) { - log.error("URL malformed"); + log.debug("URL malformed"); + message = getResourceMap().getString("action.updateURLError"); } catch (ProtocolException e) { - log.error("Protocol error."); + log.debug("Protocol error."); + message = getResourceMap().getString("action.updateProtocolError"); } catch (UnsupportedEncodingException e) { - log.error("Problem with encoding"); + log.debug("Problem with encoding"); + message = getResourceMap().getString("action.updateEncodingError"); } catch (IOException e) { - log.error("Problem with the connection"); - } - if (hasUpdated) { + log.debug("Problem with the connection"); + message = getResourceMap().getString("action.updateError"); + } finally { + if (hasUpdated) { task.setLastSync(LocalDateTime.now(),syncURL); - } else { - String message = getResourceMap().getString("action.updateError"); - String title = getResourceMap().getString("action.updateErrorTitle"); - errorBox(message, title); + } else if (!message.isEmpty()){ + errorBox(message, title); + } } //advise that it's done, to grey-out the send sync button boolean oldValue = canUpdate; @@ -498,6 +514,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, { JOptionPane.showMessageDialog(null, errorMessage, titleBar, JOptionPane.ERROR_MESSAGE); } + @Override public void changedUpdate(DocumentEvent e) { documentChanged(); @@ -524,7 +541,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** * when an item is added to the list, - * add it to the urls + * add it to the url displayed, and to the syncInfo of the task */ public void itemAdded(){ String urlToAdd = (String) urlComboBox.getSelectedItem(); 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 dca4916..70ef7be 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 @@ -56,5 +56,10 @@ closeView.Action.text = &Close closeView.Action.icon = dialog-close.png closeView.Action.shortDescription = Close -action.updateError = Synchronisation failed, check URL ? +action.updateError = Synchronisation failed +action.update400 = Bad Request +action.update404 = Not found +action.update500 = Server error action.updateErrorTitle = Synchronisation error +action.updateEncodingError = Encoding error +action.updateURLError = URL error \ No newline at end of file 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 9dd1b73..329a948 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 @@ -56,5 +56,10 @@ closeView.Action.text = &Fermer closeView.Action.icon = dialog-close.png closeView.Action.shortDescription = Fermer -action.updateError = Erreur de synchronisation, v\u00E9rifier l'URL ? -action.updateErrorTitle = Erreur de synchronisation \ No newline at end of file +action.updateError = Probl\u00E8me avec la connexion +action.updateErrorTitle = Erreur de synchronisation +action.update400 = Mauvaise requ\u00EAte +action.update404 = Mauvaise URL +action.update500 = Erreur du serveur +action.updateEncodingError = Erreur d'encodage +action.updateURLError = Erreur d'URL \ 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 bb815883028a0be60dc9689979e1fbd0092f75be Author: servantie <servantie.c@gmail.com> Date: Thu Jun 16 15:02:07 2016 +0200 showing last sync associated with url picked in combobox --- .../jtimer/ui/report/TimerTaskUpdaterView.java | 55 +++++++++++++++------- .../resources/TimerTaskUpdaterView.properties | 7 +-- .../resources/TimerTaskUpdaterView_fr.properties | 1 + 3 files changed, 42 insertions(+), 21 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 263ded8..3b6058f 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerTask; import org.jdesktop.application.*; import org.jdesktop.application.Action; @@ -81,6 +82,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** ComboBox of URLs */ protected JComboBox<String> urlComboBox; + /** LastSync */ + protected JLabel lastUpdate; + /** task to update */ protected TimerTask task; @@ -190,19 +194,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, panelOption.add(checkIncludesAnnotations, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - //display the lastSyncDate -// JLabel lastSyncDate = new JLabel(getResourceMap().getString("lastUpdateLabel")); - //if there has been an update before, display its date -// LocalDateTime lastSyncTime = task.getLastSync(); -// if (lastSyncTime != null) { -// JLabel lastUpdate = new JLabel(lastSyncTime.toString()); -// panelOption.add(lastSyncDate, new GridBagConstraints(1, 2, 1, 1, 0, 0, -// GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 1, 1), 0, 0)); -// panelOption.add(lastUpdate, new GridBagConstraints(2, 2, 1, 1, 0, 0, -// GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); -// } - - //display the various urls to sync to in a combobox to choose which one will be updated + //url combobox JLabel urlcomboBoxLabel = new JLabel(getResourceMap().getString("urlComboLabel")); urlComboBox = new JComboBox<>(); //make it editable to add new urls @@ -217,6 +209,23 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, panelOption.add(urlComboBox, new GridBagConstraints(2,3,1,1,0,0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,3,1,1), 0, 0)); + JLabel lastSyncDateLabel = new JLabel(getResourceMap().getString("lastUpdateLabel")); + panelOption.add(lastSyncDateLabel, new GridBagConstraints(1, 2, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 1, 1), 0, 0)); + //display last Sync time + lastUpdate = new JLabel(""); + if (urlComboBox.getSelectedItem() != null) { + if (task.getSynchronizingURLList().contains(urlComboBox.getSelectedItem())){ + SyncInfo syncInfo = task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()); + LocalDateTime lastSyncTime = syncInfo.getLastSync(); + //if there has been an update before, display its date + if ((lastSyncTime != null) && lastSyncTime.isAfter(LocalDateTime.MIN)) { + lastUpdate.setText(lastSyncTime.toString()); + } + } + } + panelOption.add(lastUpdate, new GridBagConstraints(2, 2, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); configComponent.add(panelGeneral); configComponent.add(panelOption); @@ -378,12 +387,17 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } } updateArea.setText(builder.toString()); + if (task.getSynchronizingInfo(urlSelected).getLastSync().isAfter(LocalDateTime.MIN)) { + lastUpdate.setText(task.getSynchronizingInfo(urlSelected).getLastSync().toString()); + } + else { + lastUpdate.setText(""); + } } else { updateArea.setText("No data"); } - } /** @@ -429,6 +443,12 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, synchronizeTaskOnURL(task, object); } } + if (task.getSynchronizingInfo(urlSelected).getLastSync().isAfter(LocalDateTime.MIN)) { + lastUpdate.setText(task.getSynchronizingInfo(urlSelected).getLastSync().toString()); + } + else { + lastUpdate.setText(""); + } } /** @@ -546,11 +566,10 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, public void itemAdded(){ String urlToAdd = (String) urlComboBox.getSelectedItem(); if ((!urlToAdd.isEmpty()) && (!task.getSynchronizingURLList().contains(urlToAdd))) { - urlComboBox.addItem(urlToAdd); - task.addSyncInfo(urlToAdd, LocalDateTime.MIN, true); - core.getData().changeSyncInfo(task, urlToAdd); + urlComboBox.addItem(urlToAdd); + task.addSyncInfo(urlToAdd, LocalDateTime.MIN, true); + core.getData().changeSyncInfo(task, urlToAdd); } - } @Override public void actionPerformed(ActionEvent actionEvent) { 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 70ef7be..963ee35 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 @@ -47,19 +47,20 @@ updateAnnotations.Action.shortDescription = Include annotations generateUpdate.Action.text = &Generate generateUpdate.Action.icon = applications-system.png generateUpdate.Action.shortDescription = Generate synchronisation +updateSyncTime = No recent synchronization sendUpdate.Action.text = &Send sendUpdate.Action.icon = mail-forward.png -sendUpdate.Action.shortDescription = Send synchronisation +sendUpdate.Action.shortDescription = Send synchronization closeView.Action.text = &Close closeView.Action.icon = dialog-close.png closeView.Action.shortDescription = Close -action.updateError = Synchronisation failed +action.updateError = Synchronization failed action.update400 = Bad Request action.update404 = Not found action.update500 = Server error -action.updateErrorTitle = Synchronisation error +action.updateErrorTitle = Synchronization error action.updateEncodingError = Encoding error action.updateURLError = URL error \ No newline at end of file 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 329a948..aa37b4b 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 @@ -47,6 +47,7 @@ isIncludingAnnotations.Action.text = Inclure les annotations generateUpdate.Action.text = &G\u00E9n\u00E9rer generateUpdate.Action.icon = applications-system.png generateUpdate.Action.shortDescription = G\u00E9n\u00E9rer les donn\u00E9es de synchronisation +updateSyncTime = Pas de synchronisation r\u00E9cente sendUpdate.Action.text = &Envoyer sendUpdate.Action.icon = mail-forward.png -- 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 995179ea6c8d16765f49647cbab066614ef29de1 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 17 10:38:34 2016 +0200 added a method to remove a sync URL, added more return codes. --- .../java/org/chorem/jtimer/entities/TimerTask.java | 38 +++++++++++++++------- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 2 -- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 6 ++-- .../jtimer/ui/report/TimerTaskUpdaterView.java | 34 ++++++++++++------- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 67d0293..3ee66e9 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -304,17 +304,6 @@ public class TimerTask implements Cloneable, } /** - * Add one URL to the task's syncURLList - * @param urlToAdd : the url to add - */ - public void addURLToSyncList(String urlToAdd) { - //no need to have redundant elements - if (!getSynchronizingURLAsString().contains(urlToAdd)) { - synchronisingInfoList.add(new SyncInfo(urlToAdd)); - } - } - - /** * Adds a new synchronization info if the url isn't already present * @param url a string * @param time a LocalDateTime @@ -327,6 +316,24 @@ public class TimerTask implements Cloneable, } /** + * Removes a synchronisation info attached to a url if it exists + * @param url : the url of the info to remove + * + */ + public void removeSyncInfo(String url) { + List<SyncInfo> copySyncList = new ArrayList<>(synchronisingInfoList); + if (getSynchronizingURLList().contains(url)) { + int a = getSynchronizingURLList().size(); + for (int i = 0; i<a ; ++i) { + if (synchronisingInfoList.get(i).getSyncURL().equals(url)) { + copySyncList.remove(synchronisingInfoList.get(i)); + } + } + } + synchronisingInfoList = copySyncList; + } + + /** * Returns all the synchronization info * @return a list of TimerTask.SyncInfo */ @@ -351,6 +358,15 @@ public class TimerTask implements Cloneable, } /** + * sets the activity of a sync info + * @param isActive a boolean + * @param syncInfo the SyncInfo + */ + public void setIsActive(boolean isActive, SyncInfo syncInfo) { + syncInfo.setActiveSync(isActive); + } + + /** * Add task's subtask. * * Also add parent reference. diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index aaf83d4..b427531 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -622,7 +622,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, String line = parseIn.readLine(); while ((line = parseIn.readLine()) != null) { line = line.trim(); - if ((!line.isEmpty())) { String[] urlArray = line.split(" "); //if there is no lastSyncTime @@ -633,7 +632,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, else { task.addSyncInfo(urlArray[0], LocalDateTime.MIN, false); } - } //else if there is lastSyncTime else if (urlArray.length == 3) { diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 0fececb..51bcde0 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -121,7 +121,9 @@ public class TimerTaskSynchronizer implements DataEventListener { //-> do not change last sync time else { log.debug("Sync failed on " + object.get("URL").getAsString()); - + //deactivate autosync if the sync failed + task.getSynchronizingInfo(object.get("URL").getAsString()).setActiveSync(false); + log.info("Adress deactivated"); } } @@ -153,7 +155,7 @@ public class TimerTaskSynchronizer implements DataEventListener { postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); int code = connection.getResponseCode(); - if (code == 200) { + if ((code == 200) || (code == 201) || (code == 202)){ hasUpdated = true; } else { 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 3b6058f..7220cb6 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -387,12 +387,12 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } } updateArea.setText(builder.toString()); - if (task.getSynchronizingInfo(urlSelected).getLastSync().isAfter(LocalDateTime.MIN)) { - lastUpdate.setText(task.getSynchronizingInfo(urlSelected).getLastSync().toString()); - } - else { - lastUpdate.setText(""); - } +// if (task.getSynchronizingInfo(urlSelected).getLastSync().isAfter(LocalDateTime.MIN)) { +// lastUpdate.setText(task.getSynchronizingInfo(urlSelected).getLastSync().toString()); +// } +// else { +// lastUpdate.setText(""); +// } } else { @@ -442,12 +442,12 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if (urlSelected.equals(object.get("URL").getAsString())) { synchronizeTaskOnURL(task, object); } - } - if (task.getSynchronizingInfo(urlSelected).getLastSync().isAfter(LocalDateTime.MIN)) { - lastUpdate.setText(task.getSynchronizingInfo(urlSelected).getLastSync().toString()); - } - else { - lastUpdate.setText(""); +// } +// if (task.getSynchronizingInfo(urlSelected).getLastSync().isAfter(LocalDateTime.MIN)) { +// lastUpdate.setText(task.getSynchronizingInfo(urlSelected).getLastSync().toString()); +// } +// else { +// lastUpdate.setText(""); } } @@ -570,6 +570,16 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, task.addSyncInfo(urlToAdd, LocalDateTime.MIN, true); core.getData().changeSyncInfo(task, urlToAdd); } + if (lastUpdate != null) { + if (task.getSynchronizingInfo(urlToAdd).getLastSync().isAfter(LocalDateTime.MIN)) { + lastUpdate.setText(task.getSynchronizingInfo(urlToAdd).getLastSync().toString()); + core.getData().changeSyncInfo(task, urlToAdd); + } + else { + lastUpdate.setText(""); + } + + } } @Override public void actionPerformed(ActionEvent actionEvent) { -- 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 90cb72f279bb0c71657d89dd37e07cc15e9d8f61 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 17 11:34:00 2016 +0200 removed the changes in the task editor (url no longer changed here) --- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 35 ++++------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 95ee592..8e1bae5 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -220,42 +220,17 @@ public class TimerTaskEditor extends DialogView { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); - // text change listener on annotationTextArea, titleTextField and SyncURLTextField + // text change listener on annotationTextArea and titleTextField titleChangeListener = new TextChangeListener(); annotationChangeListener = new TextChangeListener(); - panel.add(createTitlePanel(), BorderLayout.NORTH); - panel.add(createJXMonthView(), BorderLayout.CENTER); - panel.add(createEditionPanel(), BorderLayout.SOUTH); - - return panel; - } - - /** - * Create title panel - * @return title panel - */ - protected JPanel createTitlePanel(){ - - SpringLayout layout = new SpringLayout(); - JPanel panel = new JPanel(layout); - - // task title and listener + // task title titleText = new JTextField("", 20); // prevent too long task names titleText.getDocument().addDocumentListener(titleChangeListener); - //labels for title and url - JLabel titleLabel = new JLabel(getResourceMap().getString("label.title.text")); - - panel.add(titleLabel); - panel.add(titleText); - - layout.putConstraint(SpringLayout.NORTH, titleLabel, 2, SpringLayout.NORTH, panel); - layout.putConstraint(SpringLayout.WEST, titleLabel, 2, SpringLayout.WEST, panel); - - layout.putConstraint(SpringLayout.NORTH, titleText, 2, SpringLayout.NORTH, panel); - layout.putConstraint(SpringLayout.WEST, titleText, 2, SpringLayout.EAST, panel); - + panel.add(titleText, BorderLayout.NORTH); + panel.add(createJXMonthView(), BorderLayout.CENTER); + panel.add(createEditionPanel(), BorderLayout.SOUTH); return panel; } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm