Search in sources :

Example 6 with ExecutableScript

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

the class EnvScriptCachingTest method testEnabledPaEnvScriptCaching.

public void testEnabledPaEnvScriptCaching() {
    // given
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication();
    ProcessApplicationDeployment deployment = repositoryService.createDeployment(processApplication.getReference()).addClasspathResource(PROCESS_PATH).deploy();
    // when
    executeScript(processApplication);
    // then
    Map<String, List<ExecutableScript>> environmentScripts = processApplication.getEnvironmentScripts();
    assertNotNull(environmentScripts);
    List<ExecutableScript> groovyEnvScripts = environmentScripts.get(SCRIPT_LANGUAGE);
    assertNotNull(groovyEnvScripts);
    assertFalse(groovyEnvScripts.isEmpty());
    assertEquals(processEngineConfiguration.getEnvScriptResolvers().size(), groovyEnvScripts.size());
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : ProcessApplicationDeployment(org.camunda.bpm.engine.repository.ProcessApplicationDeployment) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) SourceExecutableScript(org.camunda.bpm.engine.impl.scripting.SourceExecutableScript) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) List(java.util.List)

Example 7 with ExecutableScript

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

the class BpmnParse method parseExecutionListener.

/**
 * Parses an {@link ExecutionListener} implementation for the given
 * executionListener element.
 *
 * @param executionListenerElement
 *          the XML element containing the executionListener definition.
 */
public ExecutionListener parseExecutionListener(Element executionListenerElement) {
    ExecutionListener executionListener = null;
    String className = executionListenerElement.attribute(PROPERTYNAME_CLASS);
    String expression = executionListenerElement.attribute(PROPERTYNAME_EXPRESSION);
    String delegateExpression = executionListenerElement.attribute(PROPERTYNAME_DELEGATE_EXPRESSION);
    Element scriptElement = executionListenerElement.elementNS(CAMUNDA_BPMN_EXTENSIONS_NS, "script");
    if (className != null) {
        executionListener = new ClassDelegateExecutionListener(className, parseFieldDeclarations(executionListenerElement));
    } else if (expression != null) {
        executionListener = new ExpressionExecutionListener(expressionManager.createExpression(expression));
    } else if (delegateExpression != null) {
        executionListener = new DelegateExpressionExecutionListener(expressionManager.createExpression(delegateExpression), parseFieldDeclarations(executionListenerElement));
    } else if (scriptElement != null) {
        try {
            ExecutableScript executableScript = parseCamundaScript(scriptElement);
            if (executableScript != null) {
                executionListener = new ScriptExecutionListener(executableScript);
            }
        } catch (BpmnParseException e) {
            addError(e);
        }
    } else {
        addError("Element 'class', 'expression', 'delegateExpression' or 'script' is mandatory on executionListener", executionListenerElement);
    }
    return executionListener;
}
Also used : ScriptExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ScriptExecutionListener) BpmnParseException(org.camunda.bpm.engine.BpmnParseException) Element(org.camunda.bpm.engine.impl.util.xml.Element) ClassDelegateExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ClassDelegateExecutionListener) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) DelegateExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.DelegateExpressionExecutionListener) ExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ExpressionExecutionListener) DelegateExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.DelegateExpressionExecutionListener) ClassDelegateExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ClassDelegateExecutionListener) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) ScriptExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ScriptExecutionListener) ExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ExpressionExecutionListener) DelegateExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.DelegateExpressionExecutionListener)

Example 8 with ExecutableScript

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

the class BpmnParse method parseTaskListener.

