Search in sources :

Example 16 with TaskService

use of org.activiti.engine.TaskService in project crnk-framework by crnk-project.

the class ActivitiTestBase method addTask.

protected Task addTask(String name, int priority) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.newTask();
    task.setName(name);
    task.setPriority(priority);
    task.setAssignee("john");
    task.setCategory("testCategory");
    task.setDueDate(new Date());
    task.setOwner("jane");
    task.setDescription("testDescription");
    task.setTenantId("testTenant");
    taskService.saveTask(task);
    return task;
}
Also used : Task(org.activiti.engine.task.Task) ApproveTask(io.crnk.activiti.example.model.ApproveTask) TaskService(org.activiti.engine.TaskService) Date(java.util.Date)

Example 17 with TaskService

use of org.activiti.engine.TaskService in project crnk-framework by crnk-project.

the class ActivitiModule method setupModule.

@Override
public void setupModule(ModuleContext context) {
    this.moduleContext = context;
    TaskService taskService = processEngine.getTaskService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    FormService formService = processEngine.getFormService();
    resourceMapper = new ActivitiResourceMapper(context.getTypeParser(), config.getDateTimeMapper());
    for (ProcessInstanceConfig processInstanceConfig : config.getProcessInstances().values()) {
        context.addRepository(new ProcessInstanceResourceRepository(runtimeService, resourceMapper, processInstanceConfig.getProcessInstanceClass(), processInstanceConfig.getBaseFilters()));
        for (ProcessInstanceConfig.TaskRelationshipConfig taskRel : processInstanceConfig.getTaskRelationships().values()) {
            context.addRepository(new TaskRelationshipRepository(processInstanceConfig.getProcessInstanceClass(), taskRel.getTaskClass(), taskRel.getRelationshipName(), taskRel.getTaskDefinitionKey()));
        }
    }
    for (TaskRepositoryConfig taskConfig : config.getTasks().values()) {
        context.addRepository(new TaskResourceRepository(taskService, resourceMapper, taskConfig.getTaskClass(), taskConfig.getBaseFilters()));
        Class<? extends FormResource> formClass = taskConfig.getFormClass();
        if (formClass != null) {
            context.addRepository(new FormResourceRepository(formService, taskService, resourceMapper, formClass));
            context.addRepository(new FormRelationshipRepository(taskConfig.getTaskClass(), formClass));
        }
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ActivitiResourceMapper(io.crnk.activiti.mapper.ActivitiResourceMapper) TaskService(org.activiti.engine.TaskService) FormService(org.activiti.engine.FormService) ProcessInstanceResourceRepository(io.crnk.activiti.internal.repository.ProcessInstanceResourceRepository) TaskResourceRepository(io.crnk.activiti.internal.repository.TaskResourceRepository) FormResourceRepository(io.crnk.activiti.internal.repository.FormResourceRepository) FormRelationshipRepository(io.crnk.activiti.internal.repository.FormRelationshipRepository) TaskRelationshipRepository(io.crnk.activiti.internal.repository.TaskRelationshipRepository)

Example 18 with TaskService

use of org.activiti.engine.TaskService in project tutorials by eugenp.

the class ProcessExecutionIntegrationTest method givenProcessInstance_whenCompleteTask_thenProcessExecutionContinues.

@Test
public void givenProcessInstance_whenCompleteTask_thenProcessExecutionContinues() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment().addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml").deploy();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("employeeName", "Kermit");
    variables.put("numberOfDays", new Integer(4));
    variables.put("vacationMotivation", "I'm really tired!");
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("vacationRequest", variables);
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
    Task task = tasks.get(0);
    Map<String, Object> taskVariables = new HashMap<String, Object>();
    taskVariables.put("vacationApproved", "false");
    taskVariables.put("comments", "We have a tight deadline!");
    taskService.complete(task.getId(), taskVariables);
    Task currentTask = taskService.createTaskQuery().taskName("Modify vacation request").singleResult();
    assertNotNull(currentTask);
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 19 with TaskService

use of org.activiti.engine.TaskService in project Activiti by Activiti.

the class ProcessDefinitionCacheTest method testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.

public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();
    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService2 = processEngine2.getRepositoryService();
    RuntimeService runtimeService2 = processEngine2.getRuntimeService();
    TaskService taskService2 = processEngine2.getTaskService();
    // Deploy first version of process: start->originalTask->end on first
    // process engine
    String deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();
    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    Task task = taskService2.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("original task");
    // Delete the deployment on second process engine
    repositoryService2.deleteDeployment(deploymentId, true);
    assertThat(repositoryService2.createDeploymentQuery().count()).isEqualTo(0);
    assertThat(runtimeService2.createProcessInstanceQuery().count()).isEqualTo(0);
    // deploy a revised version of the process: start->revisedTask->end on
    // first process engine
    // 
    // Before the bugfix, this would set the cache on the first process
    // engine,
    // but the second process engine still has the original process
    // definition in his cache.
    // Since there is a deployment delete in between, the new generated
    // process definition id is the same
    // as in the original deployment, making the second process engine using
    // the old cached process definition.
    deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml").deploy().getId();
    // Start process instance on second process engine -> must use revised
    // process definition
    repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceByKey("oneTaskProcess");
    task = taskService2.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("revised task");
    // cleanup
    repositoryService1.deleteDeployment(deploymentId, true);
    processEngine1.close();
    processEngine2.close();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 20 with TaskService

use of org.activiti.engine.TaskService in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testGetTasksWithPagingAndVariablesLimit.

@Test
public void testGetTasksWithPagingAndVariablesLimit() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    List<ProcessInstance> startedProcesses = new ArrayList<ProcessInstance>();
    // system.workflow.engine.activiti.taskvariableslimit is set to 200 in test-resources/alfresco-global.properties
    try {
        // MNT-16040: Create tasks with a number of variables just below the taskvariableslimit and test that skipCount is working as expected.
        int numberOfTasks = 15;
        for (int i = 0; i < numberOfTasks; i++) {
            startedProcesses.add(startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null));
        }
        TaskService taskService = activitiProcessEngine.getTaskService();
        List<Task> taskList = new ArrayList<Task>();
        for (int i = 0; i < numberOfTasks; i++) {
            Task task = taskService.createTaskQuery().processInstanceId(startedProcesses.get(i).getProcessInstanceId()).singleResult();
            taskService.setPriority(task.getId(), (i + 1) * 10);
            // Add an extra variable to the task, there are other 12 added, so a total of 13 variables for each task.
            taskService.setVariableLocal(task.getId(), "test1", "test1");
            taskList.add(task);
        }
        TasksClient tasksClient = publicApiClient.tasksClient();
        // Test without skipCount
        Map<String, String> params = new HashMap<String, String>();
        params.put("where", "(includeProcessVariables = true AND includeTaskVariables = true)");
        JSONObject taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        JSONObject paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(15l, paginationJSON.get("count"));
        assertEquals(15l, paginationJSON.get("totalItems"));
        assertEquals(0l, paginationJSON.get("skipCount"));
        assertEquals(false, paginationJSON.get("hasMoreItems"));
        JSONArray jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(15, jsonEntries.size());
        // Test with skipCount
        params.clear();
        params.put("skipCount", "5");
        params.put("where", "(includeProcessVariables = true AND includeTaskVariables = true)");
        taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(10l, paginationJSON.get("count"));
        assertEquals(15l, paginationJSON.get("totalItems"));
        assertEquals(5l, paginationJSON.get("skipCount"));
        assertEquals(false, paginationJSON.get("hasMoreItems"));
        jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(10, jsonEntries.size());
        params.clear();
        params.put("maxItems", "10");
        params.put("where", "(includeProcessVariables = true AND includeTaskVariables = true)");
        taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(10l, paginationJSON.get("count"));
        assertEquals(15l, paginationJSON.get("totalItems"));
        assertEquals(0l, paginationJSON.get("skipCount"));
        assertEquals(true, paginationJSON.get("hasMoreItems"));
        jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(10, jsonEntries.size());
    } finally {
        cleanupProcessInstance(startedProcesses.toArray(new ProcessInstance[] {}));
    }
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) TaskService(org.activiti.engine.TaskService) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

TaskService (org.activiti.engine.TaskService)38 Task (org.activiti.engine.task.Task)25 Test (org.junit.Test)15 RuntimeService (org.activiti.engine.RuntimeService)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 ProcessEngine (org.activiti.engine.ProcessEngine)6 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 HashMap (java.util.HashMap)5 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)4 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)4 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)3 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 ArrayList (java.util.ArrayList)3 RepositoryService (org.activiti.engine.RepositoryService)3 Task (com.evolveum.midpoint.task.api.Task)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ExternalResource (com.vaadin.terminal.ExternalResource)2