org.flowable.task.service.delegate.DelegateTask Java Examples

The following examples show how to use org.flowable.task.service.delegate.DelegateTask. 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: ScriptTaskListener.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    if (script == null) {
        throw new IllegalArgumentException("The field 'script' should be set on the TaskListener");
    }

    if (language == null) {
        throw new IllegalArgumentException("The field 'language' should be set on the TaskListener");
    }

    ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();

    Object result = scriptingEngines.evaluate(script.getExpressionText(), language.getExpressionText(), delegateTask, autoStoreVariables);

    if (resultVariable != null) {
        delegateTask.setVariable(resultVariable.getExpressionText(), result);
    }
}
 
Example #2
Source File: AssigneeOverwriteFromVariable.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void notify(DelegateTask delegateTask) {
    // get mapping table from variable

    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(delegateTask.getExecutionId());
    Map<String, String> assigneeMappingTable = (Map<String, String>) execution.getVariable("assigneeMappingTable");

    // get assignee from process
    String assigneeFromProcessDefinition = delegateTask.getAssignee();

    // overwrite assignee if there is an entry in the mapping table
    if (assigneeMappingTable.containsKey(assigneeFromProcessDefinition)) {
        String assigneeFromMappingTable = assigneeMappingTable.get(assigneeFromProcessDefinition);
        delegateTask.setAssignee(assigneeFromMappingTable);
    }
}
 
Example #3
Source File: TestQueryWithIncludeVariabesTaskListener.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();

    ProcessInstance processInstance = processEngineConfiguration.getRuntimeService().createProcessInstanceQuery()
        .processInstanceId(delegateTask.getProcessInstanceId())
        .includeProcessVariables()
        .singleResult();
    PROCESS_INSTANCE_VARIABLES = processInstance.getProcessVariables();

    Task task = processEngineConfiguration.getTaskService().createTaskQuery()
        .taskId(delegateTask.getId())
        .includeProcessVariables()
        .singleResult();
    TASK_VARIABLES = task.getProcessVariables();

    TASK_LOCAL_VARIABLES = task.getTaskLocalVariables();

}
 
Example #4
Source File: DelegateExpressionTaskListener.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    // Note: we can't cache the result of the expression, because the
    // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
    Object delegate = expression.getValue(delegateTask);
    ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate);

    if (delegate instanceof TaskListener) {
        try {
            Context.getProcessEngineConfiguration()
                    .getDelegateInterceptor()
                    .handleInvocation(new TaskListenerInvocation((TaskListener) delegate, delegateTask));
        } catch (Exception e) {
            throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
        }
    } else {
        throw new ActivitiIllegalArgumentException("Delegate expression " + expression
                + " did not resolve to an implementation of " + TaskListener.class);
    }
}
 
Example #5
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void fireEvent(String taskEventName) {
    TaskDefinition taskDefinition = getTaskDefinition();
    if (taskDefinition != null) {
        List<TaskListener> taskEventListeners = getTaskDefinition().getTaskListener(taskEventName);
        if (taskEventListeners != null) {
            for (TaskListener taskListener : taskEventListeners) {
                ExecutionEntity execution = getExecution();
                if (execution != null) {
                    setEventName(taskEventName);
                }
                try {
                    Context.getProcessEngineConfiguration()
                            .getDelegateInterceptor()
                            .handleInvocation(new TaskListenerInvocation(taskListener, (DelegateTask) this));
                } catch (Exception e) {
                    throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
                }
            }
        }
    }
}
 
Example #6
Source File: SpringIdmTransactionsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {

    // save group
    Group group = identityService.newGroup("group");
    identityService.saveGroup(group);
    // save users
    User tom = identityService.newUser("tom");
    identityService.saveUser(tom);

    User mat = identityService.newUser("mat");
    identityService.saveUser(mat);
    // create memberships
    identityService.createMembership(tom.getId(), group.getId());
    identityService.createMembership(mat.getId(), group.getId());
}
 
Example #7
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 #8
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 #9
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 #10
Source File: SpringIdmTransactionsTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();
    User user = identityService.newUser("Kermit");
    user.setFirstName("Mr");
    user.setLastName("Kermit");
    identityService.saveUser(user);
}
 
Example #11
Source File: ClassDelegate.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    TaskListener taskListenerInstance = getTaskListenerInstance();

    try {
        CommandContextUtil.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation(taskListenerInstance, delegateTask));
    } catch (Exception e) {
        throw new FlowableException("Exception while invoking TaskListener: " + e.getMessage(), e);
    }
}
 
Example #12
Source File: UserTaskExecutionListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    SimulationEvent eventToSimulate = findUserTaskCompleteEvent(delegateTask);
    if (eventToSimulate != null) {
        Map<String, Object> properties = new HashMap<>();
        properties.put("taskId", delegateTask.getId());
        properties.put("variables", eventToSimulate.getProperty(UserTaskCompleteTransformer.TASK_VARIABLES));
        // we were able to resolve event to simulate automatically
        SimulationEvent e = new SimulationEvent.Builder(typeToCreate).properties(properties).build();
        SimulationRunContext.getEventCalendar().addEvent(e);
    }
}
 
