Search in sources :

Example 66 with TaskService

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

the class DefaultChecklistManager method getTasks.

@SuppressWarnings("unchecked")
public List<ChecklistItem> getTasks(long processInstanceId) {
    RuntimeEngine runtime = getRuntime();
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    Map<String, ChecklistItem> orderingIds = new HashMap<String, ChecklistItem>();
    if (processInstance != null) {
        WorkflowProcess process = (WorkflowProcess) ksession.getKieBase().getProcess(processInstance.getProcessId());
        Collection<ChecklistItem> result = ChecklistItemFactory.getPendingChecklistItems(process);
        result.addAll(ChecklistItemFactory.getLoggedChecklistItems(process, (List<NodeInstanceLog>) runtime.getAuditService().findNodeInstances(processInstance.getId())));
        for (ChecklistItem item : result) {
            if (item.getOrderingNb() != null && item.getOrderingNb().trim().length() > 0) {
                orderingIds.put(item.getOrderingNb(), item);
            }
        }
    }
    TaskService taskService = runtime.getTaskService();
    List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstanceId);
    List<ChecklistItem> result = new ArrayList<ChecklistItem>();
    for (Long taskId : taskIds) {
        Task task = taskService.getTaskById(taskId);
        if (task != null) {
            ChecklistItem item = ChecklistItemFactory.createChecklistItem(task);
            if (item.getOrderingNb() != null) {
                orderingIds.put(item.getOrderingNb(), item);
            } else {
                result.add(item);
            }
        }
    }
    for (ChecklistItem item : orderingIds.values()) {
        result.add(item);
    }
    Collections.sort(result, new Comparator<ChecklistItem>() {

        public int compare(ChecklistItem o1, ChecklistItem o2) {
            if (o1.getOrderingNb() != null && o2.getOrderingNb() != null) {
                return o1.getOrderingNb().compareTo(o2.getOrderingNb());
            } else if (o1.getTaskId() != null && o2.getTaskId() != null) {
                return o1.getTaskId().compareTo(o2.getTaskId());
            } else {
                throw new IllegalArgumentException();
            }
        }
    });
    manager.disposeRuntimeEngine(runtime);
    return result;
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess)

Example 67 with TaskService

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

the class EvaluationExample method main.

