org.activiti.engine.delegate.Expression Java Examples

The following examples show how to use org.activiti.engine.delegate.Expression. 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 Project: herd   Author: FINRAOS   File: ActivitiHelperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetExpressionVariableAsIntegerRequiredBlankValue()
{
    // Mock dependencies.
    Expression expression = mock(Expression.class);
    DelegateExecution execution = mock(DelegateExecution.class);
    when(expression.getValue(execution)).thenReturn(BLANK_TEXT);

    // Try to call the method under test.
    try
    {
        activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED);
        fail();
    }
    catch (IllegalArgumentException e)
    {
        assertEquals(String.format("\"%s\" must be specified.", VARIABLE_NAME), e.getMessage());
    }
}
 
Example #2
Source Project: activiti6-boot2   Author: dingziyang   File: ConditionUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean hasTrueCondition(SequenceFlow sequenceFlow, DelegateExecution execution) {
  String conditionExpression = null;
  if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
    ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlow.getId(), execution.getProcessDefinitionId());
    conditionExpression = getActiveValue(sequenceFlow.getConditionExpression(), DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
  } else {
    conditionExpression = sequenceFlow.getConditionExpression();
  }
  
  if (StringUtils.isNotEmpty(conditionExpression)) {

    Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
    Condition condition = new UelExpressionCondition(expression);
    if (condition.evaluate(sequenceFlow.getId(), execution)) {
      return true;
    }

    return false;

  } else {
    return true;
  }

}
 
Example #3
Source Project: activiti6-boot2   Author: dingziyang   File: BpmnDeployer.java    License: Apache License 2.0 6 votes vote down vote up
private void addAuthorizationsFromIterator(Set<Expression> exprSet, ProcessDefinitionEntity processDefinition, ExprType exprType) {
  if (exprSet != null) {
    Iterator<Expression> iterator = exprSet.iterator();
    while (iterator.hasNext()) {
      Expression expr = (Expression) iterator.next();
      IdentityLinkEntity identityLink = new IdentityLinkEntity();
      identityLink.setProcessDef(processDefinition);
      if (exprType.equals(ExprType.USER)) {
         identityLink.setUserId(expr.toString());
      } else if (exprType.equals(ExprType.GROUP)) {
        identityLink.setGroupId(expr.toString());
      }
      identityLink.setType(IdentityLinkType.CANDIDATE);
      identityLink.insert();
    }
  }
}
 
Example #4
Source Project: herd   Author: FINRAOS   File: ActivitiHelperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetRequiredExpressionVariableAsStringBlankValue()
{
    // Mock dependencies.
    Expression expression = mock(Expression.class);
    DelegateExecution execution = mock(DelegateExecution.class);
    when(expression.getValue(execution)).thenReturn(BLANK_TEXT);

    // Try to call the method under test.
    try
    {
        activitiHelper.getRequiredExpressionVariableAsString(expression, execution, VARIABLE_NAME);
        fail();
    }
    catch (IllegalArgumentException e)
    {
        assertEquals(String.format("\"%s\" must be specified.", VARIABLE_NAME), e.getMessage());
    }
}
 
Example #5
Source Project: openwebflow   Author: bluejoe2008   File: TaskDelagationAssignmentHandler.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void handleAssignment(TaskAssignmentHandlerChain chain, Expression assigneeExpression,
		Expression ownerExpression, Set<Expression> candidateUserExpressions,
		Set<Expression> candidateGroupExpressions, TaskEntity task, ActivityExecution execution)
{
	//先执行其它规则
	chain.resume(assigneeExpression, ownerExpression, candidateUserExpressions,
		      candidateGroupExpressions, task, execution);

	overwriteAssignee(task);

	Map<String, Object> userIdMap = new HashMap<String, Object>();
	Map<String, Object> groupIdMap = new HashMap<String, Object>();
	retrieveCandidateUserIdsAndGroupIds(task, userIdMap, groupIdMap);
	Map<String, Object> newUserIdMap = new HashMap<String, Object>();
	Map<String, Object> removeUserIdMap = new HashMap<String, Object>();

	//遍历所有的被代理人
	List<DelegationEntity> entries = _delegationManager.listDelegationEntities();
	overwriteCandicateUserIds(userIdMap, newUserIdMap, removeUserIdMap, entries);
	overwriteCandicateGroupIds(groupIdMap, newUserIdMap, entries);

	addCandidateUsers(task, newUserIdMap.keySet());
	removeCandidateUsers(task, removeUserIdMap.keySet());
}
 
