branch feature/sync updated (31ba1e9 -> 4c3886a)
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 discards 31ba1e9 New display of SyncInfo edition, with URL test button discards 4cdc4fb corrected the title change not activating validation button in task editor discards 68a6cc9 corrected all the imports with * discards 162928d modified the taskToJSONFormat method to include the current day discards ee05750 1488a94 modified json creation to not iterate on inactive urls, and optimized a little discards d8f9541 adding a lastSync at the exit of jtimer discards 065aaf9 removed an unused method discards eec2299 corrected a variable name discards c719c22 checkbox for active sync showing up properly discards b03cc9a tests for addition/removal of SyncInfo in tasks discards 4588ea2 remove milliseconds of lastSyncTime from sync save file discards 362b361 surrounded log.debug to only generate if Debug is enabled discards 09f14bd deletion of url saved to sync file properly + corrected parsing of syncInfo discards 2d9e642 when a url is deleted in the combobox, it's saved in the file discards 7d1d920 checking the isActive checkbox de/activates the sync on the url chosen discards e2106d5 added logs, made method synchronizeTaskOnURL static and returning an int discards bf43b49 corrected text on the checkbox isActiveSync discards f3431bc added some logging (more to come) and added properties discards 9db7005 added a checkbox for activity of url (not listening on it yet) discards 5506ddb added a test on parseSyncInfo in GTimerIncrementalSaver discards 7aee74f added a test for taskToJSONFormat discards 2a0e547 minor cleanup in methods discards 9d74422 removed an unused field (lastSync) in TimerTask, clarified some documentations discards 90cb72f removed the changes in the task editor (url no longer changed here) discards 995179e added a method to remove a sync URL, added more return codes. discards bb81588 showing last sync associated with url picked in combobox discards 30d6c44 checking for response codes and sending error messages to user (if needed) discards 5dbad0a major change: List<SyncInfo> added to TimerTask to store synchronization info discards 4253a46 simplified code receiving discards 2ba81c9 corrected sent time (was sending milliseconds instead of seconds) discards 7ca1419 changed acceptance discards 2524961 changed timestamp to remove milliseconds and standardized timezone to match iso discards 47ce041 added url shows up in combobox list discards d9b3a17 added possibility to edit a url and adds it to the syncURLList of the task discards 8720f1d disables send sync button when sync has been done once discards 2635e0d edited to change update into synchronization discards 3cda6fb fix to display error message when the sync went wrong discards 10eaac3 added a combobox in manual sync to pick which url to sync on discards 0a0946b removed timezone display in TimerTaskUpdaterView (useless) discards 8dd4914 cleaned up synchronizeTaskOnURL method discards a1ed187 corrected output of manual sync (was not sending the json at all) discards e644144 changed the signature of synchronizeTaskOnURL (removed TimerTask param) + documented method discards d31583a logs instead of stacktrace discards 72dbf0a changed syncURL to syncURLList, updated methods for sync accordingly discards 5bc2777 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) discards 6eae5ab removed a useless toString(), removed unused imports discards 19655c6 corrected firstdayofweek discards 62f6e70 added a check for empty tasksToSync discards 66dee36 added the timezone as option in JTimerConfig, updated json creation accordingly discards aeb5909 minor typos corrected, set autosyncdelay to every two hours discards 2c25465 removed useless tabs discards 83614a5 added the synchronizer to the config and started treating errors discards 45ddb6e changed name of parseSyncURL to parseSyncInfo (clearer) discards d6dd1a0 corrected the json creation to deal with times added before the task's creation date (and be able to send them, that way) corrected the url creation in the synchronization discards 140eb26 (minor) added timezone in json output (kept forgetting it) discards 62a42e9 minor changes (comments) discards f31cbed added an automatic synchronization (every min), currently synchronizes all the times of the tasks that have been modified since the last automatic sync. Sends all the times from creation date for now discards 089074f corrected update to synchronisation discards 1a9ed28 removed a duplicated try/catch in the sendUpdate() method discards 2ec9c11 changed the return of taskToJSONFormat back to String (to avoid having several toString() in the TimerTaskUpdaterView, when it can be done once in the method) discards 431e815 added the gson library to the project to enable easier generation of json output for the updates, adapted the update functions to accomodate (removed useless prettyfier) discards b8e6eb5 removed a useless comment discards 49c2fb6 added an error message if the update isn't done, asking to check for url discards a774a64 saving synchronisation time when update successful discards 624a2ef be able to pick previous month and current month for update with a button discards b8b27e2 displayed the checkbox to include annotations with the update, includes it in the update if checked. discards eacb097 set up ids for times in the json output to be dates (one task at one date has only one value for duration in jtimer), minor properties change discards fbe0fc5 showing an info log when receiving a 200 OK after an update. small typo correction in properties file discards 5790868 small typo corrected with " at the wrong places or missing in the json output discards 3708b2b corrected method for getting times that was ignoring the date parameters and always sending all the times of a task discards d63c6c1 Deletion of TaskJsonDisplayer class that was used to test the display of the json Adding an update option to the UI and an update frame (TimeTaskUpdaterView) to display the data to be sent (not finished) based on the Report UI discards 1f186b5 "use of simpler json format, sends update request to url when url is changed with the json of the task." discards 8edf5d3 Display of a task after edition of url in prettified json format methods to jsonify and then prettify a task (small typo edit) discards 82d8d45 Added synchronisation date changes (forgotten) discards 4cea3f8 Adding a check on the parser for empty url strings discards df3c9e7 Synchronising URL and time of last synchronisation added to Timer Task Display of synchronising URL added to TimerTaskEditor +events to deal with editing of synchronising URL Parsing and saving to [taskname.task].sync file of synchronising information adds 5bc154c Fix test failing on windows adds 075995c fixes #1357: Empty time must not be add to file adds b333168 Update libs adds 8c26185 Move 'system' package outside 'ui' package to allow native system init adds a4f8192 Downgrade testng adds dd09cbd Update libs adds b8fe6a6 Code style and fix analysis adds 8a7047e Use default methods to remove a lot of empty implemented methods adds f6b06cb refs #1345: Downgrade jna to 3.5.2 for testing new b342e9e "use of simpler json format, sends update request to url when url is changed with the json of the task." new 9ccd774 Deletion of TaskJsonDisplayer class that was used to test the display of the json Adding an update option to the UI and an update frame (TimeTaskUpdaterView) to display the data to be sent (not finished) based on the Report UI new ca9fd6f corrected method for getting times that was ignoring the date parameters and always sending all the times of a task new 59ff4b7 small typo corrected with " at the wrong places or missing in the json output new b65ba97 showing an info log when receiving a 200 OK after an update. small typo correction in properties file new fc44c09 set up ids for times in the json output to be dates (one task at one date has only one value for duration in jtimer), minor properties change new 5249bb5 displayed the checkbox to include annotations with the update, includes it in the update if checked. new 34fb354 be able to pick previous month and current month for update with a button new 8793f5b saving synchronisation time when update successful new 3cbcd20 added an error message if the update isn't done, asking to check for url new 62133e8 removed a useless comment new 16cb347 added the gson library to the project to enable easier generation of json output for the updates, adapted the update functions to accomodate (removed useless prettyfier) new 84fa2a1 changed the return of taskToJSONFormat back to String (to avoid having several toString() in the TimerTaskUpdaterView, when it can be done once in the method) new d16f8d6 removed a duplicated try/catch in the sendUpdate() method new 392d34d corrected update to synchronisation new 283362d added an automatic synchronization (every min), currently synchronizes all the times of the tasks that have been modified since the last automatic sync. Sends all the times from creation date for now new d41d0e1 minor changes (comments) new 0ec3116 (minor) added timezone in json output (kept forgetting it) new 09a46c6 corrected the json creation to deal with times added before the task's creation date (and be able to send them, that way) corrected the url creation in the synchronization new 7962d8a changed name of parseSyncURL to parseSyncInfo (clearer) new 0d8ac91 added the synchronizer to the config and started treating errors new 12a5c2e removed useless tabs new 8636440 minor typos corrected, set autosyncdelay to every two hours new a1a81ad added the timezone as option in JTimerConfig, updated json creation accordingly new 50a1fab added a check for empty tasksToSync new 6a17f8f corrected firstdayofweek new e068db8 removed a useless toString(), removed unused imports new 6db4110 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) new 9a1555e changed syncURL to syncURLList, updated methods for sync accordingly new 6cd63ea logs instead of stacktrace new 033fa5d changed the signature of synchronizeTaskOnURL (removed TimerTask param) + documented method new 40dcd7a corrected output of manual sync (was not sending the json at all) new 325be32 cleaned up synchronizeTaskOnURL method new acf7e13 removed timezone display in TimerTaskUpdaterView (useless) new 917eba7 added a combobox in manual sync to pick which url to sync on new 97bcca4 fix to display error message when the sync went wrong new 4748cb8 edited to change update into synchronization new 6f03ae4 disables send sync button when sync has been done once new 4bf37eb added possibility to edit a url and adds it to the syncURLList of the task new 1fd9626 added url shows up in combobox list new 22c9fbd changed timestamp to remove milliseconds and standardized timezone to match iso new 4663ae4 changed acceptance new 831a2c5 corrected sent time (was sending milliseconds instead of seconds) new cbe46a2 simplified code receiving new cf626e7 major change: List<SyncInfo> added to TimerTask to store synchronization info new 03be19d checking for response codes and sending error messages to user (if needed) new ba2e1ce showing last sync associated with url picked in combobox new 9832694 added a method to remove a sync URL, added more return codes. new ee015fa removed the changes in the task editor (url no longer changed here) new c7745ed removed an unused field (lastSync) in TimerTask, clarified some documentations new 0441eec minor cleanup in methods new 666d668 added a test for taskToJSONFormat new bc0e7aa added a test on parseSyncInfo in GTimerIncrementalSaver new ee8c1d3 added a checkbox for activity of url (not listening on it yet) new 0606c67 added some logging (more to come) and added properties new a0b0cdc corrected text on the checkbox isActiveSync new 4d96253 added logs, made method synchronizeTaskOnURL static and returning an int new 3f3eb51 when a url is deleted in the combobox, it's saved in the file new df1422c deletion of url saved to sync file properly + corrected parsing of syncInfo new 7baa9b5 surrounded log.debug to only generate if Debug is enabled new 462d5df remove milliseconds of lastSyncTime from sync save file new cf919e0 tests for addition/removal of SyncInfo in tasks new 280206e checkbox for active sync showing up properly new 4bebabf corrected a variable name new f269eaf removed an unused method new b799e6d adding a lastSync at the exit of jtimer new 398309a 1488a94 modified json creation to not iterate on inactive urls, and optimized a little new aad45ef modified the taskToJSONFormat method to include the current day new 496b34a corrected all the imports with * new 372caf2 corrected the title change not activating validation button in task editor new 8dba28c New display of SyncInfo edition, with URL test button new de218b6 adapted the combobox actions in the taskSyncInfo editor new 0260856 corrected a double addition of urls in the synclist, edited some doc new d2e1455 changed LocalDateTime type for last sync to Date, used YAML to save sync info new 4c3886a display of lastSync This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (31ba1e9) \ N -- N -- N refs/heads/feature/sync (4c3886a) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omits" are not gone; other references still refer to them. Any revisions marked "discards" are gone forever. The 75 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 4c3886a652a9864d805fd0468ceb66020110a71f Author: servantie <servantie.c@gmail.com> Date: Thu Jul 7 15:43:46 2016 +0200 display of lastSync commit d2e14551e26cf9459cdb38d46cb748041253a915 Author: servantie <servantie.c@gmail.com> Date: Thu Jul 7 14:23:29 2016 +0200 changed LocalDateTime type for last sync to Date, used YAML to save sync info adapted test file to comply with yaml output commit 0260856f2f650a1fd0eef4f21ec129e789d69f65 Author: servantie <servantie.c@gmail.com> Date: Wed Jul 6 15:06:20 2016 +0200 corrected a double addition of urls in the synclist, edited some doc 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 commit 8dba28cb1330e9c4b54f840a60935fe57b116e35 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 30 15:49:29 2016 +0200 New display of SyncInfo edition, with URL test button commit 372caf2bbb184c4332cb0cbd30239032072e4035 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 17:54:00 2016 +0200 corrected the title change not activating validation button in task editor commit 496b34a6a97d9e02aa352c04bc81708764a32a88 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 17:45:17 2016 +0200 corrected all the imports with * commit aad45effbef54c77f9b3273c234d50dcc1a2417f Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 16:33:33 2016 +0200 modified the taskToJSONFormat method to include the current day commit 398309a950488ca3bf0be26ae2b4c497be4ee708 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 15:18:59 2016 +0200 1488a94 modified json creation to not iterate on inactive urls, and optimized a little commit b799e6daa2a419de9a48c5c0ad132782c1d1c865 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 11:58:27 2016 +0200 adding a lastSync at the exit of jtimer (syncs the tasks that have been added to the synchronizer for one last time) commit f269eaffd16fc28512ef342572b643332b70bb0d Author: servantie <servantie.c@gmail.com> Date: Mon Jun 27 10:11:11 2016 +0200 removed an unused method commit 4bebabf2f4a7c1e9f6f9e8b9732817f33748a1cb Author: servantie <servantie.c@gmail.com> Date: Mon Jun 27 09:48:44 2016 +0200 corrected a variable name commit 280206e7b9a3fade902584cffc75ff9de4baad8e Author: servantie <servantie.c@gmail.com> Date: Fri Jun 24 15:14:29 2016 +0200 checkbox for active sync showing up properly commit cf919e0de7d4e901ed204570262cb1fff558550b Author: servantie <servantie.c@gmail.com> Date: Thu Jun 23 18:05:35 2016 +0200 tests for addition/removal of SyncInfo in tasks commit 462d5dfeece1bbf0e38fa0e4a1718431103e4786 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 23 11:42:54 2016 +0200 remove milliseconds of lastSyncTime from sync save file commit 7baa9b58b47f172775343ad51bac60eb8a5d6c5b Author: servantie <servantie.c@gmail.com> Date: Thu Jun 23 11:19:04 2016 +0200 surrounded log.debug to only generate if Debug is enabled commit df1422c476a44effea2069d630c5e9841549c2d3 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 22 17:52:52 2016 +0200 deletion of url saved to sync file properly + corrected parsing of syncInfo (catching a DateTimeParseException, and taking a 00:00:00 instead of 00:00:00.000 format) commit 3f3eb51b8bf0272ce35eed3cc5c324135bad9317 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 22 16:28:55 2016 +0200 when a url is deleted in the combobox, it's saved in the file commit 4d96253b49200b2696aabca6687f937a26f40e42 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 22 16:38:43 2016 +0200 added logs, made method synchronizeTaskOnURL static and returning an int (http response) commit a0b0cdcb3aa2f7ac277d306e32201b3f935285d8 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 17:47:53 2016 +0200 corrected text on the checkbox isActiveSync commit 0606c67de0f8a58ccf9709c10bfffe8ad8396662 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 17:27:12 2016 +0200 added some logging (more to come) and added properties commit ee8c1d395231f102526d49f5eea7f4dc11d79988 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 14:49:18 2016 +0200 added a checkbox for activity of url (not listening on it yet) commit bc0e7aabbb4d8b2d6bb164af0582b0200b5ca192 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 11:20:58 2016 +0200 added a test on parseSyncInfo in GTimerIncrementalSaver commit 666d668de79b3f2989a049f94dc0f7fe38fe46bd Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 10:27:46 2016 +0200 added a test for taskToJSONFormat commit 0441eec8a8908ff54d8200b8c801a6d90e2eb707 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 20 16:45:26 2016 +0200 minor cleanup in methods commit c7745ed439e8018c6360abb1c1c488ee41f0c349 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 20 11:44:32 2016 +0200 removed an unused field (lastSync) in TimerTask, clarified some documentations commit ee015fa31758ca1048beec8822cfa10e90aef1a5 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 983269415b8a8588d7a4e5f13a44944460518e0f 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 ba2e1ce02a5e477ceb1b14ccf1bf0e3e07ffb18d 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 03be19d38c41fb4ea7425f1eac360c417099dfc9 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 cf626e7e021add91527984f3c00b94bfb8d94e61 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 cbe46a22bc69bc33c21ac4be743456aec0d42448 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 14 11:43:38 2016 +0200 simplified code receiving commit 831a2c52a3c3bedb615a993511b7b73d5cab905f Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 14:56:37 2016 +0200 corrected sent time (was sending milliseconds instead of seconds) commit 4663ae4b32739f1006215d4b3c144d21707d62b1 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 14:20:25 2016 +0200 changed acceptance commit 22c9fbd23a76c9da9a9ed111aa3562b24bc81ac7 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 12:35:15 2016 +0200 changed timestamp to remove milliseconds and standardized timezone to match iso commit 1fd962667579c5ce23891a1971988a4cd3ab37dd Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 10:39:36 2016 +0200 added url shows up in combobox list commit 4bf37eb06dc9bf13e047a32e2df6deb142ef7dda Author: servantie <servantie.c@gmail.com> Date: Fri Jun 10 11:10:54 2016 +0200 added possibility to edit a url and adds it to the syncURLList of the task (not updated in the combobox yet, but saved) commit 6f03ae4e3303e666bcf7d00d64c68edd02fbc376 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 10 10:18:24 2016 +0200 disables send sync button when sync has been done once commit 4748cb86badaa61b235589bf1a967dd1547e4cbb Author: servantie <servantie.c@gmail.com> Date: Fri Jun 10 09:54:08 2016 +0200 edited to change update into synchronization commit 97bcca40456cd3be1661ede9fc19105fb3973539 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 17:57:32 2016 +0200 fix to display error message when the sync went wrong commit 917eba7f1f90a18a858d475e3dd05eec2211d8d6 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 16:25:23 2016 +0200 added a combobox in manual sync to pick which url to sync on (if one sync fails, pop up shows to say so, but textarea isn't updated on "generate update" button pressing) commit acf7e13705191f57ee7f9996928f288193143645 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 15:15:58 2016 +0200 removed timezone display in TimerTaskUpdaterView (useless) commit 325be3227e7281d7751b1e32603767fa8ae05b39 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 14:43:41 2016 +0200 cleaned up synchronizeTaskOnURL method commit 40dcd7a1e432840bc3c9653f1e231ceb556619dc 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 033fa5dac11882cea7fd021f836e0f126afe7e0e 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 commit 6cd63ea15575b77ad520169f3d77a15902efb3ba Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 16:45:51 2016 +0200 logs instead of stacktrace commit 9a1555e0af209f6dc507f4861a1c79ac5273f2fc Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 15:56:18 2016 +0200 changed syncURL to syncURLList, updated methods for sync accordingly commit 6db411056180bdd1f62fc61e11c84bcac09b2fd2 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 10:00:30 2016 +0200 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) commit e068db82dc6fc337cea7c94173d6dae125c0c0af Author: servantie <servantie.c@gmail.com> Date: Tue Jun 7 16:31:23 2016 +0200 removed a useless toString(), removed unused imports commit 6a17f8f2a2e58a9829e87ab756fafe8de8516406 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 7 14:47:41 2016 +0200 corrected firstdayofweek commit 50a1fab1d3bfe117a10b547aef90915fc8e6d787 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 6 13:55:14 2016 +0200 added a check for empty tasksToSync commit a1a81ad675676c9332a26266ee33bd9e1c599ca4 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 6 11:25:44 2016 +0200 added the timezone as option in JTimerConfig, updated json creation accordingly commit 8636440c05c1d3d2fede0057a58b21582e29a0c9 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 17:24:03 2016 +0200 minor typos corrected, set autosyncdelay to every two hours commit 12a5c2e37bdaae9f960e4f96da27d8515b8bbcaf Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 16:35:15 2016 +0200 removed useless tabs commit 0d8ac912509ed4f7394e99d03f3cc6c95b430a98 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 15:19:06 2016 +0200 added the synchronizer to the config and started treating errors commit 7962d8afda634907fb7c411eda4fbe04a00b5d01 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 11:15:30 2016 +0200 changed name of parseSyncURL to parseSyncInfo (clearer) commit 09a46c6a29ec59af2f0ba6ebae8b12a75354c4da Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 09:52:06 2016 +0200 corrected the json creation to deal with times added before the task's creation date (and be able to send them, that way) corrected the url creation in the synchronization commit 0ec31167fb7a38fd3a7c9f8f4bcae1dfaa39d6ce Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:47:05 2016 +0200 (minor) added timezone in json output (kept forgetting it) commit d41d0e1d706fee32c91c73f7778186bc5bb0e99a Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:44:41 2016 +0200 minor changes (comments) commit 283362d7320c98a48ff9cbc100d0730c79768bb1 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:34:13 2016 +0200 added an automatic synchronization (every min), currently synchronizes all the times of the tasks that have been modified since the last automatic sync. Sends all the times from creation date for now commit 392d34dfbd436eb04a69af8cd2017ec97b5ae8fd Author: servantie <servantie.c@gmail.com> Date: Wed Jun 1 14:40:52 2016 +0200 corrected update to synchronisation commit d16f8d68bd6d68659c78cb8a7da222f0ccc218fb Author: servantie <servantie.c@gmail.com> Date: Mon May 23 17:36:50 2016 +0200 removed a duplicated try/catch in the sendUpdate() method commit 84fa2a13c050c8c275786c79481f1749ce3d0859 Author: servantie <servantie.c@gmail.com> Date: Mon May 23 17:20:24 2016 +0200 changed the return of taskToJSONFormat back to String (to avoid having several toString() in the TimerTaskUpdaterView, when it can be done once in the method) commit 16cb34765159069459e814f84b940f3f67bcbe2b Author: servantie <servantie.c@gmail.com> Date: Mon May 23 17:15:04 2016 +0200 added the gson library to the project to enable easier generation of json output for the updates, adapted the update functions to accomodate (removed useless prettyfier) commit 62133e8f2ca86866586c7e6c260b6d5ccd2dc54e Author: servantie <servantie.c@gmail.com> Date: Fri May 20 17:47:10 2016 +0200 removed a useless comment commit 3cbcd20b9aca4e243d190e0bf46c287ed6d885ac Author: servantie <servantie.c@gmail.com> Date: Fri May 20 11:41:53 2016 +0200 added an error message if the update isn't done, asking to check for url commit 8793f5b2a95f894b72cc606e79aaacaeb12e6c82 Author: servantie <servantie.c@gmail.com> Date: Fri May 20 09:48:12 2016 +0200 saving synchronisation time when update successful commit 34fb3544605bc89d2c8dbc6b3403f64cc5920733 Author: servantie <servantie.c@gmail.com> Date: Thu May 19 16:06:24 2016 +0200 be able to pick previous month and current month for update with a button commit 5249bb573725847edd58afb1fe57984be0e090db Author: servantie <servantie.c@gmail.com> Date: Thu May 19 10:57:29 2016 +0200 displayed the checkbox to include annotations with the update, includes it in the update if checked. commit fc44c09c7adab4e5597c382998feb595a5ba090d Author: servantie <servantie.c@gmail.com> Date: Wed May 18 17:33:52 2016 +0200 set up ids for times in the json output to be dates (one task at one date has only one value for duration in jtimer), minor properties change commit b65ba97a8017dedafae07939811e0a66160c3978 Author: servantie <servantie.c@gmail.com> Date: Wed May 18 16:04:40 2016 +0200 showing an info log when receiving a 200 OK after an update. small typo correction in properties file commit 59ff4b7949e4adf25804bca9e475210e1099372c Author: servantie <servantie.c@gmail.com> Date: Wed May 18 10:07:43 2016 +0200 small typo corrected with " at the wrong places or missing in the json output commit ca9fd6f2f7517e72d5d0994f6d3852a6260a2be9 Author: servantie <servantie.c@gmail.com> Date: Wed May 18 09:53:29 2016 +0200 corrected method for getting times that was ignoring the date parameters and always sending all the times of a task commit 9ccd7748005256d715919b297623e8f1fdc8520e Author: servantie <servantie.c@gmail.com> Date: Tue May 17 14:27:32 2016 +0200 Deletion of TaskJsonDisplayer class that was used to test the display of the json Adding an update option to the UI and an update frame (TimeTaskUpdaterView) to display the data to be sent (not finished) based on the Report UI commit b342e9ef3465ea90450855941e4940344a2f03ea Author: servantie <servantie.c@gmail.com> Date: Tue May 10 11:30:43 2016 +0200 "use of simpler json format, sends update request to url when url is changed with the json of the task." Summary of changes: pom.xml | 12 +- src/license/THIRD-PARTY.properties | 19 + src/main/java/org/chorem/jtimer/JTimer.java | 26 +- src/main/java/org/chorem/jtimer/JTimerFactory.java | 4 +- .../org/chorem/jtimer/data/CommonVetoable.java | 147 ++----- .../org/chorem/jtimer/data/DataEventListener.java | 117 +++-- .../java/org/chorem/jtimer/data/TimerCore.java | 5 +- .../org/chorem/jtimer/data/TimerDataManager.java | 11 +- .../jtimer/data/VetoableDataEventListener.java | 90 ++-- .../java/org/chorem/jtimer/entities/SyncInfo.java | 52 ++- .../org/chorem/jtimer/entities/TimerAlert.java | 13 +- .../java/org/chorem/jtimer/entities/TimerTask.java | 25 +- .../chorem/jtimer/entities/TimerTaskHelper.java | 53 ++- .../java/org/chorem/jtimer/io/AbstractSaver.java | 43 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 471 +++++---------------- .../java/org/chorem/jtimer/io/GTimerTimeUtil.java | 13 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 4 +- .../chorem/jtimer/{ui => }/system/SystemInfo.java | 9 +- .../jtimer/{ui => }/system/SystemInfoFactory.java | 23 +- .../{ui => }/system/macos/ApplicationServices.java | 20 +- .../{ui => }/system/macos/MacOSSystemInfo.java | 14 +- .../jtimer/{ui => }/system/macos/package-info.java | 4 +- .../jtimer/{ui => }/system/package-info.java | 4 +- .../{ui => }/system/unix/UnixSystemInfo.java | 35 +- .../chorem/jtimer/{ui => }/system/unix/X11.java | 2 +- .../chorem/jtimer/{ui => }/system/unix/Xss.java | 4 +- .../jtimer/{ui => }/system/unix/package-info.java | 4 +- .../jtimer/{ui => }/system/win32/Kernel32.java | 2 +- .../jtimer/{ui => }/system/win32/User32.java | 2 +- .../{ui => }/system/win32/Win32SystemInfo.java | 12 +- .../jtimer/{ui => }/system/win32/package-info.java | 4 +- src/main/java/org/chorem/jtimer/ui/HelpFrame.java | 4 +- .../java/org/chorem/jtimer/ui/NewTaskView.java | 2 +- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 95 +---- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 22 +- .../chorem/jtimer/ui/alert/AlertCellEditor.java | 20 +- .../chorem/jtimer/ui/alert/AlertCellRenderer.java | 3 - .../org/chorem/jtimer/ui/alert/AlertEditor.java | 11 +- .../chorem/jtimer/ui/alert/AlertTableModel.java | 20 +- .../org/chorem/jtimer/ui/report/ReportUtils.java | 60 +-- .../org/chorem/jtimer/ui/report/ReportView.java | 35 +- .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 109 +++-- .../ui/system/UnsupportedSystemInfoException.java | 66 --- .../chorem/jtimer/ui/systray/SystrayManager.java | 205 +-------- .../org/chorem/jtimer/ui/tasks/IdleDialog.java | 6 +- .../chorem/jtimer/ui/tasks/RefreshTreeTask.java | 6 +- .../org/chorem/jtimer/ui/tasks/RunTaskJob.java | 59 +-- .../jtimer/ui/tree/CheckBoxTreeCellEditor.java | 10 +- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 104 +---- .../ProjectsAndTasksRunningCellRenderer.java | 129 ------ .../ui/treetable/dnd/TimerTaskTranferable.java | 13 +- .../chorem/jtimer/ui/widget/DurationEditor.java | 6 +- .../chorem/jtimer/ui/widget/JPopupTrayIcon.java | 39 +- .../org/chorem/jtimer/io/AbstractSaverTest.java | 13 +- .../jtimer/io/GTimerIncrementalSaverTest.java | 76 +++- .../{ui => }/system/SystemInfoFactoryTest.java | 22 +- .../chorem/jtimer/utils/DailySortedMapTest.java | 6 +- src/test/resources/testdata/0.task | 1 + src/test/resources/testdata/41.task.sync | 9 +- 59 files changed, 784 insertions(+), 1611 deletions(-) create mode 100644 src/license/THIRD-PARTY.properties rename src/main/java/org/chorem/jtimer/{ui => }/system/SystemInfo.java (84%) rename src/main/java/org/chorem/jtimer/{ui => }/system/SystemInfoFactory.java (74%) rename src/main/java/org/chorem/jtimer/{ui => }/system/macos/ApplicationServices.java (76%) rename src/main/java/org/chorem/jtimer/{ui => }/system/macos/MacOSSystemInfo.java (85%) rename src/main/java/org/chorem/jtimer/{ui => }/system/macos/package-info.java (88%) rename src/main/java/org/chorem/jtimer/{ui => }/system/package-info.java (89%) rename src/main/java/org/chorem/jtimer/{ui => }/system/unix/UnixSystemInfo.java (77%) rename src/main/java/org/chorem/jtimer/{ui => }/system/unix/X11.java (96%) rename src/main/java/org/chorem/jtimer/{ui => }/system/unix/Xss.java (96%) rename src/main/java/org/chorem/jtimer/{ui => }/system/unix/package-info.java (88%) rename src/main/java/org/chorem/jtimer/{ui => }/system/win32/Kernel32.java (97%) rename src/main/java/org/chorem/jtimer/{ui => }/system/win32/User32.java (97%) rename src/main/java/org/chorem/jtimer/{ui => }/system/win32/Win32SystemInfo.java (91%) rename src/main/java/org/chorem/jtimer/{ui => }/system/win32/package-info.java (88%) delete mode 100644 src/main/java/org/chorem/jtimer/ui/system/UnsupportedSystemInfoException.java rename src/test/java/org/chorem/jtimer/{ui => }/system/SystemInfoFactoryTest.java (70%) -- 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 b342e9ef3465ea90450855941e4940344a2f03ea Author: servantie <servantie.c@gmail.com> Date: Tue May 10 11:30:43 2016 +0200 "use of simpler json format, sends update request to url when url is changed with the json of the task." --- .../org/chorem/jtimer/data/CommonVetoable.java | 8 ++ .../org/chorem/jtimer/data/DataEventListener.java | 9 ++ .../org/chorem/jtimer/data/TimerDataManager.java | 16 +++ .../jtimer/data/VetoableDataEventListener.java | 8 ++ .../java/org/chorem/jtimer/entities/TimerTask.java | 38 ++++++- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 116 +++++++++++++++++++++ .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 82 +++++++++++++-- .../jtimer/ui/resources/TimerTaskEditor.properties | 2 + .../ui/resources/TimerTaskEditor_fr.properties | 2 + 9 files changed, 272 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/CommonVetoable.java b/src/main/java/org/chorem/jtimer/data/CommonVetoable.java index 8510936..f74f4d3 100644 --- a/src/main/java/org/chorem/jtimer/data/CommonVetoable.java +++ b/src/main/java/org/chorem/jtimer/data/CommonVetoable.java @@ -202,4 +202,12 @@ public class CommonVetoable implements VetoableDataEventListener { // mais pas une combinaison des deux } } + + /* + * {@inheritDoc} + */ + @Override + public void checkSetTaskURL(TimerTask task, String newURL) { + + } } diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index 78a30b5..c0f5a28 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -189,4 +189,13 @@ public interface DataEventListener extends EventListener { default void dataLoaded(Collection<TimerProject> projects) { } + /** + * Task url changed + * @param task task with url change + * @param newURL new URl to change + */ + default void modifyTaskURL(TimerTask task, String newURL) { + + } } + diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index 25453c6..a5c957c 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -409,6 +409,22 @@ public class TimerDataManager { } /** + * Edit Task URL + */ + public void editTaskURL(TimerTask task, String newURL) { + + TimerTask newTask = task.clone(); + newTask.setSynchronisingURL(newURL); + for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { + vetoableDataEventListener.checkSetTaskURL(task, newURL); + } + task.setSynchronisingURL(newURL); + // send notification + for (DataEventListener dataEventListener : dataEventListeners) { + dataEventListener.modifyTaskURL(task, newURL); + } + } + /** * Move task. * * @param destination task to move to diff --git a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java b/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java index ac7a801..3c5e144 100644 --- a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java @@ -146,4 +146,12 @@ public interface VetoableDataEventListener extends EventListener { } + /** + * Check sync URL ofr a task + * @param task task to change the url + * @param newURL the new URL + */ + default void checkSetTaskURL(TimerTask task, String newURL) { + + } } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 586baa8..f2fc144 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -23,6 +23,7 @@ package org.chorem.jtimer.entities; import java.io.Serializable; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -47,7 +48,7 @@ public class TimerTask implements Cloneable, /** serialVersionUID */ private static final long serialVersionUID = -7590755569706702695L; - /** Task uuid used to managed task equality. */ + /** Task uuid used to managed task equality. */s - protected String uuid = UUID.randomUUID().toString(); /** Task number. */ @@ -89,6 +90,15 @@ public class TimerTask implements Cloneable, protected List<TimerAlert> alerts; /** + * Last synchronisation date + */ + protected LocalDateTime lastSync; + + /** + * URL to synchronise task + */ + protected String synchronisingURL; + /** * Constructor. */ public TimerTask() { @@ -219,6 +229,32 @@ public class TimerTask implements Cloneable, } /** + * Get task's last sync + * @return the date of the sync + */ + public LocalDateTime getLastSync() { return lastSync; } + + /** + * Sets task's last sync + * @param syncDate : date of the sync + */ + public void setLastSync(LocalDateTime syncDate) { + this.lastSync = syncDate; + } + /** + * Get task's sync URL + * @return the URL + */ + public String getSynchronisingURL() { return synchronisingURL; } + + /** + * Sets task's sync URL + * @param synchronisingURL : the sync URL + */ + public void setSynchronisingURL(String synchronisingURL) { + this.synchronisingURL = synchronisingURL; + } + /** * 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 67f2f01..d979c43 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -43,6 +43,7 @@ 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; @@ -115,6 +116,9 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, /** Extension alert. */ protected static final String GTIMER_ALERT_EXTENSION = "alert"; + /** Extension sync. */ + protected static final String GTIMER_SYNC_EXTENSION = "sync"; + /** Empty gtimer project name. */ protected static final String GTIMER_EMPTY_PROJECT_NAME = "No project"; @@ -346,6 +350,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, parseAnnotations(task); parseAlerts(task); + parseSyncURL(task); } } catch (NumberFormatException e) { if (log.isWarnEnabled()) { @@ -584,6 +589,61 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } + /** Try and find sync information and load it + * + * @param task task to load sync info + */ + protected void parseSyncURL(TimerTask task) throws IOException { + int taskNumber = task.getNumber(); + File syncTaskFile = new File(dataSaveDirectory + File.separator + taskNumber +"."+ GTIMER_TASK_EXTENSION +"."+ GTIMER_SYNC_EXTENSION); + + if (syncTaskFile.exists()) { + if (log.isDebugEnabled()) { + log.debug("Synchronisation information found for task " + task.getName()); + } + + try (BufferedReader parseIn = new BufferedReader(new FileReader(syncTaskFile))) { + + // first line : "format: 1.2" + String line = parseIn.readLine(); + while ((line = parseIn.readLine()) != null) { + line = line.trim(); + + if (!line.isEmpty()) { + String syncType = line.substring(0, line.indexOf(' ')); + String syncInfo = line.substring(line.indexOf(' ') +1, line.length()); + + + try { + if (syncType.equals("SyncURL:")) { + task.setSynchronisingURL(syncInfo); + + } + 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); + } + 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"); + } + + } + + } + } + } + } + + } + /** * Find task alert and load it. * @@ -1067,6 +1127,54 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } + /** + * Save synchronisation info for a task. + * + * @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.getSynchronisingURL() != null) { + File backupfile = null; + try (Writer out = new OutputStreamWriter(new FileOutputStream(synchronisationTaskFile), "ISO-8859-1")) { + + // first make backup + backupfile = makeBackupFile(synchronisationTaskFile); + out.write("Format: " + GTIMER_FILE_VERSION + "\n"); + + //save URL + String saveURL = task.getSynchronisingURL(); + out.write("SyncURL: " + saveURL + "\n"); + + //save last sync (if there is one) + if (task.getLastSync() !=null) { + String saveLastSync = task.getLastSync().toString(); + out.write("LastSync: " + saveLastSync + "\n"); + + } + + deleteBackupFile(backupfile); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.debug("Can't save task synchronisation information", e); + } + + // can be null if backup throws the exception + if (backupfile != null) { + restoreBackupFile(backupfile); + } + } + } else { + synchronisationTaskFile.delete(); + } + + } /** * Save task alerts. @@ -1227,6 +1335,14 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, + alertFileToDelete.getPath() + ")"); } } + //and delete sync information file + File syncFileToDelete = new File(dataSaveDirectory + File.separator + fileNumber+ "."+ GTIMER_TASK_EXTENSION + "." + GTIMER_SYNC_EXTENSION); + if (syncFileToDelete.exists()) { + syncFileToDelete.delete(); + if (log.isDebugEnabled()) { + log.debug("Synchronisation file deleted for " + taskOrProject.getName() + "(" + syncFileToDelete.getPath() +")"); + } + } } // second, go recursively on subtasks diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 8ecfbb0..885f4f7 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -34,7 +34,6 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.stream.Collectors; - import javax.swing.ActionMap; import javax.swing.JButton; import javax.swing.JComponent; @@ -52,7 +51,6 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; @@ -91,6 +89,13 @@ public class TimerTaskEditor extends DialogView { protected JSpinner spinnerS; /** 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; @@ -114,6 +119,9 @@ 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). @@ -219,17 +227,59 @@ public class TimerTaskEditor extends DialogView { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); - // text change listener on annotationTextArea and titleTextField + // 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); + panel.add(createEditionPanel(), BorderLayout.SOUTH); - // task title + return panel; + } + + /** + * Create title panel + * @return title panel + */ + protected JPanel createTitlePanel(){ + + SpringLayout layout = new SpringLayout(); + JPanel panel = new JPanel(layout); + + // 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.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); - panel.add(titleText, BorderLayout.NORTH); - panel.add(createJXMonthView(), BorderLayout.CENTER); - panel.add(createEditionPanel(), BorderLayout.SOUTH); return panel; } @@ -522,6 +572,11 @@ public class TimerTaskEditor extends DialogView { titleText.setCaretPosition(0); titleText.getDocument().addDocumentListener(titleChangeListener); + //URL + synchronizeURL.getDocument().removeDocumentListener(URLChangeListener); + synchronizeURL.setText(cloneTask.getSynchronisingURL()); + synchronizeURL.getDocument().addDocumentListener(URLChangeListener); + } /** @@ -534,6 +589,8 @@ public class TimerTaskEditor extends DialogView { isTitleChanged = true; } else if (issuer == annotationChangeListener) { isAnnotationChanged = true; + } else if (issuer == URLChangeListener) { + isURLChanged = true; } updateTask(); } @@ -572,6 +629,11 @@ public class TimerTaskEditor extends DialogView { cloneTask.setName(titleText.getText()); } + // sync URL + if (isURLChanged) { + cloneTask.setSynchronisingURL(synchronizeURL.getText()); + } + dateChanged.add(getSelectedDay().getTime()); setDataChanged(true); @@ -597,7 +659,11 @@ public class TimerTaskEditor extends DialogView { if (isTitleChanged) { dataManager.editTask(task, cloneTask.getName()); } - + // url + if (isURLChanged) { + dataManager.editTaskURL(task, cloneTask.getSynchronisingURL()); + } + for (Date date : dateChanged) { if (log.isDebugEnabled()) { log.debug("Applying changes on: " + date); diff --git a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties index ddf2b8e..027a244 100644 --- a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties +++ b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor.properties @@ -29,3 +29,5 @@ cancel.Action.shortDescription = Revert changes and quit label.time.text = Time: label.annotation.text = Annotation: +label.syncURL.text = URL: +label.title.text = Title: \ No newline at end of file diff --git a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties index 6cd6223..9f6b39f 100644 --- a/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties +++ b/src/main/resources/org/chorem/jtimer/ui/resources/TimerTaskEditor_fr.properties @@ -29,3 +29,5 @@ cancel.Action.shortDescription = Annuler et quitter label.time.text = Temps: label.annotation.text = Note: +label.syncURL.text = URL: +label.title.text = Titre: \ 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 9ccd7748005256d715919b297623e8f1fdc8520e Author: servantie <servantie.c@gmail.com> Date: Tue May 17 14:27:32 2016 +0200 Deletion of TaskJsonDisplayer class that was used to test the display of the json Adding an update option to the UI and an update frame (TimeTaskUpdaterView) to display the data to be sent (not finished) based on the Report UI --- src/main/java/org/chorem/jtimer/JTimer.java | 16 +- .../chorem/jtimer/entities/TimerTaskHelper.java | 73 ++++ .../chorem/jtimer/io/GTimerIncrementalSaver.java | 6 +- .../jtimer/ui/report/TimerTaskUpdaterView.java | 411 +++++++++++++++++++++ .../org/chorem/jtimer/resources/JTimer.properties | 4 + .../chorem/jtimer/resources/JTimer_fr.properties | 6 +- .../resources/TimerTaskUpdaterView.properties | 50 +++ .../resources/TimerTaskUpdaterView_fr.properties | 62 ++++ 8 files changed, 622 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index eefd80c..4a0a733 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -74,6 +74,7 @@ import org.chorem.jtimer.ui.StatusBar; import org.chorem.jtimer.ui.TimerTaskEditor; import org.chorem.jtimer.ui.alert.AlertEditor; import org.chorem.jtimer.ui.report.ReportView; +import org.chorem.jtimer.ui.report.TimerTaskUpdaterView; import org.chorem.jtimer.ui.systray.SystrayManager; import org.chorem.jtimer.ui.tasks.IdleDialog; import org.chorem.jtimer.ui.tasks.RefreshTreeTask; @@ -367,7 +368,7 @@ public class JTimer extends SingleFrameApplication implements "closeProject", "deleteProject", "---", "quit"}; menuBar.add(createMenu("projectMenu", projectMenuActionNames)); - String[] taskMenuActionNames = { "newTask", "editTask", "closeTask", + String[] taskMenuActionNames = { "newTask", "editTask", "updateTask", "closeTask", "deleteTask", "---", "startTask", "stopAllTasks", "---", "addAnnotation", "editAlert", "increment1Task", "increment5Task", "increment30Task", "decrement1Task", @@ -660,6 +661,17 @@ public class JTimer extends SingleFrameApplication implements TimerTaskEditor editor = new TimerTaskEditor(this, task, core); show(editor); } + /** + * Update task. + * Enabled when a task is selected + */ + @Action(enabledProperty = "selectedSingleTask") + public void updateTask() { + TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); + + TimerTaskUpdaterView updater = new TimerTaskUpdaterView(this, core, task); + show(updater); + } /** * Start selected task in tree. @@ -1476,7 +1488,7 @@ public class JTimer extends SingleFrameApplication implements if (isSelectedSingleTask()) { actionNames = new String[] { "startTask", "---", - "newTask", "editTask", "closeTask", "deleteTask", + "newTask", "editTask", "updateTask", "closeTask", "deleteTask", "---", "addAnnotation", "editAlert", "increment1Task", "increment5Task", "increment30Task", "decrement1Task", "decrement5Task", "decrement30Task", "setToZero" }; diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index e6f8eb2..f962f49 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -22,6 +22,8 @@ package org.chorem.jtimer.entities; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -329,4 +331,75 @@ public class TimerTaskHelper { return components; } + + /** + * Returns a String in JSON format (cf schema (simplified) + * with all times and annotations of a task (without subtasks) + * @param task the task to make a JSON from + * @return result the string in JSON + */ + public static String taskToJSONFormat(TimerTask task) { + Date startDate = task.getCreationDate(); + Date endDate = new Date(); + String resultingJSON = taskToJSONFormat(task, startDate, endDate); + return resultingJSON; + } + + + /** + * Returns a String in JSON format (cf schema (simplified) + * with all times and annotations of a task (without subtasks) + * in a given period between two dates + * @param task the task to make a JSON from + * @param startDate the beginning date + * @param endDate the end date + * @return result the string in JSON + */ + public static String taskToJSONFormat(TimerTask task, Date startDate, Date endDate) { + //todo : change id with something else ? + String taskID = Integer.toString(task.getNumber()); + String resultingJSON = "{\"uuid\":\"" + task.getName()+ "\",\"periods\":" + getTimesAndCommentsJSON(task, startDate, endDate) +"}"; + return resultingJSON; + } + + /** + * Returns a String with the times and comments of a task as : + * [{"id":"..","startDate":"..","duration":..,"info":".."},..] + * over a defined period from startDate to endDate + * @param task : task to make a json of + * @param startDate : beginning of period to work with + * @param endDate : end of period + * @return a string in json format + */ + public static String getTimesAndCommentsJSON(TimerTask task, Date startDate, Date endDate) { + String result = ""; + SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); + //todo:deal with ids (currently a useless sequence) + int sequence = 0; + if (task.getAllDaysAndTimes().size() != 0) { + result = result + "["; + SortedMap<Date, Long> timesMap = task.allDaysTimes; + for (SortedMap.Entry<Date, Long> entry : timesMap.entrySet()) { + //adding id, startDate and duration + //converting Date to LocalDate (to ease the .toString()) + //todo:deal with timezones ? + LocalDate date = entry.getKey().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + result = result + "{\"id\":"+ sequence + "\",\"startDate\":\"" + date.toString() + "T00:00:00" + + "\",\"duration\":\"" + Long.toString(entry.getValue()) + ",\"info\":\""; + //adding comments (if there are any) + if (getAnnotation(task, entry.getKey()).size() != 0) { + for (String s : getAnnotation(task, entry.getKey())) { + result = result + s + ","; + } + } + result = result + "\"},"; + ++sequence; + } + //deleting trailing ',' because of the loop + result = result.substring(0, result.length()-1); + result = result + "]"; + } + return result; + } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index d979c43..e991db0 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -1149,9 +1149,10 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write("Format: " + GTIMER_FILE_VERSION + "\n"); //save URL - String saveURL = task.getSynchronisingURL(); + if(!(task.getSynchronisingURL().equals("")) || task.getSynchronisingURL() !=null) { + String saveURL = task.getSynchronisingURL(); out.write("SyncURL: " + saveURL + "\n"); - + } //save last sync (if there is one) if (task.getLastSync() !=null) { String saveLastSync = task.getLastSync().toString(); @@ -1173,7 +1174,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } else { synchronisationTaskFile.delete(); } - } /** diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java new file mode 100644 index 0000000..1181dc2 --- /dev/null +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -0,0 +1,411 @@ + +/* + * #%L + * jTimer + * %% + * Copyright (C) 2008 - 2016 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package org.chorem.jtimer.ui.report; + +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.TimerTask; +import org.jdesktop.application.*; +import org.jdesktop.application.Action; +import org.jdesktop.swingx.JXDatePicker; +import org.jdesktop.swingx.JXTaskPane; +import org.jdesktop.swingx.JXTaskPaneContainer; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.*; +import java.text.DateFormat; +import java.util.*; + +import static org.chorem.jtimer.entities.TimerTaskHelper.taskToJSONFormat; + +/** + * Updates UI + * + * Created by servantie on 13/05/16. + */ +public class TimerTaskUpdaterView extends FrameView implements DocumentListener { + + /** Class logger */ + protected static Log log = LogFactory.getLog(TimerTaskUpdaterView.class); + + /** Timer core. */ + protected TimerCore core; + + /** Include annotations on updates */ + protected JCheckBox checkIncludesAnnotations; + + /** Date pickers, from... to */ + protected JXDatePicker datePickerFrom, datePickerTo; + + /** update output view*/ + protected JTextArea updateArea; + /** update output (as json) */ + protected String updateJson; + + /** task to update */ + protected TimerTask task; + + /** can update */ + protected boolean canUpdate; + + /** + * UpdaterView constructor. + * + * @param application parent reference + * @param core core reference + */ + public TimerTaskUpdaterView(Application application, TimerCore core, TimerTask task) { + + super(application); + + // modify frame name + // otherwise, get parent frame dimension + getFrame().setName("updateFrame"); + //getFrame().setTitle("Update"); + getFrame().setTitle(getResourceMap().getString("updateTitle")); + + this.core = core; + this.task = task; + setComponent(getMainComponent()); + + } + + /** + * Get main view component. + * + * TODO use less complicated UI (no gbl) + * @return main component + */ + protected JComponent getMainComponent() { + + JPanel configComponent = new JXTaskPaneContainer(); + + // panel for options + JXTaskPane panelGeneral = new JXTaskPane(getResourceMap().getString("updateGeneral")); + panelGeneral.setLayout(new GridBagLayout()); + panelGeneral.setSpecial(true); + + // first date picker + JLabel labelFrom = new JLabel(getResourceMap().getString("updateFrom")); + panelGeneral.add(labelFrom, new GridBagConstraints(0, 0, 1, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + datePickerFrom = new JXDatePicker(); + datePickerFrom.getMonthView().setDayForeground(Calendar.SUNDAY, Color.RED); + datePickerFrom.setFormats(DateFormat.getDateInstance(DateFormat.FULL)); + panelGeneral.add(datePickerFrom, new GridBagConstraints(1, 0, 1, 1, 1, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + + // second date picker + JLabel labelTo = new JLabel(getResourceMap().getString("updateTo")); + panelGeneral.add(labelTo, new GridBagConstraints(0, 1, 1, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + datePickerTo = new JXDatePicker(); + datePickerTo.getMonthView().setDayForeground(Calendar.SUNDAY, Color.RED); + datePickerTo.setFormats(DateFormat.getDateInstance(DateFormat.FULL)); + panelGeneral.add(datePickerTo, new GridBagConstraints(1, 1, 1, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + + // set current week by default + currentWeek(); + + // action button to show current or previous week + JButton currentWeekButton = new JButton(); + currentWeekButton.setBorder(BorderFactory.createEmptyBorder()); + currentWeekButton.setAction(getContext().getActionMap(this).get("currentWeek")); + panelGeneral.add(currentWeekButton, new GridBagConstraints(2, 0, 1, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + JButton previousWeekButton = new JButton(); + previousWeekButton.setBorder(BorderFactory.createEmptyBorder()); + previousWeekButton.setAction(getContext().getActionMap(this).get("previousWeek")); + panelGeneral.add(previousWeekButton, new GridBagConstraints(2, 1, 1, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + + // Option for period grouping + JPanel typePanel = new JPanel(new GridLayout(0, 2)); + panelGeneral.add(typePanel, new GridBagConstraints(0, 2, 3, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + + // miscellaneous + JXTaskPane panelOption = new JXTaskPane(getResourceMap().getString("updateOptions")); + + checkIncludesAnnotations = new JCheckBox(); + checkIncludesAnnotations.setAction(getContext().getActionMap(this).get("updateAnnotations")); + panelOption.add(checkIncludesAnnotations); + + configComponent.add(panelGeneral); + configComponent.add(panelOption); + + // panel for update output text + JPanel panelUpdate = new JPanel(new GridBagLayout()); + + updateArea = new JTextArea(); + updateArea.setFont(new Font("Courier", Font.PLAIN, 12)); + updateArea.getDocument().addDocumentListener(this); + JScrollPane jspupdate = new JScrollPane(updateArea); + panelUpdate.add(jspupdate, new GridBagConstraints(0, 0, 3, 1, 1, 1, + GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); + + // buttons + JButton generateButton = new JButton(); + generateButton.setAction(getContext().getActionMap(this).get("generateUpdate")); + panelUpdate.add(generateButton, new GridBagConstraints(0, 1, 1, 1, 1, 0, + GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); + + JButton sendUpdateButton = new JButton(); + sendUpdateButton.setAction(getContext().getActionMap(this).get("sendUpdate")); + panelUpdate.add(sendUpdateButton, new GridBagConstraints(1, 1, 1, 1, 1, 0, + GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); + + JButton closeButton = new JButton(); + closeButton.setAction(getContext().getActionMap(this).get("closeView")); + panelUpdate.add(closeButton, new GridBagConstraints(2, 1, 1, 1, 1, 0, + GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); + + // color fix on linux ? + configComponent.setBackground(panelUpdate.getBackground()); + // set minimum size to prevent "packed size" (too big) + configComponent.setMinimumSize(new Dimension(200, 0)); + + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, configComponent, panelUpdate); + splitPane.setOneTouchExpandable(true); + return splitPane; + } + + /** + * Select current week in date pickers. + */ + @org.jdesktop.application.Action + public void currentWeek() { + fillPickerDates(0); + } + + /** + * Display previous week in date pickers. + */ + @org.jdesktop.application.Action + public void previousWeek() { + fillPickerDates(-1); + } + + /** + * Fill picker date with predefined week selection (from current) + * and apply a delay (-1 = previous week). + * + * @param delay delay to add to current week + */ + protected void fillPickerDates(int delay) { + // init dates + Calendar calendarBegin = Calendar.getInstance(); + int firstDayOfWeek = JTimer.config.getReportFirstDayOfWeek(); + if (firstDayOfWeek <= 0 || firstDayOfWeek > 7) { + firstDayOfWeek = calendarBegin.getFirstDayOfWeek(); + } + calendarBegin.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); + calendarBegin.set(Calendar.HOUR, 0); + calendarBegin.set(Calendar.MINUTE, 0); + calendarBegin.set(Calendar.SECOND, 0); + calendarBegin.set(Calendar.MILLISECOND, 0); + + // calendar must be in current week by default + if (calendarBegin.getTime().after(new Date())) { + calendarBegin.add(Calendar.WEEK_OF_YEAR, -1); + } + + // get end of week + // take calendarBegin and add a week time + Calendar calendarEnd = (Calendar) calendarBegin.clone(); + calendarEnd.add(Calendar.WEEK_OF_YEAR, 1); + calendarEnd.add(Calendar.DAY_OF_YEAR, -1); // take the day before + + // apply delai + calendarBegin.add(Calendar.WEEK_OF_YEAR, delay); + calendarEnd.add(Calendar.WEEK_OF_YEAR, delay); + + datePickerFrom.setDate(calendarBegin.getTime()); + datePickerTo.setDate(calendarEnd.getTime()); + } + + /** + * Prettify the JSON String to make it + * human readable + * @param jsonString : the JSON string to prettify + * @return an easier to read String + */ + public static String prettifyJSON(String jsonString) { + int indent = 0; + String prettyJson; + String prettiest = ""; + //return line after each { + prettyJson = jsonString.replace("{", "{\n\t"); + prettyJson = prettyJson.replace("}", "\n}"); + //fix { \n }Â (useless space} + prettyJson = prettyJson.replace("{\n\t\n}", "{}"); + // return after each , + prettyJson = prettyJson.replace(",", ",\n\t"); + //change ":" into " : " + prettyJson = prettyJson.replace("\":\"", "\" : \""); + prettyJson = prettyJson.replace("\":", "\" : "); + for (int i = 0 ; i < prettyJson.length(); ++i) { + prettiest = prettiest + prettyJson.charAt(i); + if ((indent != 0) && (prettyJson.charAt(i) == '\n')) { + for (int j = 0 ; j < indent ; ++j) { + prettiest = prettiest + "\t"; + } + } + if (prettyJson.charAt(i) == '{') { + ++indent; + } + else if (prettyJson.charAt(i) == '}') { + --indent; + } + } + return prettiest; + } + + /** + * Close action. + */ + @org.jdesktop.application.Action + public void closeView() { + getApplication().hide(this); + } + + + /** + * Make update. + * + * Set content in {@link #updateArea} text area. + */ + @org.jdesktop.application.Action + public void generateUpdate() { + updateJson = ""; + // make String of information + updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), + datePickerTo.getDate()); + + if (updateJson != null && !updateJson.isEmpty()) { + updateArea.setText(prettifyJSON(updateJson)); + } else { + updateArea.setText(""); + } + } + + + /** + * Can update ? + * + * @return true if can update + */ + public boolean isUpdatingEnabled() { + return canUpdate; + } + + /** + * Change can update property. + * + * @param enabled can update + */ + public void setUpdatingEnabled(boolean enabled) { + boolean oldValue = canUpdate; + canUpdate = enabled; + firePropertyChange("updatingEnabled", oldValue, canUpdate); + } + + /** + * send update + */ + @Action(enabledProperty = "updatingEnabled") + public void sendUpdate() { + String syncURl = task.getSynchronisingURL(); + String charset = "UTF-8"; + String query=""; + try { + query = String.format("json=%s", URLEncoder.encode(updateJson, charset)); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + try { + query = String.format("json=%s", URLEncoder.encode(updateJson, charset)); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + URLConnection connection = null; + try { + connection = new URL("http://"+ syncURl).openConnection(); + } catch (IOException e) { + e.printStackTrace(); + } + connection.setDoOutput(true); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json" + charset); + + try (OutputStream output = connection.getOutputStream()) { + output.write(query.getBytes(charset)); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + //todo: deal with responses ! + InputStream response = connection.getInputStream(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void changedUpdate(DocumentEvent e) { + documentChanged(); + } + + @Override + public void insertUpdate(DocumentEvent e) { + documentChanged(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + documentChanged(); + } + + /** + * Document content changed. + * + * Update can send update property. + */ + protected void documentChanged() { + setUpdatingEnabled(updateArea.getText().trim().length() > 0); + } +} diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties index e218c6a..a926505 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties @@ -62,6 +62,10 @@ editTask.Action.text = &Edit Task editTask.Action.accelerator = F2 editTask.Action.shortDescription = Edit task +updateTask.Action.text = &Update Task +updateTask.Action.accelerator = F5 +updateTask.Action.shortDescription = Update task + closeTask.Action.text = &Open/Close Task closeTask.Action.accelerator = control O closeTask.Action.shortDescription = Open or close task diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties index d5a4e9e..eb4c7e3 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties @@ -41,6 +41,10 @@ newTask.Action.shortDescription = Cr\u00E9ation d'une nouvelle t\u00E2che editTask.Action.text = \u00C9dition de la t\u00E2ch&e editTask.Action.shortDescription = \u00C9dition de la t\u00E2che + +updateTask.Action.text = &Mettre \u00E0 jour +updateTask.Action.shortDescription = Mettre \u00E0 jour + closeTask.Action.text = &Ouvrir/Fermer la t\u00E2che closeTask.Action.shortDescription = Ouvrir ou fermer la t\u00E2che @@ -149,4 +153,4 @@ vetoable.saver.invalid.characters=Le nom contient des caract\u00E8res invalide ! # Start fail i18n startFail.title=Erreur -startFail.message=${Application.title} n'a pas r\u00E9ussi \u00E0 s'initiliser.\nV\u00E9rifiez que ${Application.title} n'est pas d\u00E9j\u00E0 lanc\u00E9. +startFail.message=${Application.title} n'a pas r\u00E9ussi \u00E0 s'initialiser.\nV\u00E9rifiez que ${Application.title} n'est pas d\u00E9j\u00E0 lanc\u00E9. 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 new file mode 100644 index 0000000..6359a52 --- /dev/null +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties @@ -0,0 +1,50 @@ +### +# #%L +# jTimer +# %% +# Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +updateTitle=${Application.title} - Update +updateGeneral=General +updateOptions=Options +updateFrom=From : +updateTo=To : +updateDaily=Daily +updateMonthly=Monthly +updateWeekly=Weekly +updateYearly=Yearly + +currentWeek.Action.icon = date_current.png +currentWeek.Action.shortDescription = Current week- + +previousWeek.Action.icon = date_previous.png +previousWeek.Action.shortDescription = Previous week + +updateAnnotations.Action.text = Include annotations + +generateUpdate.Action.text = &Generate +generateUpdate.Action.icon = applications-system.png +generateUpdate.Action.shortDescription = Generate update + +sendUpdate.Action.text = &Send +sendUpdate.Action.icon = mail-forward.png +sendUpdate.Action.shortDescription = Send update + +closeView.Action.text = &Close +closeView.Action.icon = dialog-close.png +closeView.Action.shortDescription = Close 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 new file mode 100644 index 0000000..85d01e6 --- /dev/null +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties @@ -0,0 +1,62 @@ +### +# #%L +# jTimer +# %% +# Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +# update i18n +updateTitle=${Application.title} - Mise \u00E0 jour +updateGeneral=G\u00E9n\u00E9ral +updateOptions=Options +updateFrom=De : +updateTo=\u00C0 : +updateDaily=Par jour +updateMonthly=Par mois +updateWeekly=Par semaine +updateYearly=Par ann\u00E9e +updateByProject=Par projet + +updateIncludeTime=Afficher les temps +updateAnnotationsTime=avec l'heure +updateIntermediateTotalTime=Ajout des temps totaux interm\u00E9diaires +updateProjects=Projets +updateProjectsList=Liste des projets + +currentWeek.Action.icon = date_current.png +currentWeek.Action.shortDescription = Semaine courante- + +previousWeek.Action.icon = date_previous.png +previousWeek.Action.shortDescription = Semaine precedente + +updateAnnotations.Action.text = Inclure les annotations + + +showHiddenProjects.Action.text = Show hidden projects +showHiddenProjects.Action.shortDescription = Show hidden projects + +generateUpdate.Action.text = &G\u00E9n\u00E9rer +generateUpdate.Action.icon = applications-system.png +generateUpdate.Action.shortDescription = G\u00E9n\u00E9rer la mise \u00C0 jour + +sendUpdate.Action.text = &Envoyer +sendUpdate.Action.icon = mail-forward.png +sendUpdate.Action.shortDescription = Envoyer la mise \u00C0 jour + +closeView.Action.text = &Fermer +closeView.Action.icon = dialog-close.png +closeView.Action.shortDescription = Fermer -- 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 ca9fd6f2f7517e72d5d0994f6d3852a6260a2be9 Author: servantie <servantie.c@gmail.com> Date: Wed May 18 09:53:29 2016 +0200 corrected method for getting times that was ignoring the date parameters and always sending all the times of a task --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index f962f49..ba7bad1 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -358,7 +358,7 @@ public class TimerTaskHelper { public static String taskToJSONFormat(TimerTask task, Date startDate, Date endDate) { //todo : change id with something else ? String taskID = Integer.toString(task.getNumber()); - String resultingJSON = "{\"uuid\":\"" + task.getName()+ "\",\"periods\":" + getTimesAndCommentsJSON(task, startDate, endDate) +"}"; + String resultingJSON = "{\"URL\":\"" + task.getSynchronisingURL()+ "\",\"periods\":" + getTimesAndCommentsJSON(task, startDate, endDate) +"}"; return resultingJSON; } @@ -376,10 +376,9 @@ public class TimerTaskHelper { SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); //todo:deal with ids (currently a useless sequence) int sequence = 0; - if (task.getAllDaysAndTimes().size() != 0) { + if (dates.size() != 0) { result = result + "["; - SortedMap<Date, Long> timesMap = task.allDaysTimes; - for (SortedMap.Entry<Date, Long> entry : timesMap.entrySet()) { + for (SortedMap.Entry<Date, Long> entry : dates.entrySet()) { //adding id, startDate and duration //converting Date to LocalDate (to ease the .toString()) //todo:deal with timezones ? @@ -400,6 +399,9 @@ public class TimerTaskHelper { result = result.substring(0, result.length()-1); result = result + "]"; } + else { + result ="[]"; + } return result; } } -- 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 0ec31167fb7a38fd3a7c9f8f4bcae1dfaa39d6ce Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:47:05 2016 +0200 (minor) added timezone in json output (kept forgetting it) --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 7adf2d4..c5a2a77 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -377,7 +377,7 @@ public class TimerTaskHelper { //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); periodElement.addProperty("id", dateString); - periodElement.addProperty("startDate", dateString + "T00:00:00"); + periodElement.addProperty("startDate", dateString + "T00:00:00.000+0100"); periodElement.addProperty("duration", entry.getValue()); if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { String annotations = ""; -- 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 09a46c6a29ec59af2f0ba6ebae8b12a75354c4da Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 09:52:06 2016 +0200 corrected the json creation to deal with times added before the task's creation date (and be able to send them, that way) corrected the url creation in the synchronization --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 2 +- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index c5a2a77..f2ed4a8 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -342,7 +342,7 @@ public class TimerTaskHelper { * @return result the string in JSON */ public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations) { - Date startDate = task.getCreationDate(); + Date startDate = task.getAllDaysAndTimes().firstKey(); Date endDate = new Date(); JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations); return resultingJSON; diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 05e716a..95b995d 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected int autoSyncDelay = 1000 * 60; //1min for testing purposes + protected int autoSyncDelay = 1000 * 10; //10 s for testing purposes /** timer to schedule syncs */ protected Timer timer; @@ -78,13 +78,14 @@ public class TimerTaskSynchronizer implements DataEventListener { synchronized (tasksToSync) { Collection<TimerTask> remainingTasks = new ArrayList<>(tasksToSync); for (TimerTask task : tasksToSync) { + if (log.isDebugEnabled()){ + log.debug("task " + task.getName() + " being synced."); + } //do the sync, store the result boolean syncDone = synchronizeSingleTask(task); if (remainingTasks.contains(task)) { remainingTasks.remove(task); } - log.info(" task synced : " + syncDone); - } tasksToSync = remainingTasks; @@ -109,7 +110,7 @@ public class TimerTaskSynchronizer implements DataEventListener { HttpURLConnection connection = null; URL url = null; try { - url = new URL("http://" + syncURl); + url = new URL(syncURl); } catch (MalformedURLException e) { e.printStackTrace(); } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 7962d8afda634907fb7c411eda4fbe04a00b5d01 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 11:15:30 2016 +0200 changed name of parseSyncURL to parseSyncInfo (clearer) --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 8 ++++---- src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java | 4 ++-- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index f2ed4a8..1cf5ca5 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -376,9 +376,9 @@ public class TimerTaskHelper { String dateString = date.toString(); //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); - periodElement.addProperty("id", dateString); - periodElement.addProperty("startDate", dateString + "T00:00:00.000+0100"); - periodElement.addProperty("duration", entry.getValue()); + periodElement.addProperty("periodId", dateString); + periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000+0100"); + periodElement.addProperty("periodDuration", entry.getValue()); if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { String annotations = ""; for (String s : getAnnotation(task, entry.getKey())) { @@ -386,7 +386,7 @@ public class TimerTaskHelper { } //remove trailing comma annotations = annotations.substring(0, annotations.length()-1); - periodElement.addProperty("info", annotations); + periodElement.addProperty("periodInfo", annotations); } periodArray.add(periodElement); } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index e991db0..b9f822d 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -350,7 +350,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, parseAnnotations(task); parseAlerts(task); - parseSyncURL(task); + parseSyncInfo(task); } } catch (NumberFormatException e) { if (log.isWarnEnabled()) { @@ -593,7 +593,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * * @param task task to load sync info */ - protected void parseSyncURL(TimerTask task) throws IOException { + protected void parseSyncInfo(TimerTask task) throws IOException { int taskNumber = task.getNumber(); File syncTaskFile = new File(dataSaveDirectory + File.separator + taskNumber +"."+ GTIMER_TASK_EXTENSION +"."+ GTIMER_SYNC_EXTENSION); diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 95b995d..882e6af 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -83,6 +83,7 @@ public class TimerTaskSynchronizer implements DataEventListener { } //do the sync, store the result boolean syncDone = synchronizeSingleTask(task); + //for now doesn't deal with failure in the update, just task already updated if (remainingTasks.contains(task)) { remainingTasks.remove(task); } @@ -157,7 +158,7 @@ public class TimerTaskSynchronizer implements DataEventListener { return true; } else { - log.error("Sync error, wrong URL?"); + log.error("Sync error"); return false; } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 0d8ac912509ed4f7394e99d03f3cc6c95b430a98 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 15:19:06 2016 +0200 added the synchronizer to the config and started treating errors --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 18 +++++++++- src/main/java/org/chorem/jtimer/JTimerFactory.java | 38 ++++++++++++++++++++++ .../java/org/chorem/jtimer/data/TimerCore.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 36 ++++++++++---------- 4 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 76138db..499eac9 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -168,6 +168,19 @@ public class JTimerConfig { } /** + * Returns the synchronizer class + * @return + */ + public Class<?> getIOSynchronizerClass() {return appConfig.getOptionAsClass(JTimerOption.IO_SYNC_CLASS.key); + } + + /** + * Returns autosync delay in seconds + * @return auto sync delay + */ + public long getIOSyncAutoSyncDelay() { return appConfig.getOptionAsLong(JTimerOption.IO_SYNC_AUTOSYNCDELAY.key);} + + /** * Return user idle time threshold in seconds. * * @return idle time threshold @@ -279,10 +292,13 @@ public class JTimerConfig { GTIMER_BACKUP_DIRECTORY("jtimer.io.backup.directory", "${jtimer.io.saver.directory}/backups"), IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), + IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), UI_CLOSE_TO_SYSTRAY("jtimer.ui.closetosystray", "true"), - UI_REPORT_FIRSTDAYOFWEEK("jtimer.ui.report.firstdayofweek", "0"); + UI_REPORT_FIRSTDAYOFWEEK("jtimer.ui.report.firstdayofweek", "10"); protected String key; protected String defaultValue; diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index 2a4392b..037c96c 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.java @@ -25,6 +25,7 @@ package org.chorem.jtimer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.io.Saver; +import org.chorem.jtimer.io.TimerTaskSynchronizer; /** * JTimer config class. @@ -43,6 +44,9 @@ public class JTimerFactory { /** Saver */ protected static Saver saver; + /** Synchronizer */ + protected static TimerTaskSynchronizer synchronizer; + /** * Constructeur. */ @@ -88,4 +92,38 @@ public class JTimerFactory { return saver; } + + /** + * Get synchronizer manager + */ + public static TimerTaskSynchronizer getSynchronizer(){ + if (synchronizer == null) { + + Class<?> synchronizerClass = JTimer.config.getIOSynchronizerClass(); + + // log + if (log.isInfoEnabled()) { + log.info("Using synchronizer class : " + synchronizerClass); + log.info(" with auto synchronizer delay : " + JTimer.config.getIOSyncAutoSyncDelay()); + } + + try { + // get instance + synchronizer = (TimerTaskSynchronizer) synchronizerClass.newInstance(); + + // set delay to saver + synchronizer.setAutoSyncDelay(JTimer.config.getIOSyncAutoSyncDelay() * 1000); + + } catch (InstantiationException e) { + if (log.isErrorEnabled()) { + log.error("Can't instanciate class : " + synchronizerClass, e); + } + } catch (IllegalAccessException e) { + if (log.isErrorEnabled()) { + log.error("Can't access class : " + synchronizerClass, e); + } + } + } + return synchronizer; + } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index a917f93..5091468 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -91,7 +91,7 @@ public class TimerCore { } //init sync - synchronizer = new TimerTaskSynchronizer(this); + synchronizer = JTimerFactory.getSynchronizer(); if (synchronizer != null) { data.addDataEventListener(synchronizer); } diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 882e6af..e322ab8 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,25 +26,19 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected int autoSyncDelay = 1000 * 10; //10 s for testing purposes + protected long autoSyncDelay = 1000 * 10 ; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; - /** timer core (to retrieve tasks) */ - protected TimerCore core; - /** Tasks to sync */ protected Collection<TimerTask> tasksToSync; - public TimerTaskSynchronizer(TimerCore core) { - + public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); log.info("Starting synchronising thread"); - this.core = core; - tasksToSync = Collections.synchronizedCollection(new ArrayList<>()); } @@ -52,7 +46,7 @@ public class TimerTaskSynchronizer implements DataEventListener { * Change the autosync delay * @param autoSyncDelay */ - public void setAutoSyncDelay(int autoSyncDelay) { + public void setAutoSyncDelay(long autoSyncDelay) { if (autoSyncDelay>0) { this.autoSyncDelay = autoSyncDelay; } @@ -84,25 +78,28 @@ public class TimerTaskSynchronizer implements DataEventListener { //do the sync, store the result boolean syncDone = synchronizeSingleTask(task); //for now doesn't deal with failure in the update, just task already updated - if (remainingTasks.contains(task)) { - remainingTasks.remove(task); + if (remainingTasks.contains(task)) { + remainingTasks.remove(task); + } + + if (syncDone) { + log.debug("Sync done"); + } + else { + log.debug("Sync failed"); } } tasksToSync = remainingTasks; } } - - - } - - /** * Makes one synchronization for a task, without annotations by default * * @param task + * @return boolean for failure of sync (maybe make it return an int for better treatment of failure) */ public boolean synchronizeSingleTask(TimerTask task) { String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); @@ -114,11 +111,15 @@ public class TimerTaskSynchronizer implements DataEventListener { url = new URL(syncURl); } catch (MalformedURLException e) { e.printStackTrace(); + //abort synchronization of this task if the url is wrong + return false; } try { connection = (HttpURLConnection) url.openConnection(); } catch (IOException e) { e.printStackTrace(); + //abort synchronization of this task if connection impossible + return false; } connection.setUseCaches(false); connection.setDoInput(true); @@ -145,9 +146,10 @@ public class TimerTaskSynchronizer implements DataEventListener { //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); boolean hasUpdated = false; - //check for positive answer from server + //check for answer from server for (Map.Entry<String, List<String>> entry : map.entrySet()) { for (String s : entry.getValue()) { + //positive answer, synchronization accepted if (s.equals("HTTP/1.1 200 OK")) { hasUpdated = true; } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 12a5c2e37bdaae9f960e4f96da27d8515b8bbcaf Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 16:35:15 2016 +0200 removed useless tabs --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index e322ab8..6cabf41 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -144,25 +144,25 @@ public class TimerTaskSynchronizer implements DataEventListener { e.printStackTrace(); } //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - boolean hasUpdated = false; - //check for answer from server - for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - //positive answer, synchronization accepted - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; - } + Map<String, List<String>> map = connection.getHeaderFields(); + boolean hasUpdated = false; + //check for answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + //positive answer, synchronization accepted + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } - else { - log.error("Sync error"); - return false; - } + } + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } + else { + log.error("Sync error"); + return false; + } } @Override -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 8636440c05c1d3d2fede0057a58b21582e29a0c9 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 17:24:03 2016 +0200 minor typos corrected, set autosyncdelay to every two hours --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 129 +++++++++++---------- 2 files changed, 70 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 499eac9..5d52f63 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -293,7 +293,7 @@ public class JTimerConfig { IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), - IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "3600"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 6cabf41..a15f05f 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected long autoSyncDelay = 1000 * 10 ; //every 2 hours, check for modifications to sync + protected long autoSyncDelay = 1000 * 60 * 60 * 2 ; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; @@ -103,66 +103,68 @@ public class TimerTaskSynchronizer implements DataEventListener { */ public boolean synchronizeSingleTask(TimerTask task) { String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); - String syncURl = task.getSynchronisingURL(); + String syncURL = task.getSynchronisingURL(); String charset = "UTF-8"; HttpURLConnection connection = null; URL url = null; - try { - url = new URL(syncURl); - } catch (MalformedURLException e) { - e.printStackTrace(); - //abort synchronization of this task if the url is wrong - return false; - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - e.printStackTrace(); - //abort synchronization of this task if connection impossible - return false; - } - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json"); - try { - connection.setRequestMethod("POST"); - } catch (ProtocolException e) { - e.printStackTrace(); - } - byte[] postDataBytes = new byte[0]; - try { - postDataBytes = updateJsonString.toString().getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - try { - connection.getOutputStream().write(postDataBytes); - } catch (IOException e) { - e.printStackTrace(); - } - //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - boolean hasUpdated = false; - //check for answer from server - for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - //positive answer, synchronization accepted - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; + if (syncURL != null) { + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + e.printStackTrace(); + //abort synchronization of this task if the url is wrong + return false; + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + //abort synchronization of this task if connection impossible + return false; + } + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json"); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + e.printStackTrace(); + } + byte[] postDataBytes = new byte[0]; + try { + postDataBytes = updateJsonString.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + e.printStackTrace(); + } + //get the header fields + Map<String, List<String>> map = connection.getHeaderFields(); + boolean hasUpdated = false; + //check for answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + //positive answer, synchronization accepted + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; + } } } + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } else { + log.error("Sync error"); + return false; + } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } - else { - log.error("Sync error"); - return false; - } + return false; } @Override @@ -185,9 +187,12 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void modifyTask(TimerTask task) { - //when a task is modified, add it to the to sync list (if it isn't already there= + //when a task is modified, add it to the to sync list (if it isn't already there) if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { tasksToSync.add(task); + } } } @@ -250,8 +255,10 @@ public class TimerTaskSynchronizer implements DataEventListener { @Override public void stopTask(TimerTask task) { if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { tasksToSync.add(task); - } + } } } @Override @@ -266,9 +273,11 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void modifyTaskURL(TimerTask task, String newURL) { - if(!tasksToSync.contains(task) && (!task.getSynchronisingURL().equals(null))) { - tasksToSync.add(task); - } + if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { + tasksToSync.add(task); + } } } @Override -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit a1a81ad675676c9332a26266ee33bd9e1c599ca4 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 6 11:25:44 2016 +0200 added the timezone as option in JTimerConfig, updated json creation accordingly --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 9 ++- src/main/java/org/chorem/jtimer/JTimerFactory.java | 3 + .../chorem/jtimer/entities/TimerTaskHelper.java | 8 +-- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 21 ++++-- .../jtimer/ui/report/TimerTaskUpdaterView.java | 78 ++++++++++++++-------- 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 5d52f63..0bc8dc1 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -181,6 +181,12 @@ public class JTimerConfig { public long getIOSyncAutoSyncDelay() { return appConfig.getOptionAsLong(JTimerOption.IO_SYNC_AUTOSYNCDELAY.key);} /** + * Returns timezone for sync + * @return timezone + */ + public String getIOSyncTimeZone() { return appConfig.getOption(JTimerOption.IO_SYNC_TIMEZONE.key);} + + /** * Return user idle time threshold in seconds. * * @return idle time threshold @@ -293,7 +299,8 @@ public class JTimerConfig { IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), - IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "3600"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + IO_SYNC_TIMEZONE("jtimer.io.synchronizer.timezone", "+0600"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index 037c96c..9f8ab49 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.java @@ -114,6 +114,9 @@ public class JTimerFactory { // set delay to saver synchronizer.setAutoSyncDelay(JTimer.config.getIOSyncAutoSyncDelay() * 1000); + //set timezone to synchronizer + synchronizer.setTimezone(JTimer.config.getIOSyncTimeZone()); + } catch (InstantiationException e) { if (log.isErrorEnabled()) { log.error("Can't instanciate class : " + synchronizerClass, e); diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 1cf5ca5..9ecab69 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -341,10 +341,10 @@ public class TimerTaskHelper { * @param task the task to make a JSON from * @return result the string in JSON */ - public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations) { + public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations, String timezone) { Date startDate = task.getAllDaysAndTimes().firstKey(); Date endDate = new Date(); - JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations); + JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations, timezone); return resultingJSON; } @@ -360,7 +360,7 @@ public class TimerTaskHelper { * @param withAnnotations true if annotations included * @return result the string in JSON */ - public static JsonObject taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations) { + public static JsonObject taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { JsonObject responseJSON = new JsonObject(); LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); @@ -377,7 +377,7 @@ public class TimerTaskHelper { //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); periodElement.addProperty("periodId", dateString); - periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000+0100"); + periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000" + timezone); periodElement.addProperty("periodDuration", entry.getValue()); if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { String annotations = ""; diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index a15f05f..6a1f577 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected long autoSyncDelay = 1000 * 60 * 60 * 2 ; //every 2 hours, check for modifications to sync + protected long autoSyncDelay = 1000 * 10; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; @@ -34,6 +34,9 @@ public class TimerTaskSynchronizer implements DataEventListener { /** Tasks to sync */ protected Collection<TimerTask> tasksToSync; + /** Timezone */ + protected String timezone = "+0100"; + public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); @@ -53,6 +56,16 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** + * Change the timezone + * @param timezone + */ + public void setTimezone(String timezone) { + if (!timezone.isEmpty() && !timezone.equals(null)) { + this.timezone = timezone; + } + } + + /** * Inner Task class to make the automatic sync */ protected class UpdateTask extends java.util.TimerTask { @@ -102,11 +115,11 @@ public class TimerTaskSynchronizer implements DataEventListener { * @return boolean for failure of sync (maybe make it return an int for better treatment of failure) */ public boolean synchronizeSingleTask(TimerTask task) { - String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); + String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false, timezone).toString(); String syncURL = task.getSynchronisingURL(); String charset = "UTF-8"; - HttpURLConnection connection = null; - URL url = null; + HttpURLConnection connection; + URL url; if (syncURL != null) { try { url = new URL(syncURL); diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java index df85ba6..66e165c 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -82,6 +82,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener /** can update */ protected boolean canUpdate; + /** timezone */ + protected String timezone; + /** * UpdaterView constructor. * @@ -98,6 +101,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener this.core = core; this.task = task; setComponent(getMainComponent()); + //default the timezone + timezone = "+0100"; } @@ -335,7 +340,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener // make the JSON Object of information updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), - datePickerTo.getDate(), isIncludingAnnotations()); + datePickerTo.getDate(), isIncludingAnnotations(), timezone); //make it human readable Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonOutput = gson.toJson(updateJson); @@ -384,45 +389,59 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener */ @Action(enabledProperty = "updatingEnabled") public void sendUpdate() { - String syncURl = task.getSynchronisingURL(); + String syncURL = task.getSynchronisingURL(); String charset = "UTF-8"; - String query=""; - try { - query = String.format("json=%s", URLEncoder.encode(updateJson.toString(), charset)); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + if (syncURL != null) { + HttpURLConnection connection= null; + URL url = null; + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + } + + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setRequestProperty("Content-Length", "" + updateJson.toString().length()); + connection.setDoOutput(true); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json" + charset); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + e.printStackTrace(); + } + byte[] postDataBytes = new byte[0]; + try { + postDataBytes = updateJson.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + e.printStackTrace(); + } - URLConnection connection = null; - try { - connection = new URL("http://"+ syncURl).openConnection(); - } catch (IOException e) { - e.printStackTrace(); - } - connection.setDoOutput(true); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json" + charset); - - try (OutputStream output = connection.getOutputStream()) { - output.write(query.getBytes(charset)); - } catch (IOException e) { - e.printStackTrace(); - } //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); boolean hasUpdated = false; //check for positive answer from server for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; - } + for (String s : entry.getValue()) { + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; } } + } if (hasUpdated) { core.getData().editTaskLastSync(task, LocalDateTime.now()); - } - else { + } else { log.error("Update error, wrong URL?"); String message = getResourceMap().getString("action.updateError"); String title = getResourceMap().getString("action.updateErrorTitle"); @@ -430,6 +449,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener JOptionPane.ERROR_MESSAGE); } + } } @Override -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 50a1fab1d3bfe117a10b547aef90915fc8e6d787 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 6 13:55:14 2016 +0200 added a check for empty tasksToSync --- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 6 ++++-- src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 6 ++++++ .../jtimer/ui/report/resources/TimerTaskUpdaterView.properties | 1 + .../jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 6a1f577..2099d68 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -201,10 +201,12 @@ public class TimerTaskSynchronizer implements DataEventListener { @Override public void modifyTask(TimerTask task) { //when a task is modified, add it to the to sync list (if it isn't already there) - if(!tasksToSync.contains(task)) { + if(!tasksToSync.contains(task) && (!tasksToSync.isEmpty())) { //add it only if the URL is not empty if (!(task.getSynchronisingURL().isEmpty())) { - tasksToSync.add(task); + if(!(task.getSynchronisingURL().equals(null))) { + tasksToSync.add(task); + } } } } 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 66e165c..076bb88 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -193,6 +193,12 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); } + JLabel timezoneLabel = new JLabel(getResourceMap().getString("timezone")); + JTextField timezoneText = new JTextField(this.timezone); + panelOption.add(timezoneLabel, new GridBagConstraints(1,3,1,1,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, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,2,1,1),0,0)); configComponent.add(panelGeneral); configComponent.add(panelOption); 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 ddeae17..2ab6693 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,6 +26,7 @@ updateFrom=From : updateTo=To : lastUpdateLabel=Last Sync at: +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 908ccad..91ed7cd 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,6 +27,7 @@ updateFrom=De : updateTo=\u00C0 : lastUpdateLabel=Derni\u00E8re synchronisation : +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 6a17f8f2a2e58a9829e87ab756fafe8de8516406 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 7 14:47:41 2016 +0200 corrected firstdayofweek --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 0bc8dc1..5e41240 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -305,7 +305,7 @@ public class JTimerConfig { UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), UI_CLOSE_TO_SYSTRAY("jtimer.ui.closetosystray", "true"), - UI_REPORT_FIRSTDAYOFWEEK("jtimer.ui.report.firstdayofweek", "10"); + UI_REPORT_FIRSTDAYOFWEEK("jtimer.ui.report.firstdayofweek", "0"); protected String key; protected String defaultValue; -- 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 e068db82dc6fc337cea7c94173d6dae125c0c0af Author: servantie <servantie.c@gmail.com> Date: Tue Jun 7 16:31:23 2016 +0200 removed a useless toString(), removed unused imports --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 31 +++++++++++++--------- .../jtimer/ui/report/TimerTaskUpdaterView.java | 1 - 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 5e41240..9ea5497 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -300,7 +300,7 @@ public class JTimerConfig { IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), - IO_SYNC_TIMEZONE("jtimer.io.synchronizer.timezone", "+0600"), + IO_SYNC_TIMEZONE("jtimer.io.synchronizer.timezone", "+0100"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 2099d68..425c1f4 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -3,7 +3,6 @@ package org.chorem.jtimer.io; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; @@ -12,7 +11,6 @@ import java.io.*; import java.net.*; import java.time.LocalDateTime; import java.util.*; -import java.util.Timer; /** * @@ -148,7 +146,7 @@ public class TimerTaskSynchronizer implements DataEventListener { } byte[] postDataBytes = new byte[0]; try { - postDataBytes = updateJsonString.toString().getBytes("UTF-8"); + postDataBytes = updateJsonString.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } @@ -203,8 +201,8 @@ public class TimerTaskSynchronizer implements DataEventListener { //when a task is modified, add it to the to sync list (if it isn't already there) if(!tasksToSync.contains(task) && (!tasksToSync.isEmpty())) { //add it only if the URL is not empty - if (!(task.getSynchronisingURL().isEmpty())) { - if(!(task.getSynchronisingURL().equals(null))) { + if (task.getSynchronisingURL() != null) { + if (task.getSynchronisingURL().isEmpty()){ tasksToSync.add(task); } } @@ -269,11 +267,14 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void stopTask(TimerTask task) { - if(!tasksToSync.contains(task)) { + if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if (!(task.getSynchronisingURL().isEmpty())) { - tasksToSync.add(task); - } } + if (task.getSynchronisingURL() != null) { + if (task.getSynchronisingURL().isEmpty()) { + tasksToSync.add(task); + } + } + } } @Override @@ -288,11 +289,15 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void modifyTaskURL(TimerTask task, String newURL) { - if(!tasksToSync.contains(task)) { + if (!tasksToSync.contains(task)) { + //add it only if the URL is not empty //add it only if the URL is not empty - if (!(task.getSynchronisingURL().isEmpty())) { - tasksToSync.add(task); - } } + if (task.getSynchronisingURL() != null) { + if (task.getSynchronisingURL().isEmpty()) { + tasksToSync.add(task); + } + } + } } @Override 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 076bb88..8c980a2 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -41,7 +41,6 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import java.awt.*; import java.io.IOException; -import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.*; import java.text.DateFormat; -- 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 6db411056180bdd1f62fc61e11c84bcac09b2fd2 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 10:00:30 2016 +0200 removed a check for empty url in synchronizeSingleTask as it is checked before the method is called (on the addition of tasks to the list to sync) --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 127 ++++++++++----------- 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 425c1f4..e2e480c 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -35,6 +35,9 @@ public class TimerTaskSynchronizer implements DataEventListener { /** Timezone */ protected String timezone = "+0100"; + /** + * TimerTaskSynchronizer constructor + */ public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); @@ -58,7 +61,7 @@ public class TimerTaskSynchronizer implements DataEventListener { * @param timezone */ public void setTimezone(String timezone) { - if (!timezone.isEmpty() && !timezone.equals(null)) { + if (!timezone.isEmpty()) { this.timezone = timezone; } } @@ -68,6 +71,7 @@ public class TimerTaskSynchronizer implements DataEventListener { */ protected class UpdateTask extends java.util.TimerTask { + @Override public void run() { if (log.isDebugEnabled()) { log.debug("Synchronizer wake up"); @@ -101,7 +105,8 @@ public class TimerTaskSynchronizer implements DataEventListener { } } - tasksToSync = remainingTasks; + tasksToSync.clear(); + tasksToSync.addAll(remainingTasks); } } } @@ -118,64 +123,61 @@ public class TimerTaskSynchronizer implements DataEventListener { String charset = "UTF-8"; HttpURLConnection connection; URL url; - if (syncURL != null) { - try { - url = new URL(syncURL); - } catch (MalformedURLException e) { - e.printStackTrace(); - //abort synchronization of this task if the url is wrong - return false; - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - e.printStackTrace(); - //abort synchronization of this task if connection impossible - return false; - } - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json"); - try { - connection.setRequestMethod("POST"); - } catch (ProtocolException e) { - e.printStackTrace(); - } - byte[] postDataBytes = new byte[0]; - try { - postDataBytes = updateJsonString.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - try { - connection.getOutputStream().write(postDataBytes); - } catch (IOException e) { - e.printStackTrace(); - } - //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - boolean hasUpdated = false; - //check for answer from server - for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - //positive answer, synchronization accepted - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; - } + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + log.error("URL malformed"); + //abort synchronization of this task if the url is wrong + return false; + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + log.error("couldn't open connection"); + //abort synchronization of this task if connection impossible + return false; + } + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Length", "" + Integer.toString(updateJsonString.length())); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json"); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + log.error("Protocol error."); + } + byte[] postDataBytes = new byte[0]; + try { + postDataBytes = updateJsonString.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + log.error("Problem with encoding"); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + log.error("Problem with the Outputstream"); + } + //get the header fields + Map<String, List<String>> map = connection.getHeaderFields(); + boolean hasUpdated = false; + //check for answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + //positive answer, synchronization accepted + if ("HTTP/1.1 200 OK".equals(s)) { + hasUpdated = true; } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } else { - log.error("Sync error"); - return false; - } } - return false; + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } else { + log.error("Sync error"); + return false; + } } @Override @@ -269,10 +271,8 @@ public class TimerTaskSynchronizer implements DataEventListener { public void stopTask(TimerTask task) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()) { - tasksToSync.add(task); - } + if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())) { + tasksToSync.add(task); } } } @@ -291,11 +291,8 @@ public class TimerTaskSynchronizer implements DataEventListener { public void modifyTaskURL(TimerTask task, String newURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()) { + if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())){ tasksToSync.add(task); - } } } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 9a1555e0af209f6dc507f4861a1c79ac5273f2fc Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 15:56:18 2016 +0200 changed syncURL to syncURLList, updated methods for sync accordingly --- .../org/chorem/jtimer/data/DataEventListener.java | 5 +- .../org/chorem/jtimer/data/TimerDataManager.java | 11 +-- .../java/org/chorem/jtimer/entities/TimerTask.java | 41 ++++++++--- .../chorem/jtimer/entities/TimerTaskHelper.java | 82 ++++++++++++---------- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 23 ++++-- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 44 ++++++------ .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 23 +++--- .../jtimer/ui/report/TimerTaskUpdaterView.java | 48 +++++++++---- 8 files changed, 167 insertions(+), 110 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index c0f5a28..df1ad50 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -192,10 +192,9 @@ public interface DataEventListener extends EventListener { /** * Task url changed * @param task task with url change - * @param newURL new URl to change + * @param newURLList new URlList to change */ - default void modifyTaskURL(TimerTask task, String newURL) { - + default void modifyTaskURL(TimerTask task, List<String> newURLList) { } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index a5c957c..cea7003 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -411,17 +411,12 @@ public class TimerDataManager { /** * Edit Task URL */ - public void editTaskURL(TimerTask task, String newURL) { + public void editTaskURL(TimerTask task, List<String> newURLList) { - TimerTask newTask = task.clone(); - newTask.setSynchronisingURL(newURL); - for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { - vetoableDataEventListener.checkSetTaskURL(task, newURL); - } - task.setSynchronisingURL(newURL); + task.setSynchronisingURLList(newURLList); // send notification for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTaskURL(task, newURL); + dataEventListener.modifyTaskURL(task, newURLList); } } /** diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index f2fc144..a75d4b7 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -48,7 +48,7 @@ public class TimerTask implements Cloneable, /** serialVersionUID */ private static final long serialVersionUID = -7590755569706702695L; - /** Task uuid used to managed task equality. */s - + /** Task uuid used to managed task equality. */ protected String uuid = UUID.randomUUID().toString(); /** Task number. */ @@ -97,7 +97,7 @@ public class TimerTask implements Cloneable, /** * URL to synchronise task */ - protected String synchronisingURL; + protected List<String> synchronisingURLList; /** * Constructor. */ @@ -107,7 +107,7 @@ public class TimerTask implements Cloneable, allDaysAnnotations = new TreeMap<>(); subTasks = new ArrayList<>(); alerts = new ArrayList<>(); - + synchronisingURLList = new ArrayList<>(); // wrong value to detect bug number = -1; } @@ -241,19 +241,40 @@ public class TimerTask implements Cloneable, public void setLastSync(LocalDateTime syncDate) { this.lastSync = syncDate; } + + /** + * Get task's sync URL List + * @return the URL List + */ + public List<String> getSynchronisingURLList() { return synchronisingURLList; } + /** - * Get task's sync URL - * @return the URL + * Returns one String containing all the URLs for sync, separated by " , " + * @return a string of URLs */ - public String getSynchronisingURL() { return synchronisingURL; } + public String getSynchronizingURLAsString() { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < synchronisingURLList.size(); ++i) { + if (i == synchronisingURLList.size()-1) { + builder.append(synchronisingURLList.get(i)); + } + else { + builder.append(synchronisingURLList.get(i)); + builder.append(" , "); + } + } + String urlListString = builder.toString(); + return urlListString; + } /** - * Sets task's sync URL - * @param synchronisingURL : the sync URL + * Sets task's sync URLList + * @param synchronisingURLList : the sync URL List */ - public void setSynchronisingURL(String synchronisingURL) { - this.synchronisingURL = synchronisingURL; + public void setSynchronisingURLList(List<String> synchronisingURLList) { + this.synchronisingURLList = synchronisingURLList; } + /** * Add task's subtask. * diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 9ecab69..a9a953e 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -339,18 +339,20 @@ public class TimerTaskHelper { * Returns a String in JSON format (cf schema (simplified) * with all times and annotations of a task (without subtasks) * @param task the task to make a JSON from + * @param withAnnotations true if annotations included + * @param timezone represents the timezone * @return result the string in JSON */ - public static JsonObject taskToJSONFormat(TimerTask task, boolean withAnnotations, String timezone) { + public static List<JsonObject> taskToJSONFormat(TimerTask task, boolean withAnnotations, String timezone) { Date startDate = task.getAllDaysAndTimes().firstKey(); Date endDate = new Date(); - JsonObject resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations, timezone); + List<JsonObject> resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations, timezone); return resultingJSON; } /** - * Returns a JSONObject (cf schema (simplified) + * Returns a list of JSONObject (one for each sync URL) * with all times of a task (without subtasks) * in a given period between two dates * with annotations if enabled @@ -358,44 +360,52 @@ public class TimerTaskHelper { * @param startDate the beginning date * @param endDate the end date * @param withAnnotations true if annotations included + * @param timezone represents the timezone * @return result the string in JSON */ - public static JsonObject taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { - JsonObject responseJSON = new JsonObject(); - LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - - JsonArray periodArray = new JsonArray(); - SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); - if (dates.size() != 0) { - for (SortedMap.Entry<Date, Long> entry : dates.entrySet()) { - //adding id, startDate and duration - //converting Date to LocalDate (to ease the .toString()) - //deal with timezones ? - LocalDate date = entry.getKey().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String dateString = date.toString(); - //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format - JsonObject periodElement = new JsonObject(); - periodElement.addProperty("periodId", dateString); - periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000" + timezone); - periodElement.addProperty("periodDuration", entry.getValue()); - if (withAnnotations && getAnnotation(task, entry.getKey()).size() != 0 ) { - String annotations = ""; - for (String s : getAnnotation(task, entry.getKey())) { - annotations = annotations + s + ","; + public static List<JsonObject> taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { + + ArrayList<JsonObject> jsonObjectList = new ArrayList<>(); + + for (String url : task.getSynchronisingURLList()) { + + JsonObject responseJSON = new JsonObject(); + LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + JsonArray periodArray = new JsonArray(); + SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); + if (dates.size() != 0) { + for (SortedMap.Entry<Date, Long> entry : dates.entrySet()) { + //adding id, startDate and duration + //converting Date to LocalDate (to ease the .toString()) + LocalDate date = entry.getKey().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + String dateString = date.toString(); + //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format + JsonObject periodElement = new JsonObject(); + periodElement.addProperty("periodId", dateString); + periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000" + timezone); + periodElement.addProperty("periodDuration", entry.getValue()); + if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { + StringBuilder builder = new StringBuilder(); + for (String s : getAnnotation(task, entry.getKey())) { + builder.append(s); + builder.append(","); + } + String annotations = builder.toString(); + periodElement.addProperty("periodInfo", annotations); + } - //remove trailing comma - annotations = annotations.substring(0, annotations.length()-1); - periodElement.addProperty("periodInfo", annotations); + periodArray.add(periodElement); } - periodArray.add(periodElement); } - } - responseJSON.addProperty("URL", task.getSynchronisingURL()); - responseJSON.addProperty("startDate", startPeriodDate.toString()); - responseJSON.addProperty("endDate", endPeriodDate.toString()); - responseJSON.add("periods", periodArray ); + responseJSON.addProperty("URL", url); + responseJSON.addProperty("startDate", startPeriodDate.toString()); + responseJSON.addProperty("endDate", endPeriodDate.toString()); + responseJSON.add("periods", periodArray); - return responseJSON; + jsonObjectList.add(responseJSON); + } + return jsonObjectList; } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index b9f822d..7ffbec0 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -615,8 +615,13 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, try { - if (syncType.equals("SyncURL:")) { - task.setSynchronisingURL(syncInfo); + if (syncType.equals("SyncURLList:")) { + String[] urlArray = syncInfo.trim().split(" , "); + List<String> urlList = new ArrayList<>(); + for (String url : urlArray) { + urlList.add(url); + } + task.setSynchronisingURLList(urlList); } else if (syncType.equals("LastSync:")) { @@ -1140,7 +1145,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, File synchronisationTaskFile = new File(dataSaveDirectory + File.separator + taskNumber + "." + GTIMER_TASK_EXTENSION + "." + GTIMER_SYNC_EXTENSION); - if (task.getSynchronisingURL() != null) { + if (task.getSynchronisingURLList() != null) { File backupfile = null; try (Writer out = new OutputStreamWriter(new FileOutputStream(synchronisationTaskFile), "ISO-8859-1")) { @@ -1149,9 +1154,8 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write("Format: " + GTIMER_FILE_VERSION + "\n"); //save URL - if(!(task.getSynchronisingURL().equals("")) || task.getSynchronisingURL() !=null) { - String saveURL = task.getSynchronisingURL(); - out.write("SyncURL: " + saveURL + "\n"); + if(task.getSynchronisingURLList() !=null && !(task.getSynchronisingURLList().isEmpty())) { + out.write("SyncURLList: " + task.getSynchronizingURLAsString() + "\n"); } //save last sync (if there is one) if (task.getLastSync() !=null) { @@ -1515,4 +1519,11 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } + /* + * {@inheritDoc} + */ + @Override + public void modifyTaskURL(TimerTask task, List<String> newURL) { + saveSynchronisationInfo(task); + } } diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index e2e480c..7f48a49 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -1,5 +1,6 @@ package org.chorem.jtimer.io; +import com.google.gson.JsonObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.DataEventListener; @@ -24,7 +25,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected long autoSyncDelay = 1000 * 10; //every 2 hours, check for modifications to sync + protected long autoSyncDelay = 1000 * 10L; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; @@ -90,20 +91,11 @@ public class TimerTaskSynchronizer implements DataEventListener { if (log.isDebugEnabled()){ log.debug("task " + task.getName() + " being synced."); } - //do the sync, store the result - boolean syncDone = synchronizeSingleTask(task); + synchronizeSingleTask(task); //for now doesn't deal with failure in the update, just task already updated if (remainingTasks.contains(task)) { remainingTasks.remove(task); } - - if (syncDone) { - log.debug("Sync done"); - } - else { - log.debug("Sync failed"); - } - } tasksToSync.clear(); tasksToSync.addAll(remainingTasks); @@ -112,14 +104,22 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** - * Makes one synchronization for a task, without annotations by default + * Synchronizes one Task (calls to synchronizeTaskOnURL for each syncURLList element of the task) * * @param task - * @return boolean for failure of sync (maybe make it return an int for better treatment of failure) */ - public boolean synchronizeSingleTask(TimerTask task) { - String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false, timezone).toString(); - String syncURL = task.getSynchronisingURL(); + public void synchronizeSingleTask(TimerTask task) { + List<JsonObject> jsonObjectList = TimerTaskHelper.taskToJSONFormat(task, false, timezone); + + for (JsonObject object : jsonObjectList) { + synchronizeTaskOnURL(task, object); + } + } + + public boolean synchronizeTaskOnURL(TimerTask task, JsonObject object) { + + String updateJsonString = object.toString(); + String syncURL = object.get("URL").getAsString(); String charset = "UTF-8"; HttpURLConnection connection; URL url; @@ -203,10 +203,8 @@ public class TimerTaskSynchronizer implements DataEventListener { //when a task is modified, add it to the to sync list (if it isn't already there) if(!tasksToSync.contains(task) && (!tasksToSync.isEmpty())) { //add it only if the URL is not empty - if (task.getSynchronisingURL() != null) { - if (task.getSynchronisingURL().isEmpty()){ - tasksToSync.add(task); - } + if ((task.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())){ + tasksToSync.add(task); } } } @@ -271,7 +269,7 @@ public class TimerTaskSynchronizer implements DataEventListener { public void stopTask(TimerTask task) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())) { + if ((task.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())) { tasksToSync.add(task); } } @@ -288,10 +286,10 @@ public class TimerTaskSynchronizer implements DataEventListener { * @param task modified task */ @Override - public void modifyTaskURL(TimerTask task, String newURL) { + public void modifyTaskURL(TimerTask task, List<String> newURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty - if ((task.getSynchronisingURL() != null) && !(task.getSynchronisingURL().isEmpty())){ + if ((task.getSynchronisingURLList() != null) && !(task.getSynchronisingURLList().isEmpty())){ tasksToSync.add(task); } } diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 885f4f7..1b86b13 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -94,7 +94,7 @@ public class TimerTaskEditor extends DialogView { protected JTextField synchronizeURL; /** change listener on sync URl */ - protected DocumentListener URLChangeListener; + protected DocumentListener urlChangeListener; /** change listener on spinners */ protected ChangeListener spinnerListener; @@ -230,7 +230,7 @@ public class TimerTaskEditor extends DialogView { // text change listener on annotationTextArea, titleTextField and SyncURLTextField titleChangeListener = new TextChangeListener(); annotationChangeListener = new TextChangeListener(); - URLChangeListener = new TextChangeListener(); + urlChangeListener = new TextChangeListener(); panel.add(createTitlePanel(), BorderLayout.NORTH); panel.add(createJXMonthView(), BorderLayout.CENTER); @@ -253,7 +253,7 @@ public class TimerTaskEditor extends DialogView { titleText.getDocument().addDocumentListener(titleChangeListener); // task syncronizeURL and listener synchronizeURL = new JTextField("",20); - synchronizeURL.getDocument().addDocumentListener(URLChangeListener); + synchronizeURL.getDocument().addDocumentListener(urlChangeListener); //labels for title and url JLabel titleLabel = new JLabel(getResourceMap().getString("label.title.text")); JLabel URLLabel = new JLabel(getResourceMap().getString("label.syncURL.text")); @@ -573,9 +573,9 @@ public class TimerTaskEditor extends DialogView { titleText.getDocument().addDocumentListener(titleChangeListener); //URL - synchronizeURL.getDocument().removeDocumentListener(URLChangeListener); - synchronizeURL.setText(cloneTask.getSynchronisingURL()); - synchronizeURL.getDocument().addDocumentListener(URLChangeListener); + synchronizeURL.getDocument().removeDocumentListener(urlChangeListener); + synchronizeURL.setText(cloneTask.getSynchronizingURLAsString()); + synchronizeURL.getDocument().addDocumentListener(urlChangeListener); } @@ -589,7 +589,7 @@ public class TimerTaskEditor extends DialogView { isTitleChanged = true; } else if (issuer == annotationChangeListener) { isAnnotationChanged = true; - } else if (issuer == URLChangeListener) { + } else if (issuer == urlChangeListener) { isURLChanged = true; } updateTask(); @@ -631,7 +631,12 @@ public class TimerTaskEditor extends DialogView { // sync URL if (isURLChanged) { - cloneTask.setSynchronisingURL(synchronizeURL.getText()); + String[] urlArray = synchronizeURL.getText().trim().split(" , "); + List<String> urlList = new ArrayList<>(); + for (String url : urlArray) { + urlList.add(url); + } + cloneTask.setSynchronisingURLList(urlList); } dateChanged.add(getSelectedDay().getTime()); @@ -661,7 +666,7 @@ public class TimerTaskEditor extends DialogView { } // url if (isURLChanged) { - dataManager.editTaskURL(task, cloneTask.getSynchronisingURL()); + dataManager.editTaskURL(task, cloneTask.getSynchronisingURLList()); } for (Date date : dateChanged) { diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java index 8c980a2..f2653ab 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -73,7 +73,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener /** update output view*/ protected JTextArea updateArea; - protected JsonObject updateJson; + protected List<JsonObject> updateJson; /** task to update */ protected TimerTask task; @@ -103,6 +103,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener //default the timezone timezone = "+0100"; + updateJson = new ArrayList<>(); + } /** @@ -342,18 +344,21 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener */ @org.jdesktop.application.Action public void generateUpdate() { + //get the various objects for updates (on several urls) + updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), + datePickerTo.getDate(), isIncludingAnnotations(), timezone); + if (!updateJson.isEmpty()) { + //to make it human readable + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + StringBuilder builder = new StringBuilder(); + for (JsonObject object : updateJson) { + builder.append(gson.toJson(object)); + } + updateArea.setText(builder.toString()); - // make the JSON Object of information - updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), - datePickerTo.getDate(), isIncludingAnnotations(), timezone); - //make it human readable - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String jsonOutput = gson.toJson(updateJson); - - if (updateJson != null) { - updateArea.setText(jsonOutput); - } else { - updateArea.setText(""); + } + else { + updateArea.setText("No data"); } } @@ -390,11 +395,24 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener } /** - * send update + * goes through the Jsons to send and sends them */ @Action(enabledProperty = "updatingEnabled") public void sendUpdate() { - String syncURL = task.getSynchronisingURL(); + for (JsonObject object : updateJson) { + synchronizeTaskOnURL(task, object); + } + } + + + /** + * Sends the update of a task to one url + * @param task task to update + * @param object json of task info + */ + public void synchronizeTaskOnURL(TimerTask task, JsonObject object) { + String updateJsonString = object.toString(); + String syncURL = object.get("URL").getAsString(); String charset = "UTF-8"; if (syncURL != null) { HttpURLConnection connection= null; @@ -412,7 +430,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener connection.setUseCaches(false); connection.setDoInput(true); - connection.setRequestProperty("Content-Length", "" + updateJson.toString().length()); + connection.setRequestProperty("Content-Length", "" + updateJsonString); connection.setDoOutput(true); connection.setRequestProperty("Accept-Charset", charset); connection.setRequestProperty("Content-Type", "application/json" + charset); -- 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 6cd63ea15575b77ad520169f3d77a15902efb3ba Author: servantie <servantie.c@gmail.com> Date: Wed Jun 8 16:45:51 2016 +0200 logs instead of stacktrace --- .../org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java index f2653ab..4537971 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -89,6 +89,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener * * @param application parent reference * @param core core reference + * @param task the task to update */ public TimerTaskUpdaterView(Application application, TimerCore core, TimerTask task) { @@ -420,12 +421,12 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener try { url = new URL(syncURL); } catch (MalformedURLException e) { - e.printStackTrace(); + log.error("Malformed URL"); } try { connection = (HttpURLConnection) url.openConnection(); } catch (IOException e) { - e.printStackTrace(); + log.error("Connection error"); } connection.setUseCaches(false); @@ -437,18 +438,18 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener try { connection.setRequestMethod("POST"); } catch (ProtocolException e) { - e.printStackTrace(); + log.error("Protocol Error"); } byte[] postDataBytes = new byte[0]; try { postDataBytes = updateJson.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + log.error("Unsupported Encoding"); } try { connection.getOutputStream().write(postDataBytes); } catch (IOException e) { - e.printStackTrace(); + log.error("OutputStream error"); } //get the header fields @@ -457,7 +458,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener //check for positive answer from server for (Map.Entry<String, List<String>> entry : map.entrySet()) { for (String s : entry.getValue()) { - if (s.equals("HTTP/1.1 200 OK")) { + if ("HTTP/1.1 200 OK".equals(s)) { hasUpdated = true; } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 033fa5dac11882cea7fd021f836e0f126afe7e0e 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 40dcd7a1e432840bc3c9653f1e231ceb556619dc 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 325be3227e7281d7751b1e32603767fa8ae05b39 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>.
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 acf7e13705191f57ee7f9996928f288193143645 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 15:15:58 2016 +0200 removed timezone display in TimerTaskUpdaterView (useless) --- .../java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 6 ++---- .../org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 14 ++------------ .../ui/report/resources/TimerTaskUpdaterView.properties | 1 - .../ui/report/resources/TimerTaskUpdaterView_fr.properties | 1 - 4 files changed, 4 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 b0ea2d0..37c685f 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -146,11 +146,11 @@ public class TimerTaskSynchronizer implements DataEventListener { connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", "" + Integer.toString(updateJsonString.length())); + 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"); + postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); @@ -165,14 +165,12 @@ public class TimerTaskSynchronizer implements DataEventListener { } } 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 } 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 26a48ac..d98fcb9 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -102,7 +102,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener this.task = task; timezone = "+0100"; setComponent(getMainComponent()); - //default the timezone updateJson = new ArrayList<>(); @@ -197,14 +196,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); } - //display of the timezone - JLabel timezoneLabel = new JLabel(getResourceMap().getString("timezone")); - 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,2,0,0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,2,1,1),0,0)); - configComponent.add(panelGeneral); configComponent.add(panelOption); @@ -408,7 +399,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener } } - /** * Sends the update of a task to one url * @param task task to update @@ -428,11 +418,11 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", "" + Integer.toString(updateJsonString.length())); + 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"); + postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); 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 09a82f9..ddeae17 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,6 @@ updateFrom=From : updateTo=To : lastUpdateLabel=Last Sync at: -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 4a9a20a..908ccad 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,6 @@ updateFrom=De : updateTo=\u00C0 : lastUpdateLabel=Derni\u00E8re synchronisation : -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 917eba7f1f90a18a858d475e3dd05eec2211d8d6 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 16:25:23 2016 +0200 added a combobox in manual sync to pick which url to sync on (if one sync fails, pop up shows to say so, but textarea isn't updated on "generate update" button pressing) --- .../jtimer/ui/report/TimerTaskUpdaterView.java | 37 +++++++++++++++++++--- .../resources/TimerTaskUpdaterView.properties | 3 +- .../resources/TimerTaskUpdaterView_fr.properties | 1 + 3 files changed, 36 insertions(+), 5 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 d98fcb9..0af876d 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -73,8 +73,15 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener /** update output view*/ protected JTextArea updateArea; + /** 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; + /** task to update */ protected TimerTask task; @@ -101,6 +108,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener this.core = core; this.task = task; timezone = "+0100"; + urlSyncList = task.getSynchronisingURLList(); + setComponent(getMainComponent()); updateJson = new ArrayList<>(); @@ -189,13 +198,26 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener //if there has been an update before, display its date LocalDateTime lastSyncTime = task.getLastSync(); if (lastSyncTime != null) { - JLabel lastUpdate = new JLabel(lastSyncTime.toLocalDate().toString()); + 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")); + urlComboBox = new JComboBox<>(); + //add the urls to the combobox + for (String url : urlSyncList) { + urlComboBox.addItem(url); + } + panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1,3,1,1,0,0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(3,1,1,1), 0, 0)); + panelOption.add(urlComboBox, new GridBagConstraints(2,3,1,1,0,0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,3,1,1), 0, 0)); + + configComponent.add(panelGeneral); configComponent.add(panelOption); @@ -343,11 +365,14 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), datePickerTo.getDate(), isIncludingAnnotations(), timezone); if (!updateJson.isEmpty()) { + String urlSelected = (String) urlComboBox.getSelectedItem(); //to make it human readable Gson gson = new GsonBuilder().setPrettyPrinting().create(); StringBuilder builder = new StringBuilder(); for (JsonObject object : updateJson) { - builder.append(gson.toJson(object)); + if (urlSelected.equals(object.get("URL").getAsString())) { + builder.append(gson.toJson(object)); + } } updateArea.setText(builder.toString()); @@ -390,12 +415,16 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener } /** - * goes through the Jsons to send and sends them + * sends the sync of the task associated with the current url selected + * in the combobox (urlComboBox) */ @Action(enabledProperty = "updatingEnabled") public void sendUpdate() { + String urlSelected = (String) urlComboBox.getSelectedItem(); for (JsonObject object : updateJson) { - synchronizeTaskOnURL(task, object); + if (urlSelected.equals(object.get("URL").getAsString())) { + synchronizeTaskOnURL(task, object); + } } } 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 ddeae17..dca4916 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 @@ -25,7 +25,8 @@ updateOptions=Options updateFrom=From : updateTo=To : -lastUpdateLabel=Last Sync at: +lastUpdateLabel=Last Synchronisation at: +urlComboLabel = Synchronisation Url: 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 908ccad..d34c270 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,6 +27,7 @@ updateFrom=De : updateTo=\u00C0 : lastUpdateLabel=Derni\u00E8re synchronisation : +urlComboLabel=Url de synchronisation : 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 97bcca40456cd3be1661ede9fc19105fb3973539 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 9 17:57:32 2016 +0200 fix to display error message when the sync went wrong --- .../org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 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 0af876d..3c9f162 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -361,6 +361,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener */ @org.jdesktop.application.Action public void generateUpdate() { + //reinitialiser les trucs + updateArea.setText(""); + updateJson = new ArrayList<>(); //get the various objects for updates (on several urls) updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), datePickerTo.getDate(), isIncludingAnnotations(), timezone); @@ -464,6 +467,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener } } } + connection.disconnect(); } catch (MalformedURLException e) { log.error("URL malformed"); //abort synchronization of this task if the url is wrong @@ -481,12 +485,14 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener 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); - + infoBox(message, title); } } + public static void infoBox(String infoMessage, String titleBar) + { + JOptionPane.showMessageDialog(null, infoMessage, "Erreur : " + titleBar, JOptionPane.ERROR_MESSAGE); + } @Override public void changedUpdate(DocumentEvent e) { documentChanged(); -- 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 4748cb86badaa61b235589bf1a967dd1547e4cbb Author: servantie <servantie.c@gmail.com> Date: Fri Jun 10 09:54:08 2016 +0200 edited to change update into synchronization --- .../chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 16 +++++++++------- .../org/chorem/jtimer/resources/JTimer.properties | 4 ++-- .../org/chorem/jtimer/resources/JTimer_fr.properties | 4 ++-- .../report/resources/TimerTaskUpdaterView_fr.properties | 2 +- 4 files changed, 14 insertions(+), 12 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 3c9f162..6fdc404 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -93,7 +93,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener /** * UpdaterView constructor. - * * @param application parent reference * @param core core reference * @param task the task to update @@ -470,28 +469,31 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener connection.disconnect(); } 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"); - infoBox(message, title); + errorBox(message, title); } + canUpdate = false; } - public static void infoBox(String infoMessage, String titleBar) + /** + * Method to display an error message (in case the sync goes wrong) + * @param errorMessage the message to display + * @param titleBar the title of the frame + */ + public static void errorBox(String errorMessage, String titleBar) { - JOptionPane.showMessageDialog(null, infoMessage, "Erreur : " + titleBar, JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, errorMessage, titleBar, JOptionPane.ERROR_MESSAGE); } @Override public void changedUpdate(DocumentEvent e) { diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties index a926505..5233547 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties @@ -62,9 +62,9 @@ editTask.Action.text = &Edit Task editTask.Action.accelerator = F2 editTask.Action.shortDescription = Edit task -updateTask.Action.text = &Update Task +updateTask.Action.text = &Synchronise Task updateTask.Action.accelerator = F5 -updateTask.Action.shortDescription = Update task +updateTask.Action.shortDescription = Synchronise task closeTask.Action.text = &Open/Close Task closeTask.Action.accelerator = control O diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties index eb4c7e3..c7ab52b 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties @@ -42,8 +42,8 @@ editTask.Action.text = \u00C9dition de la t\u00E2ch&e editTask.Action.shortDescription = \u00C9dition de la t\u00E2che -updateTask.Action.text = &Mettre \u00E0 jour -updateTask.Action.shortDescription = Mettre \u00E0 jour +updateTask.Action.text = &Synchroniser la t\u00E2che +updateTask.Action.shortDescription = Synchroniser closeTask.Action.text = &Ouvrir/Fermer la t\u00E2che closeTask.Action.shortDescription = Ouvrir ou fermer la t\u00E2che 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 d34c270..9dd1b73 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 @@ -46,7 +46,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ées de synchronisation +generateUpdate.Action.shortDescription = G\u00E9n\u00E9rer les donn\u00E9es de synchronisation 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 6f03ae4e3303e666bcf7d00d64c68edd02fbc376 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 10 10:18:24 2016 +0200 disables send sync button when sync has been done once --- src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 3 +++ 1 file changed, 3 insertions(+) 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 6fdc404..5f46583 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -483,7 +483,10 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener String title = getResourceMap().getString("action.updateErrorTitle"); errorBox(message, title); } + //advise that it's done, to grey-out the send sync button + boolean oldValue = canUpdate; canUpdate = false; + firePropertyChange("updatingEnabled", oldValue, canUpdate); } /** -- 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 4bf37eb06dc9bf13e047a32e2df6deb142ef7dda Author: servantie <servantie.c@gmail.com> Date: Fri Jun 10 11:10:54 2016 +0200 added possibility to edit a url and adds it to the syncURLList of the task (not updated in the combobox yet, but saved) --- .../java/org/chorem/jtimer/entities/TimerTask.java | 11 +++++++++ .../jtimer/ui/report/TimerTaskUpdaterView.java | 26 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index a75d4b7..ae3acb4 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -276,6 +276,17 @@ 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 (!synchronisingURLList.contains(urlToAdd)) { + synchronisingURLList.add(urlToAdd); + } + } + + /** * Add task's subtask. * * Also add parent reference. 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 5f46583..19e838c 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -40,6 +40,10 @@ import javax.swing.*; import javax.swing.event.DocumentEvent; 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.*; @@ -56,7 +60,7 @@ import static org.chorem.jtimer.entities.TimerTaskHelper.taskToJSONFormat; * * Created by servantie on 13/05/16. */ -public class TimerTaskUpdaterView extends FrameView implements DocumentListener { +public class TimerTaskUpdaterView extends FrameView implements DocumentListener, ActionListener { /** Class logger */ protected static Log log = LogFactory.getLog(TimerTaskUpdaterView.class); @@ -207,6 +211,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener //display the various urls to sync to in a combobox to choose which one will be updated JLabel urlcomboBoxLabel = new JLabel(getResourceMap().getString("urlComboLabel")); urlComboBox = new JComboBox<>(); + //make it editable to add new urls -todo: save these urls to the task- + urlComboBox.setEditable(true); + urlComboBox.addActionListener(this); //add the urls to the combobox for (String url : urlSyncList) { urlComboBox.addItem(url); @@ -521,4 +528,21 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener protected void documentChanged() { setUpdatingEnabled(updateArea.getText().trim().length() > 0); } + + /** + * when an item is added to the list, + * add it to the urls + */ + public void itemAdded(){ + String urlToAdd = (String) urlComboBox.getSelectedItem(); + if (!urlToAdd.isEmpty()) { + task.addURLToSyncList(urlToAdd); + } + + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + itemAdded(); + } } -- 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 1fd962667579c5ce23891a1971988a4cd3ab37dd Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 10:39:36 2016 +0200 added url shows up in combobox list --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 8 ++++---- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 3 +++ .../java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 9 +++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index a9a953e..7c28891 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -383,9 +383,9 @@ public class TimerTaskHelper { String dateString = date.toString(); //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); - periodElement.addProperty("periodId", dateString); - periodElement.addProperty("periodStartDate", dateString + "T00:00:00.000" + timezone); - periodElement.addProperty("periodDuration", entry.getValue()); + periodElement.addProperty("id", dateString); + periodElement.addProperty("startDate", dateString + "T00:00:00.000" + timezone); + periodElement.addProperty("duration", entry.getValue()); if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { StringBuilder builder = new StringBuilder(); for (String s : getAnnotation(task, entry.getKey())) { @@ -393,7 +393,7 @@ public class TimerTaskHelper { builder.append(","); } String annotations = builder.toString(); - periodElement.addProperty("periodInfo", annotations); + periodElement.addProperty("info", annotations); } periodArray.add(periodElement); diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 37c685f..601c0a5 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -161,6 +161,9 @@ public class TimerTaskSynchronizer implements DataEventListener { if ("HTTP/1.1 200 OK".equals(s)) { hasUpdated = true; } + else { + log.info("Error" + s); + } } } } catch (MalformedURLException e) { 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 19e838c..b302fde 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -211,7 +211,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, //display the various urls to sync to in a combobox to choose which one will be updated JLabel urlcomboBoxLabel = new JLabel(getResourceMap().getString("urlComboLabel")); urlComboBox = new JComboBox<>(); - //make it editable to add new urls -todo: save these urls to the task- + //make it editable to add new urls urlComboBox.setEditable(true); urlComboBox.addActionListener(this); //add the urls to the combobox @@ -469,8 +469,12 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, for (String s : entry.getValue()) { //positive answer, synchronization accepted if ("HTTP/1.1 200 OK".equals(s)) { + log.debug("OK (200)"); hasUpdated = true; } + else if ("HTTP/1.1 400 Bad Request".equals(s)) { + log.debug("Bad Request (400)"); + } } } connection.disconnect(); @@ -535,7 +539,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, */ public void itemAdded(){ String urlToAdd = (String) urlComboBox.getSelectedItem(); - if (!urlToAdd.isEmpty()) { + if ((!urlToAdd.isEmpty()) && (!urlSyncList.contains(urlToAdd))) { + urlComboBox.addItem(urlToAdd); task.addURLToSyncList(urlToAdd); } -- 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 22c9fbd23a76c9da9a9ed111aa3562b24bc81ac7 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 12:35:15 2016 +0200 changed timestamp to remove milliseconds and standardized timezone to match iso --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 6 +++--- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 2 +- .../java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 7 ++++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 9ea5497..1a857c4 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -300,7 +300,7 @@ public class JTimerConfig { IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), - IO_SYNC_TIMEZONE("jtimer.io.synchronizer.timezone", "+0100"), + IO_SYNC_TIMEZONE("jtimer.io.synchronizer.timezone", "+01:00"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 7c28891..78b42a6 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -384,7 +384,7 @@ public class TimerTaskHelper { //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); periodElement.addProperty("id", dateString); - periodElement.addProperty("startDate", dateString + "T00:00:00.000" + timezone); + periodElement.addProperty("startDate", dateString + "T00:00:00" + timezone); periodElement.addProperty("duration", entry.getValue()); if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { StringBuilder builder = new StringBuilder(); @@ -400,8 +400,8 @@ public class TimerTaskHelper { } } responseJSON.addProperty("URL", url); - responseJSON.addProperty("startDate", startPeriodDate.toString()); - responseJSON.addProperty("endDate", endPeriodDate.toString()); + 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); diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 601c0a5..557a96a 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -34,7 +34,7 @@ public class TimerTaskSynchronizer implements DataEventListener { protected Collection<TimerTask> tasksToSync; /** Timezone */ - protected String timezone = "+0100"; + protected String timezone = "+01:00"; /** * TimerTaskSynchronizer constructor 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 b302fde..e497368 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -110,7 +110,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, this.core = core; this.task = task; - timezone = "+0100"; + timezone = "+01:00"; urlSyncList = task.getSynchronisingURLList(); setComponent(getMainComponent()); @@ -469,12 +469,13 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, for (String s : entry.getValue()) { //positive answer, synchronization accepted if ("HTTP/1.1 200 OK".equals(s)) { - log.debug("OK (200)"); + log.info("OK (200)"); hasUpdated = true; } else if ("HTTP/1.1 400 Bad Request".equals(s)) { - log.debug("Bad Request (400)"); + log.info("Bad Request (400)"); } + log.info(s); } } connection.disconnect(); -- 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 4663ae4b32739f1006215d4b3c144d21707d62b1 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 14:20:25 2016 +0200 changed acceptance --- src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 e497368..24b697f 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -468,8 +468,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, 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)) { - log.info("OK (200)"); + if (s.startsWith("HTTP/1.1 2")){ + log.info("OK git" + s); hasUpdated = true; } else if ("HTTP/1.1 400 Bad Request".equals(s)) { -- 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 831a2c52a3c3bedb615a993511b7b73d5cab905f Author: servantie <servantie.c@gmail.com> Date: Mon Jun 13 14:56:37 2016 +0200 corrected sent time (was sending milliseconds instead of seconds) --- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 78b42a6..c17001c 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -385,7 +385,7 @@ public class TimerTaskHelper { JsonObject periodElement = new JsonObject(); periodElement.addProperty("id", dateString); periodElement.addProperty("startDate", dateString + "T00:00:00" + timezone); - periodElement.addProperty("duration", entry.getValue()); + periodElement.addProperty("duration", entry.getValue()/1000); if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { StringBuilder builder = new StringBuilder(); for (String s : getAnnotation(task, entry.getKey())) { -- 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 cbe46a22bc69bc33c21ac4be743456aec0d42448 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 cf626e7e021add91527984f3c00b94bfb8d94e61 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 | 8 +- .../org/chorem/jtimer/data/TimerDataManager.java | 23 +++-- .../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 | 3 + .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 53 +--------- .../jtimer/ui/report/TimerTaskUpdaterView.java | 34 +++--- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 3 + .../ProjectsAndTasksRunningCellRenderer.java | 1 + 12 files changed, 317 insertions(+), 213 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index df1ad50..7bad531 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -190,11 +190,11 @@ public interface DataEventListener extends EventListener { } /** - * Task url changed - * @param task task with url change - * @param newURLList new URlList to change + * SyncInfo changed + * @param task + * @param syncURL String */ - default void modifyTaskURL(TimerTask task, List<String> newURLList) { + default void changeSyncInfo(TimerTask task, String syncURL) { } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index cea7003..835af87 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -22,6 +22,7 @@ package org.chorem.jtimer.data; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -409,17 +410,6 @@ public class TimerDataManager { } /** - * Edit Task URL - */ - public void editTaskURL(TimerTask task, List<String> newURLList) { - - task.setSynchronisingURLList(newURLList); - // send notification - for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.modifyTaskURL(task, newURLList); - } - } - /** * Move task. * * @param destination task to move to @@ -646,4 +636,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 ae3acb4..ac18c14 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 c17001c..e6f821d 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -367,44 +367,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 7ffbec0..757e583 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; @@ -604,51 +604,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()) { - 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. * @@ -824,7 +825,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, backupDirFile.mkdirs(); } - // + // try (ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileName))) { // Create a buffer for reading the files @@ -1138,14 +1139,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")) { @@ -1153,17 +1152,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()) { @@ -1296,6 +1305,11 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } @Override + public void changeSyncInfo(TimerTask task, String syncURL) { + saveSynchronisationInfo(task); + } + + @Override public void deleteProject(TimerProject project) { deleteTaskOrProject(project, GTIMER_PROJECT_EXTENSION); } @@ -1392,6 +1406,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 @@ -1519,11 +1534,5 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } - /* - * {@inheritDoc} - */ - @Override - public void modifyTaskURL(TimerTask task, List<String> newURL) { - saveSynchronisationInfo(task); - } -} + +} \ No newline at end of file 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 cd069c0..11b7fde 100644 --- a/src/main/java/org/chorem/jtimer/ui/StatusBar.java +++ b/src/main/java/org/chorem/jtimer/ui/StatusBar.java @@ -137,6 +137,9 @@ public class StatusBar extends JPanel implements DataEventListener { modifyTask(null); } + /* + * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) + */ @Override public void deleteProject(TimerProject project) { updateTodayTime(); diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 1b86b13..a9635fa 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -90,12 +90,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; @@ -119,9 +113,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). @@ -230,7 +221,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); @@ -251,34 +241,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; @@ -571,12 +545,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); - } /** @@ -589,10 +557,8 @@ public class TimerTaskEditor extends DialogView { isTitleChanged = true; } else if (issuer == annotationChangeListener) { isAnnotationChanged = true; - } else if (issuer == urlChangeListener) { - isURLChanged = true; + updateTask(); } - updateTask(); } /** @@ -629,16 +595,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); @@ -664,11 +620,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/treetable/ProjectsAndTasksModel.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java index 3a167ec..d365546 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java @@ -373,6 +373,9 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements }); } + /* + * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) + */ @Override public void deleteProject(TimerProject project) { notifyTaskChanged(project, OPERATION_DELETE); 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 905fa9d..e8e41dd 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java @@ -156,6 +156,7 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen } } + @Override public void startTask(TimerTask task) { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 03be19d38c41fb4ea7425f1eac360c417099dfc9 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 ba2e1ce02a5e477ceb1b14ccf1bf0e3e07ffb18d 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 983269415b8a8588d7a4e5f13a44944460518e0f 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 ac18c14..34a1675 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 757e583..b4f4888 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -608,7 +608,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 @@ -619,7 +618,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 ee015fa31758ca1048beec8822cfa10e90aef1a5 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 a9635fa..094e28b 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -218,42 +218,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>.
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 c7745ed439e8018c6360abb1c1c488ee41f0c349 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 20 11:44:32 2016 +0200 removed an unused field (lastSync) in TimerTask, clarified some documentations --- src/main/java/org/chorem/jtimer/entities/TimerTask.java | 11 ++++------- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 34a1675..962842f 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -90,11 +90,6 @@ public class TimerTask implements Cloneable, protected List<TimerAlert> alerts; /** - * Last synchronisation date - */ - protected LocalDateTime lastSync; - - /** * Synchronisation Info */ protected List<SyncInfo> synchronisingInfoList; @@ -304,7 +299,7 @@ public class TimerTask implements Cloneable, } /** - * Adds a new synchronization info if the url isn't already present + * Adds a new synchronization info if the url isn't already present in the list * @param url a string * @param time a LocalDateTime * @param isActive a boolean for activity (true to sync auto) @@ -334,7 +329,7 @@ public class TimerTask implements Cloneable, } /** - * Returns all the synchronization info + * Returns all the synchronization info as a List * @return a list of TimerTask.SyncInfo */ public List<SyncInfo> getSynchronizingInfoList() { @@ -344,7 +339,9 @@ 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) * @param urlString + * @return a SyncInfo matching the url */ public SyncInfo getSynchronizingInfo(String urlString) { for (SyncInfo sync : synchronisingInfoList) { diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index e6f821d..b2270b0 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -336,8 +336,9 @@ public class TimerTaskHelper { } /** - * Returns a String in JSON format (cf schema (simplified) + * Returns a list of JSONObject (1/SyncURL) (follows the schema) * with all times and annotations of a task (without subtasks) + * with annotations if enabled * @param task the task to make a JSON from * @param withAnnotations true if annotations included * @param timezone represents the timezone -- 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 0441eec8a8908ff54d8200b8c801a6d90e2eb707 Author: servantie <servantie.c@gmail.com> Date: Mon Jun 20 16:45:26 2016 +0200 minor cleanup in methods --- .../java/org/chorem/jtimer/entities/SyncInfo.java | 2 +- .../java/org/chorem/jtimer/entities/TimerTask.java | 14 ++++++------ .../chorem/jtimer/entities/TimerTaskHelper.java | 7 +++--- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 2 +- .../jtimer/ui/report/TimerTaskUpdaterView.java | 25 +++++++++------------- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java index d5d9e00..cf81350 100644 --- a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -54,7 +54,7 @@ public class SyncInfo { * Sets the isActiveSync boolean * @param isActive boolean */ - public void setActiveSync(boolean isActive) { + public void isActiveSync(boolean isActive) { isActiveSync = isActive; } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 962842f..8e876d9 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -270,13 +270,13 @@ public class TimerTask implements Cloneable, * @return the URL List */ public List<String> getSynchronizingURLList() { - List<String> resutList = new ArrayList<>(); + List<String> resultList = new ArrayList<>(); if (!synchronisingInfoList.isEmpty()) { for (SyncInfo sync : synchronisingInfoList) { - resutList.add(sync.getSyncURL()); + resultList.add(sync.getSyncURL()); } } - return resutList; + return resultList; } /** @@ -305,8 +305,10 @@ public class TimerTask implements Cloneable, * @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)); + if (!url.isEmpty()) { + if (!getSynchronizingURLList().contains(url)) { + synchronisingInfoList.add(new SyncInfo(url, time, isActive)); + } } } @@ -360,7 +362,7 @@ public class TimerTask implements Cloneable, * @param syncInfo the SyncInfo */ public void setIsActive(boolean isActive, SyncInfo syncInfo) { - syncInfo.setActiveSync(isActive); + syncInfo.isActiveSync(isActive); } /** diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index b2270b0..8f5e0a7 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -367,6 +367,7 @@ public class TimerTaskHelper { public static List<JsonObject> taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { ArrayList<JsonObject> jsonObjectList = new ArrayList<>(); + String timestamp = "T00:00:00"; for (String url : task.getSynchronizingURLList()) { boolean isActive = task.getSynchronizingInfo(url).getActiveSync(); @@ -386,7 +387,7 @@ public class TimerTaskHelper { //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); periodElement.addProperty("id", dateString); - periodElement.addProperty("startDate", dateString + "T00:00:00" + timezone); + periodElement.addProperty("startDate", dateString + timestamp + timezone); periodElement.addProperty("duration", entry.getValue()/1000); if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { StringBuilder builder = new StringBuilder(); @@ -402,8 +403,8 @@ public class TimerTaskHelper { } } responseJSON.addProperty("URL", url); - responseJSON.addProperty("startDate", startPeriodDate.toString() + "T00:00:00" + timezone); - responseJSON.addProperty("endDate", endPeriodDate.toString() + "T00:00:00" + timezone); + responseJSON.addProperty("startDate", startPeriodDate.toString() + timestamp + timezone); + responseJSON.addProperty("endDate", endPeriodDate.toString() + timestamp + timezone); responseJSON.add("periods", periodArray); jsonObjectList.add(responseJSON); diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index b4f4888..f09a060 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -608,7 +608,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, String line = parseIn.readLine(); while ((line = parseIn.readLine()) != null) { line = line.trim(); - if ((!line.isEmpty())) { + if (!line.isEmpty()) { String[] urlArray = line.split(" "); //if there is no lastSyncTime if (urlArray.length == 2) { diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 51bcde0..ea3660c 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -122,7 +122,7 @@ public class TimerTaskSynchronizer implements DataEventListener { else { log.debug("Sync failed on " + object.get("URL").getAsString()); //deactivate autosync if the sync failed - task.getSynchronizingInfo(object.get("URL").getAsString()).setActiveSync(false); + task.getSynchronizingInfo(object.get("URL").getAsString()).isActiveSync(false); log.info("Adress deactivated"); } 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 7220cb6..bc20e94 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -82,7 +82,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** ComboBox of URLs */ protected JComboBox<String> urlComboBox; - /** LastSync */ + /** LastSync */ protected JLabel lastUpdate; /** task to update */ @@ -204,6 +204,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, for (String url : task.getSynchronizingURLList()) { urlComboBox.addItem(url); } + + urlComboBox.setActionCommand("comboBox"); panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1,3,1,1,0,0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(3,1,1,1), 0, 0)); panelOption.add(urlComboBox, new GridBagConstraints(2,3,1,1,0,0, @@ -386,14 +388,13 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, builder.append(gson.toJson(object)); } } - 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).getActiveSync()) { + //todo : get in properties + updateArea.setText("Url inactive"); + } + else { + updateArea.setText(builder.toString()); + } } else { updateArea.setText("No data"); @@ -442,12 +443,6 @@ 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(""); } } -- 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 666d668de79b3f2989a049f94dc0f7fe38fe46bd Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 10:27:46 2016 +0200 added a test for taskToJSONFormat --- .../java/org/chorem/jtimer/entities/TimerTask.java | 10 +++++ .../jtimer/ui/report/TimerTaskUpdaterView.java | 2 +- .../jtimer/entities/TimerTaskHelperTest.java | 47 ++++++++++++++++++++++ .../jtimer/io/GTimerIncrementalSaverTest.java | 2 +- src/test/resources/testdata/41.task | 8 ++++ src/test/resources/testdata/41.task.sync | 3 ++ 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 8e876d9..f17643a 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -313,6 +313,16 @@ public class TimerTask implements Cloneable, } /** + * Adds a new synchronization info with just url provided + * (default isActive = true and time is minimum) + * @param url a String + */ + public void addSyncInfo(String url) { + addSyncInfo(url, LocalDateTime.MIN, true); + } + + + /** * Removes a synchronisation info attached to a url if it exists * @param url : the url of the info to remove * 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 bc20e94..3929948 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -562,7 +562,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, String urlToAdd = (String) urlComboBox.getSelectedItem(); if ((!urlToAdd.isEmpty()) && (!task.getSynchronizingURLList().contains(urlToAdd))) { urlComboBox.addItem(urlToAdd); - task.addSyncInfo(urlToAdd, LocalDateTime.MIN, true); + task.addSyncInfo(urlToAdd); core.getData().changeSyncInfo(task, urlToAdd); } if (lastUpdate != null) { diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java index 88eb68f..abd36ea 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java @@ -21,10 +21,15 @@ */ package org.chorem.jtimer.entities; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import org.chorem.jtimer.AbstractJTimerTest; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -49,4 +54,46 @@ public class TimerTaskHelperTest extends AbstractJTimerTest { Assert.assertEquals(components.get(1), task1); Assert.assertEquals(components.get(2), task2); } + + /** + * Test json production + */ + @Test + public void taskToJSONFormatTest() { + TimerTask task = new TimerTask(); + task.setName("JsonBuilder Test"); + task.addSyncInfo("http://localhost:3000"); + //date : 2016-05-10 + task.setTime(new Date(1462831200000L), 452000L); + //date : 2016-05-12 + task.setTime(new Date(1463004000000L), 4533000L); + + //create json object list to get + List<JsonObject> listOfObjects = new ArrayList<>(); + + JsonObject objectToHave = new JsonObject(); + JsonArray periodArray = new JsonArray(); + JsonObject periodElement1 = new JsonObject(); + periodElement1.addProperty("id", "2016-05-10"); + periodElement1.addProperty("startDate", "2016-05-10T00:00:00+01:00"); + periodElement1.addProperty("duration", 452); + periodArray.add(periodElement1); + JsonObject periodElement2 = new JsonObject(); + periodElement2.addProperty("id", "2016-05-12"); + periodElement2.addProperty("startDate", "2016-05-12T00:00:00+01:00"); + periodElement2.addProperty("duration", 4533); + periodArray.add(periodElement2); + + objectToHave.addProperty("URL", "http://localhost:3000"); + objectToHave.addProperty("startDate", "2016-05-10T00:00:00+01:00"); + objectToHave.addProperty("endDate", "2016-05-20T00:00:00+01:00"); + objectToHave.add("periods", periodArray); + listOfObjects.add(objectToHave); + + + //make a list of json objects from the task + List<JsonObject> taskJsonList = TimerTaskHelper.taskToJSONFormat(task, new Date(1462831200000L), new Date(1463695200000L), false, "+01:00"); + //compare it + Assert.assertEquals(taskJsonList, listOfObjects); + } } diff --git a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java index d436038..4a9a04d 100644 --- a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java +++ b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java @@ -84,7 +84,7 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { Assert.assertNotNull(projects); Assert.assertEquals(getProjectsCount(projects), 6); - Assert.assertEquals(getTasksCount(projects), 40); + Assert.assertEquals(getTasksCount(projects), 41); Assert.assertEquals(getAnnotationsCount(projects), 9); Assert.assertEquals(getAlertsCount(projects), 6); diff --git a/src/test/resources/testdata/41.task b/src/test/resources/testdata/41.task new file mode 100644 index 0000000..a64c2cc --- /dev/null +++ b/src/test/resources/testdata/41.task @@ -0,0 +1,8 @@ +Format: 1.2 +Name: JsonBuilder Test +Created: 1243600123 +Options: 0 +Project: 1 +Data: +20090131 452 +20090205 4533 diff --git a/src/test/resources/testdata/41.task.sync b/src/test/resources/testdata/41.task.sync new file mode 100644 index 0000000..01cb6d9 --- /dev/null +++ b/src/test/resources/testdata/41.task.sync @@ -0,0 +1,3 @@ +Format: 1.2 +SyncInfo: +http://localhost:3000 true -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit bc0e7aabbb4d8b2d6bb164af0582b0200b5ca192 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 11:20:58 2016 +0200 added a test on parseSyncInfo in GTimerIncrementalSaver --- .../jtimer/io/GTimerIncrementalSaverTest.java | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java index 4a9a04d..e8dd169 100644 --- a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java +++ b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java @@ -25,10 +25,18 @@ package org.chorem.jtimer.io; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import org.apache.commons.io.FileUtils; import org.chorem.jtimer.AbstractJTimerTest; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; @@ -338,7 +346,6 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { } }*/ } - /** * Test que les lignes avec 0 ne sont pas chargées dans les fichiers de temps. * @@ -409,4 +416,26 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { } }*/ } + + /** + * Test that synchronization Info is properly parsed + * @throws IOException + */ + @Test + public void parseSyncInfoTest() throws IOException{ + + GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; + + TimerTask task = new TimerTask(); + task.setNumber(41); + + gsaver.parseSyncInfo(task); + + SyncInfo syncInfo = new SyncInfo("http://localhost:3000"); + + Assert.assertNotNull(task.getSynchronizingInfoList()); + Assert.assertEquals(task.getSynchronizingInfoList().get(0).getSyncURL(), syncInfo.getSyncURL()); + Assert.assertEquals(task.getSynchronizingInfoList().get(0).getActiveSync(), syncInfo.getActiveSync()); + + } } -- 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 ee8c1d395231f102526d49f5eea7f4dc11d79988 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 14:49:18 2016 +0200 added a checkbox for activity of url (not listening on it yet) --- .../jtimer/ui/report/TimerTaskUpdaterView.java | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 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 3929948..202baa2 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -70,6 +70,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** Include annotations on updates */ protected JCheckBox checkIncludesAnnotations; + /** Activate a sync URL */ + protected JCheckBox checkIsActiveSync; + /** Date pickers, from... to */ protected JXDatePicker datePickerFrom, datePickerTo; @@ -206,16 +209,19 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } urlComboBox.setActionCommand("comboBox"); - panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1,3,1,1,0,0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(3,1,1,1), 0, 0)); - panelOption.add(urlComboBox, new GridBagConstraints(2,3,1,1,0,0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,3,1,1), 0, 0)); + panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1, 2, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2,1,1,1), 0, 0)); + panelOption.add(urlComboBox, new GridBagConstraints(2, 2, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 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)); + panelOption.add(lastSyncDateLabel, new GridBagConstraints(1, 3, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(3, 1, 1, 1), 0, 0)); //display last Sync time lastUpdate = new JLabel(""); + //todo : properties + checkIsActiveSync = new JCheckBox("active"); + checkIsActiveSync.setAction(getContext().getActionMap(this).get("isActiveSync")); if (urlComboBox.getSelectedItem() != null) { if (task.getSynchronizingURLList().contains(urlComboBox.getSelectedItem())){ SyncInfo syncInfo = task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()); @@ -224,11 +230,13 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if ((lastSyncTime != null) && lastSyncTime.isAfter(LocalDateTime.MIN)) { lastUpdate.setText(lastSyncTime.toString()); } + checkIsActiveSync.setSelected(task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).getActiveSync()); } } - panelOption.add(lastUpdate, new GridBagConstraints(2, 2, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); - + panelOption.add(lastUpdate, new GridBagConstraints(2, 3, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 3, 1, 1), 0, 0)); + panelOption.add(checkIsActiveSync, new GridBagConstraints(1, 4, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(4, 1, 1, 1), 0, 0)); configComponent.add(panelGeneral); configComponent.add(panelOption); -- 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 0606c67de0f8a58ccf9709c10bfffe8ad8396662 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 17:27:12 2016 +0200 added some logging (more to come) and added properties --- .../java/org/chorem/jtimer/entities/SyncInfo.java | 6 +++++ .../jtimer/ui/report/TimerTaskUpdaterView.java | 30 +++++++++++++++++----- .../resources/TimerTaskUpdaterView.properties | 8 +++--- .../resources/TimerTaskUpdaterView_fr.properties | 2 ++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java index cf81350..f1fee01 100644 --- a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -9,8 +9,14 @@ import java.time.LocalDateTime; * Created by servantie on 13/06/16. */ public class SyncInfo { + + /** the url to synchronize on */ String syncURL; + + /** the last time the synchronization happened successfully */ LocalDateTime lastSync; + + /** true if the synchronization is active */ boolean isActiveSync; /** 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 202baa2..7bc1787 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -214,13 +214,14 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, panelOption.add(urlComboBox, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); + //display last Sync time JLabel lastSyncDateLabel = new JLabel(getResourceMap().getString("lastUpdateLabel")); panelOption.add(lastSyncDateLabel, new GridBagConstraints(1, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(3, 1, 1, 1), 0, 0)); - //display last Sync time - lastUpdate = new JLabel(""); - //todo : properties - checkIsActiveSync = new JCheckBox("active"); + + lastUpdate = new JLabel(); + //checkbox for active sync + checkIsActiveSync = new JCheckBox(getResourceMap().getString("isActiveSync")); checkIsActiveSync.setAction(getContext().getActionMap(this).get("isActiveSync")); if (urlComboBox.getSelectedItem() != null) { if (task.getSynchronizingURLList().contains(urlComboBox.getSelectedItem())){ @@ -233,6 +234,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, checkIsActiveSync.setSelected(task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).getActiveSync()); } } + panelOption.add(lastUpdate, new GridBagConstraints(2, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 3, 1, 1), 0, 0)); panelOption.add(checkIsActiveSync, new GridBagConstraints(1, 4, 1, 1, 0, 0, @@ -397,8 +399,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } } if (!task.getSynchronizingInfo(urlSelected).getActiveSync()) { - //todo : get in properties - updateArea.setText("Url inactive"); + updateArea.setText(getResourceMap().getString("isNotActiveURL")); } else { updateArea.setText(builder.toString()); @@ -410,7 +411,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } /** - * Show annotation checkbox checked. + * Add annotation checkbox checked. */ @Action public boolean isIncludingAnnotations() { @@ -418,6 +419,14 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, return ischeckedIncludeAnnotations; } + /** + * Active sync checkbox checked + */ + @Action + public boolean isActiveSync() { + boolean isActiveSyncURL = checkIsActiveSync.isSelected(); + return isActiveSyncURL; + } /** @@ -479,9 +488,16 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, connection.setRequestProperty("Accept-Charset", charset); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestMethod("POST"); + //logging connection + log.info("Sending json to : " + syncURL); + postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); int code = connection.getResponseCode(); + + //logging code return + log.info("Code return : " + code); + if ((code == 200) || (code == 2001) || (code == 202)) { hasUpdated = true; } 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 963ee35..1e8718e 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 @@ -19,14 +19,16 @@ # <http://www.gnu.org/licenses/gpl-3.0.html>. # #L% ### -updateTitle=${Application.title} - Synchronisation +updateTitle=${Application.title} - Synchronization updateGeneral=General updateOptions=Options updateFrom=From : updateTo=To : -lastUpdateLabel=Last Synchronisation at: -urlComboLabel = Synchronisation Url: +lastUpdateLabel=Last Synchronization at: +urlComboLabel = Synchronization Url: +isActiveSync = Active sync +isNotActiveURL = Inactive Synchronization 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 aa37b4b..0febdcb 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 @@ -28,6 +28,8 @@ updateTo=\u00C0 : lastUpdateLabel=Derni\u00E8re synchronisation : urlComboLabel=Url de synchronisation : +isActiveSync= Synchronisation active +isNotActiveURL = Synchronisation vers cette URL d\u00E9sactiv\u00E9e 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 a0b0cdcb3aa2f7ac277d306e32201b3f935285d8 Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 17:47:53 2016 +0200 corrected text on the checkbox isActiveSync --- src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java | 4 +++- .../chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties | 4 ++-- .../jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties | 4 ++-- 3 files changed, 7 insertions(+), 5 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 7bc1787..e0be355 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -221,7 +221,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, lastUpdate = new JLabel(); //checkbox for active sync - checkIsActiveSync = new JCheckBox(getResourceMap().getString("isActiveSync")); + checkIsActiveSync = new JCheckBox(); checkIsActiveSync.setAction(getContext().getActionMap(this).get("isActiveSync")); if (urlComboBox.getSelectedItem() != null) { if (task.getSynchronizingURLList().contains(urlComboBox.getSelectedItem())){ @@ -230,6 +230,8 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, //if there has been an update before, display its date if ((lastSyncTime != null) && lastSyncTime.isAfter(LocalDateTime.MIN)) { lastUpdate.setText(lastSyncTime.toString()); + //logging change of lastSync + log.info(lastSyncTime.toString()); } checkIsActiveSync.setSelected(task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).getActiveSync()); } 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 1e8718e..938b3ca 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 @@ -27,7 +27,6 @@ updateTo=To : lastUpdateLabel=Last Synchronization at: urlComboLabel = Synchronization Url: -isActiveSync = Active sync isNotActiveURL = Inactive Synchronization @@ -65,4 +64,5 @@ action.update404 = Not found action.update500 = Server error action.updateErrorTitle = Synchronization error action.updateEncodingError = Encoding error -action.updateURLError = URL error \ No newline at end of file +action.updateURLError = URL error +isActiveSync.Action.text = Active synchronization \ 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 0febdcb..722dc83 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 @@ -28,7 +28,6 @@ updateTo=\u00C0 : lastUpdateLabel=Derni\u00E8re synchronisation : urlComboLabel=Url de synchronisation : -isActiveSync= Synchronisation active isNotActiveURL = Synchronisation vers cette URL d\u00E9sactiv\u00E9e @@ -65,4 +64,5 @@ 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 +action.updateURLError = Erreur d'URL +isActiveSync.Action.text = Synchronisation Active \ 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 4d96253b49200b2696aabca6687f937a26f40e42 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 22 16:38:43 2016 +0200 added logs, made method synchronizeTaskOnURL static and returning an int (http response) --- .../java/org/chorem/jtimer/entities/SyncInfo.java | 4 +- .../java/org/chorem/jtimer/entities/TimerTask.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 43 +++--- .../jtimer/ui/report/TimerTaskUpdaterView.java | 160 +++++++++++---------- .../resources/TimerTaskUpdaterView.properties | 1 + .../resources/TimerTaskUpdaterView_fr.properties | 1 + 6 files changed, 110 insertions(+), 101 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java index f1fee01..1eb90c4 100644 --- a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -57,10 +57,10 @@ public class SyncInfo { } /** - * Sets the isActiveSync boolean + * Sets the setIsActiveSync boolean * @param isActive boolean */ - public void isActiveSync(boolean isActive) { + public void setIsActiveSync(boolean isActive) { isActiveSync = isActive; } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index f17643a..986b180 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -372,7 +372,7 @@ public class TimerTask implements Cloneable, * @param syncInfo the SyncInfo */ public void setIsActive(boolean isActive, SyncInfo syncInfo) { - syncInfo.isActiveSync(isActive); + syncInfo.setIsActiveSync(isActive); } /** diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index ea3660c..5063ce9 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -112,18 +112,23 @@ public class TimerTaskSynchronizer implements DataEventListener { List<JsonObject> jsonObjectList = TimerTaskHelper.taskToJSONFormat(task, false, timezone); for (JsonObject object : jsonObjectList) { - boolean successfulSync = synchronizeTaskOnURL(object); + int SyncResult = synchronizeTaskOnURL(object); + boolean successfulSync = false; + String syncURL = object.get("URL").getAsString(); + if (SyncResult > 199 && SyncResult < 300) { + successfulSync = true; + } + else if (SyncResult == 0) { + log.debug("Error in connection " + syncURL); + } //sync successful -> change the last sync time if (successfulSync) { - log.debug("Sync successful on " + object.get("URL").getAsString()); - task.setLastSync(LocalDateTime.now(), object.get("URL").getAsString()); + log.debug("Sync successful on " + syncURL); + task.setLastSync(LocalDateTime.now(), syncURL); } //-> 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()).isActiveSync(false); - log.info("Adress deactivated"); + log.debug("Sync failed on " + syncURL); } } @@ -132,16 +137,16 @@ public class TimerTaskSynchronizer implements DataEventListener { /** * Sends one synchronization (one JSON object) * @param object the object to sync - * @return a boolean indicating failure or success + * @return an int (http response code or 0 in case of a problem) */ - public boolean synchronizeTaskOnURL(JsonObject object) { + public static int 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; + int upDateValue = 0; try { url = new URL(syncURL); connection = (HttpURLConnection) url.openConnection(); @@ -154,23 +159,19 @@ public class TimerTaskSynchronizer implements DataEventListener { connection.setRequestMethod("POST"); postDataBytes = updateJsonString.getBytes(charset); connection.getOutputStream().write(postDataBytes); - int code = connection.getResponseCode(); - if ((code == 200) || (code == 201) || (code == 202)){ - hasUpdated = true; - } - else { - log.info("Error"); - } + upDateValue = connection.getResponseCode(); } catch (MalformedURLException e) { - log.error("URL malformed"); + log.error("URL malformed : " + syncURL); } catch (ProtocolException e) { log.error("Protocol error."); } catch (UnsupportedEncodingException e) { - log.error("Problem with encoding"); + log.error("Problem with encoding " + syncURL); } catch (IOException e) { - log.error("Problem with the connection"); + log.error("Problem with the connection " + syncURL); + }catch (IllegalArgumentException e) { + log.error("Port value not valid " + syncURL); } - return hasUpdated; + return upDateValue; } @Override 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 e0be355..3844abb 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -31,6 +31,7 @@ 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.chorem.jtimer.io.TimerTaskSynchronizer; import org.jdesktop.application.*; import org.jdesktop.application.Action; import org.jdesktop.swingx.JXDatePicker; @@ -43,9 +44,8 @@ import javax.swing.event.DocumentListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.text.DateFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -59,7 +59,7 @@ import static org.chorem.jtimer.entities.TimerTaskHelper.taskToJSONFormat; * * Created by servantie on 13/05/16. */ -public class TimerTaskUpdaterView extends FrameView implements DocumentListener, ActionListener { +public class TimerTaskUpdaterView extends FrameView implements DocumentListener, ActionListener, ItemListener { /** Class logger */ protected static Log log = LogFactory.getLog(TimerTaskUpdaterView.class); @@ -113,10 +113,10 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, this.core = core; this.task = task; timezone = "+01:00"; + updateJson = new ArrayList<>(); setComponent(getMainComponent()); - updateJson = new ArrayList<>(); } @@ -170,6 +170,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, panelGeneral.add(previousWeekButton, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + // Option for period grouping JPanel typePanel = new JPanel(new GridLayout(0, 2)); panelGeneral.add(typePanel, new GridBagConstraints(0, 2, 3, 1, 0, 0, @@ -191,17 +192,19 @@ 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)); + panelOption.add(checkIncludesAnnotations, new GridBagConstraints(2, 4, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 1, 1, 1), 0, 0)); //url combobox JLabel urlcomboBoxLabel = new JLabel(getResourceMap().getString("urlComboLabel")); urlComboBox = new JComboBox<>(); //make it editable to add new urls urlComboBox.setEditable(true); + urlComboBox.addItemListener(this); urlComboBox.addActionListener(this); //add the urls to the combobox for (String url : task.getSynchronizingURLList()) { @@ -209,10 +212,10 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } urlComboBox.setActionCommand("comboBox"); - panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1, 2, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2,1,1,1), 0, 0)); - panelOption.add(urlComboBox, new GridBagConstraints(2, 2, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 2, 1, 1), 0, 0)); + panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1, 1, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,1,1,1), 0, 0)); + panelOption.add(urlComboBox, new GridBagConstraints(2, 1, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 1, 1, 1), 0, 0)); //display last Sync time JLabel lastSyncDateLabel = new JLabel(getResourceMap().getString("lastUpdateLabel")); @@ -222,6 +225,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, lastUpdate = new JLabel(); //checkbox for active sync checkIsActiveSync = new JCheckBox(); + checkIsActiveSync.addActionListener(this); checkIsActiveSync.setAction(getContext().getActionMap(this).get("isActiveSync")); if (urlComboBox.getSelectedItem() != null) { if (task.getSynchronizingURLList().contains(urlComboBox.getSelectedItem())){ @@ -231,7 +235,10 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if ((lastSyncTime != null) && lastSyncTime.isAfter(LocalDateTime.MIN)) { lastUpdate.setText(lastSyncTime.toString()); //logging change of lastSync - log.info(lastSyncTime.toString()); + log.info("Last Sync time loaded : " + lastSyncTime.toString()); + } + else { + log.info("No Last Sync time loaded"); } checkIsActiveSync.setSelected(task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).getActiveSync()); } @@ -422,11 +429,13 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } /** - * Active sync checkbox checked + * Active sync checkbox checked, activates sync */ @Action public boolean isActiveSync() { boolean isActiveSyncURL = checkIsActiveSync.isSelected(); + task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).setIsActiveSync(isActiveSyncURL); + log.info("Activity of url changed "); return isActiveSyncURL; } @@ -471,75 +480,37 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, * @param object json of task info */ public void synchronizeTaskOnURL(TimerTask task, JsonObject object) { - String updateJsonString = object.toString(); + int syncAnswer = TimerTaskSynchronizer.synchronizeTaskOnURL(object); String syncURL = object.get("URL").getAsString(); - String charset = "UTF-8"; - HttpURLConnection connection; - URL url; - byte[] postDataBytes; + String message =""; + String title = ""; boolean hasUpdated = false; - String message = ""; - String title = getResourceMap().getString("action.updateErrorTitle"); - 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"); - //logging connection - log.info("Sending json to : " + syncURL); - - postDataBytes = updateJsonString.getBytes(charset); - connection.getOutputStream().write(postDataBytes); - int code = connection.getResponseCode(); - - //logging code return - log.info("Code return : " + code); - - if ((code == 200) || (code == 2001) || (code == 202)) { + if ((syncAnswer == 200) || (syncAnswer == 201) || (syncAnswer == 202)) { hasUpdated = true; + log.info("Update accepted for URL : " + syncURL); } - else if (code == 400) { - log.debug("Bad Request"); + else if (syncAnswer == 400) { + log.debug("Bad Request for URL : " + syncURL); message = getResourceMap().getString("action.update400"); } - else if (code == 404) { - log.debug("Not Found"); + else if (syncAnswer == 404) { + log.debug("URL Not Found : " + syncURL); message = getResourceMap().getString("action.update404"); } - else if (code == 500) { - log.debug("Server Error"); + else if (syncAnswer == 500) { + log.debug("Server Error on URL : " + syncURL); message = getResourceMap().getString("action.update500"); } else { log.debug("Error"); message = getResourceMap().getString("action.updateError"); } - connection.disconnect(); - - } catch (MalformedURLException e) { - log.debug("URL malformed"); - message = getResourceMap().getString("action.updateURLError"); - } catch (ProtocolException e) { - log.debug("Protocol error."); - message = getResourceMap().getString("action.updateProtocolError"); - } catch (UnsupportedEncodingException e) { - log.debug("Problem with encoding"); - message = getResourceMap().getString("action.updateEncodingError"); - } catch (IOException e) { - log.debug("Problem with the connection"); - message = getResourceMap().getString("action.updateError"); - } finally { if (hasUpdated) { - task.setLastSync(LocalDateTime.now(),syncURL); + task.setLastSync(LocalDateTime.now(), syncURL); + core.getData().changeSyncInfo(task, syncURL); } else if (!message.isEmpty()){ errorBox(message, title); } - } //advise that it's done, to grey-out the send sync button boolean oldValue = canUpdate; canUpdate = false; @@ -587,23 +558,58 @@ 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); - core.getData().changeSyncInfo(task, urlToAdd); + urlComboBox.addItem(urlToAdd); + task.addSyncInfo(urlToAdd); + core.getData().changeSyncInfo(task, urlToAdd); + log.info("New SyncInfo with URL : " + 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 itemStateChanged(ItemEvent itemEvent) { + if (itemEvent.getStateChange()== ItemEvent.SELECTED) { + if (urlComboBox.getSelectedItem() != null) { + String urlToDisplay = urlComboBox.getSelectedItem().toString(); + if (!urlToDisplay.isEmpty()) { + log.info("Selected an object : " + urlComboBox.getSelectedItem().toString()); + //display last Sync Time + if (lastUpdate != null && task.getSynchronizingInfo(urlToDisplay).getLastSync() != null) { + if (task.getSynchronizingInfo(urlToDisplay).getLastSync().isAfter(LocalDateTime.MIN)) { + lastUpdate.setText(task.getSynchronizingInfo(urlToDisplay).getLastSync().toString()); + } + else { + lastUpdate.setText(""); + } + } + } + } } } + + @Override public void actionPerformed(ActionEvent actionEvent) { - itemAdded(); + String actionCommand = actionEvent.getActionCommand(); + if (actionCommand.equals("comboBox")) { + String urlToAdd = (String) urlComboBox.getSelectedItem(); + if (!task.getSynchronizingURLList().contains(urlToAdd)) { + log.info("New URL detected !"); + itemAdded(); + } + } + else if (actionCommand.equals("comboBoxChanged")) { + log.info("There has been a change in the comboBox"); + + } + else if (actionCommand.equals("comboBoxEdited")) { + log.info("The comboBox was edited"); + } + else if (actionCommand.equals(getResourceMap().getString("isActiveSync.Action.text"))) { + log.info("Checkbox ticked, unticked"); + } + else { + log.info("Action performed, not a new URL. Action: " + actionEvent.getActionCommand()); + } } -} +} \ No newline at end of file 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 938b3ca..2b669a8 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 @@ -65,4 +65,5 @@ action.update500 = Server error action.updateErrorTitle = Synchronization error action.updateEncodingError = Encoding error action.updateURLError = URL error + isActiveSync.Action.text = Active synchronization \ 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 722dc83..db5d2a1 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 @@ -65,4 +65,5 @@ action.update404 = Mauvaise URL action.update500 = Erreur du serveur action.updateEncodingError = Erreur d'encodage action.updateURLError = Erreur d'URL + isActiveSync.Action.text = Synchronisation Active \ 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 3f3eb51b8bf0272ce35eed3cc5c324135bad9317 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 22 16:28:55 2016 +0200 when a url is deleted in the combobox, it's saved in the file --- .../org/chorem/jtimer/data/DataEventListener.java | 8 ++++++ .../org/chorem/jtimer/data/TimerDataManager.java | 12 +++++++++ .../chorem/jtimer/io/GTimerIncrementalSaver.java | 10 +++++++- .../jtimer/ui/report/TimerTaskUpdaterView.java | 30 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index 7bad531..04b0e0a 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -195,6 +195,14 @@ public interface DataEventListener extends EventListener { * @param syncURL String */ default void changeSyncInfo(TimerTask task, String syncURL) { + + } + + /** + * SyncInfo deleted + */ + default void deleteSyncInfo(TimerTask task, String syncURL) { + } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index 835af87..faac507 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -647,4 +647,16 @@ public class TimerDataManager { dataEventListener.changeSyncInfo(task, url); } } + + /** + * When a syncInfo is deleted + */ + public void deleteSyncInfo(TimerTask task, String url) { + if (task.getSynchronizingURLList().contains(url)) { + task.removeSyncInfo(url); + } + for (DataEventListener dataEventListener : dataEventListeners) { + dataEventListener.deleteSyncInfo(task, url); + } + } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index f09a060..d821000 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -1532,5 +1532,13 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } + /** when a syncInfo is deleted make a save + * + * @param task + * @param url + */ + public void deleteSyncInfo(TimerTask task, String url) { + saveSynchronisationInfo(task); + } -} \ No newline at end of file +} 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 3844abb..522a60e 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -73,6 +73,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** Activate a sync URL */ protected JCheckBox checkIsActiveSync; + /** button to delete a URL */ + protected JButton deleteButton; + /** Date pickers, from... to */ protected JXDatePicker datePickerFrom, datePickerTo; @@ -244,6 +247,19 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } } + //option to delete url + //todo : properties ! + deleteButton = new JButton("Delete"); + deleteButton.addActionListener(this); + deleteButton.setActionCommand("deleteURL"); + + panelOption.add(deleteButton, new GridBagConstraints(1, 5, 1, 1, 0, 0, + GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 1, 1), 0, 0)); + + + + + panelOption.add(lastUpdate, new GridBagConstraints(2, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 3, 1, 1), 0, 0)); panelOption.add(checkIsActiveSync, new GridBagConstraints(1, 4, 1, 1, 0, 0, @@ -608,6 +624,20 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, else if (actionCommand.equals(getResourceMap().getString("isActiveSync.Action.text"))) { log.info("Checkbox ticked, unticked"); } + else if (actionCommand.equals("deleteURL")) { + String urlToUse = (String) urlComboBox.getSelectedItem(); + //if the delete button has been clicked, delete the task (if it exists) + if ((urlToUse != null) && !urlToUse.isEmpty() && (task.getSynchronizingURLList().contains(urlToUse))) { + task.removeSyncInfo(urlToUse); + urlComboBox.removeItem(urlToUse); + log.info("SyncInfo deleted " + urlToUse); + core.getData().deleteSyncInfo(task, urlToUse); + } + else { + //todo : properties! + errorBox("No task to delete", "Error"); + } + } else { log.info("Action performed, not a new URL. Action: " + actionEvent.getActionCommand()); } -- 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 df1422c476a44effea2069d630c5e9841549c2d3 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 22 17:52:52 2016 +0200 deletion of url saved to sync file properly + corrected parsing of syncInfo (catching a DateTimeParseException, and taking a 00:00:00 instead of 00:00:00.000 format) --- .../org/chorem/jtimer/data/TimerDataManager.java | 2 ++ .../chorem/jtimer/io/GTimerIncrementalSaver.java | 10 ++++++++-- .../jtimer/ui/report/TimerTaskUpdaterView.java | 21 +++++++-------------- .../resources/TimerTaskUpdaterView.properties | 5 +++++ .../resources/TimerTaskUpdaterView_fr.properties | 4 ++++ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index faac507..46e79dd 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -646,6 +646,7 @@ public class TimerDataManager { for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.changeSyncInfo(task, url); } + log.info("SyncInfo changed: " + url); } /** @@ -658,5 +659,6 @@ public class TimerDataManager { for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.deleteSyncInfo(task, url); } + log.info("SyncInfo deleted: " + url); } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index d821000..720b82e 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -43,6 +43,7 @@ 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; @@ -621,8 +622,13 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } //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); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); + LocalDateTime date = null; + try { + date = LocalDateTime.parse(urlArray[2], formatter); + } catch (DateTimeParseException e) { + log.error("Error parsing SyncTime for " + urlArray[0]); + } if ("true".equals(urlArray[1])) { task.addSyncInfo(urlArray[0], date, 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 522a60e..e912b4d 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -248,8 +248,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } //option to delete url - //todo : properties ! - deleteButton = new JButton("Delete"); + deleteButton = new JButton(getResourceMap().getString("deleteButton")); deleteButton.addActionListener(this); deleteButton.setActionCommand("deleteURL"); @@ -411,7 +410,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, updateArea.setText(""); updateJson = new ArrayList<>(); //get the various objects for updates (on several urls) - updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), + updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), datePickerTo.getDate(), isIncludingAnnotations(), timezone); if (!updateJson.isEmpty()) { String urlSelected = (String) urlComboBox.getSelectedItem(); @@ -423,15 +422,11 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, builder.append(gson.toJson(object)); } } - if (!task.getSynchronizingInfo(urlSelected).getActiveSync()) { - updateArea.setText(getResourceMap().getString("isNotActiveURL")); - } - else { + if (task.getSynchronizingInfo(urlSelected).getActiveSync()) { updateArea.setText(builder.toString()); } - } - else { - updateArea.setText("No data"); + } else { + updateArea.setText(getResourceMap().getString("isNotActiveURL")); } } @@ -573,7 +568,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, */ public void itemAdded(){ String urlToAdd = (String) urlComboBox.getSelectedItem(); - if ((!urlToAdd.isEmpty()) && (!task.getSynchronizingURLList().contains(urlToAdd))) { + if ((urlToAdd != null) && (!urlToAdd.isEmpty()) && (!task.getSynchronizingURLList().contains(urlToAdd))) { urlComboBox.addItem(urlToAdd); task.addSyncInfo(urlToAdd); core.getData().changeSyncInfo(task, urlToAdd); @@ -630,12 +625,10 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if ((urlToUse != null) && !urlToUse.isEmpty() && (task.getSynchronizingURLList().contains(urlToUse))) { task.removeSyncInfo(urlToUse); urlComboBox.removeItem(urlToUse); - log.info("SyncInfo deleted " + urlToUse); core.getData().deleteSyncInfo(task, urlToUse); } else { - //todo : properties! - errorBox("No task to delete", "Error"); + errorBox(getResourceMap().getString("deleteErrorMessage"), getResourceMap().getString("deleteErrorTitle")); } } else { 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 2b669a8..6de32f8 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 @@ -66,4 +66,9 @@ action.updateErrorTitle = Synchronization error action.updateEncodingError = Encoding error action.updateURLError = URL error +deleteButton = Delete URL + +deleteErrorMessage = No URL to delete +deleteErrorTitle = Deletion error + isActiveSync.Action.text = Active synchronization \ 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 db5d2a1..768678c 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 @@ -66,4 +66,8 @@ action.update500 = Erreur du serveur action.updateEncodingError = Erreur d'encodage action.updateURLError = Erreur d'URL +deleteButton = Supprimer l'URL +deleteErrorMessage = Aucune URL \u00E0 supprimer +deleteErrorTitle = Erreur de suppression + isActiveSync.Action.text = Synchronisation Active \ 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 7baa9b58b47f172775343ad51bac60eb8a5d6c5b Author: servantie <servantie.c@gmail.com> Date: Thu Jun 23 11:19:04 2016 +0200 surrounded log.debug to only generate if Debug is enabled --- .../org/chorem/jtimer/data/TimerDataManager.java | 8 ++- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 5 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 32 ++++++--- .../jtimer/ui/report/TimerTaskUpdaterView.java | 84 +++++++++++++++------- 4 files changed, 91 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index 46e79dd..df9d8c0 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -646,7 +646,9 @@ public class TimerDataManager { for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.changeSyncInfo(task, url); } - log.info("SyncInfo changed: " + url); + if (log.isDebugEnabled()) { + log.debug("SyncInfo changed: " + url); + } } /** @@ -659,6 +661,8 @@ public class TimerDataManager { for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.deleteSyncInfo(task, url); } - log.info("SyncInfo deleted: " + url); + if (log.isDebugEnabled()) { + log.debug("SyncInfo deleted: " + url); + } } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 720b82e..91c2d11 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -627,7 +627,9 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, try { date = LocalDateTime.parse(urlArray[2], formatter); } catch (DateTimeParseException e) { - log.error("Error parsing SyncTime for " + urlArray[0]); + if (log.isErrorEnabled()) { + log.error("Error parsing SyncTime for " + urlArray[0]); + } } if ("true".equals(urlArray[1])) { task.addSyncInfo(urlArray[0], date, true); @@ -1170,6 +1172,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write("false "); } //write lastsync + //todo: remove the milliseconds if (sync.getLastSync().isAfter(LocalDateTime.MIN)) { out.write(sync.getLastSync().toString() + "\n"); } diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 5063ce9..42c83cf 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -119,16 +119,22 @@ public class TimerTaskSynchronizer implements DataEventListener { successfulSync = true; } else if (SyncResult == 0) { - log.debug("Error in connection " + syncURL); + if (log.isDebugEnabled()) { + log.debug("Error in connection " + syncURL); + } } //sync successful -> change the last sync time if (successfulSync) { - log.debug("Sync successful on " + syncURL); + if (log.isDebugEnabled()) { + log.debug("Sync successful on " + syncURL); + } task.setLastSync(LocalDateTime.now(), syncURL); } //-> do not change last sync time else { - log.debug("Sync failed on " + syncURL); + if (log.isDebugEnabled()) { + log.debug("Sync failed on " + syncURL); + } } } @@ -161,15 +167,25 @@ public class TimerTaskSynchronizer implements DataEventListener { connection.getOutputStream().write(postDataBytes); upDateValue = connection.getResponseCode(); } catch (MalformedURLException e) { - log.error("URL malformed : " + syncURL); + if (log.isErrorEnabled()) { + log.error("URL malformed : " + syncURL); + } } catch (ProtocolException e) { - log.error("Protocol error."); + if (log.isErrorEnabled()) { + log.error("Protocol error."); + } } catch (UnsupportedEncodingException e) { - log.error("Problem with encoding " + syncURL); + if (log.isErrorEnabled()) { + log.error("Problem with encoding " + syncURL); + } } catch (IOException e) { - log.error("Problem with the connection " + syncURL); + if (log.isErrorEnabled()) { + log.error("Problem with the connection " + syncURL); + } }catch (IllegalArgumentException e) { - log.error("Port value not valid " + syncURL); + if (log.isErrorEnabled()) { + log.error("Port value not valid " + syncURL); + } } return upDateValue; } 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 e912b4d..c45ada3 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -238,10 +238,14 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if ((lastSyncTime != null) && lastSyncTime.isAfter(LocalDateTime.MIN)) { lastUpdate.setText(lastSyncTime.toString()); //logging change of lastSync - log.info("Last Sync time loaded : " + lastSyncTime.toString()); + if (log.isDebugEnabled()) { + log.debug("Last Sync time loaded : " + lastSyncTime.toString()); + } } else { - log.info("No Last Sync time loaded"); + if (log.isDebugEnabled()) { + log.debug("No Last Sync time loaded"); + } } checkIsActiveSync.setSelected(task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).getActiveSync()); } @@ -446,7 +450,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, public boolean isActiveSync() { boolean isActiveSyncURL = checkIsActiveSync.isSelected(); task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).setIsActiveSync(isActiveSyncURL); - log.info("Activity of url changed "); + if (log.isDebugEnabled()) { + log.debug("Activity of url changed "); + } return isActiveSyncURL; } @@ -498,23 +504,33 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, boolean hasUpdated = false; if ((syncAnswer == 200) || (syncAnswer == 201) || (syncAnswer == 202)) { hasUpdated = true; - log.info("Update accepted for URL : " + syncURL); - } + if (log.isDebugEnabled()) { + log.debug("Update accepted for URL : " + syncURL); + } + } else if (syncAnswer == 400) { - log.debug("Bad Request for URL : " + syncURL); - message = getResourceMap().getString("action.update400"); + if (log.isDebugEnabled()) { + log.debug("Bad Request for URL : " + syncURL); + } + message = getResourceMap().getString("action.update400"); } else if (syncAnswer == 404) { - log.debug("URL Not Found : " + syncURL); - message = getResourceMap().getString("action.update404"); + if (log.isDebugEnabled()) { + log.debug("URL Not Found : " + syncURL); + } + message = getResourceMap().getString("action.update404"); } else if (syncAnswer == 500) { - log.debug("Server Error on URL : " + syncURL); - message = getResourceMap().getString("action.update500"); + if (log.isDebugEnabled()) { + log.debug("Server Error on URL : " + syncURL); + } + message = getResourceMap().getString("action.update500"); } else { - log.debug("Error"); - message = getResourceMap().getString("action.updateError"); + if (log.isDebugEnabled()) { + log.debug("Error"); + } + message = getResourceMap().getString("action.updateError"); } if (hasUpdated) { task.setLastSync(LocalDateTime.now(), syncURL); @@ -572,7 +588,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, urlComboBox.addItem(urlToAdd); task.addSyncInfo(urlToAdd); core.getData().changeSyncInfo(task, urlToAdd); - log.info("New SyncInfo with URL : " + urlToAdd); + if (log.isDebugEnabled()) { + log.debug("New SyncInfo with URL : " + urlToAdd); + } } } @@ -583,7 +601,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if (urlComboBox.getSelectedItem() != null) { String urlToDisplay = urlComboBox.getSelectedItem().toString(); if (!urlToDisplay.isEmpty()) { - log.info("Selected an object : " + urlComboBox.getSelectedItem().toString()); + if (log.isDebugEnabled()) { + log.debug("Selected an object : " + urlComboBox.getSelectedItem().toString()); + } //display last Sync Time if (lastUpdate != null && task.getSynchronizingInfo(urlToDisplay).getLastSync() != null) { if (task.getSynchronizingInfo(urlToDisplay).getLastSync().isAfter(LocalDateTime.MIN)) { @@ -605,20 +625,28 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if (actionCommand.equals("comboBox")) { String urlToAdd = (String) urlComboBox.getSelectedItem(); if (!task.getSynchronizingURLList().contains(urlToAdd)) { - log.info("New URL detected !"); + if (log.isDebugEnabled()) { + log.debug("New URL detected !"); + } itemAdded(); } } - else if (actionCommand.equals("comboBoxChanged")) { - log.info("There has been a change in the comboBox"); - - } - else if (actionCommand.equals("comboBoxEdited")) { - log.info("The comboBox was edited"); - } - else if (actionCommand.equals(getResourceMap().getString("isActiveSync.Action.text"))) { - log.info("Checkbox ticked, unticked"); - } +// else if (actionCommand.equals("comboBoxChanged")) { +// if (log.isDebugEnabled()) { +// log.debug("There has been a change in the comboBox"); +// } +// +// } +// else if (actionCommand.equals("comboBoxEdited")) { +// if (log.isDebugEnabled()) { +// log.debug("The comboBox was edited"); +// } +// } +// else if (actionCommand.equals(getResourceMap().getString("isActiveSync.Action.text"))) { +// if (log.isDebugEnabled()) { +// log.debug("Checkbox ticked, unticked"); +// } +// } else if (actionCommand.equals("deleteURL")) { String urlToUse = (String) urlComboBox.getSelectedItem(); //if the delete button has been clicked, delete the task (if it exists) @@ -632,7 +660,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } } else { - log.info("Action performed, not a new URL. Action: " + actionEvent.getActionCommand()); + if (log.isDebugEnabled()) { + log.debug("Action performed, not a new URL. Action: " + actionEvent.getActionCommand()); + } } } } \ 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 462d5dfeece1bbf0e38fa0e4a1718431103e4786 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 23 11:42:54 2016 +0200 remove milliseconds of lastSyncTime from sync save file --- src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 91c2d11..48c5754 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -1171,10 +1171,11 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, else { out.write("false "); } - //write lastsync - //todo: remove the milliseconds + //write lastsync (HH:MM:SS) if (sync.getLastSync().isAfter(LocalDateTime.MIN)) { - out.write(sync.getLastSync().toString() + "\n"); + //remove the milliseconds + String syncString = sync.getLastSync().toString().substring(0, sync.getLastSync().toString().length()-4); + out.write(syncString + "\n"); } else { out.write("\n"); -- 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 cf919e0de7d4e901ed204570262cb1fff558550b Author: servantie <servantie.c@gmail.com> Date: Thu Jun 23 18:05:35 2016 +0200 tests for addition/removal of SyncInfo in tasks --- .../org/chorem/jtimer/entities/TimerTaskTest.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java index 87cc0e1..6db7cb0 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java @@ -116,4 +116,46 @@ public class TimerTaskTest extends AbstractJTimerTest { Assert.assertEquals(task.getSubTasks().size(), 1); Assert.assertEquals(clonedTask.getSubTasks().size(), 0); } + + /** + * Test that no URL is present twice for a task + */ + @Test + public void addSyncInfoTest() { + TimerTask task = new TimerTask(); + String url1 = "localhost/test"; + String url2 = "localhost/test"; + + task.addSyncInfo(url1); + task.addSyncInfo(url2); + + Assert.assertTrue(task.getSynchronizingInfoList().size() == 1); + + String url3 = "localhost"; + task.addSyncInfo(url3); + + Assert.assertTrue(task.getSynchronizingInfoList().size() == 2); + } + + /** + * Test that removal of URL works ? + */ + @Test + public void removeSyncInfoTest() { + TimerTask task = new TimerTask(); + + String url1 = "localhost/test"; + String url2 = "localhost/other"; + + task.addSyncInfo(url1); + task.addSyncInfo(url2); + + Assert.assertTrue(task.getSynchronizingInfoList().size() == 2); + + task.removeSyncInfo(url1); + + Assert.assertTrue(task.getSynchronizingInfoList().size() == 1); + Assert.assertTrue(task.getSynchronizingURLList().contains(url2)); + + } } -- 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 280206e7b9a3fade902584cffc75ff9de4baad8e Author: servantie <servantie.c@gmail.com> Date: Fri Jun 24 15:14:29 2016 +0200 checkbox for active sync showing up properly --- .../java/org/chorem/jtimer/entities/TimerTask.java | 4 +-- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 3 +- .../jtimer/ui/report/TimerTaskUpdaterView.java | 40 ++++++---------------- 4 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 986b180..8d3c158 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -305,10 +305,8 @@ public class TimerTask implements Cloneable, * @param isActive a boolean for activity (true to sync auto) */ public void addSyncInfo(String url, LocalDateTime time, boolean isActive) { - if (!url.isEmpty()) { - if (!getSynchronizingURLList().contains(url)) { + if (!url.isEmpty() && !getSynchronizingURLList().contains(url)) { synchronisingInfoList.add(new SyncInfo(url, time, isActive)); - } } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 48c5754..97907cb 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -1172,7 +1172,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write("false "); } //write lastsync (HH:MM:SS) - if (sync.getLastSync().isAfter(LocalDateTime.MIN)) { + if (sync.getLastSync() != null && sync.getLastSync().isAfter(LocalDateTime.MIN)) { //remove the milliseconds String syncString = sync.getLastSync().toString().substring(0, sync.getLastSync().toString().length()-4); out.write(syncString + "\n"); diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 42c83cf..050ea7c 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -42,7 +42,7 @@ public class TimerTaskSynchronizer implements DataEventListener { public TimerTaskSynchronizer() { timer = new Timer(); timer.schedule(new UpdateTask(), autoSyncDelay, autoSyncDelay); - log.info("Starting synchronising thread"); + log.info("Starting synchronizing thread"); tasksToSync = Collections.synchronizedCollection(new ArrayList<>()); } @@ -136,7 +136,6 @@ public class TimerTaskSynchronizer implements DataEventListener { log.debug("Sync failed on " + syncURL); } } - } } diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java index c45ada3..99612fd 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -231,8 +231,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, checkIsActiveSync.addActionListener(this); checkIsActiveSync.setAction(getContext().getActionMap(this).get("isActiveSync")); if (urlComboBox.getSelectedItem() != null) { - if (task.getSynchronizingURLList().contains(urlComboBox.getSelectedItem())){ - SyncInfo syncInfo = task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()); + String selectedURL = (String) urlComboBox.getSelectedItem(); + if (task.getSynchronizingURLList().contains(selectedURL)){ + SyncInfo syncInfo = task.getSynchronizingInfo(selectedURL); LocalDateTime lastSyncTime = syncInfo.getLastSync(); //if there has been an update before, display its date if ((lastSyncTime != null) && lastSyncTime.isAfter(LocalDateTime.MIN)) { @@ -258,15 +259,11 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, panelOption.add(deleteButton, new GridBagConstraints(1, 5, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 1, 1), 0, 0)); - - - - - panelOption.add(lastUpdate, new GridBagConstraints(2, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 3, 1, 1), 0, 0)); panelOption.add(checkIsActiveSync, new GridBagConstraints(1, 4, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(4, 1, 1, 1), 0, 0)); + configComponent.add(panelGeneral); configComponent.add(panelOption); @@ -402,7 +399,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, getApplication().hide(this); } - /** * Make update. * @@ -445,6 +441,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** * Active sync checkbox checked, activates sync + * todo: solve problem of not showing up as ticked */ @Action public boolean isActiveSync() { @@ -456,7 +453,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, return isActiveSyncURL; } - /** * Can update ? * @@ -604,6 +600,9 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, if (log.isDebugEnabled()) { log.debug("Selected an object : " + urlComboBox.getSelectedItem().toString()); } + if (checkIsActiveSync != null) { + checkIsActiveSync.setSelected(task.getSynchronizingInfo(urlToDisplay).getActiveSync()); + } //display last Sync Time if (lastUpdate != null && task.getSynchronizingInfo(urlToDisplay).getLastSync() != null) { if (task.getSynchronizingInfo(urlToDisplay).getLastSync().isAfter(LocalDateTime.MIN)) { @@ -618,36 +617,19 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, } } - @Override public void actionPerformed(ActionEvent actionEvent) { String actionCommand = actionEvent.getActionCommand(); - if (actionCommand.equals("comboBox")) { + if ("comboBox".equals(actionCommand)) { String urlToAdd = (String) urlComboBox.getSelectedItem(); if (!task.getSynchronizingURLList().contains(urlToAdd)) { if (log.isDebugEnabled()) { - log.debug("New URL detected !"); + log.debug("New URL added"); } itemAdded(); } } -// else if (actionCommand.equals("comboBoxChanged")) { -// if (log.isDebugEnabled()) { -// log.debug("There has been a change in the comboBox"); -// } -// -// } -// else if (actionCommand.equals("comboBoxEdited")) { -// if (log.isDebugEnabled()) { -// log.debug("The comboBox was edited"); -// } -// } -// else if (actionCommand.equals(getResourceMap().getString("isActiveSync.Action.text"))) { -// if (log.isDebugEnabled()) { -// log.debug("Checkbox ticked, unticked"); -// } -// } - else if (actionCommand.equals("deleteURL")) { + else if ("deleteURL".equals(actionCommand)) { String urlToUse = (String) urlComboBox.getSelectedItem(); //if the delete button has been clicked, delete the task (if it exists) if ((urlToUse != null) && !urlToUse.isEmpty() && (task.getSynchronizingURLList().contains(urlToUse))) { -- 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 4bebabf2f4a7c1e9f6f9e8b9732817f33748a1cb Author: servantie <servantie.c@gmail.com> Date: Mon Jun 27 09:48:44 2016 +0200 corrected a variable name --- src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 050ea7c..45eb6bb 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -112,13 +112,13 @@ public class TimerTaskSynchronizer implements DataEventListener { List<JsonObject> jsonObjectList = TimerTaskHelper.taskToJSONFormat(task, false, timezone); for (JsonObject object : jsonObjectList) { - int SyncResult = synchronizeTaskOnURL(object); + int syncResult = synchronizeTaskOnURL(object); boolean successfulSync = false; String syncURL = object.get("URL").getAsString(); - if (SyncResult > 199 && SyncResult < 300) { + if (syncResult > 199 && syncResult < 300) { successfulSync = true; } - else if (SyncResult == 0) { + else if (syncResult == 0) { if (log.isDebugEnabled()) { log.debug("Error in connection " + syncURL); } -- 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 f269eaffd16fc28512ef342572b643332b70bb0d Author: servantie <servantie.c@gmail.com> Date: Mon Jun 27 10:11:11 2016 +0200 removed an unused method --- .../java/org/chorem/jtimer/entities/TimerTask.java | 19 ------------------- .../org/chorem/jtimer/io/GTimerIncrementalSaver.java | 1 + 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 8d3c158..9c5f8b7 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -280,25 +280,6 @@ public class TimerTask implements Cloneable, } /** - * Returns one String containing all the URLs for sync, separated by " , " - * @return a string of URLs - */ - public String getSynchronizingURLAsString() { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < synchronisingInfoList.size(); ++i) { - if (i == synchronisingInfoList.size()-1) { - builder.append(synchronisingInfoList.get(i).getSyncURL()); - } - else { - builder.append(synchronisingInfoList.get(i).getSyncURL()); - builder.append(" , "); - } - } - String urlListString = builder.toString(); - return urlListString; - } - - /** * Adds a new synchronization info if the url isn't already present in the list * @param url a string * @param time a LocalDateTime diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 97907cb..f01dea7 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -1547,6 +1547,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * @param task * @param url */ + @Override public void deleteSyncInfo(TimerTask task, String url) { saveSynchronisationInfo(task); } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit b799e6daa2a419de9a48c5c0ad132782c1d1c865 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 11:58:27 2016 +0200 adding a lastSync at the exit of jtimer (syncs the tasks that have been added to the synchronizer for one last time) --- .../java/org/chorem/jtimer/data/TimerCore.java | 3 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 4 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 58 +++++++++++++++++----- .../jtimer/ui/report/TimerTaskUpdaterView.java | 1 - 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index 5091468..b6eba6d 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -198,7 +198,8 @@ public class TimerCore { if (log.isInfoEnabled()) { log.info("Exiting application"); } - + //try one last sync + synchronizer.lastSync(); // unlock fs directory try { saver.unlock(); diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index f01dea7..ef651cf 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -622,7 +622,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } //else if there is lastSyncTime else if (urlArray.length == 3) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"); LocalDateTime date = null; try { date = LocalDateTime.parse(urlArray[2], formatter); @@ -1174,7 +1174,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, //write lastsync (HH:MM:SS) if (sync.getLastSync() != null && sync.getLastSync().isAfter(LocalDateTime.MIN)) { //remove the milliseconds - String syncString = sync.getLastSync().toString().substring(0, sync.getLastSync().toString().length()-4); + String syncString = sync.getLastSync().toString(); out.write(syncString + "\n"); } else { diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 45eb6bb..836cb91 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -25,7 +25,8 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected long autoSyncDelay = 1000 * 10L; //every 2 hours, check for modifications to sync + //every hour, check for modifications to sync + protected long autoSyncDelay = 1000 * 20L; /** timer to schedule syncs */ protected Timer timer; @@ -68,6 +69,16 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** + * Synchronizes tasks that have been modified + */ + public void lastSync() { + log.info("Synchronizing at exit"); + for (TimerTask task : tasksToSync) { + synchronizeSingleTask(task); + } + } + + /** * Inner Task class to make the automatic sync */ protected class UpdateTask extends java.util.TimerTask { @@ -127,15 +138,10 @@ public class TimerTaskSynchronizer implements DataEventListener { if (successfulSync) { if (log.isDebugEnabled()) { log.debug("Sync successful on " + syncURL); + log.debug(LocalDateTime.now()); } task.setLastSync(LocalDateTime.now(), syncURL); } - //-> do not change last sync time - else { - if (log.isDebugEnabled()) { - log.debug("Sync failed on " + syncURL); - } - } } } @@ -167,23 +173,23 @@ public class TimerTaskSynchronizer implements DataEventListener { upDateValue = connection.getResponseCode(); } catch (MalformedURLException e) { if (log.isErrorEnabled()) { - log.error("URL malformed : " + syncURL); + log.error("URL malformed : " + syncURL + " Code : " + upDateValue); } } catch (ProtocolException e) { if (log.isErrorEnabled()) { - log.error("Protocol error."); + log.error("Protocol error."+ " Code : " + upDateValue); } } catch (UnsupportedEncodingException e) { if (log.isErrorEnabled()) { - log.error("Problem with encoding " + syncURL); + log.error("Problem with encoding " + syncURL + " Code : " + upDateValue); } } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("Problem with the connection " + syncURL); + log.error("Problem with the connection " + syncURL + " Code : " + upDateValue); } }catch (IllegalArgumentException e) { if (log.isErrorEnabled()) { - log.error("Port value not valid " + syncURL); + log.error("Port value not valid " + syncURL + " Code : " + upDateValue); } } return upDateValue; @@ -238,8 +244,20 @@ public class TimerTaskSynchronizer implements DataEventListener { } + /** + * When the time is modified, the task is added to the sync list + * @param task task where time is changed + * @param date date + * @param time task time + */ @Override public void setTaskTime(TimerTask task, Date date, Long time) { + if (!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { + tasksToSync.add(task); + } + } } @Override @@ -267,8 +285,19 @@ public class TimerTaskSynchronizer implements DataEventListener { } + /** + * Tasks are added to synchronization list when started + * @param task started task + */ + @Override public void startTask(TimerTask task) { + if (!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { + tasksToSync.add(task); + } + } } /** * Tasks are added to synchronization list when stopped @@ -289,6 +318,11 @@ public class TimerTaskSynchronizer implements DataEventListener { } + /** + * When the syncInfo is changed, add the task to sync list + * @param task the task to sync + * @param syncURL the url to sync on (a String) + */ @Override public void changeSyncInfo(TimerTask task, String syncURL) { if (!tasksToSync.contains(task)) { 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 99612fd..01a945f 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -441,7 +441,6 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, /** * Active sync checkbox checked, activates sync - * todo: solve problem of not showing up as ticked */ @Action public boolean isActiveSync() { -- 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 398309a950488ca3bf0be26ae2b4c497be4ee708 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 15:18:59 2016 +0200 1488a94 modified json creation to not iterate on inactive urls, and optimized a little --- .../java/org/chorem/jtimer/entities/TimerTask.java | 16 +++++ .../chorem/jtimer/entities/TimerTaskHelper.java | 77 +++++++++++----------- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 7 +- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 9c5f8b7..3bc22d5 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -280,6 +280,22 @@ public class TimerTask implements Cloneable, } /** + * Returns only the URLs that are active + * @return a List<String> with only active urls + */ + public List<String> getActiveSynchronizingURLList() { + List<String> resultList = new ArrayList<>(); + if (!synchronisingInfoList.isEmpty()) { + for (SyncInfo sync : synchronisingInfoList) { + if (sync.isActiveSync) { + resultList.add(sync.getSyncURL()); + } + } + } + return resultList; + } + + /** * Adds a new synchronization info if the url isn't already present in the list * @param url a string * @param time a LocalDateTime diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index 8f5e0a7..ffec6b0 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -365,49 +365,46 @@ public class TimerTaskHelper { * @return result the string in JSON */ public static List<JsonObject> taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { - ArrayList<JsonObject> jsonObjectList = new ArrayList<>(); - String timestamp = "T00:00:00"; - - 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 + timestamp + 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 timestamp = "T00:00:00" + timezone; + //start and end period dates are the same for all the objects + LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + String startPeriodString = startPeriodDate.toString() + timestamp; + LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + String endPeriodString = endPeriodDate.toString() + timestamp; + SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); + //only create jsons if there are times to send + if (dates.size() != 0) { + //iterate over active urls only + for (String url : task.getActiveSynchronizingURLList()) { + JsonObject responseJSON = new JsonObject(); + JsonArray periodArray = new JsonArray(); + 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 + timestamp + timezone); + periodElement.addProperty("duration", entry.getValue()/1000); + if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { + StringBuilder annotationBuilder = new StringBuilder(); + for (String s : getAnnotation(task, entry.getKey())) { + annotationBuilder.append(s); + annotationBuilder.append(","); + } + periodElement.addProperty("info", annotationBuilder.toString()); } - String annotations = builder.toString(); - periodElement.addProperty("info", annotations); - + periodArray.add(periodElement); } - periodArray.add(periodElement); - } - } - responseJSON.addProperty("URL", url); - responseJSON.addProperty("startDate", startPeriodDate.toString() + timestamp + timezone); - responseJSON.addProperty("endDate", endPeriodDate.toString() + timestamp + timezone); - responseJSON.add("periods", periodArray); - - jsonObjectList.add(responseJSON); + responseJSON.addProperty("URL", url); + responseJSON.addProperty("startDate", startPeriodString); + responseJSON.addProperty("endDate", endPeriodString); + responseJSON.add("periods", periodArray); + + jsonObjectList.add(responseJSON); } } return jsonObjectList; diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 836cb91..61ceb0c 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { /** auto sync delay */ //every hour, check for modifications to sync - protected long autoSyncDelay = 1000 * 20L; + protected long autoSyncDelay = 1000 * 60 * 60L; /** timer to schedule syncs */ protected Timer timer; @@ -69,11 +69,14 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** - * Synchronizes tasks that have been modified + * Synchronizes at exit the tasks left in the sync */ public void lastSync() { log.info("Synchronizing at exit"); for (TimerTask task : tasksToSync) { + if (log.isDebugEnabled()) { + log.debug(task.getName()); + } synchronizeSingleTask(task); } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit aad45effbef54c77f9b3273c234d50dcc1a2417f Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 16:33:33 2016 +0200 modified the taskToJSONFormat method to include the current day --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 1a857c4..cf70f92 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -299,7 +299,7 @@ public class JTimerConfig { IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), - IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "3600"), IO_SYNC_TIMEZONE("jtimer.io.synchronizer.timezone", "+01:00"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index ffec6b0..c55d8d8 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -347,6 +347,8 @@ public class TimerTaskHelper { public static List<JsonObject> taskToJSONFormat(TimerTask task, boolean withAnnotations, String timezone) { Date startDate = task.getAllDaysAndTimes().firstKey(); Date endDate = new Date(); + //get the current day too by making endDate a day later + endDate.setTime(endDate.getTime() + 86400 * 1000L); List<JsonObject> resultingJSON = taskToJSONFormat(task, startDate, endDate, withAnnotations, timezone); return resultingJSON; } @@ -387,7 +389,7 @@ public class TimerTaskHelper { //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format JsonObject periodElement = new JsonObject(); periodElement.addProperty("id", dateString); - periodElement.addProperty("startDate", dateString + timestamp + timezone); + periodElement.addProperty("startDate", dateString + timestamp); periodElement.addProperty("duration", entry.getValue()/1000); if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { StringBuilder annotationBuilder = new StringBuilder(); @@ -407,6 +409,7 @@ public class TimerTaskHelper { jsonObjectList.add(responseJSON); } } + return jsonObjectList; } } -- 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 496b34a6a97d9e02aa352c04bc81708764a32a88 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 17:45:17 2016 +0200 corrected all the imports with * --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 15 ++++++++--- .../jtimer/ui/report/TimerTaskUpdaterView.java | 30 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 61ceb0c..97b77e5 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -1,6 +1,12 @@ package org.chorem.jtimer.io; import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Timer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.DataEventListener; @@ -8,10 +14,13 @@ import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; -import java.io.*; -import java.net.*; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; import java.time.LocalDateTime; -import java.util.*; /** * 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 01a945f..929c530 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -25,6 +25,7 @@ package org.chorem.jtimer.ui.report; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; @@ -32,24 +33,45 @@ import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.io.TimerTaskSynchronizer; -import org.jdesktop.application.*; import org.jdesktop.application.Action; +import org.jdesktop.application.Application; +import org.jdesktop.application.FrameView; import org.jdesktop.swingx.JXDatePicker; import org.jdesktop.swingx.JXTaskPane; import org.jdesktop.swingx.JXTaskPaneContainer; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTextArea; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import java.awt.*; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; + import java.text.DateFormat; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; import static org.chorem.jtimer.entities.TimerTaskHelper.taskToJSONFormat; -- 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 372caf2bbb184c4332cb0cbd30239032072e4035 Author: servantie <servantie.c@gmail.com> Date: Wed Jun 29 17:54:00 2016 +0200 corrected the title change not activating validation button in task editor --- src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 094e28b..7c54d41 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -532,8 +532,8 @@ public class TimerTaskEditor extends DialogView { isTitleChanged = true; } else if (issuer == annotationChangeListener) { isAnnotationChanged = true; - updateTask(); } + updateTask(); } /** -- 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 8dba28cb1330e9c4b54f840a60935fe57b116e35 Author: servantie <servantie.c@gmail.com> Date: Thu Jun 30 15:49:29 2016 +0200 New display of SyncInfo edition, with URL test button --- src/main/java/org/chorem/jtimer/JTimer.java | 4 +- .../org/chorem/jtimer/data/DataEventListener.java | 5 +- .../java/org/chorem/jtimer/data/TimerCore.java | 2 - .../org/chorem/jtimer/data/TimerDataManager.java | 21 +- .../java/org/chorem/jtimer/entities/SyncInfo.java | 35 +- .../java/org/chorem/jtimer/entities/TimerTask.java | 39 +- .../chorem/jtimer/entities/TimerTaskHelper.java | 86 ++- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 74 ++- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 16 +- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 2 +- .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 385 ++++++++++++ .../jtimer/ui/report/TimerTaskUpdaterView.java | 671 --------------------- .../chorem/jtimer/ui/systray/SystrayManager.java | 7 +- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 2 - .../ProjectsAndTasksRunningCellRenderer.java | 1 - .../org/chorem/jtimer/resources/JTimer.properties | 4 +- .../chorem/jtimer/resources/JTimer_fr.properties | 4 +- .../resources/TimerTaskSyncInfoEditor.properties | 46 ++ .../TimerTaskSyncInfoEditor_fr.properties | 46 ++ .../resources/TimerTaskUpdaterView.properties | 74 --- .../resources/TimerTaskUpdaterView_fr.properties | 73 --- .../org/chorem/jtimer/entities/TimerTaskTest.java | 12 +- src/test/resources/testdata/41.task.sync | 2 +- 23 files changed, 671 insertions(+), 940 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index 4a0a733..eeae51d 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -74,7 +74,7 @@ import org.chorem.jtimer.ui.StatusBar; import org.chorem.jtimer.ui.TimerTaskEditor; import org.chorem.jtimer.ui.alert.AlertEditor; import org.chorem.jtimer.ui.report.ReportView; -import org.chorem.jtimer.ui.report.TimerTaskUpdaterView; +import org.chorem.jtimer.ui.report.TimerTaskSyncInfoEditor; import org.chorem.jtimer.ui.systray.SystrayManager; import org.chorem.jtimer.ui.tasks.IdleDialog; import org.chorem.jtimer.ui.tasks.RefreshTreeTask; @@ -669,7 +669,7 @@ public class JTimer extends SingleFrameApplication implements public void updateTask() { TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); - TimerTaskUpdaterView updater = new TimerTaskUpdaterView(this, core, task); + TimerTaskSyncInfoEditor updater = new TimerTaskSyncInfoEditor(this, core, task); show(updater); } diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index 04b0e0a..ea7d9e9 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -27,6 +27,7 @@ import java.util.Date; import java.util.EventListener; import java.util.List; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; @@ -194,14 +195,14 @@ public interface DataEventListener extends EventListener { * @param task * @param syncURL String */ - default void changeSyncInfo(TimerTask task, String syncURL) { + default void changeSyncInfo(TimerTask task, SyncInfo syncURL) { } /** * SyncInfo deleted */ - default void deleteSyncInfo(TimerTask task, String syncURL) { + default void deleteSyncInfo(TimerTask task, SyncInfo syncURL) { } } diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index b6eba6d..d29448b 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -198,8 +198,6 @@ public class TimerCore { if (log.isInfoEnabled()) { log.info("Exiting application"); } - //try one last sync - synchronizer.lastSync(); // unlock fs directory try { saver.unlock(); diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index df9d8c0..d51edec 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -37,6 +37,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; @@ -638,31 +639,31 @@ public class TimerDataManager { } /** - * Edit Synchronisation Information + * Edit Synchronization Information */ - public void changeSyncInfo(TimerTask task, String url) { - task.addSyncInfo(url, LocalDateTime.MIN, true); + public void changeSyncInfo(TimerTask task, SyncInfo info) { + task.addSyncInfo(info); for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.changeSyncInfo(task, url); + dataEventListener.changeSyncInfo(task, info); } if (log.isDebugEnabled()) { - log.debug("SyncInfo changed: " + url); + log.debug("SyncInfo changed: " + info.getSyncURL()); } } /** * When a syncInfo is deleted */ - public void deleteSyncInfo(TimerTask task, String url) { - if (task.getSynchronizingURLList().contains(url)) { - task.removeSyncInfo(url); + public void deleteSyncInfo(TimerTask task, SyncInfo info) { + if (task.getSynchronizingInfoList().contains(info)) { + task.removeSyncInfo(info); } for (DataEventListener dataEventListener : dataEventListeners) { - dataEventListener.deleteSyncInfo(task, url); + dataEventListener.deleteSyncInfo(task, info); } if (log.isDebugEnabled()) { - log.debug("SyncInfo deleted: " + url); + log.debug("SyncInfo deleted: " + info.getSyncURL()); } } } diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java index 1eb90c4..7963eac 100644 --- a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -19,25 +19,33 @@ public class SyncInfo { /** true if the synchronization is active */ boolean isActiveSync; + /** true if annotations included */ + boolean isWithAnnotations; + /** * 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 + * @param isWithAnnotations if true, will add annotations */ - public SyncInfo(String syncURL, LocalDateTime lastSync, boolean isActiveSync) { + public SyncInfo(String syncURL, LocalDateTime lastSync, boolean isActiveSync, boolean isWithAnnotations) { this.syncURL = syncURL; this.lastSync = lastSync; this.isActiveSync = isActiveSync; + this.isWithAnnotations = isWithAnnotations; } /** - * Constructor with just the url, at creation the sync is considered active by default + * Constructor with just the url, at creation the sync is considered active by default, + * and annotations are not sent by default * @param syncURL the url to sync to */ public SyncInfo(String syncURL) { this.syncURL = syncURL; this.isActiveSync = true; + this.isWithAnnotations = false; + this.lastSync = LocalDateTime.MIN; } /** @@ -50,7 +58,7 @@ public class SyncInfo { /** * Returns a boolean if sync should send to this url - * @return boolean + * @return aboolean */ public boolean getActiveSync() { return isActiveSync; @@ -65,6 +73,19 @@ public class SyncInfo { } /** + * Returns a boolean for the inclusion of annotations + * in the sync + * @return a boolean + */ + public boolean getIsWithAnnotations(){ return isWithAnnotations;} + + /** + * Sets the isWithAnnotations boolean + * @param hasAnnotations boolean + */ + public void setIsWithAnnotations(boolean hasAnnotations){ isWithAnnotations = hasAnnotations;} + + /** * Set the syncURL * @param syncURL String */ @@ -87,5 +108,13 @@ public class SyncInfo { public void setLastSync(LocalDateTime syncTime) { lastSync = syncTime; } + + /** + * Overrides the toString() method to return the url (for combobox) + */ + @Override + public String toString() { + return syncURL; + } } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 3bc22d5..b691fea 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -90,7 +90,7 @@ public class TimerTask implements Cloneable, protected List<TimerAlert> alerts; /** - * Synchronisation Info + * Synchronization Info */ protected List<SyncInfo> synchronisingInfoList; @@ -260,7 +260,7 @@ public class TimerTask implements Cloneable, } } if (!urlinList) { - synchronisingInfoList.add(new SyncInfo(syncURL, syncDate, true)); + synchronisingInfoList.add(new SyncInfo(syncURL)); } } @@ -300,37 +300,44 @@ public class TimerTask implements Cloneable, * @param url a string * @param time a LocalDateTime * @param isActive a boolean for activity (true to sync auto) + * @param isWithAnnotations a boolean for annotations (false default) */ - public void addSyncInfo(String url, LocalDateTime time, boolean isActive) { + public void addSyncInfo(String url, LocalDateTime time, boolean isActive, boolean isWithAnnotations) { if (!url.isEmpty() && !getSynchronizingURLList().contains(url)) { - synchronisingInfoList.add(new SyncInfo(url, time, isActive)); + synchronisingInfoList.add(new SyncInfo(url, time, isActive, isWithAnnotations)); } } /** * Adds a new synchronization info with just url provided - * (default isActive = true and time is minimum) + * (default isActive = true and isWithAnnotations false) * @param url a String */ public void addSyncInfo(String url) { - addSyncInfo(url, LocalDateTime.MIN, true); + addSyncInfo(url, LocalDateTime.MIN, true, false); + } + + /** + * Adds a SyncInfo to the task + * @param info a SyncInfo + */ + + public void addSyncInfo(SyncInfo info) { + if (!getSynchronizingInfoList().contains(info)) { + synchronisingInfoList.add(info); + } } /** - * Removes a synchronisation info attached to a url if it exists - * @param url : the url of the info to remove + * Removes a synchronization info attached to a url if it exists + * @param info : the sync info to remove * */ - public void removeSyncInfo(String url) { + public void removeSyncInfo(SyncInfo info) { 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)); - } - } + if (getSynchronizingURLList().contains(info.getSyncURL())) { + copySyncList.remove(info); } synchronisingInfoList = copySyncList; } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index c55d8d8..e893536 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -368,48 +368,68 @@ public class TimerTaskHelper { */ public static List<JsonObject> taskToJSONFormat(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timezone) { ArrayList<JsonObject> jsonObjectList = new ArrayList<>(); - String timestamp = "T00:00:00" + timezone; - //start and end period dates are the same for all the objects - LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String startPeriodString = startPeriodDate.toString() + timestamp; - LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String endPeriodString = endPeriodDate.toString() + timestamp; SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); //only create jsons if there are times to send if (dates.size() != 0) { //iterate over active urls only for (String url : task.getActiveSynchronizingURLList()) { - JsonObject responseJSON = new JsonObject(); - JsonArray periodArray = new JsonArray(); - 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 + timestamp); - periodElement.addProperty("duration", entry.getValue()/1000); - if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { - StringBuilder annotationBuilder = new StringBuilder(); - for (String s : getAnnotation(task, entry.getKey())) { - annotationBuilder.append(s); - annotationBuilder.append(","); - } - periodElement.addProperty("info", annotationBuilder.toString()); - } - periodArray.add(periodElement); - } - responseJSON.addProperty("URL", url); - responseJSON.addProperty("startDate", startPeriodString); - responseJSON.addProperty("endDate", endPeriodString); - responseJSON.add("periods", periodArray); - + JsonObject responseJSON = taskURLToJSONObject(task, url, startDate, endDate, withAnnotations, timezone); jsonObjectList.add(responseJSON); } } return jsonObjectList; } + + /** + * Makes only one object for a task associated to a URL + */ + public static JsonObject taskURLToJSONObject(TimerTask task, String url, Date startDate, Date endDate, boolean withAnnotations, String timezone) { + JsonObject resultingObject = new JsonObject(); + JsonArray periodArray = new JsonArray(); + String timestamp = "T00:00:00" + timezone; + SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); + LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + String startPeriodString = startPeriodDate.toString() + timestamp; + LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + String endPeriodString = endPeriodDate.toString() + timestamp; + 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 + timestamp); + periodElement.addProperty("duration", entry.getValue()/1000); + if (withAnnotations && !(getAnnotation(task, entry.getKey()).isEmpty())) { + StringBuilder annotationBuilder = new StringBuilder(); + for (String s : getAnnotation(task, entry.getKey())) { + annotationBuilder.append(s); + annotationBuilder.append(","); + } + periodElement.addProperty("info", annotationBuilder.toString()); + } + periodArray.add(periodElement); + } + resultingObject.addProperty("URL", url); + resultingObject.addProperty("startDate", startPeriodString); + resultingObject.addProperty("endDate", endPeriodString); + resultingObject.add("periods", periodArray); + + return resultingObject; + } + + /** + * Makes a single object with all the times + */ + public static JsonObject taskURLToJSONObject(TimerTask task, String url, boolean withAnnotations, String timezone) { + Date startDate = task.getAllDaysAndTimes().firstKey(); + Date endDate = new Date(); + //get the current day too by making endDate a day later + endDate.setTime(endDate.getTime() + 86400 * 1000L); + JsonObject resultingObject = taskURLToJSONObject(task, url, startDate, endDate, withAnnotations, timezone); + return resultingObject; + } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index ef651cf..22ef2c6 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -600,7 +600,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, if (syncTaskFile.exists()) { if (log.isDebugEnabled()) { - log.debug("Synchronisation information found for task " + task.getName()); + log.debug("Synchronization information found for task " + task.getName()); } try (BufferedReader parseIn = new BufferedReader(new FileReader(syncTaskFile))) { @@ -612,29 +612,50 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, if (!line.isEmpty()) { String[] urlArray = line.split(" "); //if there is no lastSyncTime - if (urlArray.length == 2) { + if (urlArray.length == 3) { if ("true".equals(urlArray[1])) { - task.addSyncInfo(urlArray[0], LocalDateTime.MIN, true); + if ("true".equals(urlArray[2])) { + task.addSyncInfo(urlArray[0], LocalDateTime.MIN, true, true); + } + else { + task.addSyncInfo(urlArray[0], LocalDateTime.MIN, true, false); + } } else { - task.addSyncInfo(urlArray[0], LocalDateTime.MIN, false); + if ("true".equals(urlArray[2])) { + task.addSyncInfo(urlArray[0], LocalDateTime.MIN, false, true); + } + else { + task.addSyncInfo(urlArray[0], LocalDateTime.MIN, false, false); + } } } //else if there is lastSyncTime - else if (urlArray.length == 3) { + else if (urlArray.length == 4) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"); LocalDateTime date = null; try { - date = LocalDateTime.parse(urlArray[2], formatter); + date = LocalDateTime.parse(urlArray[3], formatter); } catch (DateTimeParseException e) { if (log.isErrorEnabled()) { log.error("Error parsing SyncTime for " + urlArray[0]); } } if ("true".equals(urlArray[1])) { - task.addSyncInfo(urlArray[0], date, true); - } else { - task.addSyncInfo(urlArray[0], date, false); + if ("true".equals(urlArray[2])) { + task.addSyncInfo(urlArray[0], date, true, true); + } + else { + task.addSyncInfo(urlArray[0], date, true, false); + } + } + else { + if ("true".equals(urlArray[2])) { + task.addSyncInfo(urlArray[0], date, false, true); + } + else { + task.addSyncInfo(urlArray[0], date, false, false); + } } } } @@ -650,7 +671,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } else { if (log.isDebugEnabled()) { - log.debug("Synchronisation information not found for task " + task.getName()); + log.debug("Synchronization information not found for task " + task.getName()); } } } @@ -1140,22 +1161,22 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } /** - * Save synchronisation info for a task. + * Save synchronization info for a task. * * @param task task to save annotation */ - protected void saveSynchronisationInfo(TimerTask task) { + protected void saveSynchronizationInfo(TimerTask task) { int taskNumber = task.getNumber(); - File synchronisationTaskFile = new File(dataSaveDirectory + File.separator + 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(synchronisationTaskFile), "ISO-8859-1")) { + try (Writer out = new OutputStreamWriter(new FileOutputStream(synchronizationTaskFile), "ISO-8859-1")) { // first make backup - backupfile = makeBackupFile(synchronisationTaskFile); + backupfile = makeBackupFile(synchronizationTaskFile); out.write("Format: " + GTIMER_FILE_VERSION + "\n"); //start Sync Save @@ -1171,6 +1192,13 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, 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 @@ -1184,7 +1212,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, deleteBackupFile(backupfile); } catch (IOException e) { if (log.isErrorEnabled()) { - log.debug("Can't save task synchronisation information", e); + log.debug("Can't save task synchronization information", e); } // can be null if backup throws the exception @@ -1193,7 +1221,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } } else { - synchronisationTaskFile.delete(); + synchronizationTaskFile.delete(); } } @@ -1313,8 +1341,8 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } @Override - public void changeSyncInfo(TimerTask task, String syncURL) { - saveSynchronisationInfo(task); + public void changeSyncInfo(TimerTask task, SyncInfo syncURL) { + saveSynchronizationInfo(task); } @Override @@ -1366,7 +1394,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, if (syncFileToDelete.exists()) { syncFileToDelete.delete(); if (log.isDebugEnabled()) { - log.debug("Synchronisation file deleted for " + taskOrProject.getName() + "(" + syncFileToDelete.getPath() +")"); + log.debug("Synchronization file deleted for " + taskOrProject.getName() + "(" + syncFileToDelete.getPath() +")"); } } } @@ -1414,7 +1442,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // Potentiellement aussi lors d'un move. saveTaskAnnotation(task); saveAlerts(task); - saveSynchronisationInfo(task); + saveSynchronizationInfo(task); // fix a bug with the gtimer subtask // save format du to composed task name @@ -1548,8 +1576,8 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * @param url */ @Override - public void deleteSyncInfo(TimerTask task, String url) { - saveSynchronisationInfo(task); + public void deleteSyncInfo(TimerTask task, SyncInfo url) { + saveSynchronizationInfo(task); } } diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 97b77e5..ca42cd5 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -10,6 +10,7 @@ import java.util.Timer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.DataEventListener; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; @@ -78,19 +79,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } /** - * Synchronizes at exit the tasks left in the sync - */ - public void lastSync() { - log.info("Synchronizing at exit"); - for (TimerTask task : tasksToSync) { - if (log.isDebugEnabled()) { - log.debug(task.getName()); - } - synchronizeSingleTask(task); - } - } - - /** * Inner Task class to make the automatic sync */ protected class UpdateTask extends java.util.TimerTask { @@ -336,7 +324,7 @@ public class TimerTaskSynchronizer implements DataEventListener { * @param syncURL the url to sync on (a String) */ @Override - public void changeSyncInfo(TimerTask task, String syncURL) { + public void changeSyncInfo(TimerTask task, SyncInfo syncURL) { if (!tasksToSync.contains(task)) { //add it only if the URL is not empty if ((task.getSynchronizingURLList() != null) && !(task.getSynchronizingURLList().isEmpty())) { diff --git a/src/main/java/org/chorem/jtimer/ui/StatusBar.java b/src/main/java/org/chorem/jtimer/ui/StatusBar.java index 11b7fde..7802885 100644 --- a/src/main/java/org/chorem/jtimer/ui/StatusBar.java +++ b/src/main/java/org/chorem/jtimer/ui/StatusBar.java @@ -34,6 +34,7 @@ import javax.swing.SwingConstants; import org.apache.commons.lang3.time.DurationFormatUtils; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.data.TimerDataManager; +import org.chorem.jtimer.entities.SyncInfo; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; @@ -136,7 +137,6 @@ public class StatusBar extends JPanel implements DataEventListener { // and call modifyTask modifyTask(null); } - /* * @see org.chorem.jtimer.data.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) */ diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java new file mode 100644 index 0000000..ab0c4da --- /dev/null +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -0,0 +1,385 @@ + +/* + * #%L + * jTimer + * %% + * Copyright (C) 2008 - 2016 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package org.chorem.jtimer.ui.report; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.SyncInfo; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TimerTaskHelper; +import org.chorem.jtimer.io.TimerTaskSynchronizer; +import org.jdesktop.application.Action; +import org.jdesktop.application.Application; +import org.jdesktop.application.FrameView; + +/** + * UI to modify Synchronization Info of a task + * + * Created by servantie on 13/05/16. + */ +public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener, ItemListener { + + /** Class logger */ + protected static Log log = LogFactory.getLog(TimerTaskSyncInfoEditor.class); + + /** Timer core. */ + protected TimerCore core; + + /** Include annotations on updates */ + protected JCheckBox checkIncludesAnnotations; + + /** Activate a sync URL */ + protected JCheckBox checkIsActiveSync; + + /** button to delete a URL */ + protected JButton deleteButton; + + /** button to test a url */ + protected JButton testSyncUrlButton; + + /** task in json format (1/synchronizing url) */ + protected List<JsonObject> updateJson; + + /** ComboBox of URLs */ + protected JComboBox<SyncInfo> urlComboBox; + + /** LastSync */ + protected JLabel lastUpdate; + /** lastSync Label */ + protected JLabel lastSyncDateLabel; + + /** task to update */ + protected TimerTask task; + + /** timezone */ + protected String timezone; + + /** + * UpdaterView constructor. + * @param application parent reference + * @param core core reference + * @param task the task to update + */ + public TimerTaskSyncInfoEditor(Application application, TimerCore core, TimerTask task) { + + super(application); + // modify frame name + getFrame().setName("syncFrame"); + getFrame().setTitle(getResourceMap().getString("syncTitle")); + + this.core = core; + this.task = task; + timezone = "+01:00"; + updateJson = new ArrayList<>(); + + setComponent(getMainComponent()); + + + } + + /** + * Get main view component. + * + * @return main component + */ + protected JComponent getMainComponent() { + + JPanel configComponent = new JPanel(); + configComponent.setLayout(new BorderLayout(5, 5)); + + JPanel urlPanel = new JPanel(); + urlPanel.setLayout(new BorderLayout(5,5)); + + //url combobox + JLabel urlcomboBoxLabel = new JLabel(getResourceMap().getString("urlComboLabel")); + urlComboBox = new JComboBox<>(new DefaultComboBoxModel<>()); + //make it editable to add new urls + urlComboBox.setEditable(true); + urlComboBox.addItemListener(this); + urlComboBox.addActionListener(this); + //add the urls to the combobox + for (SyncInfo info : task.getSynchronizingInfoList()) { + urlComboBox.addItem(info); + } + urlComboBox.setActionCommand("comboBox"); + + urlPanel.add(urlcomboBoxLabel, BorderLayout.NORTH); + urlPanel.add(urlComboBox, BorderLayout.SOUTH); + + //a box containing the url sync time label and the checkboxes + Box labelBox = new Box(BoxLayout.PAGE_AXIS); + + + //checkbox to include annotations + checkIncludesAnnotations = new JCheckBox(); + checkIncludesAnnotations.setAction(getContext().getActionMap(this).get("isIncludingAnnotations")); + //checkbox for active sync + checkIsActiveSync = new JCheckBox(); + checkIsActiveSync.addActionListener(this); + checkIsActiveSync.setAction(getContext().getActionMap(this).get("isActiveSync")); + //display last Sync time + lastSyncDateLabel = new JLabel(getResourceMap().getString("lastUpdateLabel")); + lastUpdate = new JLabel(); + if (urlComboBox.getSelectedItem() != null) { + SyncInfo selectedInfo = (SyncInfo) urlComboBox.getSelectedItem(); + if (task.getSynchronizingInfoList().contains(selectedInfo)){ + SyncInfo syncInfo = task.getSynchronizingInfo(selectedInfo.getSyncURL()); + 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()); + //logging change of lastSync + if (log.isDebugEnabled()) { + log.debug("Last Sync time loaded : " + lastSyncTime.toString()); + } + lastSyncDateLabel.setVisible(true); + } + else { + if (log.isDebugEnabled()) { + log.debug("No Last Sync time loaded"); + } + lastSyncDateLabel.setVisible(false); + } + checkIsActiveSync.setSelected(task.getSynchronizingInfo(selectedInfo.getSyncURL()).getActiveSync()); + } + } + labelBox.add(checkIsActiveSync); + labelBox.add(checkIncludesAnnotations); + labelBox.add(lastSyncDateLabel); + labelBox.add(lastUpdate); + + //box to hold the delete button and the test sync button + Box deleteBox = new Box(BoxLayout.PAGE_AXIS); + //option to delete url + deleteButton = new JButton(getResourceMap().getString("deleteButton")); + deleteButton.addActionListener(this); + deleteButton.setActionCommand("deleteURL"); + + testSyncUrlButton = new JButton(getResourceMap().getString("testSyncButton")); + testSyncUrlButton.addActionListener(this); + testSyncUrlButton.setActionCommand("testURL"); + + + deleteBox.add(deleteButton); + deleteBox.add(testSyncUrlButton); + + // button to close + JButton closeButton = new JButton(); + closeButton.setAction(getContext().getActionMap(this).get("closeView")); + + //adding components to the main one + + configComponent.add(urlPanel, BorderLayout.NORTH); + configComponent.add(labelBox, BorderLayout.WEST); + configComponent.add(deleteBox, BorderLayout.EAST); + configComponent.add(closeButton, BorderLayout.SOUTH); + + // color fix on linux ? + configComponent.setBackground(urlPanel.getBackground()); + // set minimum size to prevent "packed size" (too big) + configComponent.setMinimumSize(new Dimension(100, 100)); + + return configComponent; + } + + /** + * Close action. + */ + @org.jdesktop.application.Action + public void closeView() { + getApplication().hide(this); + } + + + /** + * Add annotation checkbox checked. + */ + @Action + public boolean isIncludingAnnotations() { + boolean ischeckedIncludeAnnotations = checkIncludesAnnotations.isSelected(); + task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsWithAnnotations(ischeckedIncludeAnnotations); + if (log.isDebugEnabled()) { + log.debug("Inclusion of annotations in sync changed"); + } + return ischeckedIncludeAnnotations; + } + + /** + * Active sync checkbox checked, activates sync + */ + @Action + public boolean isActiveSync() { + boolean isActiveSyncURL = checkIsActiveSync.isSelected(); + task.getSynchronizingInfo(((SyncInfo) urlComboBox.getSelectedItem()).getSyncURL()).setIsActiveSync(isActiveSyncURL); + if (log.isDebugEnabled()) { + log.debug("Activity of url changed "); + } + return isActiveSyncURL; + } + + /** + * Method to display an error message + * @param errorMessage the message to display + * @param titleBar the title of the frame + */ + public static void errorBox(String errorMessage, String titleBar) + { + JOptionPane.showMessageDialog(null, errorMessage, titleBar, JOptionPane.ERROR_MESSAGE); + } + + /** + * Method to display an info message + * @param infoMessage the message to display + * @param titleBar the title of the frame + */ + public static void infoBox(String infoMessage, String titleBar) { + JOptionPane.showMessageDialog(null, infoMessage, titleBar, JOptionPane.INFORMATION_MESSAGE); + } + + + /** + * when an item is added to the list, + * add it to the url displayed, and to the syncInfo of the task + */ + public void itemAdded(String urlToAdd){ + if ((urlToAdd != null) && ((!task.getSynchronizingURLList().contains(urlToAdd)))) { + SyncInfo infoToAdd = new SyncInfo(urlToAdd); + urlComboBox.addItem(infoToAdd); + task.addSyncInfo(urlToAdd); + core.getData().changeSyncInfo(task, infoToAdd); + if (log.isDebugEnabled()) { + log.debug("New SyncInfo with URL : " + urlToAdd); + } + } + + } + + @Override + public void itemStateChanged(ItemEvent itemEvent) { + if (itemEvent.getStateChange()== ItemEvent.SELECTED) { + if (urlComboBox.getSelectedItem() != null) { + SyncInfo syncInfo; + if (urlComboBox.getSelectedItem() instanceof String) { + syncInfo = new SyncInfo((String)urlComboBox.getSelectedItem()); + } + else { + syncInfo = (SyncInfo) urlComboBox.getSelectedItem(); + } + String urlToDisplay = syncInfo.getSyncURL(); + if (!urlToDisplay.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("Selected an object : " + urlToDisplay); + } + if (checkIsActiveSync != null) { + checkIsActiveSync.setSelected(syncInfo.getActiveSync()); + } + if (checkIncludesAnnotations != null) { + checkIncludesAnnotations.setSelected(syncInfo.getIsWithAnnotations()); + } + //display last Sync Time + if (lastUpdate != null && syncInfo.getLastSync() != null) { + if (syncInfo.getLastSync().isAfter(LocalDateTime.MIN)) { + lastUpdate.setText(syncInfo.getLastSync().toString()); + lastSyncDateLabel.setVisible(true); + } + else { + lastUpdate.setText(""); + + lastSyncDateLabel.setVisible(false); + } + } + } + } + } + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + String actionCommand = actionEvent.getActionCommand(); + 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); + } + } + } + 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")); + } + } + 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")); + } + } + } + else { + if (log.isDebugEnabled()) { + log.debug("Action performed. Action: " + actionEvent.getActionCommand()); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java deleted file mode 100644 index 929c530..0000000 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ /dev/null @@ -1,671 +0,0 @@ - -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2016 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package org.chorem.jtimer.ui.report; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; - -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.chorem.jtimer.io.TimerTaskSynchronizer; -import org.jdesktop.application.Action; -import org.jdesktop.application.Application; -import org.jdesktop.application.FrameView; -import org.jdesktop.swingx.JXDatePicker; -import org.jdesktop.swingx.JXTaskPane; -import org.jdesktop.swingx.JXTaskPaneContainer; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -import java.text.DateFormat; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import static org.chorem.jtimer.entities.TimerTaskHelper.taskToJSONFormat; - -/** - * Updates UI - * - * Created by servantie on 13/05/16. - */ -public class TimerTaskUpdaterView extends FrameView implements DocumentListener, ActionListener, ItemListener { - - /** Class logger */ - protected static Log log = LogFactory.getLog(TimerTaskUpdaterView.class); - - /** Timer core. */ - protected TimerCore core; - - /** Include annotations on updates */ - protected JCheckBox checkIncludesAnnotations; - - /** Activate a sync URL */ - protected JCheckBox checkIsActiveSync; - - /** button to delete a URL */ - protected JButton deleteButton; - - /** Date pickers, from... to */ - protected JXDatePicker datePickerFrom, datePickerTo; - - /** update output view*/ - protected JTextArea updateArea; - - /** task in json format (1/synchronizing url) */ - protected List<JsonObject> updateJson; - - /** ComboBox of URLs */ - protected JComboBox<String> urlComboBox; - - /** LastSync */ - protected JLabel lastUpdate; - - /** task to update */ - protected TimerTask task; - - /** can update */ - protected boolean canUpdate; - - /** timezone */ - protected String timezone; - - /** - * UpdaterView constructor. - * @param application parent reference - * @param core core reference - * @param task the task to update - */ - public TimerTaskUpdaterView(Application application, TimerCore core, TimerTask task) { - - super(application); - // modify frame name - getFrame().setName("updateFrame"); - getFrame().setTitle(getResourceMap().getString("updateTitle")); - - this.core = core; - this.task = task; - timezone = "+01:00"; - updateJson = new ArrayList<>(); - - setComponent(getMainComponent()); - - - } - - /** - * Get main view component. - * - * TODO use less complicated UI (no gbl) - * @return main component - */ - protected JComponent getMainComponent() { - - JPanel configComponent = new JXTaskPaneContainer(); - - // panel for options - JXTaskPane panelGeneral = new JXTaskPane(getResourceMap().getString("updateGeneral")); - panelGeneral.setLayout(new GridBagLayout()); - panelGeneral.setSpecial(true); - - // first date picker - JLabel labelFrom = new JLabel(getResourceMap().getString("updateFrom")); - panelGeneral.add(labelFrom, new GridBagConstraints(0, 0, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - datePickerFrom = new JXDatePicker(); - datePickerFrom.getMonthView().setDayForeground(Calendar.SUNDAY, Color.RED); - datePickerFrom.setFormats(DateFormat.getDateInstance(DateFormat.FULL)); - panelGeneral.add(datePickerFrom, new GridBagConstraints(1, 0, 1, 1, 1, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - - // second date picker - JLabel labelTo = new JLabel(getResourceMap().getString("updateTo")); - panelGeneral.add(labelTo, new GridBagConstraints(0, 1, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - datePickerTo = new JXDatePicker(); - datePickerTo.getMonthView().setDayForeground(Calendar.SUNDAY, Color.RED); - datePickerTo.setFormats(DateFormat.getDateInstance(DateFormat.FULL)); - panelGeneral.add(datePickerTo, new GridBagConstraints(1, 1, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - - // set current week by default - currentWeek(); - - // action button to show current or previous week - JButton currentWeekButton = new JButton(); - currentWeekButton.setBorder(BorderFactory.createEmptyBorder()); - currentWeekButton.setAction(getContext().getActionMap(this).get("currentWeek")); - panelGeneral.add(currentWeekButton, new GridBagConstraints(2, 0, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - JButton previousWeekButton = new JButton(); - previousWeekButton.setBorder(BorderFactory.createEmptyBorder()); - previousWeekButton.setAction(getContext().getActionMap(this).get("previousWeek")); - panelGeneral.add(previousWeekButton, new GridBagConstraints(2, 1, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - - - // Option for period grouping - JPanel typePanel = new JPanel(new GridLayout(0, 2)); - panelGeneral.add(typePanel, new GridBagConstraints(0, 2, 3, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); - //button to have the whole month selected in the datepicker - JButton currentMonthButton = new JButton(); - currentMonthButton.setBorder(BorderFactory.createEmptyBorder()); - currentMonthButton.setAction(getContext().getActionMap(this).get("pickCurrentMonth")); - panelGeneral.add(currentMonthButton, new GridBagConstraints(1, 2, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - JButton previousMonthButton = new JButton(); - previousMonthButton.setBorder(BorderFactory.createEmptyBorder()); - previousMonthButton.setAction(getContext().getActionMap(this).get("pickPreviousMonth")); - panelGeneral.add(previousMonthButton, new GridBagConstraints(1, 3, 1, 1, 0, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - - - // miscellaneous - 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(2, 4, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 1, 1, 1), 0, 0)); - - //url combobox - JLabel urlcomboBoxLabel = new JLabel(getResourceMap().getString("urlComboLabel")); - urlComboBox = new JComboBox<>(); - //make it editable to add new urls - urlComboBox.setEditable(true); - urlComboBox.addItemListener(this); - urlComboBox.addActionListener(this); - //add the urls to the combobox - for (String url : task.getSynchronizingURLList()) { - urlComboBox.addItem(url); - } - - urlComboBox.setActionCommand("comboBox"); - panelOption.add(urlcomboBoxLabel, new GridBagConstraints(1, 1, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1,1,1,1), 0, 0)); - panelOption.add(urlComboBox, new GridBagConstraints(2, 1, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 1, 1, 1), 0, 0)); - - //display last Sync time - JLabel lastSyncDateLabel = new JLabel(getResourceMap().getString("lastUpdateLabel")); - panelOption.add(lastSyncDateLabel, new GridBagConstraints(1, 3, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(3, 1, 1, 1), 0, 0)); - - lastUpdate = new JLabel(); - //checkbox for active sync - checkIsActiveSync = new JCheckBox(); - checkIsActiveSync.addActionListener(this); - checkIsActiveSync.setAction(getContext().getActionMap(this).get("isActiveSync")); - if (urlComboBox.getSelectedItem() != null) { - String selectedURL = (String) urlComboBox.getSelectedItem(); - if (task.getSynchronizingURLList().contains(selectedURL)){ - SyncInfo syncInfo = task.getSynchronizingInfo(selectedURL); - 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()); - //logging change of lastSync - if (log.isDebugEnabled()) { - log.debug("Last Sync time loaded : " + lastSyncTime.toString()); - } - } - else { - if (log.isDebugEnabled()) { - log.debug("No Last Sync time loaded"); - } - } - checkIsActiveSync.setSelected(task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).getActiveSync()); - } - } - - //option to delete url - deleteButton = new JButton(getResourceMap().getString("deleteButton")); - deleteButton.addActionListener(this); - deleteButton.setActionCommand("deleteURL"); - - panelOption.add(deleteButton, new GridBagConstraints(1, 5, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 1, 1), 0, 0)); - panelOption.add(lastUpdate, new GridBagConstraints(2, 3, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(1, 3, 1, 1), 0, 0)); - panelOption.add(checkIsActiveSync, new GridBagConstraints(1, 4, 1, 1, 0, 0, - GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(4, 1, 1, 1), 0, 0)); - - configComponent.add(panelGeneral); - configComponent.add(panelOption); - - // panel for update output text - JPanel panelUpdate = new JPanel(new GridBagLayout()); - - updateArea = new JTextArea(); - updateArea.setFont(new Font("Courier", Font.PLAIN, 12)); - updateArea.getDocument().addDocumentListener(this); - JScrollPane jspupdate = new JScrollPane(updateArea); - panelUpdate.add(jspupdate, new GridBagConstraints(0, 0, 3, 1, 1, 1, - GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); - - // buttons - JButton generateButton = new JButton(); - generateButton.setAction(getContext().getActionMap(this).get("generateUpdate")); - panelUpdate.add(generateButton, new GridBagConstraints(0, 1, 1, 1, 1, 0, - GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); - - JButton sendUpdateButton = new JButton(); - sendUpdateButton.setAction(getContext().getActionMap(this).get("sendUpdate")); - panelUpdate.add(sendUpdateButton, new GridBagConstraints(1, 1, 1, 1, 1, 0, - GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); - - JButton closeButton = new JButton(); - closeButton.setAction(getContext().getActionMap(this).get("closeView")); - panelUpdate.add(closeButton, new GridBagConstraints(2, 1, 1, 1, 1, 0, - GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); - - // color fix on linux ? - configComponent.setBackground(panelUpdate.getBackground()); - // set minimum size to prevent "packed size" (too big) - configComponent.setMinimumSize(new Dimension(200, 0)); - - JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, configComponent, panelUpdate); - splitPane.setOneTouchExpandable(true); - return splitPane; - } - - /** - * Select current week in date pickers. - */ - @org.jdesktop.application.Action - public void currentWeek() { - fillPickerDates(0); - } - - /** - * Display previous week in date pickers. - */ - @org.jdesktop.application.Action - public void previousWeek() { - fillPickerDates(-1); - } - - /** - * Have current month selected in date pickers - */ - @org.jdesktop.application.Action - public void pickCurrentMonth() { - Calendar calendar = Calendar.getInstance(); - datePickerTo.setDate(calendar.getTime()); - //set it to the first day of the month - calendar.set(calendar.DAY_OF_MONTH, 1); - datePickerFrom.setDate(calendar.getTime()); - - } - - /** - * Have previous month selected in date pickers - */ - @org.jdesktop.application.Action - public void pickPreviousMonth() { - //get number of days in the previous month - //there has to be a better way to do this.. - LocalDate currentDate = LocalDate.now(); - currentDate.minusMonths(1); - int numberOfDays = currentDate.minusMonths(1).lengthOfMonth(); - - Calendar calendar = Calendar.getInstance(); - //previous month, first day - calendar.add(calendar.MONTH, -1); - calendar.set(calendar.DAY_OF_MONTH, 1); - datePickerFrom.setDate(calendar.getTime()); - Calendar calendarEnd = (Calendar) calendar.clone(); - calendarEnd.set(calendar.DAY_OF_MONTH, numberOfDays); - datePickerTo.setDate(calendarEnd.getTime()); - - } - /** - * Fill picker date with predefined week selection (from current) - * and apply a delay (-1 = previous week). - * - * @param delay delay to add to current week - */ - protected void fillPickerDates(int delay) { - // init dates - Calendar calendarBegin = Calendar.getInstance(); - int firstDayOfWeek = JTimer.config.getReportFirstDayOfWeek(); - if (firstDayOfWeek <= 0 || firstDayOfWeek > 7) { - firstDayOfWeek = calendarBegin.getFirstDayOfWeek(); - } - calendarBegin.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); - calendarBegin.set(Calendar.HOUR, 0); - calendarBegin.set(Calendar.MINUTE, 0); - calendarBegin.set(Calendar.SECOND, 0); - calendarBegin.set(Calendar.MILLISECOND, 0); - - // calendar must be in current week by default - if (calendarBegin.getTime().after(new Date())) { - calendarBegin.add(Calendar.WEEK_OF_YEAR, -1); - } - - // get end of week - // take calendarBegin and add a week time - Calendar calendarEnd = (Calendar) calendarBegin.clone(); - calendarEnd.add(Calendar.WEEK_OF_YEAR, 1); - calendarEnd.add(Calendar.DAY_OF_YEAR, -1); // take the day before - - // apply delai - calendarBegin.add(Calendar.WEEK_OF_YEAR, delay); - calendarEnd.add(Calendar.WEEK_OF_YEAR, delay); - - datePickerFrom.setDate(calendarBegin.getTime()); - datePickerTo.setDate(calendarEnd.getTime()); - } - - /** - * Close action. - */ - @org.jdesktop.application.Action - public void closeView() { - getApplication().hide(this); - } - - /** - * Make update. - * - * Set content in {@link #updateArea} text area. - */ - @org.jdesktop.application.Action - public void generateUpdate() { - //reinitialiser les trucs - updateArea.setText(""); - updateJson = new ArrayList<>(); - //get the various objects for updates (on several urls) - updateJson = taskToJSONFormat(task, datePickerFrom.getDate(), - datePickerTo.getDate(), isIncludingAnnotations(), timezone); - if (!updateJson.isEmpty()) { - String urlSelected = (String) urlComboBox.getSelectedItem(); - //to make it human readable - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - StringBuilder builder = new StringBuilder(); - for (JsonObject object : updateJson) { - if (urlSelected.equals(object.get("URL").getAsString())) { - builder.append(gson.toJson(object)); - } - } - if (task.getSynchronizingInfo(urlSelected).getActiveSync()) { - updateArea.setText(builder.toString()); - } - } else { - updateArea.setText(getResourceMap().getString("isNotActiveURL")); - } - } - - /** - * Add annotation checkbox checked. - */ - @Action - public boolean isIncludingAnnotations() { - boolean ischeckedIncludeAnnotations = checkIncludesAnnotations.isSelected(); - return ischeckedIncludeAnnotations; - } - - /** - * Active sync checkbox checked, activates sync - */ - @Action - public boolean isActiveSync() { - boolean isActiveSyncURL = checkIsActiveSync.isSelected(); - task.getSynchronizingInfo((String) urlComboBox.getSelectedItem()).setIsActiveSync(isActiveSyncURL); - if (log.isDebugEnabled()) { - log.debug("Activity of url changed "); - } - return isActiveSyncURL; - } - - /** - * Can update ? - * - * @return true if can update - */ - public boolean isUpdatingEnabled() { - return canUpdate; - } - - /** - * Change can update property. - * - * @param enabled can update - */ - public void setUpdatingEnabled(boolean enabled) { - boolean oldValue = canUpdate; - canUpdate = enabled; - firePropertyChange("updatingEnabled", oldValue, canUpdate); - } - - /** - * sends the sync of the task associated with the current url selected - * in the combobox (urlComboBox) - */ - @Action(enabledProperty = "updatingEnabled") - public void sendUpdate() { - String urlSelected = (String) urlComboBox.getSelectedItem(); - for (JsonObject object : updateJson) { - if (urlSelected.equals(object.get("URL").getAsString())) { - synchronizeTaskOnURL(task, object); - } - } - } - - /** - * Sends the update of a task to one url - * @param task task to update - * @param object json of task info - */ - public void synchronizeTaskOnURL(TimerTask task, JsonObject object) { - int syncAnswer = TimerTaskSynchronizer.synchronizeTaskOnURL(object); - String syncURL = object.get("URL").getAsString(); - String message =""; - String title = ""; - boolean hasUpdated = false; - if ((syncAnswer == 200) || (syncAnswer == 201) || (syncAnswer == 202)) { - hasUpdated = true; - if (log.isDebugEnabled()) { - log.debug("Update accepted for URL : " + syncURL); - } - } - else if (syncAnswer == 400) { - if (log.isDebugEnabled()) { - log.debug("Bad Request for URL : " + syncURL); - } - message = getResourceMap().getString("action.update400"); - } - else if (syncAnswer == 404) { - if (log.isDebugEnabled()) { - log.debug("URL Not Found : " + syncURL); - } - message = getResourceMap().getString("action.update404"); - } - else if (syncAnswer == 500) { - if (log.isDebugEnabled()) { - log.debug("Server Error on URL : " + syncURL); - } - message = getResourceMap().getString("action.update500"); - } - else { - if (log.isDebugEnabled()) { - log.debug("Error"); - } - message = getResourceMap().getString("action.updateError"); - } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now(), syncURL); - core.getData().changeSyncInfo(task, syncURL); - } else if (!message.isEmpty()){ - errorBox(message, title); - } - //advise that it's done, to grey-out the send sync button - boolean oldValue = canUpdate; - canUpdate = false; - firePropertyChange("updatingEnabled", oldValue, canUpdate); - } - - /** - * Method to display an error message (in case the sync goes wrong) - * @param errorMessage the message to display - * @param titleBar the title of the frame - */ - public static void errorBox(String errorMessage, String titleBar) - { - JOptionPane.showMessageDialog(null, errorMessage, titleBar, JOptionPane.ERROR_MESSAGE); - } - - @Override - public void changedUpdate(DocumentEvent e) { - documentChanged(); - } - - @Override - public void insertUpdate(DocumentEvent e) { - documentChanged(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - documentChanged(); - } - - /** - * Document content changed. - * - * Update can send update property. - */ - protected void documentChanged() { - setUpdatingEnabled(updateArea.getText().trim().length() > 0); - } - - /** - * when an item is added to the list, - * add it to the url displayed, and to the syncInfo of the task - */ - public void itemAdded(){ - String urlToAdd = (String) urlComboBox.getSelectedItem(); - if ((urlToAdd != null) && (!urlToAdd.isEmpty()) && (!task.getSynchronizingURLList().contains(urlToAdd))) { - urlComboBox.addItem(urlToAdd); - task.addSyncInfo(urlToAdd); - core.getData().changeSyncInfo(task, urlToAdd); - if (log.isDebugEnabled()) { - log.debug("New SyncInfo with URL : " + urlToAdd); - } - } - - } - - @Override - public void itemStateChanged(ItemEvent itemEvent) { - if (itemEvent.getStateChange()== ItemEvent.SELECTED) { - if (urlComboBox.getSelectedItem() != null) { - String urlToDisplay = urlComboBox.getSelectedItem().toString(); - if (!urlToDisplay.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Selected an object : " + urlComboBox.getSelectedItem().toString()); - } - if (checkIsActiveSync != null) { - checkIsActiveSync.setSelected(task.getSynchronizingInfo(urlToDisplay).getActiveSync()); - } - //display last Sync Time - if (lastUpdate != null && task.getSynchronizingInfo(urlToDisplay).getLastSync() != null) { - if (task.getSynchronizingInfo(urlToDisplay).getLastSync().isAfter(LocalDateTime.MIN)) { - lastUpdate.setText(task.getSynchronizingInfo(urlToDisplay).getLastSync().toString()); - } - else { - lastUpdate.setText(""); - } - } - } - } - } - } - - @Override - public void actionPerformed(ActionEvent actionEvent) { - String actionCommand = actionEvent.getActionCommand(); - if ("comboBox".equals(actionCommand)) { - String urlToAdd = (String) urlComboBox.getSelectedItem(); - if (!task.getSynchronizingURLList().contains(urlToAdd)) { - if (log.isDebugEnabled()) { - log.debug("New URL added"); - } - itemAdded(); - } - } - else if ("deleteURL".equals(actionCommand)) { - String urlToUse = (String) urlComboBox.getSelectedItem(); - //if the delete button has been clicked, delete the task (if it exists) - if ((urlToUse != null) && !urlToUse.isEmpty() && (task.getSynchronizingURLList().contains(urlToUse))) { - task.removeSyncInfo(urlToUse); - urlComboBox.removeItem(urlToUse); - core.getData().deleteSyncInfo(task, urlToUse); - } - else { - errorBox(getResourceMap().getString("deleteErrorMessage"), getResourceMap().getString("deleteErrorTitle")); - } - } - else { - if (log.isDebugEnabled()) { - log.debug("Action performed, not a new URL. Action: " + actionEvent.getActionCommand()); - } - } - } -} \ No newline at end of file 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 700b0b8..322ffca 100644 --- a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java +++ b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java @@ -33,10 +33,8 @@ import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; - import javax.swing.JMenuItem; import javax.swing.JPopupMenu; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; @@ -194,6 +192,11 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat } } + + + /* + * @see org.chorem.jtimer.ui.systray.SystrayManager#startTask(org.chorem.jtimer.entities.TimerTask) + */ @Override public void startTask(TimerTask task) { startStopTask(task, true); 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 d365546..230db7e 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java @@ -29,11 +29,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import javax.swing.SwingUtilities; import javax.swing.table.TableColumn; import javax.swing.tree.TreePath; - import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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 e8e41dd..905fa9d 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java @@ -156,7 +156,6 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen } } - @Override public void startTask(TimerTask task) { diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties index 5233547..4120155 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer.properties @@ -62,9 +62,9 @@ editTask.Action.text = &Edit Task editTask.Action.accelerator = F2 editTask.Action.shortDescription = Edit task -updateTask.Action.text = &Synchronise Task +updateTask.Action.text = &Edit Synchronization Info updateTask.Action.accelerator = F5 -updateTask.Action.shortDescription = Synchronise task +updateTask.Action.shortDescription = Edit Synchronization Info closeTask.Action.text = &Open/Close Task closeTask.Action.accelerator = control O diff --git a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties index c7ab52b..b070bbf 100644 --- a/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties +++ b/src/main/resources/org/chorem/jtimer/resources/JTimer_fr.properties @@ -42,8 +42,8 @@ editTask.Action.text = \u00C9dition de la t\u00E2ch&e editTask.Action.shortDescription = \u00C9dition de la t\u00E2che -updateTask.Action.text = &Synchroniser la t\u00E2che -updateTask.Action.shortDescription = Synchroniser +updateTask.Action.text = &\u00C9dition de la synchronisation +updateTask.Action.shortDescription = Edition de la synchronisation closeTask.Action.text = &Ouvrir/Fermer la t\u00E2che closeTask.Action.shortDescription = Ouvrir ou fermer la t\u00E2che diff --git a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskSyncInfoEditor.properties b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskSyncInfoEditor.properties new file mode 100644 index 0000000..990a73e --- /dev/null +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskSyncInfoEditor.properties @@ -0,0 +1,46 @@ +### +# #%L +# jTimer +# %% +# Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +syncTitle=${Application.title} - Edition of Synchronization Info +syncGeneral=General +syncOptions=Options + +lastUpdateLabel=Last Synchronization at: +urlComboLabel = Synchronization Url: + +updateAnnotations.Action.text = Include annotations +updateAnnotations.Action.shortDescription = Include annotations + +closeView.Action.text = &Close +closeView.Action.icon = dialog-close.png +closeView.Action.shortDescription = Close + +deleteButton = Delete URL +deleteErrorMessage = No URL to delete +deleteErrorTitle = Deletion error + +testSyncButton = Test URL +testSyncSuccessMessage = Synchronization test successful ! +testSyncSuccessTitle = Successful test +testSyncFailureMessage = Test failed to synchronize, check the URL ? +testSyncFailureTitle = Synchronization test failure + +isActiveSync.Action.text = Active synchronization \ No newline at end of file diff --git a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskSyncInfoEditor_fr.properties b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskSyncInfoEditor_fr.properties new file mode 100644 index 0000000..d3e733c --- /dev/null +++ b/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskSyncInfoEditor_fr.properties @@ -0,0 +1,46 @@ +### +# #%L +# jTimer +# %% +# Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +# update i18n +syncTitle=${Application.title} - Edition de la Synchronisation +syncGeneral=G\u00E9n\u00E9ral +syncOptions=Options + +lastUpdateLabel=Derni\u00E8re synchronisation : +urlComboLabel=Url de synchronisation : + +isIncludingAnnotations.Action.text = Inclure les annotations + +closeView.Action.text = &Fermer +closeView.Action.icon = dialog-close.png +closeView.Action.shortDescription = Fermer + +deleteButton = Supprimer l'URL +deleteErrorMessage = Aucune URL \u00E0 supprimer +deleteErrorTitle = Erreur de suppression + +testSyncButton = Tester l'URL +testSyncSuccessMessage = Test r\u00E9ussi, URL de synchronisation valide ! +testSyncSuccessTitle = Test r\u00E9ussi +testSyncFailureMessage = Test \u00E9chou\u00E9, v\u00E9rifier l'URL ? +testSyncFailureTitle = Echec du test de synchronisation + +isActiveSync.Action.text = Synchronisation Active \ No newline at end of file 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 deleted file mode 100644 index 6de32f8..0000000 --- a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView.properties +++ /dev/null @@ -1,74 +0,0 @@ -### -# #%L -# jTimer -# %% -# Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program. If not, see -# <http://www.gnu.org/licenses/gpl-3.0.html>. -# #L% -### -updateTitle=${Application.title} - Synchronization -updateGeneral=General -updateOptions=Options -updateFrom=From : -updateTo=To : - -lastUpdateLabel=Last Synchronization at: -urlComboLabel = Synchronization Url: -isNotActiveURL = Inactive Synchronization - - -pickCurrentMonth.Action.text = Select current month -pickCurrentMonth.Action.shortDescription = Select current month - -pickPreviousMonth.Action.text = Select previous month -pickPreviousMonth.Action.shortDescription = Select previous month - -currentWeek.Action.icon = date_current.png -currentWeek.Action.shortDescription = Current week - -previousWeek.Action.icon = date_previous.png -previousWeek.Action.shortDescription = Previous week - -updateAnnotations.Action.text = Include annotations -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 synchronization - -closeView.Action.text = &Close -closeView.Action.icon = dialog-close.png -closeView.Action.shortDescription = Close - -action.updateError = Synchronization failed -action.update400 = Bad Request -action.update404 = Not found -action.update500 = Server error -action.updateErrorTitle = Synchronization error -action.updateEncodingError = Encoding error -action.updateURLError = URL error - -deleteButton = Delete URL - -deleteErrorMessage = No URL to delete -deleteErrorTitle = Deletion error - -isActiveSync.Action.text = Active synchronization \ 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 deleted file mode 100644 index 768678c..0000000 --- a/src/main/resources/org/chorem/jtimer/ui/report/resources/TimerTaskUpdaterView_fr.properties +++ /dev/null @@ -1,73 +0,0 @@ -### -# #%L -# jTimer -# %% -# Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program. If not, see -# <http://www.gnu.org/licenses/gpl-3.0.html>. -# #L% -### -# update i18n -updateTitle=${Application.title} - Synchronisation -updateGeneral=G\u00E9n\u00E9ral -updateOptions=Options -updateFrom=De : -updateTo=\u00C0 : - -lastUpdateLabel=Derni\u00E8re synchronisation : -urlComboLabel=Url de synchronisation : -isNotActiveURL = Synchronisation vers cette URL d\u00E9sactiv\u00E9e - - -pickCurrentMonth.Action.text = Selectionner le mois courant -pickCurrentMonth.Action.shortDescription = Selectionner le mois courant - -pickPreviousMonth.Action.text = Selectionner le mois pr\u00E9c\u00E9dent -pickPreviousMonth.Action.shortDescription = Selectionner le mois pr\u00E9c\u00E9dent - -currentWeek.Action.icon = date_current.png -currentWeek.Action.shortDescription = Semaine courante - -previousWeek.Action.icon = date_previous.png -previousWeek.Action.shortDescription = Semaine pr\u00E9c\u00E9dente - -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 -sendUpdate.Action.shortDescription = Envoyer les donn\u00E9es - -closeView.Action.text = &Fermer -closeView.Action.icon = dialog-close.png -closeView.Action.shortDescription = Fermer - -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 - -deleteButton = Supprimer l'URL -deleteErrorMessage = Aucune URL \u00E0 supprimer -deleteErrorTitle = Erreur de suppression - -isActiveSync.Action.text = Synchronisation Active \ No newline at end of file diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java index 6db7cb0..0126c0a 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java @@ -144,18 +144,18 @@ public class TimerTaskTest extends AbstractJTimerTest { public void removeSyncInfoTest() { TimerTask task = new TimerTask(); - String url1 = "localhost/test"; - String url2 = "localhost/other"; + SyncInfo info1 = new SyncInfo("localhost/test"); + SyncInfo info2 = new SyncInfo("localhost/other"); - task.addSyncInfo(url1); - task.addSyncInfo(url2); + task.addSyncInfo(info1); + task.addSyncInfo(info2); Assert.assertTrue(task.getSynchronizingInfoList().size() == 2); - task.removeSyncInfo(url1); + task.removeSyncInfo(info1); Assert.assertTrue(task.getSynchronizingInfoList().size() == 1); - Assert.assertTrue(task.getSynchronizingURLList().contains(url2)); + Assert.assertTrue(task.getSynchronizingInfoList().contains(info2)); } } diff --git a/src/test/resources/testdata/41.task.sync b/src/test/resources/testdata/41.task.sync index 01cb6d9..f4d9859 100644 --- a/src/test/resources/testdata/41.task.sync +++ b/src/test/resources/testdata/41.task.sync @@ -1,3 +1,3 @@ Format: 1.2 SyncInfo: -http://localhost:3000 true +http://localhost:3000 true false -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 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>.
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 0260856f2f650a1fd0eef4f21ec129e789d69f65 Author: servantie <servantie.c@gmail.com> Date: Wed Jul 6 15:06:20 2016 +0200 corrected a double addition of urls in the synclist, edited some doc --- src/main/java/org/chorem/jtimer/data/TimerDataManager.java | 5 +++++ src/main/java/org/chorem/jtimer/entities/SyncInfo.java | 10 +++++----- src/main/java/org/chorem/jtimer/entities/TimerTask.java | 3 ++- src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java | 7 ++----- .../org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java | 8 +++----- .../java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index d51edec..529a349 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -640,8 +640,11 @@ public class TimerDataManager { /** * Edit Synchronization Information + * @param task : the task to edit + * @param info : the SyncInfo that was added */ public void changeSyncInfo(TimerTask task, SyncInfo info) { + task.addSyncInfo(info); for (DataEventListener dataEventListener : dataEventListeners) { @@ -654,6 +657,8 @@ public class TimerDataManager { /** * When a syncInfo is deleted + * @param task : the task to edit + * @param info : the SyncInfo to remove */ public void deleteSyncInfo(TimerTask task, SyncInfo info) { if (task.getSynchronizingInfoList().contains(info)) { diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java index 7963eac..a183ea7 100644 --- a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -11,16 +11,16 @@ import java.time.LocalDateTime; public class SyncInfo { /** the url to synchronize on */ - String syncURL; + protected String syncURL; /** the last time the synchronization happened successfully */ - LocalDateTime lastSync; + protected LocalDateTime lastSync; /** true if the synchronization is active */ - boolean isActiveSync; + protected boolean isActiveSync; /** true if annotations included */ - boolean isWithAnnotations; + protected boolean isWithAnnotations; /** * constructor with all parameters @@ -60,7 +60,7 @@ public class SyncInfo { * Returns a boolean if sync should send to this url * @return aboolean */ - public boolean getActiveSync() { + public boolean getIsActiveSync() { return isActiveSync; } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 28980a1..f50d411 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 new SyncInfo with the url) + * (if the url is not in the list, returns a new SyncInfo with the url and adds it to the list) * @param urlString * @return a SyncInfo matching the url */ @@ -364,6 +364,7 @@ public class TimerTask implements Cloneable, } } SyncInfo newInfo = new SyncInfo(urlString); + synchronisingInfoList.add(newInfo); 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 83900bd..3e1fa4f 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -26,7 +26,6 @@ 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; @@ -62,7 +61,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.JTimer; @@ -74,7 +72,6 @@ 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. @@ -1184,7 +1181,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, for (SyncInfo sync : task.getSynchronizingInfoList()) { Map<String, Object> dataToSave = new HashMap<>(); dataToSave.put("url", sync.getSyncURL()); - dataToSave.put("active", sync.getActiveSync()); + dataToSave.put("active", sync.getIsActiveSync()); dataToSave.put("annotations", sync.getIsWithAnnotations()); if (sync.getLastSync()!= null && sync.getLastSync()!=LocalDateTime.MIN) { dataToSave.put("lastSyncTime", sync.getLastSync()); @@ -1234,7 +1231,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // //write url // out.write(sync.getSyncURL() + " "); // //write isActive -// if (sync.getActiveSync()) { +// if (sync.getIsActiveSync()) { // out.write("true "); // } // else { 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 8378c52..700dee8 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -22,7 +22,6 @@ */ package org.chorem.jtimer.ui.report; -import com.google.gson.Gson; import com.google.gson.JsonObject; import java.awt.BorderLayout; import java.awt.Dimension; @@ -182,7 +181,7 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener } lastSyncDateLabel.setVisible(false); } - checkIsActiveSync.setSelected(task.getSynchronizingInfo(selectedInfo.getSyncURL()).getActiveSync()); + checkIsActiveSync.setSelected(task.getSynchronizingInfo(selectedInfo.getSyncURL()).getIsActiveSync()); } } labelBox.add(checkIsActiveSync); @@ -290,9 +289,8 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener public void itemAdded(String urlToAdd){ if ((urlToAdd != null) && ((!task.getSynchronizingURLList().contains(urlToAdd)))) { SyncInfo infoToAdd = new SyncInfo(urlToAdd); - urlComboBox.addItem(infoToAdd); - task.addSyncInfo(urlToAdd); core.getData().changeSyncInfo(task, infoToAdd); + urlComboBox.addItem(infoToAdd); if (log.isDebugEnabled()) { log.debug("New SyncInfo with URL : " + urlToAdd); } @@ -317,7 +315,7 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener log.debug("Selected an object : " + urlToDisplay); } if (checkIsActiveSync != null) { - checkIsActiveSync.setSelected(syncInfo.getActiveSync()); + checkIsActiveSync.setSelected(syncInfo.getIsActiveSync()); } if (checkIncludesAnnotations != null) { checkIncludesAnnotations.setSelected(syncInfo.getIsWithAnnotations()); diff --git a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java index e8dd169..73a1724 100644 --- a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java +++ b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java @@ -435,7 +435,7 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { Assert.assertNotNull(task.getSynchronizingInfoList()); Assert.assertEquals(task.getSynchronizingInfoList().get(0).getSyncURL(), syncInfo.getSyncURL()); - Assert.assertEquals(task.getSynchronizingInfoList().get(0).getActiveSync(), syncInfo.getActiveSync()); + Assert.assertEquals(task.getSynchronizingInfoList().get(0).getIsActiveSync(), syncInfo.getIsActiveSync()); } } -- 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 d2e14551e26cf9459cdb38d46cb748041253a915 Author: servantie <servantie.c@gmail.com> Date: Thu Jul 7 14:23:29 2016 +0200 changed LocalDateTime type for last sync to Date, used YAML to save sync info adapted test file to comply with yaml output --- .../java/org/chorem/jtimer/entities/SyncInfo.java | 44 +++++- .../java/org/chorem/jtimer/entities/TimerTask.java | 13 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 151 ++------------------- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 4 +- .../jtimer/ui/report/TimerTaskSyncInfoEditor.java | 60 ++++---- src/test/resources/testdata/41.task.sync | 9 +- 6 files changed, 95 insertions(+), 186 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java index a183ea7..4b7720c 100644 --- a/src/main/java/org/chorem/jtimer/entities/SyncInfo.java +++ b/src/main/java/org/chorem/jtimer/entities/SyncInfo.java @@ -2,7 +2,7 @@ package org.chorem.jtimer.entities; -import java.time.LocalDateTime; +import java.util.Date; /** * Class to structure synchronization info @@ -14,7 +14,7 @@ public class SyncInfo { protected String syncURL; /** the last time the synchronization happened successfully */ - protected LocalDateTime lastSync; + protected Date lastSync; /** true if the synchronization is active */ protected boolean isActiveSync; @@ -23,13 +23,19 @@ public class SyncInfo { protected boolean isWithAnnotations; /** + * Empty constructor (necessary for yaml) + */ + public SyncInfo(){ + } + + /** * 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 * @param isWithAnnotations if true, will add annotations */ - public SyncInfo(String syncURL, LocalDateTime lastSync, boolean isActiveSync, boolean isWithAnnotations) { + public SyncInfo(String syncURL, Date lastSync, boolean isActiveSync, boolean isWithAnnotations) { this.syncURL = syncURL; this.lastSync = lastSync; this.isActiveSync = isActiveSync; @@ -45,14 +51,14 @@ public class SyncInfo { this.syncURL = syncURL; this.isActiveSync = true; this.isWithAnnotations = false; - this.lastSync = LocalDateTime.MIN; + this.lastSync = new Date(0); } /** * Returns the time of the last sync * @return LocalDateTime */ - public LocalDateTime getLastSync() { + public Date getLastSync() { return lastSync; } @@ -103,9 +109,9 @@ public class SyncInfo { /** * Set Sync time - * @param syncTime LocalDateTime + * @param syncTime Date */ - public void setLastSync(LocalDateTime syncTime) { + public void setLastSync(Date syncTime) { lastSync = syncTime; } @@ -116,5 +122,29 @@ public class SyncInfo { public String toString() { return syncURL; } + + /** + * Override the equals + */ + @Override + public boolean equals(Object o) { + if (o instanceof SyncInfo) { + SyncInfo objInfo = (SyncInfo) o; + if (objInfo.getSyncURL() != null) { + if (objInfo.getSyncURL().equals(this.getSyncURL())) { + return true; + } + } + } + return false; + } + /** + * Overriding hashcode + */ + @Override + public int hashCode() { + int hash = syncURL.hashCode(); + return hash; + } } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index f50d411..79a90c0 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -23,7 +23,6 @@ package org.chorem.jtimer.entities; import java.io.Serializable; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -230,9 +229,9 @@ public class TimerTask implements Cloneable, * @param urlString the url to get the last sync from * @return the date of the sync */ - public LocalDateTime getLastSync(String urlString) { + public Date getLastSync(String urlString) { //to avoid null, a default time to return if errors - LocalDateTime resultTime = LocalDateTime.MIN; + Date resultTime = new Date(0); if (!synchronisingInfoList.isEmpty()) { for(SyncInfo sync : synchronisingInfoList) { if (urlString.equals(sync.getSyncURL())) { @@ -249,7 +248,7 @@ public class TimerTask implements Cloneable, * @param syncDate : date of the sync * @param syncURL : the url that has a change of syncdate */ - public void setLastSync(LocalDateTime syncDate, String syncURL) { + public void setLastSync(Date syncDate, String syncURL) { boolean urlinList = false; if(!synchronisingInfoList.isEmpty()) { for (SyncInfo sync : synchronisingInfoList) { @@ -302,7 +301,7 @@ public class TimerTask implements Cloneable, * @param isActive a boolean for activity (true to sync auto) * @param isWithAnnotations a boolean for annotations (false default) */ - public void addSyncInfo(String url, LocalDateTime time, boolean isActive, boolean isWithAnnotations) { + public void addSyncInfo(String url, Date time, boolean isActive, boolean isWithAnnotations) { if (!url.isEmpty() && !getSynchronizingURLList().contains(url)) { synchronisingInfoList.add(new SyncInfo(url, time, isActive, isWithAnnotations)); } @@ -313,9 +312,7 @@ public class TimerTask implements Cloneable, * (default isActive = true and isWithAnnotations false) * @param url a String */ - public void addSyncInfo(String url) { - addSyncInfo(url, LocalDateTime.MIN, true, false); - } + public void addSyncInfo(String url) { addSyncInfo(url, new Date(0), true, false); } /** * Adds a SyncInfo to the task diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 3e1fa4f..1db7f70 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; @@ -71,6 +70,7 @@ 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.DumperOptions; import org.yaml.snakeyaml.Yaml; /** @@ -602,71 +602,14 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, if (log.isDebugEnabled()) { log.debug("Synchronization information found for task " + task.getName()); } - try (BufferedReader parseIn = new BufferedReader(new FileReader(syncTaskFile))) { - //format line - String line = parseIn.readLine(); - while ((line = parseIn.readLine()) != null) { - line = line.trim(); - if (!line.isEmpty()) { - String[] urlArray = line.split(" "); - //if there is no lastSyncTime - if (urlArray.length == 3) { - if ("true".equals(urlArray[1])) { - if ("true".equals(urlArray[2])) { - task.addSyncInfo(urlArray[0], LocalDateTime.MIN, true, true); - } - else { - task.addSyncInfo(urlArray[0], LocalDateTime.MIN, true, false); - } - } - else { - if ("true".equals(urlArray[2])) { - task.addSyncInfo(urlArray[0], LocalDateTime.MIN, false, true); - } - else { - task.addSyncInfo(urlArray[0], LocalDateTime.MIN, false, false); - } - } - } - //else if there is lastSyncTime - else if (urlArray.length == 4) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"); - LocalDateTime date = null; - try { - date = LocalDateTime.parse(urlArray[3], formatter); - } catch (DateTimeParseException e) { - if (log.isErrorEnabled()) { - log.error("Error parsing SyncTime for " + urlArray[0]); - } - } - if ("true".equals(urlArray[1])) { - if ("true".equals(urlArray[2])) { - task.addSyncInfo(urlArray[0], date, true, true); - } - else { - task.addSyncInfo(urlArray[0], date, true, false); - } - } - else { - if ("true".equals(urlArray[2])) { - task.addSyncInfo(urlArray[0], date, false, true); - } - else { - task.addSyncInfo(urlArray[0], date, false, false); - } - } - } - } - else { - if (log.isWarnEnabled()) { - log.warn("Unknown synchronization type " + line); - } + Yaml yaml = new Yaml(); + for (Object obj : yaml.loadAll(parseIn)) { + if (obj instanceof SyncInfo) { + task.addSyncInfo((SyncInfo) obj); } - } - } } else { @@ -1174,22 +1117,13 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, // first make backup backupfile = makeBackupFile(synchronizationTaskFile); - out.write("Format: " + GTIMER_FILE_VERSION + "\n"); - //use Yaml to write it - Yaml yaml = new Yaml(); - for (SyncInfo sync : task.getSynchronizingInfoList()) { - Map<String, Object> dataToSave = new HashMap<>(); - dataToSave.put("url", sync.getSyncURL()); - dataToSave.put("active", sync.getIsActiveSync()); - dataToSave.put("annotations", sync.getIsWithAnnotations()); - if (sync.getLastSync()!= null && sync.getLastSync()!=LocalDateTime.MIN) { - dataToSave.put("lastSyncTime", sync.getLastSync()); - } - yaml.dump(dataToSave, out); - } + //use Yaml to write it with pretty flow to make it easier to read + DumperOptions dumper = new DumperOptions(); + dumper.setPrettyFlow(true); + Yaml yaml = new Yaml(dumper); + yaml.dumpAll(task.getSynchronizingInfoList().iterator(), out); out.close(); - deleteBackupFile(backupfile); } catch (IOException e) { @@ -1205,71 +1139,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } -// /** -// * 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.getIsActiveSync()) { -// 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/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index ca42cd5..a06519a 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -2,6 +2,7 @@ package org.chorem.jtimer.io; import com.google.gson.JsonObject; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -140,7 +141,8 @@ public class TimerTaskSynchronizer implements DataEventListener { log.debug("Sync successful on " + syncURL); log.debug(LocalDateTime.now()); } - task.setLastSync(LocalDateTime.now(), syncURL); + Calendar cal = Calendar.getInstance(); + task.setLastSync(cal.getTime(), syncURL); } } } 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 700dee8..9515df8 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -29,8 +29,11 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.time.LocalDateTime; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; @@ -165,9 +168,9 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener SyncInfo selectedInfo = (SyncInfo) urlComboBox.getSelectedItem(); if (task.getSynchronizingInfoList().contains(selectedInfo)){ SyncInfo syncInfo = task.getSynchronizingInfo(selectedInfo.getSyncURL()); - LocalDateTime lastSyncTime = syncInfo.getLastSync(); + Date lastSyncTime = syncInfo.getLastSync(); //if there has been an update before, display its date - if ((lastSyncTime != null) && lastSyncTime.isAfter(LocalDateTime.MIN)) { + if ((lastSyncTime != null) && lastSyncTime.after(new Date(0))) { lastUpdate.setText(lastSyncTime.toString()); //logging change of lastSync if (log.isDebugEnabled()) { @@ -303,13 +306,16 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener if (itemEvent.getStateChange()== ItemEvent.SELECTED) { if (urlComboBox.getSelectedItem() != null) { SyncInfo syncInfo; + String urlToDisplay; if (urlComboBox.getSelectedItem() instanceof String) { - syncInfo = new SyncInfo((String)urlComboBox.getSelectedItem()); + urlToDisplay = (String)urlComboBox.getSelectedItem(); + syncInfo = new SyncInfo(urlToDisplay); + urlComboBox.setSelectedItem(syncInfo); } else { syncInfo = (SyncInfo) urlComboBox.getSelectedItem(); + urlToDisplay = syncInfo.getSyncURL(); } - String urlToDisplay = syncInfo.getSyncURL(); if (!urlToDisplay.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Selected an object : " + urlToDisplay); @@ -322,13 +328,14 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener } //display last Sync Time if (lastUpdate != null && syncInfo.getLastSync() != null) { - if (syncInfo.getLastSync().isAfter(LocalDateTime.MIN)) { - lastUpdate.setText(syncInfo.getLastSync().toString()); + if (syncInfo.getLastSync().after(new Date(0))) { + DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); + lastUpdate.setText(df.format(syncInfo.getLastSync())); + lastUpdate.setVisible(true); lastSyncDateLabel.setVisible(true); } else { - lastUpdate.setText(""); - + lastUpdate.setVisible(false); lastSyncDateLabel.setVisible(false); } } @@ -342,16 +349,26 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener String actionCommand = actionEvent.getActionCommand(); SyncInfo infoToUse; + String urlToUse; if (urlComboBox.getSelectedItem() instanceof String) { - String urlToTest = (String) urlComboBox.getSelectedItem(); - infoToUse = new SyncInfo(urlToTest); + urlToUse = (String) urlComboBox.getSelectedItem(); + infoToUse = new SyncInfo(urlToUse); } else{ infoToUse = (SyncInfo) urlComboBox.getSelectedItem(); } - - if ("comboBox".equals(actionCommand)) { - if (!task.getSynchronizingInfoList().contains(infoToUse)) { + if ("deleteURL".equals(actionCommand)) { + //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 ("comboBox".equals(actionCommand)) { + if ((infoToUse != null) && !task.getSynchronizingInfoList().contains(infoToUse)) { if (log.isDebugEnabled()) { log.debug("New URL added"); } @@ -362,16 +379,6 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener } } - else if ("deleteURL".equals(actionCommand)) { - //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)) { //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 @@ -380,13 +387,14 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener int responseCode = TimerTaskSynchronizer.synchronizeTaskOnURL(testObject); if (responseCode > 199 && responseCode < 300) { infoBox(getResourceMap().getString("testSyncSuccessMessage"), getResourceMap().getString("testSyncSuccessTitle")); - infoToUse.setLastSync(LocalDateTime.now()); + Calendar cal = Calendar.getInstance(); + infoToUse.setLastSync(cal.getTime()); + core.getData().changeSyncInfo(task, infoToUse); } else { errorBox(getResourceMap().getString("testSyncFailureMessage"), getResourceMap().getString("testSyncFailureTitle")); } } - } else { if (log.isDebugEnabled()) { diff --git a/src/test/resources/testdata/41.task.sync b/src/test/resources/testdata/41.task.sync index f4d9859..16f07b8 100644 --- a/src/test/resources/testdata/41.task.sync +++ b/src/test/resources/testdata/41.task.sync @@ -1,3 +1,6 @@ -Format: 1.2 -SyncInfo: -http://localhost:3000 true false +!!org.chorem.jtimer.entities.SyncInfo { + isActiveSync: true, + isWithAnnotations: false, + lastSync: !!timestamp '1970-01-01T00:00:00Z', + syncURL: 'http://localhost:3000' +} \ 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 4c3886a652a9864d805fd0468ceb66020110a71f Author: servantie <servantie.c@gmail.com> Date: Thu Jul 7 15:43:46 2016 +0200 display of lastSync --- .../java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 9515df8..c75664b 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskSyncInfoEditor.java @@ -98,6 +98,9 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener /** timezone */ protected String timezone; + /** dateFormat for display */ + protected DateFormat df; + /** * UpdaterView constructor. * @param application parent reference @@ -115,6 +118,7 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener this.task = task; timezone = "+01:00"; updateJson = new ArrayList<>(); + df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); setComponent(getMainComponent()); @@ -171,7 +175,7 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener Date lastSyncTime = syncInfo.getLastSync(); //if there has been an update before, display its date if ((lastSyncTime != null) && lastSyncTime.after(new Date(0))) { - lastUpdate.setText(lastSyncTime.toString()); + lastUpdate.setText(df.format(lastSyncTime)); //logging change of lastSync if (log.isDebugEnabled()) { log.debug("Last Sync time loaded : " + lastSyncTime.toString()); @@ -329,7 +333,6 @@ public class TimerTaskSyncInfoEditor extends FrameView implements ActionListener //display last Sync Time if (lastUpdate != null && syncInfo.getLastSync() != null) { if (syncInfo.getLastSync().after(new Date(0))) { - DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); lastUpdate.setText(df.format(syncInfo.getLastSync())); lastUpdate.setVisible(true); lastSyncDateLabel.setVisible(true); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm