DataSetLookupConstraints extends DataSetConstraints<DataSetLookupConstraints> { public ValidationError check(DataSetLookup lookup) { return check(lookup, null); }  boolean isUniqueColumnIds(); DataSetLookupConstraints setUniqueColumnIds(boolean uniqueColumnIds); boolean isFilterAllowed(); DataSetLookupConstraints setFilterAllowed(boolean filterAllowed); boolean isGroupAllowed(); DataSetLookupConstraints setGroupAllowed(boolean groupAllowed); boolean isGroupRequired(); DataSetLookupConstraints setGroupRequired(boolean groupRequired); int getMaxGroups(); DataSetLookupConstraints setMaxGroups(int maxGroups); String getGroupsTitle(); DataSetLookupConstraints setGroupsTitle(String groupsTitle); String getColumnsTitle(); DataSetLookupConstraints setColumnsTitle(String columnsTitle); DataSetLookupConstraints setColumnTitle(Integer index, String title); String getColumnTitle(Integer index); boolean isGroupColumn(); DataSetLookupConstraints setGroupColumn(boolean groupColumn); boolean isFunctionRequired(); DataSetLookupConstraints setFunctionRequired(boolean functionRequired); ValidationError check(DataSetLookup lookup); ValidationError check(DataSetLookup lookup, DataSetMetadata metadata); DataSetLookup newDataSetLookup(DataSetMetadata metatada); String buildUniqueColumnId(DataSetLookup lookup, String targetId); String buildUniqueColumnId(DataSetLookup lookup, GroupFunction column); static final int ERROR_GROUP_NUMBER; static final int ERROR_GROUP_NOT_ALLOWED; static final int ERROR_GROUP_REQUIRED; static final int ERROR_DUPLICATED_COLUMN_ID; }
@Test public void testValidationOk() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DATE).fixed(DateIntervalType.MONTH, true) .column(DATE) .column(AMOUNT, AggregateFunctionType.SUM) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNull(error); }
@Test public void testColumnExcess() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DATE).fixed(DateIntervalType.MONTH, true) .column(DATE) .column(AMOUNT, AggregateFunctionType.SUM) .column(AMOUNT, AggregateFunctionType.AVERAGE) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_NUMBER); }
@Test public void testColumnMissing() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DEPARTMENT) .column(AMOUNT, AggregateFunctionType.SUM) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_NUMBER); }
@Test public void testMissingGroup() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .column(DATE) .column(AMOUNT, AggregateFunctionType.SUM) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_GROUP_REQUIRED); }
@Test public void testWrongColumnType() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DEPARTMENT) .column(DEPARTMENT) .column(EMPLOYEE) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_TYPE); lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DATE) .column(DATE) .column(EMPLOYEE) .buildLookup(); error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_TYPE); }