Small error in GroupTable documentation regarding custom AggregationStrategy

Hi

2 small errors in doc. Discovered through sample project attached.

The aggregationStyle attribute allows you to specify the location of the aggregation row: TOP or BOTTOM. TOP is used by default.

In addition to the operations listed above, you can define a custom aggregation strategy by implementing the AggregationStrategy interface and passing it to the setAggregation() method of the Table.Column class inside the AggregationInfo instance. For example:

public class TimeEntryAggregation implements AggregationStrategy<List<TimeEntry>, String> {
    @Override
    public String aggregate(Collection<List<TimeEntry>> propertyValues) {
        HoursAndMinutes total = new HoursAndMinutes();
        for (List<TimeEntry> list : propertyValues) {
            for (TimeEntry timeEntry : list) {
                total.add(HoursAndMinutes.fromTimeEntry(timeEntry));
            }
        }
        return StringFormatHelper.getTotalDayAggregationString(total);
    }
    @Override
    public Class<String> getResultClass() {
        return String.class;
    }
}
AggregationInfo info = new AggregationInfo();
*info.setPropertyPath(metaPropertyPath); <= no
info.setStrategy(new TimeEntryAggregation());

Table.Column column = weeklyReportsTable.getColumn(columnId);
column.setAggregation(info);

info.setPropertyPath(metaPropertyPath); => no because if meta property path is defined the code in AggregatableDelegate will not send the entity to the custom agg strategy but the property value defined by the meta property path set

    protected Object doPropertyAggregation(AggregationInfo aggregationInfo, Collection<K> itemIds) {
        List items;

        if (aggregationInfo.getType() == AggregationInfo.Type.CUSTOM
                && aggregationInfo.getPropertyPath() == null) {
            // use items in this case;
            items = itemIds.stream()
                    .map(this::getItem)
                    .collect(Collectors.toList());
        } else {
            items = valuesByProperty(aggregationInfo.getPropertyPath(), itemIds);
        }
[...]

Also, the sample should be written this way

public class TimeEntryAggregation implements AggregationStrategy<TimeEntry, String> {
    @Override
    public String aggregate(Collection<TimeEntry> propertyValues) {
        HoursAndMinutes total = new HoursAndMinutes();
            for (TimeEntry timeEntry : propertyValues) {
                total.add(HoursAndMinutes.fromTimeEntry(timeEntry));
            }
        return StringFormatHelper.getTotalDayAggregationString(total);
    }
    @Override
    public Class<String> getResultClass() {
        return String.class;
    }
}

Regards
Michael
grouptableavg.zip (80.0 KB)

Hi,

After investigating, I can assure you that the documentation sample is correct. The sample itself has been taken from the sample-timesheets application and in the model there is a list of TimeEntry entities, i.e. o-t-m association. So, in case of doc sample it is expected to get a collection of lists of TimeEntry entities (see source).

Regards,
Gleb

Hi @gorelov
Ok I was confused by the one-to-many association then. My mistake.
On a side note, displaying the class model could help in the doc.
Or choosing a more simple case for the reader to guess the class model, like e.g aggregating figures which is fairly common.
Think about the old men :wink:

Regards
Michael

Sure, create a GitHub issue.