Example #6
Source Project: lemon   Author: xuhuisheng   File: SkipEventListener.java    License: Apache License 2.0 5 votes vote down vote up
public void doSkip(DelegateTask delegateTask) {
    delegateTask.getExecution().setVariableLocal(
            "_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);

    TaskDefinition taskDefinition = ((TaskEntity) delegateTask)
            .getTaskDefinition();
    ExpressionManager expressionManager = Context
            .getProcessEngineConfiguration().getExpressionManager();
    Expression expression = expressionManager
            .createExpression("${_ACTIVITI_SKIP_EXPRESSION_ENABLED}");
    taskDefinition.setSkipExpression(expression);
}
 
Example #7
Source Project: activiti6-boot2   Author: dingziyang   File: DefaultFormHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void parseConfiguration(List<org.activiti.bpmn.model.FormProperty> formProperties, String formKey, DeploymentEntity deployment, ProcessDefinition processDefinition) {
  this.deploymentId = deployment.getId();
  
  ExpressionManager expressionManager = Context
      .getProcessEngineConfiguration()
      .getExpressionManager();
  
  if (StringUtils.isNotEmpty(formKey)) {
    this.formKey = expressionManager.createExpression(formKey);
  }
  
  FormTypes formTypes = Context
    .getProcessEngineConfiguration()
    .getFormTypes();
  
  for (org.activiti.bpmn.model.FormProperty formProperty : formProperties) {
    FormPropertyHandler formPropertyHandler = new FormPropertyHandler();
    formPropertyHandler.setId(formProperty.getId());
    formPropertyHandler.setName(formProperty.getName());
    
    AbstractFormType type = formTypes.parseFormPropertyType(formProperty);
    formPropertyHandler.setType(type);
    formPropertyHandler.setRequired(formProperty.isRequired());
    formPropertyHandler.setReadable(formProperty.isReadable());
    formPropertyHandler.setWritable(formProperty.isWriteable());
    formPropertyHandler.setVariableName(formProperty.getVariable());

    if (StringUtils.isNotEmpty(formProperty.getExpression())) {
      Expression expression = expressionManager.createExpression(formProperty.getExpression());
      formPropertyHandler.setVariableExpression(expression);
    }

    if (StringUtils.isNotEmpty(formProperty.getDefaultExpression())) {
      Expression defaultExpression = expressionManager.createExpression(formProperty.getDefaultExpression());
      formPropertyHandler.setDefaultExpression(defaultExpression);
    }

    formPropertyHandlers.add(formPropertyHandler);
  }
}
 
Example #8
Source Project: activiti6-boot2   Author: dingziyang   File: MailActivityBehavior.java    License: Apache License 2.0 5 votes vote down vote up
protected String getStringFromField(Expression expression, DelegateExecution execution) {
  if (expression != null) {
    Object value = expression.getValue(execution);
    if (value != null) {
      return value.toString();
    }
  }
  return null;
}
 
Example #9
Source Project: herd   Author: FINRAOS   File: ActivitiHelperTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetExpressionVariableAsBoolean()
{
    // Mock dependencies.
    Expression expression = mock(Expression.class);
    DelegateExecution execution = mock(DelegateExecution.class);
    when(expression.getValue(execution)).thenReturn(BOOLEAN_VALUE.toString());

    // Call the method under test.
    Boolean result = activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE);

    // Validate the result.
    assertEquals(BOOLEAN_VALUE, result);
}
 
Example #10
Source Project: activiti6-boot2   Author: dingziyang   File: MailActivityBehavior.java    License: Apache License 2.0 5 votes vote down vote up
private Object checkAllowedTypes(Expression expression, DelegateExecution execution) {
  if (expression == null) {
    return null;
  }
  Object value = expression.getValue(execution);
  if (value == null) {
    return null;
  }
  for (Class<?> allowedType : ALLOWED_ATT_TYPES) {
    if (allowedType.isInstance(value)) {
      return value;
    }
  }
  throw new ActivitiException("Invalid attachment type: " + value.getClass());
}
 
Example #11
Source Project: maven-framework-project   Author: v5developer   File: WorkflowTraceService.java    License: MIT License 5 votes vote down vote up
private void setTaskGroup(Map<String, Object> vars, Set<Expression> candidateGroupIdExpressions) {
	String roles = "";
	for (Expression expression : candidateGroupIdExpressions) {
		String expressionText = expression.getExpressionText();
		if (expressionText.startsWith("$")) {
			expressionText = expressionText.replace("${insuranceType}", "life");
		}
		String roleName = identityService.createGroupQuery().groupId(expressionText).singleResult().getName();
		roles += roleName;
	}
	vars.put("任务所属角色", roles);
}
 
