Allow inline scripts in SCRIPT transformation (#3249)
Signed-off-by: Jan N. Klug <github@klug.nrw>pull/3450/head
parent
a5d65ce2ad
commit
95e04fccbd
|
@ -96,13 +96,20 @@ public class ScriptTransformationService implements TransformationService, Regis
|
|||
scriptRecord.lock.lock();
|
||||
try {
|
||||
if (scriptRecord.script.isBlank()) {
|
||||
Transformation transformation = transformationRegistry.get(scriptUid);
|
||||
if (transformation != null) {
|
||||
if (!SUPPORTED_CONFIGURATION_TYPE.equals(transformation.getType())) {
|
||||
throw new TransformationException("Configuration does not have correct type 'script' but '"
|
||||
+ transformation.getType() + "'.");
|
||||
if (scriptUid.startsWith("|")) {
|
||||
// inline script -> strip inline-identifier
|
||||
scriptRecord.script = scriptUid.substring(1);
|
||||
} else {
|
||||
// get script from transformation registry
|
||||
Transformation transformation = transformationRegistry.get(scriptUid);
|
||||
if (transformation != null) {
|
||||
if (!SUPPORTED_CONFIGURATION_TYPE.equals(transformation.getType())) {
|
||||
throw new TransformationException("Configuration does not have correct type 'script' but '"
|
||||
+ transformation.getType() + "'.");
|
||||
}
|
||||
scriptRecord.script = transformation.getConfiguration().getOrDefault(Transformation.FUNCTION,
|
||||
"");
|
||||
}
|
||||
scriptRecord.script = transformation.getConfiguration().getOrDefault(Transformation.FUNCTION, "");
|
||||
}
|
||||
if (scriptRecord.script.isBlank()) {
|
||||
throw new TransformationException("Could not get script for UID '" + scriptUid + "'.");
|
||||
|
|
|
@ -51,6 +51,8 @@ public class ScriptTransformationServiceTest {
|
|||
private static final String SCRIPT_UID = "scriptUid";
|
||||
private static final String INVALID_SCRIPT_UID = "invalidScriptUid";
|
||||
|
||||
private static final String INLINE_SCRIPT = "|inlineScript";
|
||||
|
||||
private static final String SCRIPT = "script";
|
||||
private static final String SCRIPT_OUTPUT = "output";
|
||||
|
||||
|
@ -176,4 +178,11 @@ public class ScriptTransformationServiceTest {
|
|||
|
||||
assertThat(e.getMessage(), is("Configuration does not have correct type 'script' but 'invalid'."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineScriptProperlyProcessed() throws TransformationException, ScriptException {
|
||||
service.transform(SCRIPT_LANGUAGE + ":" + INLINE_SCRIPT, "input");
|
||||
|
||||
verify(scriptEngine).eval(INLINE_SCRIPT.substring(1));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue