Java Code Examples for org.camunda.bpm.engine.impl.el.ExpressionManager#createExpression()

The following examples show how to use org.camunda.bpm.engine.impl.el.ExpressionManager#createExpression() . 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: ItemHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected Expression getExpressionValue(CamundaField field, ExpressionManager expressionManager) {
  CamundaExpression expression = field.getCamundaExpressionChild();

  String value = null;
  if (expression != null) {
    value = expression.getTextContent();

  }

  if (value == null) {
    value = field.getCamundaExpression();
  }

  if (value != null) {
    return expressionManager.createExpression(value);
  }

  return null;
}
 
Example 2
Source File: DefaultStartFormHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void parseConfiguration(Element activityElement, DeploymentEntity deployment, ProcessDefinitionEntity processDefinition, BpmnParse bpmnParse) {
  super.parseConfiguration(activityElement, deployment, processDefinition, bpmnParse);

  ExpressionManager expressionManager = Context
      .getProcessEngineConfiguration()
      .getExpressionManager();

  String formKeyAttribute = activityElement.attributeNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "formKey");

  if (formKeyAttribute != null) {
    this.formKey = expressionManager.createExpression(formKeyAttribute);
  }

  if (formKey != null) {
    processDefinition.setStartFormKey(true);
  }
}
 
Example 3
Source File: SentryHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initializeIfPart(IfPart ifPart, CmmnSentryDeclaration sentryDeclaration, CmmnHandlerContext context) {
  if (ifPart == null) {
    return;
  }

  Collection<ConditionExpression> conditions = ifPart.getConditions();

  if (conditions.size() > 1) {
    String id = sentryDeclaration.getId();
    LOG.multipleIgnoredConditions(id);
  }

  ExpressionManager expressionManager = context.getExpressionManager();
  ConditionExpression condition = conditions.iterator().next();
  Expression conditionExpression = expressionManager.createExpression(condition.getText());

  CmmnIfPartDeclaration ifPartDeclaration = new CmmnIfPartDeclaration();
  ifPartDeclaration.setCondition(conditionExpression);
  sentryDeclaration.setIfPart(ifPartDeclaration);
}
 
Example 4
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initializeTaskDefinitionAssignee(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  HumanTask definition = getDefinition(element);
  Role performer = definition.getPerformer();

  String assignee = null;
  if (performer != null) {
    assignee = performer.getName();
  } else {
    assignee = definition.getCamundaAssignee();
  }

  if (assignee != null) {
    ExpressionManager expressionManager = context.getExpressionManager();
    Expression assigneeExpression = expressionManager.createExpression(assignee);
    taskDefinition.setAssigneeExpression(assigneeExpression);
  }
}
 
Example 5
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeTaskDefinitionCandidateGroups(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  HumanTask definition = getDefinition(element);
  ExpressionManager expressionManager = context.getExpressionManager();

  List<String> candidateGroups = definition.getCamundaCandidateGroupsList();
  for (String candidateGroup : candidateGroups) {
    Expression candidateGroupExpression = expressionManager.createExpression(candidateGroup);
    taskDefinition.addCandidateGroupIdExpression(candidateGroupExpression);
  }
}
 
Example 6
Source File: ScriptUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: ParseUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static FailedJobRetryConfiguration parseRetryIntervals(String retryIntervals) {

    if (retryIntervals != null && !retryIntervals.isEmpty()) {

      if (StringUtil.isExpression(retryIntervals)) {
        ExpressionManager expressionManager = Context.getProcessEngineConfiguration().getExpressionManager();
        Expression expression = expressionManager.createExpression(retryIntervals);
        return new FailedJobRetryConfiguration(expression);
      }

      String[] intervals = StringUtil.split(retryIntervals, ",");
      int retries = intervals.length + 1;

      if (intervals.length == 1) {
        try {
          DurationHelper durationHelper = new DurationHelper(intervals[0]);

          if (durationHelper.isRepeat()) {
            retries = durationHelper.getTimes();
          }
        } catch (Exception e) {
          LOG.logParsingRetryIntervals(intervals[0], e);
          return null;
        }
      }
      return new FailedJobRetryConfiguration(retries, Arrays.asList(intervals));
    } else {
      return null;
    }
  }
 
