use of org.springframework.scripting.ScriptCompilationException in project symmetric-ds by JumpMind.
the class ColumnDataFilters method filterColumnValues.
protected void filterColumnValues(Context context, Table table, CsvData data) {
if (enabled && filters != null) {
for (TableColumnValueFilter filteredColumn : filters) {
try {
if (filteredColumn.isEnabled() && ((ignoreCase && filteredColumn.getTableName().equalsIgnoreCase(table.getName())) || (!ignoreCase && filteredColumn.getTableName().equals(table.getName())))) {
String columnName = filteredColumn.getColumnName();
int index = table.getColumnIndex(columnName);
if (index < 0 && ignoreCase) {
columnName = columnName.toUpperCase();
index = table.getColumnIndex(columnName);
if (index < 0) {
columnName = columnName.toLowerCase();
index = table.getColumnIndex(columnName);
}
}
if (index >= 0) {
try {
String[] columnValues = data.getParsedData(CsvData.ROW_DATA);
if (columnValues != null && columnValues.length > index) {
columnValues[index] = filteredColumn.getFilter().filter(filteredColumn.getTableName(), filteredColumn.getColumnName(), columnValues[index], context);
}
} catch (RuntimeException ex) {
// Try to log script errors so they are more
// readable
Throwable causedBy = ex;
do {
causedBy = ExceptionUtils.getCause(causedBy);
if (causedBy instanceof ScriptCompilationException) {
log.error("{}", causedBy.getMessage());
throw new RuntimeException(causedBy.getMessage());
}
} while (causedBy != null);
throw ex;
}
}
}
} catch (RuntimeException ex) {
log.error("Failed to transform value for column {} on table {}", filteredColumn.getColumnName(), filteredColumn.getTableName());
throw ex;
}
}
}
}
use of org.springframework.scripting.ScriptCompilationException in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testScriptedClassThatDoesNotHaveANoArgCtor.
@Test
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
ScriptSource script = mock(ScriptSource.class);
String badScript = "class Foo { public Foo(String foo) {}}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript);
try {
factory.getScriptedObject(script);
fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class).");
} catch (ScriptCompilationException expected) {
assertTrue(expected.contains(NoSuchMethodException.class));
}
}
Aggregations