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;
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());
}
}

View File

@ -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);
}
}