Example 8
Source File: ItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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 9
Source File: ScriptUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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 11
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeTaskDefinitionPriority(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  HumanTask definition = getDefinition(element);

  String priority = definition.getCamundaPriority();
  if (priority != null) {
    ExpressionManager expressionManager = context.getExpressionManager();
    Expression priorityExpression = expressionManager.createExpression(priority);
    taskDefinition.setPriorityExpression(priorityExpression);
  }
}
 
Example 12
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeTaskDefinitionFollowUpDate(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  HumanTask definition = getDefinition(element);

  String followUpDate = definition.getCamundaFollowUpDate();
  if (followUpDate != null) {
    ExpressionManager expressionManager = context.getExpressionManager();
    Expression followUpDateExpression = expressionManager.createExpression(followUpDate);
    taskDefinition.setFollowUpDateExpression(followUpDateExpression);
  }
}
 
Example 13
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeTaskDefinitionDueDate(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  HumanTask definition = getDefinition(element);

  String dueDate = definition.getCamundaDueDate();
  if (dueDate != null) {
    ExpressionManager expressionManager = context.getExpressionManager();
    Expression dueDateExpression = expressionManager.createExpression(dueDate);
    taskDefinition.setDueDateExpression(dueDateExpression);
  }
}
 
Example 14
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeTaskDefinitionCandidateUsers(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  HumanTask definition = getDefinition(element);
  ExpressionManager expressionManager = context.getExpressionManager();

  List<String> candidateUsers = definition.getCamundaCandidateUsersList();
  for (String candidateUser : candidateUsers) {
    Expression candidateUserExpression = expressionManager.createExpression(candidateUser);
    taskDefinition.addCandidateUserIdExpression(candidateUserExpression);
  }
}
 
Example 15
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeTaskDefinitionFormKey(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  HumanTask definition = getDefinition(element);

  String formKey = definition.getCamundaFormKey();
  if (formKey != null) {
    ExpressionManager expressionManager = context.getExpressionManager();
    Expression formKeyExpression = expressionManager.createExpression(formKey);
    taskDefinition.setFormKey(formKeyExpression);
  }
}
 
Example 16
Source File: HumanTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void initializeTaskDefinitionName(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
  String name = getName(element);
  if (name == null) {
    HumanTask definition = getDefinition(element);
    name = definition.getName();
  }

  if (name != null) {
    ExpressionManager expressionManager = context.getExpressionManager();
    Expression nameExpression = expressionManager.createExpression(name);
    taskDefinition.setNameExpression(nameExpression);
  }

}
 
Example 17
Source File: CallingTaskItemHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ParameterValueProvider createParameterValueProvider(String value, ExpressionManager expressionManager) {
  if (value == null) {
    return new NullValueProvider();

  } else if (isCompositeExpression(value, expressionManager)) {
    Expression expression = expressionManager.createExpression(value);
    return new ElValueProvider(expression);

  } else {
    return new ConstantValueProvider(value);
  }
}
 
Example 18
Source File: FormValidators.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * factory method for creating validator instances
 *
 */
public FormFieldValidator createValidator(Element constraint, BpmnParse bpmnParse, ExpressionManager expressionManager) {

  String name = constraint.attribute("name");
  String config = constraint.attribute("config");

  if("validator".equals(name)) {

    // custom validators

    if(config == null || config.isEmpty()) {
      bpmnParse.addError("validator configuration needs to provide either a fully " +
      		"qualified classname or an expression resolving to a custom FormFieldValidator implementation.",
      		constraint);

    } else {
      if(StringUtil.isExpression(config)) {
        // expression
        Expression validatorExpression = expressionManager.createExpression(config);
        return new DelegateFormFieldValidator(validatorExpression);
      } else {
        // classname
        return new DelegateFormFieldValidator(config);
      }
    }

  } else {

    // built-in validators

    Class<? extends FormFieldValidator> validator = validators.get(name);
    if(validator != null) {
      FormFieldValidator validatorInstance = createValidatorInstance(validator);
      return validatorInstance;

    } else {
      bpmnParse.addError("Cannot find validator implementation for name '"+name+"'.", constraint);

    }

  }

  return null;


}
 
