Skip to content
Snippets Groups Projects
Commit 5b920f3e authored by tpylak's avatar tpylak
Browse files

LMS-1204 Calculated Columns: better exception message when column expression is wrong

SVN: 12963
parent 825b36b3
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,7 @@ public class GridExpressionUtils ...@@ -58,7 +58,7 @@ public class GridExpressionUtils
EVALUATION_SERIOUS_ERROR_MSG + "applying the filter: "; EVALUATION_SERIOUS_ERROR_MSG + "applying the filter: ";
private static final String COLUMN_EVALUATION_SERIOUS_ERROR_TEMPLATE = private static final String COLUMN_EVALUATION_SERIOUS_ERROR_TEMPLATE =
"Error: calculating the value of a custom column '%s' failed, conntact you administrator: "; "Error: calculating the value of a custom column '%s' failed, contact your administrator: ";
private static final String COLUMN_EVALUATION_ERROR_TEMPLATE = private static final String COLUMN_EVALUATION_ERROR_TEMPLATE =
COLUMN_EVALUATION_SERIOUS_ERROR_TEMPLATE + "invalid column definition. "; COLUMN_EVALUATION_SERIOUS_ERROR_TEMPLATE + "invalid column definition. ";
...@@ -115,8 +115,7 @@ public class GridExpressionUtils ...@@ -115,8 +115,7 @@ public class GridExpressionUtils
Map<String, RowCalculator<T>> calculators = new HashMap<String, RowCalculator<T>>(); Map<String, RowCalculator<T>> calculators = new HashMap<String, RowCalculator<T>>();
for (GridCustomColumn customColumn : customColumns) for (GridCustomColumn customColumn : customColumns)
{ {
String expression = StringEscapeUtils.unescapeHtml(customColumn.getExpression()); RowCalculator<T> rowCalculator = createRowCalculator(availableColumns, customColumn);
RowCalculator<T> rowCalculator = new RowCalculator<T>(availableColumns, expression);
calculators.put(customColumn.getCode(), rowCalculator); calculators.put(customColumn.getCode(), rowCalculator);
} }
for (T rowData : allRows) for (T rowData : allRows)
...@@ -135,6 +134,19 @@ public class GridExpressionUtils ...@@ -135,6 +134,19 @@ public class GridExpressionUtils
return result; return result;
} }
private static <T> RowCalculator<T> createRowCalculator(
Set<IColumnDefinition<T>> availableColumns, GridCustomColumn customColumn)
{
String expression = StringEscapeUtils.unescapeHtml(customColumn.getExpression());
try
{
return new RowCalculator<T>(availableColumns, expression);
} catch (Exception ex)
{
throw new UserFailureException(createCustomColumnErrorMessage(customColumn, ex));
}
}
private static List<GridCustomColumnInfo> extractColumnInfos( private static List<GridCustomColumnInfo> extractColumnInfos(
List<GridCustomColumn> customColumns) List<GridCustomColumn> customColumns)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment