I have following groupTable where I want to aggregate the value of field ScoreObtained by VendorEvaluationCriteriaType.
Based on the user guide, I tried the following but I get 0 result in the expected cell as you can see above.
public void setAggregation() {
MetaPropertyPath metaPropertyPath = vendorEvaluationLineDs.getMetaClass().getPropertyPath("scoreObtained");
AggregationInfo info = new AggregationInfo();
info.setPropertyPath(metaPropertyPath);
info.setStrategy(new VendorEvaluationTypeAggregation());
vendorEvaluationLineGroupTable.getColumn("scoreObtained")
.setAggregation(info);
}
public class VendorEvaluationTypeAggregation implements AggregationStrategy<VendorEvaluationCriteriaType, BigDecimal> {
@Override
public BigDecimal aggregate(Collection<VendorEvaluationCriteriaType> propertyValues) {
BigDecimal sumValue = BigDecimal.ZERO;
if (CollectionUtils.isNotEmpty(propertyValues)) {
for (VendorEvaluationCriteriaType criteriaType : vendorEvaluationCriteriaTypesDs.getItems()) {
sumValue = getItem().getVendorEvaluationLine()
.stream()
.filter(e -> e.getVendorEvaluationCriteria().getVendorEvaluationCriteriaType().equals(criteriaType))
.map(VendorEvaluationLine::getScoreObtained)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
}
if(sumValue==null) {
sumValue = BigDecimal.ZERO;
return sumValue;
}
return sumValue;
}
@Override
public Class<BigDecimal> getResultClass() {
return BigDecimal.class;
}
}
Thanks for your help.