MergingDataSetEvaluator implements DataSetEvaluator { @Override public MapDataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext context) throws EvaluationException { MergingDataSetDefinition dsd = (MergingDataSetDefinition) dataSetDefinition; List<MapDataSet> dataSets = new ArrayList<MapDataSet>(); DataSetDefinitionService dss = Context.getService(DataSetDefinitionService.class); for (DataSetDefinition childDsd : dsd.getDataSetDefinitions()) { DataSet dataSet = dss.evaluate(childDsd, context); if (dataSet instanceof MapDataSet) { dataSets.add((MapDataSet) dataSet); } else { throw new EvaluationException("Can only merge single dimension data sets"); } } return mergeDataSets(dataSets, dsd, context); }  @Override MapDataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext context);  }
@Test public void evaluate_shouldOrderColumnsAccordingToMergeOrder() throws EvaluationException { MergingDataSetDefinition mergedDsd = new MergingDataSetDefinition(); mergedDsd.addDataSetDefinition(cohortDsd1); mergedDsd.addDataSetDefinition(cohortDsd2); MapDataSet dataSet = evaluator.evaluate(mergedDsd, evaluationContext); checkIndicatorDataSet(Arrays.asList("test-1", "test-3", "test-2"), Arrays.asList(2, 1, 2), dataSet); mergedDsd.setMergeOrder(MergingDataSetDefinition.MergeOrder.NAME); dataSet = evaluator.evaluate(mergedDsd, evaluationContext); checkIndicatorDataSet(Arrays.asList("test-1", "test-2", "test-3"), Arrays.asList(2, 2, 1), dataSet); mergedDsd.setMergeOrder(MergingDataSetDefinition.MergeOrder.LABEL); dataSet = evaluator.evaluate(mergedDsd, evaluationContext); checkIndicatorDataSet(Arrays.asList("test-2", "test-1", "test-3"), Arrays.asList(2, 2, 1), dataSet); }