org.camunda.bpm.engine.impl.scripting.ExecutableScript Java Examples
The following examples show how to use
org.camunda.bpm.engine.impl.scripting.ExecutableScript.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptBreakPointCondition.java From camunda-bpm-workbench with GNU Affero General Public License v3.0 | 6 votes |
public boolean evaluate(ExecutionEntity executionEntity) { if (script == null) { return true; } Context.getProcessEngineConfiguration().getScriptFactory(); ExecutableScript executableScript = Context.getProcessEngineConfiguration() .getScriptFactory() .createScriptFromSource(scriptingLanguage, script); Object result = Context.getProcessEngineConfiguration() .getScriptingEnvironment() .execute(executableScript, executionEntity); if (result == null) { throw new DebuggerException("Breakpoint condition evaluates to null: " + script); } else if (!(result instanceof Boolean)) { throw new DebuggerException("Script does not return boolean value: " + script); } return (Boolean) result; }
Example #2
Source File: DebugSessionImpl.java From camunda-bpm-workbench with GNU Affero General Public License v3.0 | 6 votes |
public Script getScript(String processDefinitionId, String activityId) { ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) getProcessEngine().getRepositoryService().getProcessDefinition(processDefinitionId); ActivityImpl activity = processDefinition.findActivity(activityId); ActivityBehavior activityBehavior = activity.getActivityBehavior(); if (activityBehavior instanceof ScriptTaskActivityBehavior) { Script script = new Script(); ExecutableScript taskScript = ((ScriptTaskActivityBehavior) activityBehavior).getScript(); if (!(taskScript instanceof SourceExecutableScript)) { throw new DebuggerException("Encountered non-source script"); } SourceExecutableScript sourceScript = (SourceExecutableScript) taskScript; script.setScript(sourceScript.getScriptSource()); script.setScriptingLanguage(sourceScript.getLanguage()); return script; } else { throw new DebuggerException("Activity " + activityId + " is no script task"); } }
Example #3
Source File: CustomBpmnParse.java From wecube-platform with Apache License 2.0 | 6 votes |
protected Condition parseConditionExpression(Element conditionExprElement) { String expression = translateConditionExpressionElementText(conditionExprElement); 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; }
Example #4
Source File: EnvScriptCachingTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public void testDisabledPaEnvScriptCaching() { // given processEngineConfiguration.setEnableFetchScriptEngineFromProcessApplication(false); 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); assertNull(environmentScripts.get(SCRIPT_LANGUAGE)); repositoryService.deleteDeployment(deployment.getId(), true); processEngineConfiguration.setEnableFetchScriptEngineFromProcessApplication(true); }
Example #5
Source File: EnvScriptCachingTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
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); }
Example #6
Source File: BpmnParseUtil.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
/** * Parses a camunda script element. * * @param scriptElement the script element ot parse * @return the generated executable script * @throws BpmnParseException if the a attribute is missing or the script cannot be processed */ public static ExecutableScript parseCamundaScript(Element scriptElement) { String scriptLanguage = scriptElement.attribute("scriptFormat"); if (scriptLanguage == null || scriptLanguage.isEmpty()) { throw new BpmnParseException("Missing attribute 'scriptFormat' for 'script' element", scriptElement); } else { String scriptResource = scriptElement.attribute("resource"); String scriptSource = scriptElement.getText(); try { return ScriptUtil.getScript(scriptLanguage, scriptSource, scriptResource, getExpressionManager()); } catch (ProcessEngineException e) { throw new BpmnParseException("Unable to process script", scriptElement, e); } } }
Example #7
Source File: ItemHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected ExecutableScript initializeScript(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaScript script) { String language = script.getCamundaScriptFormat(); String resource = script.getCamundaResource(); String source = script.getTextContent(); if (language == null) { language = ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE; } try { return ScriptUtil.getScript(language, source, resource, context.getExpressionManager()); } catch (ProcessEngineException e) { // ignore return null; } }
Example #8
Source File: ScriptCompilationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected Object executeScript(final ExecutableScript script) { final ScriptingEnvironment scriptingEnvironment = processEngineConfiguration.getScriptingEnvironment(); return processEngineConfiguration.getCommandExecutorTxRequired() .execute(new Command<Object>() { public Object execute(CommandContext commandContext) { return scriptingEnvironment.execute(script, null); } }); }
Example #9
Source File: ScriptExecutionListenerSpec.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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()); }
Example #10
Source File: ScriptUtil.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * Creates a new {@link ExecutableScript} from a resource. It excepts static and dynamic resources. * Dynamic means that the resource is an expression which will be evaluated during execution. * * @param language the language of the script * @param resource the resource path of the script code or an expression which evaluates to the resource path * @param expressionManager the expression manager to use to generate the expressions of dynamic scripts * @param scriptFactory the script factory used to create the script * @return the newly created script * @throws NotValidException if language or resource are null or empty */ public static ExecutableScript getScriptFromResource(String language, String resource, ExpressionManager expressionManager, ScriptFactory scriptFactory) { ensureNotEmpty(NotValidException.class, "Script language", language); ensureNotEmpty(NotValidException.class, "Script resource", resource); if (isDynamicScriptExpression(language, resource)) { Expression resourceExpression = expressionManager.createExpression(resource); return getScriptFromResourceExpression(language, resourceExpression, scriptFactory); } else { return getScriptFromResource(language, resource, scriptFactory); } }
Example #11
Source File: ScriptUtil.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * Creates a new {@link ExecutableScript} from a source. It excepts static and dynamic sources. * Dynamic means that the source is an expression which will be evaluated during execution. * * @param language the language of the script * @param source the source code of the script or an expression which evaluates to the source code * @param expressionManager the expression manager to use to generate the expressions of dynamic scripts * @param scriptFactory the script factory used to create the script * @return the newly created script * @throws NotValidException if language is null or empty or source is null */ public static ExecutableScript getScriptFormSource(String language, String source, ExpressionManager expressionManager, ScriptFactory scriptFactory) { ensureNotEmpty(NotValidException.class, "Script language", language); ensureNotNull(NotValidException.class, "Script source", source); if (isDynamicScriptExpression(language, source)) { Expression sourceExpression = expressionManager.createExpression(source); return getScriptFromSourceExpression(language, sourceExpression, scriptFactory); } else { return getScriptFromSource(language, source, scriptFactory); } }
Example #12
Source File: ItemHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected CaseVariableListener initializeVariableListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaVariableListener listener) { Collection<CamundaField> fields = listener.getCamundaFields(); List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields); ExpressionManager expressionManager = context.getExpressionManager(); String className = listener.getCamundaClass(); String expression = listener.getCamundaExpression(); String delegateExpression = listener.getCamundaDelegateExpression(); CamundaScript scriptElement = listener.getCamundaScript(); CaseVariableListener variableListener = null; if (className != null) { variableListener = new ClassDelegateCaseVariableListener(className, fieldDeclarations); } else if (expression != null) { Expression expressionExp = expressionManager.createExpression(expression); variableListener = new ExpressionCaseVariableListener(expressionExp); } else if (delegateExpression != null) { Expression delegateExp = expressionManager.createExpression(delegateExpression); variableListener = new DelegateExpressionCaseVariableListener(delegateExp, fieldDeclarations); } else if (scriptElement != null) { ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement); if (executableScript != null) { variableListener = new ScriptCaseVariableListener(executableScript); } } return variableListener; }
Example #13
Source File: ItemHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected CaseExecutionListener initializeCaseExecutionListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaCaseExecutionListener listener) { Collection<CamundaField> fields = listener.getCamundaFields(); List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields); ExpressionManager expressionManager = context.getExpressionManager(); CaseExecutionListener caseExecutionListener = null; String className = listener.getCamundaClass(); String expression = listener.getCamundaExpression(); String delegateExpression = listener.getCamundaDelegateExpression(); CamundaScript scriptElement = listener.getCamundaScript(); if (className != null) { caseExecutionListener = new ClassDelegateCaseExecutionListener(className, fieldDeclarations); } else if (expression != null) { Expression expressionExp = expressionManager.createExpression(expression); caseExecutionListener = new ExpressionCaseExecutionListener(expressionExp); } else if (delegateExpression != null) { Expression delegateExp = expressionManager.createExpression(delegateExpression); caseExecutionListener = new DelegateExpressionCaseExecutionListener(delegateExp, fieldDeclarations); } else if (scriptElement != null) { ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement); if (executableScript != null) { caseExecutionListener = new ScriptCaseExecutionListener(executableScript); } } return caseExecutionListener; }
Example #14
Source File: HumanTaskItemHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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; }
Example #15
Source File: DebugScriptEvaluation.java From camunda-bpm-workbench with GNU Affero General Public License v3.0 | 5 votes |
public void execute(DebugSessionImpl debugSession, SuspendedExecutionImpl suspendedExecution) { LOGG.info("[DEBUGGER] suspended " + suspendedExecution.getSuspendedThread().getName() + " on breakpoint evaluates script."); try { ExecutableScript executableScript = Context.getProcessEngineConfiguration() .getScriptFactory() .createScriptFromSource(language, script); Object result = Context.getProcessEngineConfiguration() .getScriptingEnvironment() .execute(executableScript, suspendedExecution.executionEntity); this.result = result; debugSession.fireScriptEvaluated(this); // fire execution update debugSession.fireExecutionUpdated(suspendedExecution); } catch(ProcessEngineException e) { LOGG.log(Level.WARNING, "[DEBUGGER] exception while evaluating script in Thread " + suspendedExecution.getSuspendedThread().getName() + " at breakpoint " + suspendedExecution.getBreakPoint() + ".", e); this.setException((Exception) e.getCause()); debugSession.fireScriptEvaluationFailed(this); } }
Example #16
Source File: ScriptingEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * Initializes the env scripts for a given language. * * @param language the language * @return the list of env scripts. Never null. */ protected List<ExecutableScript> initEnvForLanguage(String language) { List<ExecutableScript> scripts = new ArrayList<ExecutableScript>(); for (ScriptEnvResolver resolver : envResolvers) { String[] resolvedScripts = resolver.resolve(language); if(resolvedScripts != null) { for (String resolvedScript : resolvedScripts) { scripts.add(scriptFactory.createScriptFromSource(language, resolvedScript)); } } } return scripts; }
Example #17
Source File: ScriptingEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * Returns the env scripts for the given language. Performs lazy initialization of the env scripts. * * @param scriptLanguage the language * @return a list of executable environment scripts. Never null. */ protected List<ExecutableScript> getEnvScripts(String scriptLanguage) { Map<String, List<ExecutableScript>> environment = getEnv(scriptLanguage); List<ExecutableScript> envScripts = environment.get(scriptLanguage); if(envScripts == null) { synchronized (this) { envScripts = environment.get(scriptLanguage); if(envScripts == null) { envScripts = initEnvForLanguage(scriptLanguage); environment.put(scriptLanguage, envScripts); } } } return envScripts; }
Example #18
Source File: ScriptingEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected Map<String, List<ExecutableScript>> getPaEnvScripts(ProcessApplicationReference pa) { try { ProcessApplicationInterface processApplication = pa.getProcessApplication(); ProcessApplicationInterface rawObject = processApplication.getRawObject(); if (rawObject instanceof AbstractProcessApplication) { AbstractProcessApplication abstractProcessApplication = (AbstractProcessApplication) rawObject; return abstractProcessApplication.getEnvironmentScripts(); } return null; } catch (ProcessApplicationUnavailableException e) { throw new ProcessEngineException("Process Application is unavailable.", e); } }
Example #19
Source File: ScriptingEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected Map<String, List<ExecutableScript>> getEnv(String language) { ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration(); ProcessApplicationReference processApplication = Context.getCurrentProcessApplication(); Map<String, List<ExecutableScript>> result = null; if (config.isEnableFetchScriptEngineFromProcessApplication()) { if(processApplication != null) { result = getPaEnvScripts(processApplication); } } return result != null ? result : env; }
Example #20
Source File: ScriptingEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * execute a given script in the environment * * @param script the {@link ExecutableScript} to execute * @param scope the scope in which to execute the script * @return the result of the script evaluation */ public Object execute(ExecutableScript script, VariableScope scope) { // get script engine ScriptEngine scriptEngine = scriptingEngines.getScriptEngineForLanguage(script.getLanguage()); // create bindings Bindings bindings = scriptingEngines.createBindings(scriptEngine, scope); return execute(script, scope, bindings, scriptEngine); }
Example #21
Source File: ScriptingEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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); }
Example #22
Source File: BpmnParseUtil.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
/** * @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(); } }
Example #23
Source File: ScriptCaseExecutionListener.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public ExecutableScript getScript() { return script; }
Example #24
Source File: ScriptCaseVariableListener.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public ExecutableScript getScript() { return script; }
Example #25
Source File: ScriptExecutionListener.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public ScriptExecutionListener(ExecutableScript script) { this.script = script; }
Example #26
Source File: ScriptExecutionListener.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public ExecutableScript getScript() { return script; }
Example #27
Source File: ScriptTaskActivityBehavior.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public ScriptTaskActivityBehavior(ExecutableScript script, String resultVariable) { this.script = script; this.resultVariable = resultVariable; }
Example #28
Source File: ScriptTaskActivityBehavior.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public ExecutableScript getScript() { return script; }
Example #29
Source File: ScriptCaseVariableListener.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public ScriptCaseVariableListener(ExecutableScript script) { this.script = script; }
Example #30
Source File: ProcessApplicationScriptEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
/** * Returns a map of cached environment scripts per script language. */ public Map<String, List<ExecutableScript>> getEnvironmentScripts() { return environmentScripts; }