Implemented query seems properly working
This commit is contained in:
parent
32e37ee700
commit
7ed62332b4
|
@ -17,7 +17,7 @@ import org.gcube.documentstore.records.AggregatedRecord;
|
|||
public class Query {
|
||||
|
||||
public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS Z";
|
||||
public static final String DATE_OF_TIMESERIES_AS_FIELD = "startTime";
|
||||
public static final String DATE_OF_TIMESERIES_AS_FIELD = AggregatedRecord.START_TIME;
|
||||
|
||||
private Class<? extends AggregatedRecord<?, ?>> clz;
|
||||
private final RecordToDBMapper recordToDBMapper;
|
||||
|
@ -67,6 +67,12 @@ public class Query {
|
|||
stringBuffer.append(getTableField(fieldName));
|
||||
}
|
||||
|
||||
public static String getFormattedDate(Calendar calendar) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATETIME_PATTERN);
|
||||
String date = simpleDateFormat.format(calendar.getTime());
|
||||
return date;
|
||||
}
|
||||
|
||||
protected void appendValue(Serializable serializable) {
|
||||
if(serializable instanceof Number) {
|
||||
stringBuffer.append(serializable.toString());
|
||||
|
@ -75,9 +81,7 @@ public class Query {
|
|||
|
||||
if(serializable instanceof Calendar) {
|
||||
Calendar calendar = (Calendar) serializable;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATETIME_PATTERN);
|
||||
String date = simpleDateFormat.format(calendar.getTime());
|
||||
appendString(date);
|
||||
appendString(getFormattedDate(calendar));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,11 @@ public class RecordToDBMapper {
|
|||
}
|
||||
|
||||
public String getUsageRecordField(String tableField) {
|
||||
return tableFieldToUsageRecordField.get(tableField);
|
||||
String ret = tableFieldToUsageRecordField.get(tableField);
|
||||
if(ret==null && usageRecordFieldToTableField.keySet().contains(tableField)) {
|
||||
ret = tableField;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class UsageRecordDBInfo {
|
|||
|
||||
this.baseURL = configuration.getProperty(URL_PROPERTY_KEY);
|
||||
this.dbName = configuration.getProperty(typeName+DB_SUFFIX);
|
||||
this.url = baseURL + dbName;
|
||||
this.url = baseURL + "/" + dbName;
|
||||
|
||||
this.username = configuration.getProperty(typeName+USERNAME_SUFFIX);
|
||||
this.password = configuration.getProperty(typeName+PASSWORD_SUFFIX);
|
||||
|
|
|
@ -43,12 +43,12 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testGetNoContextTimeSeriesQuery() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
logger.debug("test");
|
||||
Calendar startTimeCalendar = Calendar.getInstance();
|
||||
startTimeCalendar.set(Calendar.YEAR, 2020);
|
||||
startTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 15);
|
||||
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 16);
|
||||
startTimeCalendar.set(Calendar.MINUTE, 15);
|
||||
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
startTimeCalendar.set(Calendar.MINUTE, 0);
|
||||
|
||||
Calendar entTimeCalendar = Calendar.getInstance();
|
||||
entTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||
|
@ -57,12 +57,15 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
|
|||
entTimeCalendar.set(Calendar.MINUTE, 17);
|
||||
|
||||
List<Filter> filters = new ArrayList<>();
|
||||
Filter filter = new Filter(UsageRecord.CONSUMER_ID, "name.surname");
|
||||
Filter filter = new Filter(UsageRecord.CONSUMER_ID, QueryTest.getRandomUser());
|
||||
filters.add(filter);
|
||||
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTimeCalendar.getTimeInMillis(), entTimeCalendar.getTimeInMillis(), AggregationMode.MINUTELY);
|
||||
SortedMap<Calendar, Info> timeseries = accountingPersistenceQueryPostgreSQL.getNoContextTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
logger.debug("{}", timeseries);
|
||||
for(Calendar c : timeseries.keySet()) {
|
||||
Info info = timeseries.get(c);
|
||||
logger.debug("{}", info);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue