Java Code Examples for org.flowable.task.service.delegate.DelegateTask#setVariable()

The following examples show how to use org.flowable.task.service.delegate.DelegateTask#setVariable() . 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: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    Map<String, Object> transientVariables = delegateTask.getTransientVariables();
    List<String> variableNames = new ArrayList<>(transientVariables.keySet());
    Collections.sort(variableNames);

    StringBuilder strb = new StringBuilder();
    for (String variableName : variableNames) {
        if (variableName.startsWith("transientResult")) {
            String result = (String) transientVariables.get(variableName);
            strb.append(result);
        }
    }

    delegateTask.setVariable("mergedResult", strb.toString());
}
 
Example 2
Source File: SetRandomVariablesTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    String varName;
    for (int i = 0; i < 5; i++) {
        varName = "variable-" + new Random().nextInt(10);
        delegateTask.setVariable(varName, getRandomValue());
    }

    for (int i = 0; i < 5; i++) {
        varName = "task-variable-" + new Random().nextInt(10);
        delegateTask.setVariableLocal(varName, getRandomValue());
    }
}
 
Example 3
Source File: TaskAllEventsListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    String events = (String) delegateTask.getVariable("events");
    if (events == null) {
        events = delegateTask.getEventName();
    } else {
        events = events + " - " + delegateTask.getEventName();
    }
    delegateTask.setVariable("events", events);
}
 
Example 4
Source File: DelegateTaskTestTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateTask delegateTask) {
    Set<IdentityLink> candidates = delegateTask.getCandidates();
    Set<String> candidateUsers = new HashSet<String>();
    Set<String> candidateGroups = new HashSet<String>();
    for (IdentityLink candidate : candidates) {
        if (candidate.getUserId() != null) {
            candidateUsers.add(candidate.getUserId());
        } else if (candidate.getGroupId() != null) {
            candidateGroups.add(candidate.getGroupId());
        }
    }
    delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
    delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);
}
 
Example 5
Source File: TaskCompletionListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    Integer counter = (Integer) delegateTask.getVariable("taskListenerCounter");
    if (counter == null) {
        counter = 0;
    }
    delegateTask.setVariable("taskListenerCounter", ++counter);
}
 
Example 6
Source File: ScriptTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    validateParameters();

    ScriptingEngines scriptingEngines = CommandContextUtil.getProcessEngineConfiguration().getScriptingEngines();
    Object result = scriptingEngines.evaluate(script.getExpressionText(), language.getExpressionText(), delegateTask, autoStoreVariables);

    if (resultVariable != null) {
        delegateTask.setVariable(resultVariable.getExpressionText(), result);
    }
}
 
Example 7
Source File: TestTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    Expression inputExpression = DelegateHelper.getFieldExpression(delegateTask, "input");
    Number input = (Number) inputExpression.getValue(delegateTask);

    int result = input.intValue() / 2;

    Expression resultVarExpression = DelegateHelper.getFieldExpression(delegateTask, "resultVar");
    delegateTask.setVariable(resultVarExpression.getValue(delegateTask).toString(), result);
}
 
Example 8
Source File: DelegateTaskTestTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    Set<IdentityLink> candidates = delegateTask.getCandidates();
    Set<String> candidateUsers = new HashSet<>();
    Set<String> candidateGroups = new HashSet<>();
    for (IdentityLink candidate : candidates) {
        if (candidate.getUserId() != null) {
            candidateUsers.add(candidate.getUserId());
        } else if (candidate.getGroupId() != null) {
            candidateGroups.add(candidate.getGroupId());
        }
    }
    delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
    delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);
}
 
Example 9
Source File: TaskAllEventsListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateTask delegateTask) {
    String events = (String) delegateTask.getVariable("events");
    if (events == null) {
        events = delegateTask.getEventName();
    } else {
        events = events + " - " + delegateTask.getEventName();
    }
    delegateTask.setVariable("events", events);
}
 
