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 ee0575035d3057a6f3888ca49b8aa0872732f2a6 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 009b000..96cb121 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 09128d2..3d53a15 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -357,49 +357,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>.