Search in sources :

Example 1 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class DefaultChecklistManager method addTask.

public ChecklistItem addTask(String userId, String[] actorIds, String[] groupIds, String name, String orderingId, long processInstanceId) {
    RuntimeEngine runtime = getRuntime();
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    ;
    setTaskName(task, name);
    setTaskDescription(task, orderingId);
    // task.setPriority(priority);
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    taskData.setProcessInstanceId(processInstanceId);
    // taskData.setProcessSessionId(sessionId);
    taskData.setSkipable(false);
    taskData.setDeploymentId("default-singleton");
    User cuser = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) cuser).setId(userId);
    taskData.setCreatedBy(cuser);
    task.setTaskData(taskData);
    InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) task.getPeopleAssignments();
    if (peopleAssignments == null) {
        peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
        peopleAssignments.setPotentialOwners(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setBusinessAdministrators(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setExcludedOwners(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setRecipients(new ArrayList<OrganizationalEntity>());
        peopleAssignments.setTaskStakeholders(new ArrayList<OrganizationalEntity>());
        task.setPeopleAssignments(peopleAssignments);
    }
    List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();
    for (String actorId : actorIds) {
        User user = TaskModelProvider.getFactory().newUser();
        ((InternalOrganizationalEntity) user).setId(actorId);
        potentialOwners.add(user);
    }
    for (String groupId : groupIds) {
        Group group = TaskModelProvider.getFactory().newGroup();
        ((InternalOrganizationalEntity) group).setId(groupId);
        potentialOwners.add(group);
    }
    setTaskPotentialOwners(task, potentialOwners);
    List<OrganizationalEntity> businessAdministrators = peopleAssignments.getBusinessAdministrators();
    User administrator = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) administrator).setId("Administrator");
    businessAdministrators.add(administrator);
    TaskService taskService = runtime.getTaskService();
    long taskId = taskService.addTask(task, (Map<String, Object>) null);
    manager.disposeRuntimeEngine(runtime);
    return ChecklistItemFactory.createChecklistItem(taskService.getTaskById(taskId));
}
Also used : Group(org.kie.api.task.model.Group) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments)

Example 2 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class EvaluationExample2 method main.

public static final void main(String[] args) {
    try {
        RuntimeManager manager = getRuntimeManager("evaluation/Evaluation2.bpmn");
        RuntimeEngine runtime = manager.getRuntimeEngine(null);
        KieSession ksession = runtime.getKieSession();
        // start a new process instance
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("employee", "krisv");
        params.put("reason", "Yearly performance evaluation");
        ksession.startProcess("com.sample.evaluation", params);
        // "krisv" executes his own performance evaluation
        TaskService taskService = runtime.getTaskService();
        TaskSummary task1 = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK").get(0);
        System.out.println("Krisv executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
        taskService.start(task1.getId(), "krisv");
        taskService.complete(task1.getId(), "krisv", null);
        // "john", part of the "PM" group, executes a performance evaluation
        TaskSummary task2 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK").get(0);
        System.out.println("John executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")");
        System.out.println(taskService.getTasksAssignedAsPotentialOwner("john", "en-UK").size());
        taskService.claim(task2.getId(), "john");
        taskService.start(task2.getId(), "john");
        taskService.complete(task2.getId(), "john", null);
        // "mary", part of the "HR" group, delegates a performance evaluation
        TaskSummary task3 = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK").get(0);
        System.out.println("Mary delegating task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ") to krisv");
        taskService.claim(task3.getId(), "mary");
        taskService.delegate(task3.getId(), "mary", "krisv");
        // "administrator" delegates the task back to mary
        System.out.println("Administrator delegating task back to mary");
        taskService.delegate(task3.getId(), "Administrator", "mary");
        // mary executing the task
        TaskSummary task3b = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK").get(0);
        System.out.println("Mary executing task " + task3b.getName() + "(" + task3b.getId() + ": " + task3b.getDescription() + ")");
        taskService.start(task3b.getId(), "mary");
        taskService.complete(task3b.getId(), "mary", null);
        System.out.println("Process instance completed");
        manager.disposeRuntimeEngine(runtime);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession)

Example 3 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class HumanTaskExample method main.

public static final void main(String[] args) {
    try {
        RuntimeManager manager = getRuntimeManager("humantask/HumanTask.bpmn");
        RuntimeEngine runtime = manager.getRuntimeEngine(null);
        KieSession ksession = runtime.getKieSession();
        // start a new process instance
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "krisv");
        params.put("description", "Need a new laptop computer");
        ksession.startProcess("com.sample.humantask", params);
        // "sales-rep" reviews request
        TaskService taskService = runtime.getTaskService();
        TaskSummary task1 = taskService.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK").get(0);
        System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
        taskService.claim(task1.getId(), "sales-rep");
        taskService.start(task1.getId(), "sales-rep");
        Map<String, Object> results = new HashMap<String, Object>();
        results.put("comment", "Agreed, existing laptop needs replacing");
        results.put("outcome", "Accept");
        taskService.complete(task1.getId(), "sales-rep", results);
        // "krisv" approves result
        TaskSummary task2 = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK").get(0);
        System.out.println("krisv executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")");
        taskService.start(task2.getId(), "krisv");
        results = new HashMap<String, Object>();
        results.put("outcome", "Agree");
        taskService.complete(task2.getId(), "krisv", results);
        // "john" as manager reviews request
        TaskSummary task3 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK").get(0);
        System.out.println("john executing task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ")");
        taskService.claim(task3.getId(), "john");
        taskService.start(task3.getId(), "john");
        results = new HashMap<String, Object>();
        results.put("outcome", "Agree");
        taskService.complete(task3.getId(), "john", results);
        // "sales-rep" gets notification
        TaskSummary task4 = taskService.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK").get(0);
        System.out.println("sales-rep executing task " + task4.getName() + "(" + task4.getId() + ": " + task4.getDescription() + ")");
        taskService.start(task4.getId(), "sales-rep");
        Map<String, Object> content = taskService.getTaskContent(task4.getId());
        for (Map.Entry<?, ?> entry : content.entrySet()) {
            System.out.println(entry.getKey() + " = " + entry.getValue());
        }
        taskService.complete(task4.getId(), "sales-rep", null);
        System.out.println("Process instance completed");
        manager.disposeRuntimeEngine(runtime);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class UserTaskServiceImpl method addComment.

@Override
public Long addComment(String deploymentId, Long taskId, String text, String addedBy, Date addedOn) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
        comment.setText(text);
        comment.setAddedAt(addedOn);
        comment.setAddedBy(TaskModelProvider.getFactory().newUser(addedBy));
        return ((InternalTaskService) taskService).addComment(taskId, comment);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) InternalComment(org.kie.internal.task.api.model.InternalComment) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 5 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class UserTaskServiceImpl method claim.

@Override
public void claim(String deploymentId, Long taskId, String userId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        taskService.claim(taskId, userId);
    } catch (PermissionDeniedException e) {
        throw new TaskNotFoundException(e.getMessage());
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Aggregations

TaskService (org.kie.api.task.TaskService)129 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)111 KieSession (org.kie.api.runtime.KieSession)79 Test (org.junit.Test)73 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)70 TaskSummary (org.kie.api.task.model.TaskSummary)66 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)53 InternalTaskService (org.kie.internal.task.api.InternalTaskService)52 HashMap (java.util.HashMap)41 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)39 UserTaskService (org.jbpm.services.api.UserTaskService)38 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34 ArrayList (java.util.ArrayList)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15 Task (org.kie.api.task.model.Task)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)12 BZ (qa.tools.ikeeper.annotation.BZ)10 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)9