Example #12
Source Project: herd   Author: FINRAOS   File: ActivitiHelperTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetExpressionVariableAsBooleanRequired()
{
    // Mock dependencies.
    Expression expression = mock(Expression.class);
    DelegateExecution execution = mock(DelegateExecution.class);
    when(expression.getValue(execution)).thenReturn(BOOLEAN_VALUE.toString());

    // Call the method under test.
    Boolean result = activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE);

    // Validate the result.
    assertEquals(BOOLEAN_VALUE, result);
}
 
Example #13
Source Project: openwebflow   Author: bluejoe2008   File: MyUserTaskActivityBehavior.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void handleAssignments(Expression assigneeExpression, Expression ownerExpression, Set<Expression> candidateUserExpressions,
	      Set<Expression> candidateGroupExpressions, TaskEntity task, ActivityExecution execution)
{
	createHandlerChain().resume(assigneeExpression, ownerExpression, candidateUserExpressions, 
	        candidateGroupExpressions, task, execution);
}
 
Example #14
Source Project: openwebflow   Author: bluejoe2008   File: ExpressionUtils.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Set<Expression> stringToExpressionSet(String exprs)
{
	Set<Expression> set = new LinkedHashSet<Expression>();
	for (String expr : exprs.split(";"))
	{
		set.add(stringToExpression(expr));
	}

	return set;
}
 
Example #15
Source Project: activiti6-boot2   Author: dingziyang   File: MailActivityBehavior.java    License: Apache License 2.0 5 votes vote down vote up
private Object checkAllowedTypes(Expression expression, DelegateExecution execution) {
  if (expression == null) {
    return null;
  }
  Object value = expression.getValue(execution);
  if (value == null) {
    return null;
  }
  for (Class<?> allowedType : ALLOWED_ATT_TYPES) {
    if (allowedType.isInstance(value)) {
      return value;
    }
  }
  throw new ActivitiException("Invalid attachment type: " + value.getClass());
}
 
Example #16
Source Project: activiti6-boot2   Author: dingziyang   File: DefaultActivityBehaviorFactory.java    License: Apache License 2.0 5 votes vote down vote up
public ClassDelegate createClassDelegateServiceTask(ServiceTask serviceTask) {
  Expression skipExpression;
  if (StringUtils.isNotEmpty(serviceTask.getSkipExpression())) {
    skipExpression = expressionManager.createExpression(serviceTask.getSkipExpression());
  } else {
    skipExpression = null;
  }
  return new ClassDelegate(serviceTask.getId(), serviceTask.getImplementation(), createFieldDeclarations(serviceTask.getFieldExtensions()), 
      skipExpression, serviceTask.getMapExceptions());
}
 
Example #17
Source Project: activiti6-boot2   Author: dingziyang   File: DefaultActivityBehaviorFactory.java    License: Apache License 2.0 5 votes vote down vote up
public ServiceTaskDelegateExpressionActivityBehavior createServiceTaskDelegateExpressionActivityBehavior(ServiceTask serviceTask) {
  Expression delegateExpression = expressionManager.createExpression(serviceTask.getImplementation());
  Expression skipExpression;
  if (StringUtils.isNotEmpty(serviceTask.getSkipExpression())) {
    skipExpression = expressionManager.createExpression(serviceTask.getSkipExpression());
  } else {
    skipExpression = null;
  }
  return new ServiceTaskDelegateExpressionActivityBehavior(serviceTask.getId(), delegateExpression, skipExpression, createFieldDeclarations(serviceTask.getFieldExtensions()));
}
 
Example #18
Source Project: activiti6-boot2   Author: dingziyang   File: AbstractExternalInvocationBpmnParseHandler.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractDataAssociation createDataOutputAssociation(BpmnParse bpmnParse, DataAssociation dataAssociationElement) {
  if (StringUtils.isNotEmpty(dataAssociationElement.getSourceRef())) {
    return new MessageImplicitDataOutputAssociation(dataAssociationElement.getTargetRef(), dataAssociationElement.getSourceRef());
  } else {
    Expression transformation = bpmnParse.getExpressionManager().createExpression(dataAssociationElement.getTransformation());
    AbstractDataAssociation dataOutputAssociation = new TransformationDataOutputAssociation(null, dataAssociationElement.getTargetRef(), transformation);
    return dataOutputAssociation;
  }
}
 