public static final void main(String[] args) {
    try {
        RuntimeManager manager = getRuntimeManager("evaluation/Evaluation.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);
        // complete Self Evaluation
        TaskService taskService = runtime.getTaskService();
        List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
        TaskSummary task = tasks.get(0);
        System.out.println("'krisv' completing task " + task.getName() + ": " + task.getDescription());
        taskService.start(task.getId(), "krisv");
        Map<String, Object> results = new HashMap<String, Object>();
        results.put("performance", "exceeding");
        taskService.complete(task.getId(), "krisv", results);
        // john from HR
        tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        task = tasks.get(0);
        System.out.println("'john' completing task " + task.getName() + ": " + task.getDescription());
        taskService.start(task.getId(), "john");
        results = new HashMap<String, Object>();
        results.put("performance", "acceptable");
        taskService.complete(task.getId(), "john", results);
        // mary from PM
        tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
        task = tasks.get(0);
        System.out.println("'mary' completing task " + task.getName() + ": " + task.getDescription());
        taskService.start(task.getId(), "mary");
        results = new HashMap<String, Object>();
        results.put("performance", "outstanding");
        taskService.complete(task.getId(), "mary", results);
        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 68 with TaskService

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

the class MultipleInstanceExample method main.

public static final void main(String[] args) {
    try {
        RuntimeManager manager = getRuntimeManager("multipleinstance/multipleinstance.bpmn");
        RuntimeEngine runtime = manager.getRuntimeEngine(null);
        KieSession ksession = runtime.getKieSession();
        // start a new process instance
        Map<String, Object> params = new HashMap<String, Object>();
        List<String> list = new ArrayList<String>();
        list.add("krisv");
        list.add("john doe");
        list.add("superman");
        params.put("list", list);
        ksession.startProcess("com.sample.multipleinstance", params);
        TaskService taskService = runtime.getTaskService();
        List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK");
        for (TaskSummary task : tasks) {
            System.out.println("Sales-rep executing task " + task.getName() + "(" + task.getId() + ": " + task.getDescription() + ")");
            taskService.start(task.getId(), "sales-rep");
            taskService.complete(task.getId(), "sales-rep", null);
        }
        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) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession)

Example 69 with TaskService

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

the class ProcessTest method testEvaluationProcess.

@Test
public void testEvaluationProcess() {
    RuntimeManager manager = createRuntimeManager("Evaluation.bpmn");
    RuntimeEngine engine = getRuntimeEngine(null);
    KieSession ksession = engine.getKieSession();
    KieRuntimeLogger log = KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
    TaskService taskService = engine.getTaskService();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "krisv");
    params.put("reason", "Yearly performance evaluation");
    ProcessInstance processInstance = ksession.startProcess("com.sample.evaluation", params);
    System.out.println("Process started ...");
    // complete Self Evaluation
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    System.out.println("'krisv' completing task " + task.getName() + ": " + task.getDescription());
    taskService.start(task.getId(), "krisv");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("performance", "exceeding");
    taskService.complete(task.getId(), "krisv", results);
    // john from HR
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    System.out.println("'john' completing task " + task.getName() + ": " + task.getDescription());
    taskService.claim(task.getId(), "john");
    taskService.start(task.getId(), "john");
    results = new HashMap<String, Object>();
    results.put("performance", "acceptable");
    taskService.complete(task.getId(), "john", results);
    // mary from PM
    tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    System.out.println("'mary' completing task " + task.getName() + ": " + task.getDescription());
    taskService.claim(task.getId(), "mary");
    taskService.start(task.getId(), "mary");
    results = new HashMap<String, Object>();
    results.put("performance", "outstanding");
    taskService.complete(task.getId(), "mary", results);
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
    System.out.println("Process instance completed");
    log.close();
    manager.disposeRuntimeEngine(engine);
    manager.close();
}
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) KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 70 with TaskService

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

the class AbstractKieServicesBaseTest method configureServices.

protected void configureServices() {
    buildDatasource();
    emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.domain");
    identityProvider = new TestIdentityProvider();
    formManagerService = new FormManagerServiceImpl();
    // build definition service
    bpmn2Service = new BPMN2DataServiceImpl();
    queryService = new QueryServiceImpl();
    ((QueryServiceImpl) queryService).setIdentityProvider(identityProvider);
    ((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
    ((QueryServiceImpl) queryService).init();
    // build deployment service
    deploymentService = new KModuleDeploymentService();
    ((KModuleDeploymentService) deploymentService).setBpmn2Service(bpmn2Service);
    ((KModuleDeploymentService) deploymentService).setEmf(emf);
    ((KModuleDeploymentService) deploymentService).setIdentityProvider(identityProvider);
    ((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
    ((KModuleDeploymentService) deploymentService).setFormManagerService(formManagerService);
    TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).getTaskService();
    // build runtime data service
    runtimeDataService = new RuntimeDataServiceImpl();
    ((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
    ((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(identityProvider);
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
    ((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
    ((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
    // set runtime data service as listener on deployment service
    ((KModuleDeploymentService) deploymentService).addListener(((RuntimeDataServiceImpl) runtimeDataService));
    ((KModuleDeploymentService) deploymentService).addListener(((BPMN2DataServiceImpl) bpmn2Service));
    ((KModuleDeploymentService) deploymentService).addListener(((QueryServiceImpl) queryService));
    // build process service
    processService = new ProcessServiceImpl();
    ((ProcessServiceImpl) processService).setDataService(runtimeDataService);
    ((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
    // build user task service
    userTaskService = new UserTaskServiceImpl();
    ((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
    ((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
}
Also used : FormManagerServiceImpl(org.jbpm.kie.services.impl.FormManagerServiceImpl) BPMN2DataServiceImpl(org.jbpm.kie.services.impl.bpmn2.BPMN2DataServiceImpl) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) RuntimeManagerFactoryImpl(org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl) ProcessServiceImpl(org.jbpm.kie.services.impl.ProcessServiceImpl) RuntimeDataServiceImpl(org.jbpm.kie.services.impl.RuntimeDataServiceImpl) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) TestIdentityProvider(org.jbpm.kie.services.test.TestIdentityProvider) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) UserTaskServiceImpl(org.jbpm.kie.services.impl.UserTaskServiceImpl) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl)

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