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 File: ActivitiHelperTest.java    From herd with 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 File: ActivitiHelperTest.java    From herd with 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 #3
Source File: BpmnDeployer.java    From activiti6-boot2 with 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 File: TaskDelagationAssignmentHandler.java    From openwebflow with 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 #5
Source File: ConditionUtil.java    From activiti6-boot2 with 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 #6
Source File: MyUserTaskActivityBehavior.java    From openwebflow with 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 #7
Source File: SkipEventListener.java    From lemon with 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 #8
Source File: SkipExpressionUtil.java    From activiti6-boot2 with 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 #9
Source File: MailActivityBehavior.java    From activiti6-boot2 with 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 #10
Source File: DefaultFormHandler.java    From activiti6-boot2 with 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 #11
Source File: MailActivityBehavior.java    From activiti6-boot2 with 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 #12
Source File: ConvertDateToISO8601.java    From alfresco-repository with 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 #13
Source File: ActivitiHelperTest.java    From herd with 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 #14
Source File: DefaultActivityBehaviorFactory.java    From activiti6-boot2 with 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 #15
Source File: DefaultActivityBehaviorFactory.java    From activiti6-boot2 with 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 #16
Source File: MailActivityBehavior.java    From activiti6-boot2 with 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 #17
Source File: WorkflowTraceService.java    From maven-framework-project with 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 #18
Source File: ActivitiHelperTest.java    From herd with 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 #19
Source File: ExpressionUtils.java    From openwebflow with 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 #20
Source File: AbstractExternalInvocationBpmnParseHandler.java    From activiti6-boot2 with 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 #21
Source File: MailActivityBehavior.java    From activiti6-boot2 with 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 #22
Source File: ScriptExecutionListener.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setScript(Expression script) {
  this.script = script;
}
 
Example #23
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Expression getCollectionExpression() {
  return collectionExpression;
}
 
Example #24
Source File: Assignment.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Assignment(Expression fromExpression, Expression toExpression) {
  this.fromExpression = fromExpression;
  this.toExpression = toExpression;
}
 
Example #25
Source File: DefaultFormHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setFormKey(Expression formKey) {
  this.formKey = formKey;
}
 
Example #26
Source File: MuleSendActivitiBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setPayloadExpression(Expression payloadExpression) {
  this.payloadExpression = payloadExpression;
}
 
Example #27
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ClassDelegate(String id, String className, List<FieldDeclaration> fieldDeclarations, Expression skipExpression, List<MapExceptionEntry> mapExceptions) {
  this(className, fieldDeclarations, skipExpression);
  this.serviceTaskId = id;
  this.mapExceptions = mapExceptions;
}
 
Example #28
Source File: ConvertDateToISO8601.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setSource(Expression source)
{
    this.source = source;
}
 
Example #29
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Expression getCompletionConditionExpression() {
  return completionConditionExpression;
}
 
Example #30
Source File: TaskDefinition.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setBusinessCalendarNameExpression(Expression businessCalendarNameExpression) {
  this.businessCalendarNameExpression = businessCalendarNameExpression;
}