protected TaskListener parseTaskListener(Element taskListenerElement) {
    TaskListener taskListener = null;
    String className = taskListenerElement.attribute(PROPERTYNAME_CLASS);
    String expression = taskListenerElement.attribute(PROPERTYNAME_EXPRESSION);
    String delegateExpression = taskListenerElement.attribute(PROPERTYNAME_DELEGATE_EXPRESSION);
    Element scriptElement = taskListenerElement.elementNS(CAMUNDA_BPMN_EXTENSIONS_NS, "script");
    if (className != null) {
        taskListener = new ClassDelegateTaskListener(className, parseFieldDeclarations(taskListenerElement));
    } else if (expression != null) {
        taskListener = new ExpressionTaskListener(expressionManager.createExpression(expression));
    } else if (delegateExpression != null) {
        taskListener = new DelegateExpressionTaskListener(expressionManager.createExpression(delegateExpression), parseFieldDeclarations(taskListenerElement));
    } else if (scriptElement != null) {
        try {
            ExecutableScript executableScript = parseCamundaScript(scriptElement);
            if (executableScript != null) {
                taskListener = new ScriptTaskListener(executableScript);
            }
        } catch (BpmnParseException e) {
            addError(e);
        }
    } else {
        addError("Element 'class', 'expression', 'delegateExpression' or 'script' is mandatory on taskListener", taskListenerElement);
    }
    return taskListener;
}
Also used : DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) BpmnParseException(org.camunda.bpm.engine.BpmnParseException) Element(org.camunda.bpm.engine.impl.util.xml.Element) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) 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) 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)

Example 9 with ExecutableScript

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

the class BpmnParse method parseScriptTaskElement.

/**
 * Returns a {@link ScriptTaskActivityBehavior} for the script task element
 * corresponding to the script source or resource specified.
 *
 * @param scriptTaskElement
 *          the script task element
 * @return the corresponding {@link ScriptTaskActivityBehavior}
 */
protected ScriptTaskActivityBehavior parseScriptTaskElement(Element scriptTaskElement) {
    // determine script language
    String language = scriptTaskElement.attribute("scriptFormat");
    if (language == null) {
        language = ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE;
    }
    String resultVariableName = parseResultVariable(scriptTaskElement);
    // determine script source
    String scriptSource = null;
    Element scriptElement = scriptTaskElement.element("script");
    if (scriptElement != null) {
        scriptSource = scriptElement.getText();
    }
    String scriptResource = scriptTaskElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, PROPERTYNAME_RESOURCE);
    try {
        ExecutableScript script = ScriptUtil.getScript(language, scriptSource, scriptResource, expressionManager);
        return new ScriptTaskActivityBehavior(script, resultVariableName);
    } catch (ProcessEngineException e) {
        addError("Unable to process ScriptTask: " + e.getMessage(), scriptElement);
        return null;
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 10 with ExecutableScript

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

the class BpmnParse method parseConditionExpression.

protected Condition parseConditionExpression(Element conditionExprElement) {
    String expression = conditionExprElement.getText().trim();
    String type = conditionExprElement.attributeNS(XSI_NS, TYPE);
    String language = conditionExprElement.attribute(PROPERTYNAME_LANGUAGE);
    String resource = conditionExprElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, PROPERTYNAME_RESOURCE);
    if (type != null) {
        String value = type.contains(":") ? resolveName(type) : BpmnParser.BPMN20_NS + ":" + type;
        if (!value.equals(ATTRIBUTEVALUE_T_FORMAL_EXPRESSION)) {
            addError("Invalid type, only tFormalExpression is currently supported", conditionExprElement);
        }
    }
    Condition condition = null;
    if (language == null) {
        condition = new UelExpressionCondition(expressionManager.createExpression(expression));
    } else {
        try {
            ExecutableScript script = ScriptUtil.getScript(language, expression, resource, expressionManager);
            condition = new ScriptCondition(script);
        } catch (ProcessEngineException e) {
            addError("Unable to process condition expression:" + e.getMessage(), conditionExprElement);
        }
    }
    return condition;
}
Also used : ScriptCondition(org.camunda.bpm.engine.impl.scripting.ScriptCondition) Condition(org.camunda.bpm.engine.impl.Condition) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ScriptCondition(org.camunda.bpm.engine.impl.scripting.ScriptCondition)

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