Fixed map padding

This commit is contained in:
Luca Frosini 2021-11-22 18:21:51 +01:00
parent 766df57d5f
commit 38b741dbb1
2 changed files with 18 additions and 5 deletions

View File

@ -3,6 +3,7 @@
*/ */
package org.gcube.accounting.analytics; package org.gcube.accounting.analytics;
import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
@ -15,6 +16,18 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
*/ */
public class Info { 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 Calendar calendar;
protected JsonNode value; protected JsonNode value;
@ -58,8 +71,6 @@ public class Info {
@Override @Override
public String toString(){ public String toString(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS z"); return String.format("Date : %s, Value : %s", format(calendar), value.toString());
simpleDateFormat.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE);
return String.format("Date : %s, Value : %s", simpleDateFormat.format(calendar.getTime()), value.toString());
} }
} }

View File

@ -135,7 +135,7 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
switch (key) { switch (key) {
case AggregatedRecord.START_TIME: case AggregatedRecord.START_TIME:
break; break;
case AggregatedRecord.END_TIME: case AggregatedRecord.END_TIME:
break; break;
@ -170,7 +170,9 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
for (Calendar progressTime : sequence) { for (Calendar progressTime : sequence) {
Info info = unpaddedData.get(progressTime); Info info = unpaddedData.get(progressTime);
if (info == null) { 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); unpaddedData.put(progressTime, info);
} }
} }