org.mvel2.integration.PropertyHandler Java Examples

The following examples show how to use org.mvel2.integration.PropertyHandler. 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: MvelExecutionContextBuilder.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static MvelExecutionContext build(Decision decision, Map<String, Object> inputVariables,
    Map<String, Method> customExpressionFunctions, Map<Class<?>, PropertyHandler> propertyHandlers) {

  MvelExecutionContext executionContext = new MvelExecutionContext();

  // initialize audit trail
  executionContext.setAuditContainer(DecisionExecutionAuditUtil.initializeRuleExecutionAudit(decision, inputVariables));

  ParserContext parserContext = new ParserContext();

  // add custom functions to context
  if (customExpressionFunctions != null && !customExpressionFunctions.isEmpty()) {
    for (Map.Entry<String, Method> config : customExpressionFunctions.entrySet()) {
      parserContext.addImport(config.getKey(), config.getValue());
    }
  }

  executionContext.setParserContext(parserContext);

  if (propertyHandlers != null) {
    for (Class<?> variableClass : propertyHandlers.keySet()) {
      executionContext.addPropertyHandler(variableClass, propertyHandlers.get(variableClass));
    }
  }
  
  DecisionTable decisionTable = (DecisionTable) decision.getExpression();
  
  preProcessInputVariables(decisionTable, inputVariables);

  executionContext.setStackVariables(inputVariables);

  logger.debug("Execution Context created");

  return executionContext;
}
 
Example #2
Source File: RuleEngineExecutorImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the given decision table and creates the outcome results
 *
 * @param decision
 *          the DMN decision 
 * @param input
 *          map with input variables
 * @return updated execution variables map
 */
@Override
public RuleEngineExecutionResult execute(Decision decision, Map<String, Object> input,
    Map<String, Method> customExpressionFunctions, Map<Class<?>, PropertyHandler> propertyHandlers) {

  if (decision  == null) {
    throw new IllegalArgumentException("no decision provided");
  }

  if (decision.getExpression() == null || !(decision.getExpression() instanceof DecisionTable)) {
    throw new IllegalArgumentException("no decision table present in decision");
  }
  
  DecisionTable currentDecisionTable = (DecisionTable) decision.getExpression();

  // create execution context and audit trail
  MvelExecutionContext executionContext = MvelExecutionContextBuilder.build(decision, input, 
      customExpressionFunctions, propertyHandlers);

  // evaluate decision table
  Map<String, Object> resultVariables = evaluateDecisionTable(currentDecisionTable, executionContext);

  // end audit trail
  executionContext.getAuditContainer().stopAudit(resultVariables);

  // create result container
  RuleEngineExecutionResult executionResult = new RuleEngineExecutionResult(resultVariables, executionContext.getAuditContainer());

  return executionResult;
}
 
Example #3
Source File: PatternBuilder.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
private Pattern buildPattern(RuleBuildContext context, PatternDescr patternDescr, ObjectType objectType) {
    String patternIdentifier = patternDescr.getIdentifier();
    boolean duplicateBindings = patternIdentifier != null && objectType instanceof ClassObjectType &&
            context.getDeclarationResolver().isDuplicated(context.getRule(),
                                                          patternIdentifier,
                                                          objectType.getClassName());

    Pattern pattern;
    if (!StringUtils.isEmpty(patternIdentifier) && !duplicateBindings) {

        pattern = new Pattern(context.getNextPatternId(),
                              0, // offset is 0 by default
                              objectType,
                              patternIdentifier,
                              patternDescr.isInternalFact(context));
        if (objectType instanceof ClassObjectType) {
            // make sure PatternExtractor is wired up to correct ClassObjectType and set as a target for rewiring
            context.getPkg().getClassFieldAccessorStore().wireObjectType(objectType, (AcceptsClassObjectType) pattern.getDeclaration().getExtractor());
        }
    } else {
        pattern = new Pattern(context.getNextPatternId(),
                              0, // offset is 0 by default
                              objectType,
                              null);
    }
    pattern.setPassive(patternDescr.isPassive(context));

    if (ClassObjectType.Match_ObjectType.isAssignableFrom(pattern.getObjectType())) {
        PropertyHandler handler = PropertyHandlerFactory.getPropertyHandler(RuleTerminalNodeLeftTuple.class);
        if (handler == null) {
            PropertyHandlerFactoryFixer.getPropertyHandlerClass().put(RuleTerminalNodeLeftTuple.class,
                                                                      new ActivationPropertyHandler());
        }
    }

    // adding the newly created pattern to the build stack this is necessary in case of local declaration usage
    context.getDeclarationResolver().pushOnBuildStack(pattern);

    if (duplicateBindings) {
        processDuplicateBindings(patternDescr.isUnification(), patternDescr, pattern, patternDescr, "this", patternDescr.getIdentifier(), context);
    }
    return pattern;
}
 
Example #4
Source File: MVELCompilationUnit.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public static  Map<Class, PropertyHandler> getPropertyHandlerClass() {
    return propertyHandlerClass;
}
 
Example #5
Source File: RuleEngineExecutor.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
RuleEngineExecutionResult execute(Decision decision, Map<String, Object> input,
Map<String, Method> customExpressionFunctions, Map<Class<?>, PropertyHandler> propertyHandlers);
 
Example #6
Source File: DmnEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Map<Class<?>, PropertyHandler> getCustomPropertyHandlers() {
  return customPropertyHandlers;
}
 
Example #7
Source File: DmnEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setCustomPropertyHandlers(Map<Class<?>, PropertyHandler> customPropertyHandlers) {
  this.customPropertyHandlers = customPropertyHandlers;
}
 
Example #8
Source File: MvelExecutionContext.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Map<Class<?>, PropertyHandler> getPropertyHandlers() {
    return propertyHandlers;
}
 
Example #9
Source File: MvelExecutionContext.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void addPropertyHandler(Class<?> variableClass, PropertyHandler propertyHandler) {
    propertyHandlers.put(variableClass, propertyHandler);
}