org.camunda.bpm.engine.variable.context.VariableContext Java Examples
The following examples show how to use
org.camunda.bpm.engine.variable.context.VariableContext.
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: FeelIntegrationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @DecisionResource(resource = DMN) public void testFeelInputExpression() { DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) getDmnEngineConfiguration(); configuration.setDefaultInputExpressionExpressionLanguage(DefaultDmnEngineConfiguration.FEEL_EXPRESSION_LANGUAGE); DmnEngine engine = configuration.buildEngine(); try { engine.evaluateDecision(decision, Variables.createVariables().putValue("score", 3)); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (UnsupportedOperationException e) { assertThat(e).hasMessageStartingWith("FEEL-01016"); verify(feelEngineSpy).evaluateSimpleExpression(anyString(), any(VariableContext.class)); } }
Example #2
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected Object evaluateInputEntry(DmnDecisionTableInputImpl input, DmnExpressionImpl condition, VariableContext variableContext) { if (isNonEmptyExpression(condition)) { String expressionLanguage = condition.getExpressionLanguage(); if (expressionLanguage == null) { expressionLanguage = inputEntryExpressionLanguage; } if (expressionEvaluationHandler.isFeelExpressionLanguage(expressionLanguage)) { return evaluateFeelSimpleUnaryTests(input, condition, variableContext); } else { return expressionEvaluationHandler.evaluateExpression(expressionLanguage, condition, variableContext); } } else { return true; // input entries without expressions are true } }
Example #3
Source File: ExpressionEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public Object evaluateExpression(String expressionLanguage, DmnExpressionImpl expression, VariableContext variableContext) { String expressionText = getExpressionTextForLanguage(expression, expressionLanguage); if (expressionText != null) { if (isFeelExpressionLanguage(expressionLanguage)) { return evaluateFeelSimpleExpression(expressionText, variableContext); } else if (isElExpression(expressionLanguage)) { return evaluateElExpression(expressionLanguage, expressionText, variableContext, expression); } else { return evaluateScriptExpression(expressionLanguage, variableContext, expressionText, expression); } } else { return null; } }
Example #4
Source File: ExpressionEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected Object evaluateElExpression(String expressionLanguage, String expressionText, VariableContext variableContext, CachedExpressionSupport cachedExpressionSupport) { try { ElExpression elExpression = cachedExpressionSupport.getCachedExpression(); if (elExpression == null) { synchronized (cachedExpressionSupport) { elExpression = cachedExpressionSupport.getCachedExpression(); if(elExpression == null) { elExpression = elProvider.createExpression(expressionText); cachedExpressionSupport.setCachedExpression(elExpression); } } } return elExpression.getValue(variableContext); } // yes, we catch all exceptions catch(Exception e) { throw LOG.unableToEvaluateExpression(expressionText, expressionLanguage, e); } }
Example #5
Source File: DecisionTableEvaluationHandler.java From camunda-engine-dmn with Apache License 2.0 | 6 votes |
@Override public DmnDecisionLogicEvaluationEvent evaluate(DmnDecision decision, VariableContext variableContext) { DmnDecisionTableEvaluationEventImpl evaluationResult = new DmnDecisionTableEvaluationEventImpl(); evaluationResult.setDecisionTable(decision); DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decision.getDecisionLogic(); evaluationResult.setExecutedDecisionElements(calculateExecutedDecisionElements(decisionTable)); evaluateDecisionTable(decisionTable, variableContext, evaluationResult); // apply hit policy decisionTable.getHitPolicyHandler().apply(evaluationResult); // notify listeners for (DmnDecisionTableEvaluationListener evaluationListener : evaluationListeners) { evaluationListener.notify(evaluationResult); } return evaluationResult; }
Example #6
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void evaluateDecisionTable(DmnDecisionTableImpl decisionTable, VariableContext variableContext, DmnDecisionTableEvaluationEventImpl evaluationResult) { int inputSize = decisionTable.getInputs().size(); List<DmnDecisionTableRuleImpl> matchingRules = new ArrayList<DmnDecisionTableRuleImpl>(decisionTable.getRules()); for (int inputIdx = 0; inputIdx < inputSize; inputIdx++) { // evaluate input DmnDecisionTableInputImpl input = decisionTable.getInputs().get(inputIdx); DmnEvaluatedInput evaluatedInput = evaluateInput(input, variableContext); evaluationResult.getInputs().add(evaluatedInput); // compose local variable context out of global variable context enhanced with the value of the current input. VariableContext localVariableContext = getLocalVariableContext(input, evaluatedInput, variableContext); // filter rules applicable with this input matchingRules = evaluateInputForAvailableRules(inputIdx, input, matchingRules, localVariableContext); } setEvaluationOutput(decisionTable, matchingRules, variableContext, evaluationResult); }
Example #7
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public DmnDecisionLogicEvaluationEvent evaluate(DmnDecision decision, VariableContext variableContext) { DmnDecisionTableEvaluationEventImpl evaluationResult = new DmnDecisionTableEvaluationEventImpl(); evaluationResult.setDecisionTable(decision); DmnDecisionTableImpl decisionTable = (DmnDecisionTableImpl) decision.getDecisionLogic(); evaluationResult.setExecutedDecisionElements(calculateExecutedDecisionElements(decisionTable)); evaluateDecisionTable(decisionTable, variableContext, evaluationResult); // apply hit policy decisionTable.getHitPolicyHandler().apply(evaluationResult); // notify listeners for (DmnDecisionTableEvaluationListener evaluationListener : evaluationListeners) { evaluationListener.notify(evaluationResult); } return evaluationResult; }
Example #8
Source File: VariableContextElResolver.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public Object getValue(ELContext context, Object base, Object property) { if (base == null) { VariableContext variableContext = (VariableContext) context.getContext(VariableContext.class); if(variableContext != null) { if(VARIABLE_CONTEXT_KEY.equals(property)) { context.setPropertyResolved(true); return variableContext; } TypedValue typedValue = variableContext.resolve((String) property); if(typedValue != null) { context.setPropertyResolved(true); return unpack(typedValue); } } } return null; }
Example #9
Source File: FeelIntegrationTest.java From camunda-engine-dmn with Apache License 2.0 | 6 votes |
@Test @DecisionResource(resource = DMN) public void testFeelOutputEntryWithCustomEngine() { DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) getDmnEngineConfiguration(); configuration.setDefaultOutputEntryExpressionLanguage(DefaultDmnEngineConfiguration.FEEL_EXPRESSION_LANGUAGE); DmnEngine engine = configuration.buildEngine(); // stubbing the default FEEL engine behavior doReturn("a").when(feelEngineSpy).evaluateSimpleExpression(eq("\"a\""), any(VariableContext.class)); DmnDecisionResult decisionResult = engine.evaluateDecision(decision, Variables.createVariables().putValue("score", 3)); assertThat(decisionResult.getSingleEntry()).isEqualTo("a"); verify(feelEngineSpy).evaluateSimpleExpression(anyString(), any(VariableContext.class)); }
Example #10
Source File: DecisionTableEvaluationHandler.java From camunda-engine-dmn with Apache License 2.0 | 6 votes |
protected Map<String, DmnEvaluatedOutput> evaluateOutputEntries(List<DmnDecisionTableOutputImpl> decisionTableOutputs, DmnDecisionTableRuleImpl matchingRule, VariableContext variableContext) { Map<String, DmnEvaluatedOutput> outputEntries = new LinkedHashMap<String, DmnEvaluatedOutput>(); for (int outputIdx = 0; outputIdx < decisionTableOutputs.size(); outputIdx++) { // evaluate output entry, skip empty expressions DmnExpressionImpl conclusion = matchingRule.getConclusions().get(outputIdx); if (isNonEmptyExpression(conclusion)) { Object value = evaluateOutputEntry(conclusion, variableContext); // transform to output type DmnDecisionTableOutputImpl decisionTableOutput = decisionTableOutputs.get(outputIdx); TypedValue typedValue = decisionTableOutput.getTypeDefinition().transform(value); // set on result DmnEvaluatedOutputImpl evaluatedOutput = new DmnEvaluatedOutputImpl(decisionTableOutput, typedValue); outputEntries.put(decisionTableOutput.getOutputName(), evaluatedOutput); } } return outputEntries; }
Example #11
Source File: FeelIntegrationTest.java From camunda-engine-dmn with Apache License 2.0 | 6 votes |
@Test @DecisionResource(resource = DMN) public void testFeelOutputEntry() { DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) getDmnEngineConfiguration(); configuration.setDefaultOutputEntryExpressionLanguage(DefaultDmnEngineConfiguration.FEEL_EXPRESSION_LANGUAGE); DmnEngine engine = configuration.buildEngine(); try { engine.evaluateDecision(decision, Variables.createVariables().putValue("score", 3)); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (UnsupportedOperationException e) { assertThat(e).hasMessageStartingWith("FEEL-01016"); verify(feelEngineSpy).evaluateSimpleExpression(anyString(), any(VariableContext.class)); } }
Example #12
Source File: DecisionLiteralExpressionEvaluationHandler.java From camunda-engine-dmn with Apache License 2.0 | 6 votes |
@Override public DmnDecisionLogicEvaluationEvent evaluate(DmnDecision decision, VariableContext variableContext) { DmnDecisionLiteralExpressionEvaluationEventImpl evaluationResult = new DmnDecisionLiteralExpressionEvaluationEventImpl(); evaluationResult.setDecision(decision); evaluationResult.setExecutedDecisionElements(1); DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic(); DmnVariableImpl variable = dmnDecisionLiteralExpression.getVariable(); DmnExpressionImpl expression = dmnDecisionLiteralExpression.getExpression(); Object evaluateExpression = evaluateLiteralExpression(expression, variableContext); TypedValue typedValue = variable.getTypeDefinition().transform(evaluateExpression); evaluationResult.setOutputValue(typedValue); evaluationResult.setOutputName(variable.getName()); return evaluationResult; }
Example #13
Source File: VariableContextElResolver.java From camunda-engine-dmn with Apache License 2.0 | 6 votes |
@Override public Object getValue(ELContext context, Object base, Object property) { if (base == null) { VariableContext variableContext = (VariableContext) context.getContext(VariableContext.class); if(variableContext != null) { if(VARIABLE_CONTEXT_KEY.equals(property)) { context.setPropertyResolved(true); return variableContext; } TypedValue typedValue = variableContext.resolve((String) property); if(typedValue != null) { context.setPropertyResolved(true); return unpack(typedValue); } } } return null; }
Example #14
Source File: DecisionLiteralExpressionEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public DmnDecisionLogicEvaluationEvent evaluate(DmnDecision decision, VariableContext variableContext) { DmnDecisionLiteralExpressionEvaluationEventImpl evaluationResult = new DmnDecisionLiteralExpressionEvaluationEventImpl(); evaluationResult.setDecision(decision); evaluationResult.setExecutedDecisionElements(1); DmnDecisionLiteralExpressionImpl dmnDecisionLiteralExpression = (DmnDecisionLiteralExpressionImpl) decision.getDecisionLogic(); DmnVariableImpl variable = dmnDecisionLiteralExpression.getVariable(); DmnExpressionImpl expression = dmnDecisionLiteralExpression.getExpression(); Object evaluateExpression = evaluateLiteralExpression(expression, variableContext); TypedValue typedValue = variable.getTypeDefinition().transform(evaluateExpression); evaluationResult.setOutputValue(typedValue); evaluationResult.setOutputName(variable.getName()); return evaluationResult; }
Example #15
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected DmnEvaluatedDecisionRule evaluateMatchingRule(List<DmnDecisionTableOutputImpl> decisionTableOutputs, DmnDecisionTableRuleImpl matchingRule, VariableContext variableContext) { DmnEvaluatedDecisionRuleImpl evaluatedDecisionRule = new DmnEvaluatedDecisionRuleImpl(matchingRule); Map<String, DmnEvaluatedOutput> outputEntries = evaluateOutputEntries(decisionTableOutputs, matchingRule, variableContext); evaluatedDecisionRule.setOutputEntries(outputEntries); return evaluatedDecisionRule; }
Example #16
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected Object evaluateInputExpression(DmnExpressionImpl expression, VariableContext variableContext) { String expressionLanguage = expression.getExpressionLanguage(); if (expressionLanguage == null) { expressionLanguage = inputExpressionExpressionLanguage; } return expressionEvaluationHandler.evaluateExpression(expressionLanguage, expression, variableContext); }
Example #17
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected VariableContext getLocalVariableContext(DmnDecisionTableInputImpl input, DmnEvaluatedInput evaluatedInput, VariableContext variableContext) { if (isNonEmptyExpression(input.getExpression())) { String inputVariableName = evaluatedInput.getInputVariable(); return CompositeVariableContext.compose( Variables.createVariables() .putValue("inputVariableName", inputVariableName) .putValueTyped(inputVariableName, evaluatedInput.getValue()) .asVariableContext(), variableContext ); } else { return variableContext; } }
Example #18
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected DmnEvaluatedInput evaluateInput(DmnDecisionTableInputImpl input, VariableContext variableContext) { DmnEvaluatedInputImpl evaluatedInput = new DmnEvaluatedInputImpl(input); DmnExpressionImpl expression = input.getExpression(); if (expression != null) { Object value = evaluateInputExpression(expression, variableContext); TypedValue typedValue = expression.getTypeDefinition().transform(value); evaluatedInput.setValue(typedValue); } else { evaluatedInput.setValue(Variables.untypedNullValue()); } return evaluatedInput; }
Example #19
Source File: FeelRule.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public <T> T evaluateExpression(String expression, Object value) { if (functionProvider != null) { List<FeelCustomFunctionProvider> functionProviders = Collections.singletonList(functionProvider); feelEngine = new ScalaFeelEngine(functionProviders); } VariableContext variableCtx = Variables.putValue("variable", value).asVariableContext(); return feelEngine.evaluateSimpleExpression(expression, variableCtx); }
Example #20
Source File: DecisionTableEvaluationHandler.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected void setEvaluationOutput(DmnDecisionTableImpl decisionTable, List<DmnDecisionTableRuleImpl> matchingRules, VariableContext variableContext, DmnDecisionTableEvaluationEventImpl evaluationResult) { List<DmnDecisionTableOutputImpl> decisionTableOutputs = decisionTable.getOutputs(); List<DmnEvaluatedDecisionRule> evaluatedDecisionRules = new ArrayList<DmnEvaluatedDecisionRule>(); for (DmnDecisionTableRuleImpl matchingRule : matchingRules) { DmnEvaluatedDecisionRule evaluatedRule = evaluateMatchingRule(decisionTableOutputs, matchingRule, variableContext); evaluatedDecisionRules.add(evaluatedRule); } evaluationResult.setMatchingRules(evaluatedDecisionRules); }
Example #21
Source File: DefaultDmnDecisionContext.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected VariableMap buildVariableMapFromVariableContext(VariableContext variableContext) { VariableMap variableMap = Variables.createVariables(); Set<String> variables = variableContext.keySet(); for(String variable: variables) { variableMap.put(variable, variableContext.resolve(variable)); } return variableMap; }
Example #22
Source File: DefaultDmnEngine.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public DmnDecisionTableResult evaluateDecisionTable(String decisionKey, DmnModelInstance dmnModelInstance, VariableContext variableContext) { ensureNotNull("decisionKey", decisionKey); List<DmnDecision> decisions = parseDecisions(dmnModelInstance); for (DmnDecision decision : decisions) { if (decisionKey.equals(decision.getKey())) { return evaluateDecisionTable(decision, variableContext); } } throw LOG.unableToFindDecisionWithKey(decisionKey); }
Example #23
Source File: FeelIntegrationTest.java From camunda-engine-dmn with Apache License 2.0 | 5 votes |
@Test @DecisionResource(resource = DMN) public void testFeelInputEntry() { DmnDecisionResult decisionResult = dmnEngine.evaluateDecision(decision, Variables.createVariables().putValue("score", 3)); assertThat(decisionResult.getSingleEntry()).isEqualTo("a"); verify(feelEngineSpy, atLeastOnce()).evaluateSimpleUnaryTests(anyString(), anyString(), any(VariableContext.class)); }
Example #24
Source File: DefaultDmnEngine.java From camunda-engine-dmn with Apache License 2.0 | 5 votes |
public DmnDecisionResult evaluateDecision(String decisionKey, DmnModelInstance dmnModelInstance, VariableContext variableContext) { ensureNotNull("decisionKey", decisionKey); List<DmnDecision> decisions = parseDecisions(dmnModelInstance); for (DmnDecision decision : decisions) { if (decisionKey.equals(decision.getKey())) { return evaluateDecision(decision, variableContext); } } throw LOG.unableToFindDecisionWithKey(decisionKey); }
Example #25
Source File: DefaultDmnEngine.java From camunda-engine-dmn with Apache License 2.0 | 5 votes |
public DmnDecisionResult evaluateDecision(String decisionKey, InputStream inputStream, VariableContext variableContext) { ensureNotNull("decisionKey", decisionKey); List<DmnDecision> decisions = parseDecisions(inputStream); for (DmnDecision decision : decisions) { if (decisionKey.equals(decision.getKey())) { return evaluateDecision(decision, variableContext); } } throw LOG.unableToFindDecisionWithKey(decisionKey); }
Example #26
Source File: DefaultDmnEngine.java From camunda-engine-dmn with Apache License 2.0 | 5 votes |
public DmnDecisionResult evaluateDecision(DmnDecision decision, VariableContext variableContext) { ensureNotNull("decision", decision); ensureNotNull("variableContext", variableContext); if (decision instanceof DmnDecisionImpl) { DefaultDmnDecisionContext decisionContext = new DefaultDmnDecisionContext(dmnEngineConfiguration); return decisionContext.evaluateDecision(decision, variableContext); } else { throw LOG.decisionTypeNotSupported(decision); } }
Example #27
Source File: DefaultDmnEngine.java From camunda-engine-dmn with Apache License 2.0 | 5 votes |
public DmnDecisionTableResult evaluateDecisionTable(String decisionKey, DmnModelInstance dmnModelInstance, VariableContext variableContext) { ensureNotNull("decisionKey", decisionKey); List<DmnDecision> decisions = parseDecisions(dmnModelInstance); for (DmnDecision decision : decisions) { if (decisionKey.equals(decision.getKey())) { return evaluateDecisionTable(decision, variableContext); } } throw LOG.unableToFindDecisionWithKey(decisionKey); }
Example #28
Source File: DefaultDmnEngine.java From camunda-engine-dmn with Apache License 2.0 | 5 votes |
public DmnDecisionTableResult evaluateDecisionTable(String decisionKey, InputStream inputStream, VariableContext variableContext) { ensureNotNull("decisionKey", decisionKey); List<DmnDecision> decisions = parseDecisions(inputStream); for (DmnDecision decision : decisions) { if (decisionKey.equals(decision.getKey())) { return evaluateDecisionTable(decision, variableContext); } } throw LOG.unableToFindDecisionWithKey(decisionKey); }
Example #29
Source File: DefaultDmnEngine.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public DmnDecisionResult evaluateDecision(String decisionKey, InputStream inputStream, VariableContext variableContext) { ensureNotNull("decisionKey", decisionKey); List<DmnDecision> decisions = parseDecisions(inputStream); for (DmnDecision decision : decisions) { if (decisionKey.equals(decision.getKey())) { return evaluateDecision(decision, variableContext); } } throw LOG.unableToFindDecisionWithKey(decisionKey); }
Example #30
Source File: DefaultDmnEngine.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public DmnDecisionTableResult evaluateDecisionTable(String decisionKey, InputStream inputStream, VariableContext variableContext) { ensureNotNull("decisionKey", decisionKey); List<DmnDecision> decisions = parseDecisions(inputStream); for (DmnDecision decision : decisions) { if (decisionKey.equals(decision.getKey())) { return evaluateDecisionTable(decision, variableContext); } } throw LOG.unableToFindDecisionWithKey(decisionKey); }