AggregationService { public AggregationResult aggregate(AggregationParameters parameters, DataSet dataset) { if (parameters.getOperations().isEmpty() || parameters.getGroupBy().isEmpty()) { throw new TDPException(CommonErrorCodes.BAD_AGGREGATION_PARAMETERS); } AggregationResult result = new AggregationResult(parameters.getOperations().get(0).getOperator()); Aggregator aggregator = factory.get(parameters); final DataSetMetadata metadata = dataset.getMetadata(); final RowMetadata rowMetadata = metadata != null ? metadata.getRowMetadata() : new RowMetadata(); final Predicate<DataSetRow> filter = filterService.build(parameters.getFilter(), rowMetadata); dataset.getRecords().filter(filter).forEach(row -> aggregator.accept(row, result)); aggregator.normalize(result); return result; }  AggregationResult aggregate(AggregationParameters parameters, DataSet dataset);  }
@Test(expected = TDPException.class) public void shouldNotAggregateBecauseNoOperation() { service.aggregate(new AggregationParameters(), new DataSet()); }
@Test(expected = TDPException.class) public void shouldNotAggregateBecauseNoGroupBy() { final AggregationParameters params = new AggregationParameters(); params.addOperation(new AggregationOperation("0001", Operator.AVERAGE)); service.aggregate(params, new DataSet()); }