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;
}
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));
}
}
}
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);
}
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();
}
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[] {}));
}
}
Aggregations