Example #19
Source Project: alfresco-repository   Author: Alfresco   File: ConvertDateToISO8601.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String getExpressionString(Expression expression, VariableScope variableScope) 
{
    if (expression != null) 
    {
        return (String) expression.getValue(variableScope);
    }
    return null;
}
 
Example #20
Source Project: activiti6-boot2   Author: dingziyang   File: SkipExpressionUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean shouldSkipFlowElement(ActivityExecution execution, Expression skipExpression) {
  Object value = skipExpression.getValue(execution);
  
  if (value instanceof Boolean) {
    return ((Boolean)value).booleanValue();
    
  } else {
    throw new ActivitiIllegalArgumentException("Skip expression does not resolve to a boolean: " + skipExpression.getExpressionText());
  }
}
 
Example #21
Source Project: activiti6-boot2   Author: dingziyang   File: MailActivityBehavior.java    License: Apache License 2.0 5 votes vote down vote up
private void getFilesFromFields(Expression expression, DelegateExecution execution, List<File> files, List<DataSource> dataSources) {
  Object value = checkAllowedTypes(expression, execution);
  if (value != null) {
    if (value instanceof File) {
      files.add((File) value);
    } else if (value instanceof String) {
      files.add(new File((String) value));
    } else if (value instanceof File[]) {
      Collections.addAll(files, (File[]) value);
    } else if (value instanceof String[]) {
      String[] paths = (String[]) value;
      for (String path : paths) {
        files.add(new File(path));
      }
    } else if (value instanceof DataSource) {
      dataSources.add((DataSource) value);
    } else if (value instanceof DataSource[]) {
      for (DataSource ds : (DataSource[]) value) {
        if (ds != null) {
          dataSources.add(ds);
        }
      }
    }
  }
  for (Iterator<File> it = files.iterator(); it.hasNext(); ) {
    File file = it.next();
    if (!fileExists(file)) {
      it.remove();
    }
  }
}
 
Example #22
Source Project: activiti6-boot2   Author: dingziyang   File: BackwardsCompatibleExpressionDelegate.java    License: Apache License 2.0 4 votes vote down vote up
public void setExpression(Expression expression) {
  this.expression = expression;
}
 
Example #23
Source Project: activiti6-boot2   Author: dingziyang   File: DelegateExpressionTaskListener.java    License: Apache License 2.0 4 votes vote down vote up
public DelegateExpressionTaskListener(Expression expression, List<FieldDeclaration> fieldDeclarations) {
  this.expression = expression;
  this.fieldDeclarations = fieldDeclarations;
}
 
Example #24
Source Project: activiti6-boot2   Author: dingziyang   File: MailActivityBehavior.java    License: Apache License 2.0 4 votes vote down vote up
protected Expression getExpression(DelegateExecution execution, Expression var) {
  String variable = (String) execution.getVariable(var.getExpressionText());
  return Context.getProcessEngineConfiguration().getExpressionManager().createExpression(variable);
}
 
Example #25
Source Project: activiti-learn   Author: chanjarster   File: TaskListenerBeanWithFieldInjection.java    License: Apache License 2.0 4 votes vote down vote up
public void setText1(Expression text1) {
  this.text1 = text1;
}
 
Example #26
Source Project: activiti6-boot2   Author: dingziyang   File: DefaultFormHandler.java    License: Apache License 2.0 4 votes vote down vote up
public void setFormKey(Expression formKey) {
  this.formKey = formKey;
}
 
Example #27
Source Project: activiti6-boot2   Author: dingziyang   File: ClassDelegate.java    License: Apache License 2.0 4 votes vote down vote up
public ClassDelegate(Class<?> clazz, List<FieldDeclaration> fieldDeclarations, Expression skipExpression) {
  this(clazz.getName(), fieldDeclarations, skipExpression);
}
 
Example #28
Source Project: activiti6-boot2   Author: dingziyang   File: FormPropertyHandler.java    License: Apache License 2.0 4 votes vote down vote up
public Expression getVariableExpression() {
  return variableExpression;
}
 
Example #29
Source Project: activiti6-boot2   Author: dingziyang   File: FormPropertyHandler.java    License: Apache License 2.0 4 votes vote down vote up
public void setVariableExpression(Expression variableExpression) {
  this.variableExpression = variableExpression;
}
 
Example #30
Source Project: activiti6-boot2   Author: dingziyang   File: MuleSendActivitiBehavior.java    License: Apache License 2.0 4 votes vote down vote up
public Expression getEndpointUrl() {
  return endpointUrl;
}