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 de218b66c1984081a9deff704f3bdb6b5b2c5ef8 Author: servantie <servantie.c@gmail.com> Date: Tue Jul 5 14:53:32 2016 +0200 adapted the combobox actions in the taskSyncInfo editor --- .../java/org/chorem/jtimer/entities/TimerTask.java | 6 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 134 ++++++++++++++------- .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 76 +++++++----- 3 files changed, 139 insertions(+), 77 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index b691fea..28980a1 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -353,7 +353,7 @@ public class TimerTask implements Cloneable, /** * Returns the sync info matching a url - * (if the url is not in the list, returns a SyncInfo with an "error" string as url) + * (if the url is not in the list, returns a new SyncInfo with the url) * @param urlString * @return a SyncInfo matching the url */ @@ -363,8 +363,8 @@ public class TimerTask implements Cloneable, return sync; } } - SyncInfo errorInfo = new SyncInfo("error"); - return errorInfo; + SyncInfo newInfo = new SyncInfo(urlString); + return newInfo; } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 22ef2c6..83900bd 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -26,6 +26,7 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; @@ -72,6 +73,8 @@ import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerAlert.Type; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; /** * Charge et sauve les fichiers au format gTimer. @@ -1158,14 +1161,10 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } else { annotationTaskFile.delete(); } - } - /** - * Save synchronization info for a task. - * - * @param task task to save annotation - */ + protected void saveSynchronizationInfo(TimerTask task) { + int taskNumber = task.getNumber(); File synchronizationTaskFile = new File(dataSaveDirectory + File.separator @@ -1173,58 +1172,107 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, if ((task.getSynchronizingURLList() != null) || (!task.getSynchronizingURLList().isEmpty())) { File backupfile = null; + try (Writer out = new OutputStreamWriter(new FileOutputStream(synchronizationTaskFile), "ISO-8859-1")) { // first make backup backupfile = makeBackupFile(synchronizationTaskFile); out.write("Format: " + GTIMER_FILE_VERSION + "\n"); - //start Sync Save - out.write("SyncInfo:\n"); - //loop across SyncInfo + //use Yaml to write it + Yaml yaml = new Yaml(); for (SyncInfo sync : task.getSynchronizingInfoList()) { - //write url - out.write(sync.getSyncURL() + " "); - //write isActive - if (sync.getActiveSync()) { - out.write("true "); - } - else { - out.write("false "); - } - //write isWithAnnotations - if(sync.getIsWithAnnotations()) { - out.write("true "); - } - else { - out.write("false "); - } - //write lastsync (HH:MM:SS) - if (sync.getLastSync() != null && sync.getLastSync().isAfter(LocalDateTime.MIN)) { - //remove the milliseconds - String syncString = sync.getLastSync().toString(); - out.write(syncString + "\n"); - } - else { - out.write("\n"); + Map<String, Object> dataToSave = new HashMap<>(); + dataToSave.put("url", sync.getSyncURL()); + dataToSave.put("active", sync.getActiveSync()); + dataToSave.put("annotations", sync.getIsWithAnnotations()); + if (sync.getLastSync()!= null && sync.getLastSync()!=LocalDateTime.MIN) { + dataToSave.put("lastSyncTime", sync.getLastSync()); } + yaml.dump(dataToSave, out); } + out.close(); + deleteBackupFile(backupfile); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.debug("Can't save task synchronization information", e); - } + } + catch (IOException e) { + if (log.isErrorEnabled()) { + log.debug("Can't save task synchronization information", e); + } - // can be null if backup throws the exception - if (backupfile != null) { - restoreBackupFile(backupfile); - } + // can be null if backup throws the exception + if (backupfile != null) { + restoreBackupFile(backupfile); } - } else { - synchronizationTaskFile.delete(); + } } } +// /** +// * Save synchronization info for a task. +// * +// * @param task task to save annotation +// */ +// protected void saveSynchronizationInfo(TimerTask task) { +// int taskNumber = task.getNumber(); +// +// File synchronizationTaskFile = new File(dataSaveDirectory + File.separator +// + taskNumber + "." + GTIMER_TASK_EXTENSION + "." + GTIMER_SYNC_EXTENSION); +// +// if ((task.getSynchronizingURLList() != null) || (!task.getSynchronizingURLList().isEmpty())) { +// File backupfile = null; +// try (Writer out = new OutputStreamWriter(new FileOutputStream(synchronizationTaskFile), "ISO-8859-1")) { +// +// // first make backup +// backupfile = makeBackupFile(synchronizationTaskFile); +// out.write("Format: " + GTIMER_FILE_VERSION + "\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 isWithAnnotations +// if(sync.getIsWithAnnotations()) { +// out.write("true "); +// } +// else { +// out.write("false "); +// } +// //write lastsync (HH:MM:SS) +// if (sync.getLastSync() != null && sync.getLastSync().isAfter(LocalDateTime.MIN)) { +// //remove the milliseconds +// String syncString = sync.getLastSync().toString(); +// out.write(syncString + "\n"); +// } +// else { +// out.write("\n"); +// } +// } +// deleteBackupFile(backupfile); +// } catch (IOException e) { +// if (log.isErrorEnabled()) { +// log.debug("Can't save task synchronization information", e); +// } +// +// // can be null if backup throws the exception +// if (backupfile != null) { +// restoreBackupFile(backupfile); +// } +// } +// } else { +// synchronizationTaskFile.delete(); +// } +// } + /** * Save task alerts. * diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java index ab0c4da..8378c52 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -239,7 +239,9 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener @Action public boolean isIncludingAnnotations() { boolean ischeckedIncludeAnnotations = checkIncludesAnnotations.isSelected(); - task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsWithAnnotations(ischeckedIncludeAnnotations); + if (urlComboBox.getSelectedItem() instanceof SyncInfo) { + task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsWithAnnotations(ischeckedIncludeAnnotations); + } if (log.isDebugEnabled()) { log.debug("Inclusion of annotations in sync changed"); } @@ -252,7 +254,9 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener @Action public boolean isActiveSync() { boolean isActiveSyncURL = checkIsActiveSync.isSelected(); - task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsActiveSync(isActiveSyncURL); + if (urlComboBox.getSelectedItem() instanceof SyncInfo) { + task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsActiveSync(isActiveSyncURL); + } if (log.isDebugEnabled()) { log.debug("Activity of url changed "); } @@ -337,44 +341,54 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener @Override public void actionPerformed(ActionEvent actionEvent) { + String actionCommand = actionEvent.getActionCommand(); + SyncInfo infoToUse; + if (urlComboBox.getSelectedItem() instanceof String) { + String urlToTest = (String) urlComboBox.getSelectedItem(); + infoToUse = new SyncInfo(urlToTest); + } + else{ + infoToUse = (SyncInfo) urlComboBox.getSelectedItem(); + } + if ("comboBox".equals(actionCommand)) { - if (urlComboBox.getSelectedItem() instanceof String) { - String urlToAdd = (String) urlComboBox.getSelectedItem(); - if (!task.getSynchronizingInfoList().contains(urlToAdd)) { - if (log.isDebugEnabled()) { - log.debug("New URL added"); - } - itemAdded(urlToAdd); + if (!task.getSynchronizingInfoList().contains(infoToUse)) { + if (log.isDebugEnabled()) { + log.debug("New URL added"); } + itemAdded(infoToUse.getSyncURL()); } + else if (log.isDebugEnabled()) { + log.debug("URL already existing in SyncInfo, no addition."); + } + } else if ("deleteURL".equals(actionCommand)) { - SyncInfo infoToUse = (SyncInfo) urlComboBox.getSelectedItem(); - //if the delete button has been clicked, delete the task (if it exists) - if ((infoToUse != null) && (task.getSynchronizingInfoList().contains(infoToUse))) { - task.removeSyncInfo(infoToUse); - urlComboBox.removeItem(infoToUse); - core.getData().deleteSyncInfo(task, infoToUse); - } - else { - errorBox(getResourceMap().getString("deleteErrorMessage"), getResourceMap().getString("deleteErrorTitle")); - } + //if the delete button has been clicked, delete the task (if it exists) + if ((infoToUse != null) && (task.getSynchronizingInfoList().contains(infoToUse))) { + task.removeSyncInfo(infoToUse); + urlComboBox.removeItem(infoToUse); + core.getData().deleteSyncInfo(task, infoToUse); + } else { + errorBox(getResourceMap().getString("deleteErrorMessage"), getResourceMap().getString("deleteErrorTitle")); + } } else if ("testURL".equals(actionCommand)) { - SyncInfo infoToTest = (SyncInfo) urlComboBox.getSelectedItem(); - //if the test button has been clicked, test the sync on the URL and returns a message to the user - //tests only if the info exists - if ((infoToTest != null) && task.getSynchronizingInfoList().contains(infoToTest)) { - JsonObject testObject = TimerTaskHelper.taskURLToJSONObject(task, infoToTest.getSyncURL(), isIncludingAnnotations(), timezone); - int responseCode = TimerTaskSynchronizer.synchronizeTaskOnURL(testObject); - if (responseCode > 199 && responseCode < 300) { - infoBox(getResourceMap().getString("testSyncSuccessMessage"), getResourceMap().getString("testSyncSuccessTitle")); - } - else { - errorBox(getResourceMap().getString("testSyncFailureMessage"), getResourceMap().getString("testSyncFailureTitle")); + //if the test button has been clicked, test the sync on the URL and returns a message to the user + //tests only if the info exists + if ((infoToUse != null) && task.getSynchronizingInfoList().contains(infoToUse)) { + JsonObject testObject = TimerTaskHelper.taskURLToJSONObject(task, infoToUse.getSyncURL(), isIncludingAnnotations(), timezone); + int responseCode = TimerTaskSynchronizer.synchronizeTaskOnURL(testObject); + if (responseCode > 199 && responseCode < 300) { + infoBox(getResourceMap().getString("testSyncSuccessMessage"), getResourceMap().getString("testSyncSuccessTitle")); + infoToUse.setLastSync(LocalDateTime.now()); + } + else { + errorBox(getResourceMap().getString("testSyncFailureMessage"), getResourceMap().getString("testSyncFailureTitle")); + } } - } + } else { if (log.isDebugEnabled()) { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.