Search in sources :

Example 81 with UserTaskInstanceDesc

use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.

the class UserTaskAdminServiceImplTest method testGetTaskInstancesAsPotOwnersMultipleInstances.

@Test
public void testGetTaskInstancesAsPotOwnersMultipleInstances() {
    String PO_TASK_QUERY = "select ti.taskId, ti.activationTime, ti.actualOwner, ti.createdBy, ti.createdOn, ti.deploymentId, " + "ti.description, ti.dueDate, ti.name, ti.parentId, ti.priority, ti.processId, ti.processInstanceId, " + "ti.processSessionId, ti.status, ti.workItemId, oe.id, eo.entity_id " + "from AuditTaskImpl ti " + "left join PeopleAssignments_PotOwners po on ti.taskId = po.task_id " + "left join OrganizationalEntity oe on po.entity_id = oe.id " + " left join PeopleAssignments_ExclOwners eo on ti.taskId = eo.task_id ";
    SqlQueryDefinition query = new SqlQueryDefinition("getMyTaskInstances", "jdbc/testDS1", Target.PO_TASK);
    query.setExpression(PO_TASK_QUERY);
    queryService.registerQuery(query);
    List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
    assertNotNull(queries);
    assertEquals(1, queries.size());
    QueryDefinition registeredQuery = queries.get(0);
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    registeredQuery = queryService.getQuery(query.getName());
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    Long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    assertNotNull(processInstanceId2);
    identityProvider.setName("notvalid");
    List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    identityProvider.setName("salaboy");
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(2, taskInstanceLogs.size());
    identityProvider.setName("Administrator");
    userTaskAdminService.addPotentialOwners(taskInstanceLogs.get(0).getTaskId(), false, factory.newUser("john"));
    identityProvider.setName("salaboy");
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(2, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
    processService.abortProcessInstance(processInstanceId2);
    processInstanceId2 = null;
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 82 with UserTaskInstanceDesc

use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.

the class RuntimeDataServiceImpl method getTaskEvents.

public List<TaskEvent> getTaskEvents(long taskId, QueryFilter filter) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("taskId", taskId);
    applyQueryContext(params, filter);
    applyQueryFilter(params, filter);
    List<TaskEvent> taskEvents = commandService.execute(new QueryNameCommand<List<TaskEvent>>("getAllTasksEvents", params));
    if (taskEvents == null || taskEvents.isEmpty()) {
        UserTaskInstanceDesc task = getTaskById(taskId);
        if (task == null) {
            throw new TaskNotFoundException(MessageFormat.format(TASK_NOT_FOUND, taskId));
        }
    }
    return taskEvents;
}
Also used : TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) HashMap(java.util.HashMap) TaskEvent(org.kie.internal.task.api.model.TaskEvent) List(java.util.List) ArrayList(java.util.ArrayList) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 83 with UserTaskInstanceDesc

use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.

the class RuntimeDataServiceImpl method getProcessInstanceById.

public ProcessInstanceDesc getProcessInstanceById(long processId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("processId", processId);
    params.put("maxResults", 1);
    List<ProcessInstanceDesc> processInstances = commandService.execute(new QueryNameCommand<List<ProcessInstanceDesc>>("getProcessInstanceById", params));
    if (!processInstances.isEmpty()) {
        ProcessInstanceDesc desc = processInstances.iterator().next();
        List<String> statuses = new ArrayList<String>();
        statuses.add(Status.Ready.name());
        statuses.add(Status.Reserved.name());
        statuses.add(Status.InProgress.name());
        params = new HashMap<String, Object>();
        params.put("processInstanceId", desc.getId());
        params.put("statuses", statuses);
        List<UserTaskInstanceDesc> tasks = commandService.execute(new QueryNameCommand<List<UserTaskInstanceDesc>>("getTaskInstancesByProcessInstanceId", params));
        ((org.jbpm.kie.services.impl.model.ProcessInstanceDesc) desc).setActiveTasks(tasks);
        return desc;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) List(java.util.List) ArrayList(java.util.ArrayList) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 84 with UserTaskInstanceDesc

use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.

the class UserTaskServiceImpl method release.

@Override
public void release(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.release(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)

Example 85 with UserTaskInstanceDesc

use of org.jbpm.services.api.model.UserTaskInstanceDesc in project jbpm by kiegroup.

the class UserTaskServiceImpl method complete.

@Override
public void complete(String deploymentId, Long taskId, String userId, Map<String, Object> params) {
    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;
    }
    if (manager instanceof InternalRuntimeManager) {
        params = process(params, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        taskService.complete(taskId, userId, params);
    } catch (PermissionDeniedException e) {
        throw new TaskNotFoundException(e.getMessage());
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) 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

UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)118 Test (org.junit.Test)67 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)36 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)35 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)35 InternalTaskService (org.kie.internal.task.api.InternalTaskService)35 UserTaskService (org.jbpm.services.api.UserTaskService)34 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)34 TaskService (org.kie.api.task.TaskService)34 HashMap (java.util.HashMap)23 QueryContext (org.kie.api.runtime.query.QueryContext)22 ArrayList (java.util.ArrayList)18 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)16 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)16 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)15 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)11 QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 CorrelationKey (org.kie.internal.process.CorrelationKey)7 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)6