From 38b741dbb100b5cb89f61265e0a5236c2f71362a Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 22 Nov 2021 18:21:51 +0100 Subject: [PATCH] Fixed map padding --- .../org/gcube/accounting/analytics/Info.java | 17 ++++++++++++++--- .../persistence/AccountingPersistenceQuery.java | 6 ++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/accounting/analytics/Info.java b/src/main/java/org/gcube/accounting/analytics/Info.java index 1372ca1..2a7e2a9 100644 --- a/src/main/java/org/gcube/accounting/analytics/Info.java +++ b/src/main/java/org/gcube/accounting/analytics/Info.java @@ -3,6 +3,7 @@ */ package org.gcube.accounting.analytics; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -15,6 +16,18 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode; */ public class Info { + public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS Z"; + + public static DateFormat getDateFormat() { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATETIME_PATTERN); + simpleDateFormat.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE); + return simpleDateFormat; + } + + public static String format(Calendar calendar) { + return getDateFormat().format(calendar.getTime()); + } + protected Calendar calendar; protected JsonNode value; @@ -58,8 +71,6 @@ public class Info { @Override public String toString(){ - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS z"); - simpleDateFormat.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE); - return String.format("Date : %s, Value : %s", simpleDateFormat.format(calendar.getTime()), value.toString()); + return String.format("Date : %s, Value : %s", format(calendar), value.toString()); } } diff --git a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java index 787eac8..0b13d33 100644 --- a/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java +++ b/src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java @@ -135,7 +135,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ switch (key) { case AggregatedRecord.START_TIME: break; - + case AggregatedRecord.END_TIME: break; @@ -170,7 +170,9 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ for (Calendar progressTime : sequence) { Info info = unpaddedData.get(progressTime); if (info == null) { - info = new Info(progressTime, jsonNode); + ObjectNode objectNode = jsonNode.deepCopy(); + objectNode.put(AggregatedStorageUsageRecord.START_TIME, Info.format(progressTime)); + info = new Info(progressTime, objectNode); unpaddedData.put(progressTime, info); } }