Search in sources :

Example 1 with ExecutableScript

use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.

the class HumanTaskItemHandler method initializeTaskListener.

protected TaskListener initializeTaskListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaTaskListener listener) {
    Collection<CamundaField> fields = listener.getCamundaFields();
    List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields);
    ExpressionManager expressionManager = context.getExpressionManager();
    TaskListener taskListener = null;
    String className = listener.getCamundaClass();
    String expression = listener.getCamundaExpression();
    String delegateExpression = listener.getCamundaDelegateExpression();
    CamundaScript scriptElement = listener.getCamundaScript();
    if (className != null) {
        taskListener = new ClassDelegateTaskListener(className, fieldDeclarations);
    } else if (expression != null) {
        Expression expressionExp = expressionManager.createExpression(expression);
        taskListener = new ExpressionTaskListener(expressionExp);
    } else if (delegateExpression != null) {
        Expression delegateExp = expressionManager.createExpression(delegateExpression);
        taskListener = new DelegateExpressionTaskListener(delegateExp, fieldDeclarations);
    } else if (scriptElement != null) {
        ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement);
        if (executableScript != null) {
            taskListener = new ScriptTaskListener(executableScript);
        }
    }
    return taskListener;
}
Also used : CamundaField(org.camunda.bpm.model.cmmn.instance.camunda.CamundaField) ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) FieldDeclaration(org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration) Expression(org.camunda.bpm.engine.delegate.Expression) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) CamundaScript(org.camunda.bpm.model.cmmn.instance.camunda.CamundaScript)

Example 2 with ExecutableScript

use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.

the class JuelFormEngine method executeScript.

protected Object executeScript(String scriptSrc, VariableScope scope) {
    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    ScriptFactory scriptFactory = processEngineConfiguration.getScriptFactory();
    ExecutableScript script = scriptFactory.createScriptFromSource(ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE, scriptSrc);
    ScriptInvocation invocation = new ScriptInvocation(script, scope);
    try {
        processEngineConfiguration.getDelegateInterceptor().handleInvocation(invocation);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new ProcessEngineException(e);
    }
    return invocation.getInvocationResult();
}
Also used : ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) ScriptFactory(org.camunda.bpm.engine.impl.scripting.ScriptFactory) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ScriptInvocation(org.camunda.bpm.engine.impl.delegate.ScriptInvocation)

Example 3 with ExecutableScript

use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.

the class ScriptingEnvironment method execute.

public Object execute(ExecutableScript script, VariableScope scope, Bindings bindings, ScriptEngine scriptEngine) {
    final String scriptLanguage = script.getLanguage();
    // first, evaluate the env scripts (if any)
    List<ExecutableScript> envScripts = getEnvScripts(scriptLanguage);
    for (ExecutableScript envScript : envScripts) {
        envScript.execute(scriptEngine, scope, bindings);
    }
    // next evaluate the actual script
    return script.execute(scriptEngine, scope, bindings);
}
Also used : ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript)

Example 4 with ExecutableScript

use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.

the class BpmnParseUtil method parseParamValueProvider.

/**
 * @throws BpmnParseException if the parameter is invalid
 */
protected static ParameterValueProvider parseParamValueProvider(Element parameterElement) {
    // LIST
    if ("list".equals(parameterElement.getTagName())) {
        List<ParameterValueProvider> providerList = new ArrayList<ParameterValueProvider>();
        for (Element element : parameterElement.elements()) {
            // parse nested provider
            providerList.add(parseParamValueProvider(element));
        }
        return new ListValueProvider(providerList);
    }
    // MAP
    if ("map".equals(parameterElement.getTagName())) {
        TreeMap<ParameterValueProvider, ParameterValueProvider> providerMap = new TreeMap<ParameterValueProvider, ParameterValueProvider>();
        for (Element entryElement : parameterElement.elements("entry")) {
            // entry must provide key
            String keyAttribute = entryElement.attribute("key");
            if (keyAttribute == null || keyAttribute.isEmpty()) {
                throw new BpmnParseException("Missing attribute 'key' for 'entry' element", entryElement);
            }
            // parse nested provider
            providerMap.put(new ElValueProvider(getExpressionManager().createExpression(keyAttribute)), parseNestedParamValueProvider(entryElement));
        }
        return new MapValueProvider(providerMap);
    }
    // SCRIPT
    if ("script".equals(parameterElement.getTagName())) {
        ExecutableScript executableScript = parseCamundaScript(parameterElement);
        if (executableScript != null) {
            return new ScriptValueProvider(executableScript);
        } else {
            return new NullValueProvider();
        }
    }
    String textContent = parameterElement.getText().trim();
    if (!textContent.isEmpty()) {
        // EL
        return new ElValueProvider(getExpressionManager().createExpression(textContent));
    } else {
        // NULL value
        return new NullValueProvider();
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element) ArrayList(java.util.ArrayList) ElValueProvider(org.camunda.bpm.engine.impl.el.ElValueProvider) ScriptValueProvider(org.camunda.bpm.engine.impl.scripting.ScriptValueProvider) TreeMap(java.util.TreeMap) MapValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.MapValueProvider) BpmnParseException(org.camunda.bpm.engine.BpmnParseException) ParameterValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider) ListValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.ListValueProvider) NullValueProvider(org.camunda.bpm.engine.impl.core.variable.mapping.value.NullValueProvider) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript)

Example 5 with ExecutableScript

use of org.camunda.bpm.engine.impl.scripting.ExecutableScript in project camunda-bpm-platform by camunda.

the class ScriptExecutionListenerSpec method verifyListener.

public void verifyListener(DelegateListener<? extends BaseDelegateExecution> listener) {
    assertTrue(listener instanceof ScriptCaseExecutionListener);
    ScriptCaseExecutionListener scriptListener = (ScriptCaseExecutionListener) listener;
    ExecutableScript executableScript = scriptListener.getScript();
    assertNotNull(executableScript);
    assertEquals(SCRIPT_FORMAT, executableScript.getLanguage());
}
Also used : ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ScriptCaseExecutionListener(org.camunda.bpm.engine.impl.cmmn.listener.ScriptCaseExecutionListener)

Aggregations

ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)12 Element (org.camunda.bpm.engine.impl.util.xml.Element)4 BpmnParseException (org.camunda.bpm.engine.BpmnParseException)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)3 Expression (org.camunda.bpm.engine.delegate.Expression)3 FieldDeclaration (org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration)3 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)3 CamundaField (org.camunda.bpm.model.cmmn.instance.camunda.CamundaField)3 CamundaScript (org.camunda.bpm.model.cmmn.instance.camunda.CamundaScript)3 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)2 ScriptCaseExecutionListener (org.camunda.bpm.engine.impl.cmmn.listener.ScriptCaseExecutionListener)2 ClassDelegateTaskListener (org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener)2 DelegateExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)2 ExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener)2 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)2 CamundaExpression (org.camunda.bpm.model.cmmn.instance.camunda.CamundaExpression)2 CamundaString (org.camunda.bpm.model.cmmn.instance.camunda.CamundaString)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1