branch feature/sync updated (d31583a -> 8dd4914)
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 d31583a logs instead of stacktrace new e644144 changed the signature of synchronizeTaskOnURL (removed TimerTask param) + documented method new a1ed187 corrected output of manual sync (was not sending the json at all) new 8dd4914 cleaned up synchronizeTaskOnURL method 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 8dd491445173160fea1d4ca8fea0292a7d2eced9 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 14:43:41 2016 +0200 cleaned up synchronizeTaskOnURL method commit a1ed18739f4b9c1a4237c1dc336de8cfa77fed80 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 12:01:13 2016 +0200 corrected output of manual sync (was not sending the json at all) commit e644144fe8a62953057b20e43bb51eb48615e3ad Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 10:59:52 2016 +0200 changed the signature of synchronizeTaskOnURL (removed TimerTask param) + documented method Summary of changes: .../chorem/jtimer/io/TimerTaskSynchronizer.java | 91 +++++++++++----------- .../jtimer/ui/report/TimerTaskUpdaterView.java | 90 ++++++++++----------- .../resources/TimerTaskUpdaterView.properties | 2 +- .../resources/TimerTaskUpdaterView_fr.properties | 2 +- 4 files changed, 87 insertions(+), 98 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 e644144fe8a62953057b20e43bb51eb48615e3ad Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 10:59:52 2016 +0200 changed the signature of synchronizeTaskOnURL (removed TimerTask param) + documented method --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 7f48a49..694c43e 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -112,11 +112,27 @@ public class TimerTaskSynchronizer implements DataEventListener { List<JsonObject> jsonObjectList = TimerTaskHelper.taskToJSONFormat(task, false, timezone); for (JsonObject object : jsonObjectList) { - synchronizeTaskOnURL(task, object); + boolean successfulSync = synchronizeTaskOnURL(object); + //sync successful -> change the last sync time + if (successfulSync) { + log.debug("Sync successful on " + object.get("URL").getAsString()); + task.setLastSync(LocalDateTime.now()); + } + //-> do not change last sync time + else { + log.debug("Sync failed on " + object.get("URL").getAsString()); + + } + } } - public boolean synchronizeTaskOnURL(TimerTask task, JsonObject object) { + /** + * Sends one synchronization (one JSON object) + * @param object the object to sync + * @return a boolean indicating failure or success + */ + public boolean synchronizeTaskOnURL(JsonObject object) { String updateJsonString = object.toString(); String syncURL = object.get("URL").getAsString(); @@ -171,13 +187,7 @@ public class TimerTaskSynchronizer implements DataEventListener { } } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } else { - log.error("Sync error"); - return false; - } + return hasUpdated; } @Override -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit a1ed18739f4b9c1a4237c1dc336de8cfa77fed80 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 12:01:13 2016 +0200 corrected output of manual sync (was not sending the json at all) --- .../jtimer/ui/report/TimerTaskUpdaterView.java | 21 ++++++++++++--------- .../resources/TimerTaskUpdaterView.properties | 2 +- .../resources/TimerTaskUpdaterView_fr.properties | 2 +- 3 files changed, 14 insertions(+), 11 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 4537971..4d7ea5f 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -100,9 +100,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener this.core = core; this.task = task; + timezone = "+0100"; setComponent(getMainComponent()); //default the timezone - timezone = "+0100"; updateJson = new ArrayList<>(); @@ -179,27 +179,30 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener JXTaskPane panelOption = new JXTaskPane(getResourceMap().getString("updateOptions")); panelOption.setLayout(new GridBagLayout()); + //checkbox to include annotations checkIncludesAnnotations = new JCheckBox(); checkIncludesAnnotations.setAction(getContext().getActionMap(this).get("isIncludingAnnotations")); panelOption.add(checkIncludesAnnotations, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - JLabel lastUpdateLabel = new JLabel(getResourceMap().getString("lastUpdateLabel")); + //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.toLocalDate().toString()); - panelOption.add(lastUpdateLabel, new GridBagConstraints(1, 2, 1, 1, 0, 0, + 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 of the timezone JLabel timezoneLabel = new JLabel(getResourceMap().getString("timezone")); - JTextField timezoneText = new JTextField(this.timezone); - panelOption.add(timezoneLabel, new GridBagConstraints(1,3,1,1,0,0, + JLabel timezoneText = new JLabel(this.timezone); + panelOption.add(timezoneLabel, new GridBagConstraints(1,3,1,2,0,0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2,1,1,1),0,0)); - panelOption.add(timezoneText, new GridBagConstraints(2,3,1,1,0,0, + panelOption.add(timezoneText, new GridBagConstraints(2,3,1,2,0,0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,2,1,1),0,0)); configComponent.add(panelGeneral); @@ -431,10 +434,10 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener connection.setUseCaches(false); connection.setDoInput(true); - connection.setRequestProperty("Content-Length", "" + updateJsonString); connection.setDoOutput(true); + connection.setRequestProperty("Content-Length", "" + Integer.toString(updateJsonString.length())); connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json" + charset); + connection.setRequestProperty("Content-Type", "application/json"); try { connection.setRequestMethod("POST"); } catch (ProtocolException e) { @@ -442,7 +445,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener } byte[] postDataBytes = new byte[0]; try { - postDataBytes = updateJson.toString().getBytes("UTF-8"); + postDataBytes = object.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { log.error("Unsupported Encoding"); } 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 2ab6693..09a82f9 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 @@ -26,7 +26,7 @@ updateFrom=From : updateTo=To : lastUpdateLabel=Last Sync at: -timezone= Timezone +timezone= Timezone: pickCurrentMonth.Action.text = Select current month 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 91ed7cd..4a9a20a 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 @@ -27,7 +27,7 @@ updateFrom=De : updateTo=\u00C0 : lastUpdateLabel=Derni\u00E8re synchronisation : -timezone= Timezone +timezone= Timezone : pickCurrentMonth.Action.text = Selectionner le mois courant -- 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 8dd491445173160fea1d4ca8fea0292a7d2eced9 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 14:43:41 2016 +0200 cleaned up synchronizeTaskOnURL method --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 63 ++++++++----------- .../jtimer/ui/report/TimerTaskUpdaterView.java | 71 +++++++++------------- 2 files changed, 55 insertions(+), 79 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 694c43e..b0ea2d0 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -133,59 +133,46 @@ public class TimerTaskSynchronizer implements DataEventListener { * @return a boolean indicating failure or success */ public boolean synchronizeTaskOnURL(JsonObject object) { - String updateJsonString = object.toString(); String syncURL = object.get("URL").getAsString(); String charset = "UTF-8"; HttpURLConnection connection; URL url; + byte[] postDataBytes; + boolean hasUpdated = false; try { url = new URL(syncURL); + connection = (HttpURLConnection) url.openConnection(); + 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"); + connection.setRequestMethod("POST"); + postDataBytes = updateJsonString.getBytes("UTF-8"); + 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)) { + hasUpdated = true; + } + } + } } 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; - } - } + log.error("Problem with the connection"); + //abort synchronization of this task if connection impossible } return hasUpdated; } 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 4d7ea5f..26a48ac 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -418,64 +418,53 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener String updateJsonString = object.toString(); String syncURL = object.get("URL").getAsString(); String charset = "UTF-8"; - if (syncURL != null) { - HttpURLConnection connection= null; - URL url = null; - try { - url = new URL(syncURL); - } catch (MalformedURLException e) { - log.error("Malformed URL"); - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - log.error("Connection error"); - } - + HttpURLConnection connection; + URL url; + byte[] postDataBytes; + boolean hasUpdated = false; + try { + url = new URL(syncURL); + connection = (HttpURLConnection) url.openConnection(); 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 = object.toString().getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - log.error("Unsupported Encoding"); - } - try { - connection.getOutputStream().write(postDataBytes); - } catch (IOException e) { - log.error("OutputStream error"); - } - + connection.setRequestMethod("POST"); + postDataBytes = updateJsonString.getBytes("UTF-8"); + connection.getOutputStream().write(postDataBytes); //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); - boolean hasUpdated = false; - //check for positive answer from server + //check for answer from server for (Map.Entry<String, List<String>> entry : map.entrySet()) { for (String s : entry.getValue()) { + //positive answer, synchronization accepted if ("HTTP/1.1 200 OK".equals(s)) { hasUpdated = true; } } } - if (hasUpdated) { + } catch (MalformedURLException e) { + log.error("URL malformed"); + //abort synchronization of this task if the url is wrong + } catch (ProtocolException e) { + log.error("Protocol error."); + } catch (UnsupportedEncodingException e) { + log.error("Problem with encoding"); + } catch (IOException e) { + log.error("Problem with the connection"); + //abort synchronization of this task if connection impossible + } + if (hasUpdated) { core.getData().editTaskLastSync(task, LocalDateTime.now()); - } else { - log.error("Update error, wrong URL?"); - String message = getResourceMap().getString("action.updateError"); - String title = getResourceMap().getString("action.updateErrorTitle"); - JOptionPane.showMessageDialog(this.getMainComponent(), message, title, - JOptionPane.ERROR_MESSAGE); + } else { + log.error("Update error, wrong URL?"); + String message = getResourceMap().getString("action.updateError"); + String title = getResourceMap().getString("action.updateErrorTitle"); + JOptionPane.showMessageDialog(this.getMainComponent(), message, title, + JOptionPane.ERROR_MESSAGE); - } } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm