Search in sources :

Example 6 with ScriptCompilationException

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;
            }
        }
    }
}
Also used : ScriptCompilationException(org.springframework.scripting.ScriptCompilationException) INodeGroupExtensionPoint(org.jumpmind.symmetric.ext.INodeGroupExtensionPoint)

Example 7 with ScriptCompilationException

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));
    }
}
Also used : ScriptCompilationException(org.springframework.scripting.ScriptCompilationException) ScriptSource(org.springframework.scripting.ScriptSource) Test(org.junit.Test)

Aggregations

ScriptCompilationException (org.springframework.scripting.ScriptCompilationException)7 EvalError (bsh.EvalError)3 GroovyObject (groovy.lang.GroovyObject)2 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)2 Interpreter (bsh.Interpreter)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Map (java.util.Map)1 INodeGroupExtensionPoint (org.jumpmind.symmetric.ext.INodeGroupExtensionPoint)1 Test (org.junit.Test)1 ScriptSource (org.springframework.scripting.ScriptSource)1