Skip to content

Commit

Permalink
#184 comparation offset: support for non time fields
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Mar 3, 2017
1 parent 40cdb23 commit a62e320
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,32 @@ public KPIDataLoader setTimeRange(long fromMillis, long toMillis)
{
timeRanges.add(TimeRange.offset(mainTimeRange, compareOffset));

fieldNameExtractor = (field, timeRange) -> {
if (timeRange.isMainTimeRange())
{
return field.getFieldName();
}
else if (field.isGroupBy())
{
return "_" + field.getOffsetFieldName();
}
else
{
return field.getOffsetFieldName();
}
};

final KPIField groupByField = kpi.getGroupByField();
if (groupByField.getValueType().isDate())
{
fieldNameExtractor = (field, timeRange) -> {
if (timeRange.isMainTimeRange())
{
return field.getFieldName();
}
else if (field.isGroupBy())
{
return "_" + field.getOffsetFieldName();
}
else
{
return field.getOffsetFieldName();
}
};
dataSetValueKeyExtractor = (bucket, timeRange) -> {
final long millis = convertToMillis(bucket.getKey());
return JSONDate.toJson(timeRange.subtractOffset(millis));
};
}
else
{
throw new AdempiereException("Only fields of type Date are supported for groupping by with offset");
dataSetValueKeyExtractor = (bucket, timeRange) -> groupByField.convertValueToJson(bucket.getKey());
}
}

Expand Down

0 comments on commit a62e320

Please sign in to comment.