Example 10
Source File: MyTaskListenerBean.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("taskListenerVar", "working");
    if (someField != null) {
        delegateTask.setVariable("taskListenerField", someField.getValue(delegateTask));
    }
}
 
Example 11
Source File: TaskServiceTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("variableFromClassDelegate", "From class delegate");
}
 
Example 12
Source File: MyTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("calledThroughNotify", delegateTask.getName() + "-notify");
}
 
Example 13
Source File: TestCacheTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
    TaskService taskService = processEngineConfiguration.getTaskService();
    Task task = taskService.createTaskQuery().taskId(delegateTask.getId()).singleResult();
    if (task != null && task.getId().equals(delegateTask.getId())) {
        TASK_ID = task.getId();
    }
    
    HistoryService historyService = processEngineConfiguration.getHistoryService();
    HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(delegateTask.getId()).singleResult();
    if (historicTask != null && historicTask.getId().equals(delegateTask.getId())) {
        HISTORIC_TASK_ID = historicTask.getId();
    }

    delegateTask.setVariable("varFromTheListener", "valueFromTheListener");
    delegateTask.setVariableLocal("localVar", "localValue");

    // Used in CacheTaskTest#testTaskQueryWithIncludeVariables
    ProcessInstance processInstance = processEngineConfiguration.getRuntimeService().createProcessInstanceQuery()
        .processInstanceId(task.getProcessInstanceId())
        .includeProcessVariables()
        .singleResult();
    PROCESS_VARIABLES = processInstance.getProcessVariables();

    HistoricProcessInstance historicProcessInstance = processEngineConfiguration.getHistoryService().createHistoricProcessInstanceQuery()
        .processInstanceId(task.getProcessInstanceId())
        .includeProcessVariables()
        .singleResult();
    HISTORIC_PROCESS_VARIABLES = historicProcessInstance.getProcessVariables();

    // Used in CacheTaskTest#testTaskQueryWithIncludeVariables
    Task taskFromQuery = processEngineConfiguration.getTaskService().createTaskQuery()
        .taskId(delegateTask.getId())
        .includeProcessVariables()
        .includeTaskLocalVariables()
        .singleResult();
    TASK_PROCESS_VARIABLES = taskFromQuery.getProcessVariables();
    TASK_LOCAL_VARIABLES = taskFromQuery.getTaskLocalVariables();

    HistoricTaskInstance historicTaskFromQuery = processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery()
        .taskId(delegateTask.getId())
        .includeProcessVariables()
        .includeTaskLocalVariables()
        .singleResult();
    HISTORIC_TASK_PROCESS_VARIABLES = historicTaskFromQuery.getProcessVariables();
    HISTORIC_TASK_LOCAL_VARIABLES = historicTaskFromQuery.getTaskLocalVariables();

}
 
Example 14
Source File: TestTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("variableFromClassDelegate", "Hello World from class delegate");
}
 
Example 15
Source File: TestTaskOriginalAssigneeListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("taskId", delegateTask.getId());
    delegateTask.setVariable("previousAssignee", ((TaskEntityImpl) delegateTask).getOriginalAssignee());
    delegateTask.setVariable("currentAssignee", delegateTask.getAssignee());
}
 
Example 16
Source File: MyTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void calledInExpression(DelegateTask task, String eventName) {
    task.setVariable("calledInExpression", task.getName() + "-" + eventName);
}
 
Example 17
Source File: MyTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("calledThroughNotify", delegateTask.getName() + "-notify");
}
 
Example 18
Source File: AsyncTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("taskListener", "listener invoked");
}
 
Example 19
Source File: AsyncTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("taskListener", "listener invoked");
}
 
Example 20
Source File: TaskCompleteListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void notify(DelegateTask delegateTask) {
    delegateTask.setVariable("greeting", "Hello from " + greeter.getValue(delegateTask));
    delegateTask.setVariable("shortName", shortName.getValue(delegateTask));

    delegateTask.setVariableLocal("myTaskVariable", "test");
}