Example #13
Source File: UserTaskExecutionListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private SimulationEvent findUserTaskCompleteEvent(DelegateTask delegateTask) {
    if (delegateTask.hasVariable(StartReplayProcessEventHandler.PROCESS_INSTANCE_ID)) {
        String toSimulateProcessInstanceId = (String) delegateTask.getVariable(StartReplayProcessEventHandler.PROCESS_INSTANCE_ID);
        String toSimulateTaskDefinitionKey = delegateTask.getTaskDefinitionKey();
        for (SimulationEvent e : events) {
            if (typeToFind.equals(e.getType()) && toSimulateProcessInstanceId.equals(e.getProperty(UserTaskCompleteTransformer.PROCESS_INSTANCE_ID))
                    && toSimulateTaskDefinitionKey.equals(e.getProperty(UserTaskCompleteTransformer.TASK_DEFINITION_KEY)))
                return e;
        }
    }
    return null;
}
 
Example #14
Source File: IdmTransactionsTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();
    User user = identityService.newUser("Kermit");
    user.setFirstName("Mr");
    user.setLastName("Kermit");
    identityService.saveUser(user);
}
 
Example #15
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 #16
Source File: ClassDelegate.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    if (taskListenerInstance == null) {
        taskListenerInstance = getTaskListenerInstance();
    }
    try {
        Context.getProcessEngineConfiguration()
                .getDelegateInterceptor()
                .handleInvocation(new TaskListenerInvocation(taskListenerInstance, delegateTask));
    } catch (Exception e) {
        throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
    }
}
 
Example #17
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 #18
Source File: CustomListenerFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public TaskListener createExpressionTaskListener(FlowableListener activitiListener) {
    return new TaskListener() {
        @Override
        public void notify(DelegateTask delegateTask) {
            CustomListenerFactoryTest.COUNTER.addAndGet(100);
        }
    };
}
 
Example #19
Source File: TaskCompletionListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateTask delegateTask) {
    Integer counter = (Integer) delegateTask.getVariable("taskListenerCounter");
    if (counter == null) {
        counter = 0;
    }
    delegateTask.setVariable("taskListenerCounter", ++counter);
}
 
Example #20
Source File: CustomListenerFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public TaskListener createExpressionTaskListener(FlowableListener activitiListener) {
    return new TaskListener() {
        public void notify(DelegateTask delegateTask) {
            CustomListenerFactoryTest.COUNTER.addAndGet(100);
        }
    };
}
 
Example #21
Source File: SecureJavascriptTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    validateParameters();
    if (SecureJavascriptTaskParseHandler.LANGUAGE_JAVASCRIPT.equalsIgnoreCase(language.getValue(delegateTask).toString())) {
        Object result = SecureJavascriptUtil.evaluateScript(delegateTask, script.getExpressionText());
        if (resultVariable != null) {
            delegateTask.setVariable(resultVariable.getExpressionText(), result);
        }
    } else {
        super.notify(delegateTask);
    }
}
 
Example #22
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 #23
Source File: DelegateHelper.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Similar to {@link #getFieldExpression(DelegateExecution, String)}, but for use within a {@link TaskListener}.
 */
public static Expression getFieldExpression(DelegateTask task, String fieldName) {
    String eventHandlerId = task.getEventHandlerId();
    if (eventHandlerId != null && task.getProcessDefinitionId() != null) {
        org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(task.getProcessDefinitionId());
        UserTask userTask = (UserTask) process.getFlowElementMap().get(task.getTaskDefinitionKey());
        
        FlowableListener flowableListener = null;
        for (FlowableListener f : userTask.getTaskListeners()) {
            if (f.getId() != null && f.getId().equals(eventHandlerId)) {
                flowableListener = f;
            }
        }
        
        if (flowableListener != null) {
            List<FieldExtension> fieldExtensions = flowableListener.getFieldExtensions();
            if (fieldExtensions != null && fieldExtensions.size() > 0) {
                for (FieldExtension fieldExtension : fieldExtensions) {
                    if (fieldName.equals(fieldExtension.getFieldName())) {
                        return createExpressionForField(fieldExtension);
                    }
                }
            }
        }
    }
    return null;
}
 
Example #24
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 #25
Source File: MyTaskListenerBean.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(delegateTask.getExecutionId());
    execution.setVariable("taskListenerVar", "working");
    if (someField != null) {
        execution.setVariable("taskListenerField", someField.getValue(delegateTask));
    }
}
 
Example #26
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);
        ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(delegateTask.getExecutionId());
        execution.setVariable(varName, getRandomValue());
    }

    for (int i = 0; i < 5; i++) {
        varName = "task-variable-" + new Random().nextInt(10);
        delegateTask.setVariableLocal(varName, getRandomValue());
    }
}
 
Example #27
Source File: CmmnClassDelegate.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected TaskListener getTaskListenerInstance(DelegateTask delegateTask) {
    Object delegateInstance = instantiate(className);
    applyFieldExtensions(fieldExtensions, delegateTask, false);

    if (delegateInstance instanceof TaskListener) {
        return (TaskListener) delegateInstance;
    } else {
        throw new FlowableIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + TaskListener.class);
    }
}
 
Example #28
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 #29
Source File: TaskCompleteListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(delegateTask.getExecutionId());
    execution.setVariable("greeting", "Hello from " + greeter.getValue(execution));
    execution.setVariable("shortName", shortName.getValue(execution));

    delegateTask.setVariableLocal("myTaskVariable", "test");
}
 
Example #30
Source File: CdiTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask task) {
    // test whether cdi is setup correctly. (if not, just do not deliver the
    // event)
    try {
        ProgrammaticBeanLookup.lookup(ProcessEngine.class);
    } catch (Exception e) {
        return;
    }

    BusinessProcessEvent event = createEvent(task);
    Annotation[] qualifiers = getQualifiers(event);
    getBeanManager().fireEvent(event, qualifiers);
}