Example 19
Source File: DefaultFormHandler.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void parseFormProperties(BpmnParse bpmnParse, ExpressionManager expressionManager, Element extensionElement) {
  FormTypes formTypes = getFormTypes();

  List<Element> formPropertyElements = extensionElement.elementsNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, FORM_PROPERTY_ELEMENT);
  for (Element formPropertyElement : formPropertyElements) {
    FormPropertyHandler formPropertyHandler = new FormPropertyHandler();

    String id = formPropertyElement.attribute("id");
    if (id==null) {
      bpmnParse.addError("attribute 'id' is required", formPropertyElement);
    }
    formPropertyHandler.setId(id);

    String name = formPropertyElement.attribute("name");
    formPropertyHandler.setName(name);

    AbstractFormFieldType type = formTypes.parseFormPropertyType(formPropertyElement, bpmnParse);
    formPropertyHandler.setType(type);

    String requiredText = formPropertyElement.attribute("required", "false");
    Boolean required = bpmnParse.parseBooleanAttribute(requiredText);
    if (required!=null) {
      formPropertyHandler.setRequired(required);
    } else {
      bpmnParse.addError("attribute 'required' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
    }

    String readableText = formPropertyElement.attribute("readable", "true");
    Boolean readable = bpmnParse.parseBooleanAttribute(readableText);
    if (readable!=null) {
      formPropertyHandler.setReadable(readable);
    } else {
      bpmnParse.addError("attribute 'readable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
    }

    String writableText = formPropertyElement.attribute("writable", "true");
    Boolean writable = bpmnParse.parseBooleanAttribute(writableText);
    if (writable!=null) {
      formPropertyHandler.setWritable(writable);
    } else {
      bpmnParse.addError("attribute 'writable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
    }

    String variableName = formPropertyElement.attribute("variable");
    formPropertyHandler.setVariableName(variableName);

    String expressionText = formPropertyElement.attribute("expression");
    if (expressionText!=null) {
      Expression expression = expressionManager.createExpression(expressionText);
      formPropertyHandler.setVariableExpression(expression);
    }

    String defaultExpressionText = formPropertyElement.attribute("default");
    if (defaultExpressionText!=null) {
      Expression defaultExpression = expressionManager.createExpression(defaultExpressionText);
      formPropertyHandler.setDefaultExpression(defaultExpression);
    }

    formPropertyHandlers.add(formPropertyHandler);
  }
}
 
Example 20
Source File: DefaultFormHandler.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void parseFormField(Element formField, BpmnParse bpmnParse, ExpressionManager expressionManager) {

    FormFieldHandler formFieldHandler = new FormFieldHandler();

    // parse Id
    String id = formField.attribute("id");
    if(id == null || id.isEmpty()) {
      bpmnParse.addError("attribute id must be set for FormFieldGroup and must have a non-empty value", formField);
    } else {
      formFieldHandler.setId(id);
    }

    if (id.equals(businessKeyFieldId)) {
      formFieldHandler.setBusinessKey(true);
    }

    // parse name
    String name = formField.attribute("label");
    if (name != null) {
      Expression nameExpression = expressionManager.createExpression(name);
      formFieldHandler.setLabel(nameExpression);
    }

    // parse properties
    parseProperties(formField, formFieldHandler, bpmnParse, expressionManager);

    // parse validation
    parseValidation(formField, formFieldHandler, bpmnParse, expressionManager);

    // parse type
    FormTypes formTypes = getFormTypes();
    AbstractFormFieldType formType = formTypes.parseFormPropertyType(formField, bpmnParse);
    formFieldHandler.setType(formType);

    // parse default value
    String defaultValue = formField.attribute("defaultValue");
    if(defaultValue != null) {
      Expression defaultValueExpression = expressionManager.createExpression(defaultValue);
      formFieldHandler.setDefaultValueExpression(defaultValueExpression);
    }

    formFieldHandlers.add(formFieldHandler);

  }