use of org.camunda.bpm.engine.TaskService in project camunda-bpm-platform by camunda.
the class TaskResourceImpl method setAssignee.
public void setAssignee(UserIdDto dto) {
TaskService taskService = engine.getTaskService();
taskService.setAssignee(taskId, dto.getUserId());
}
use of org.camunda.bpm.engine.TaskService in project camunda-bpm-platform by camunda.
the class RuntimeServiceTest method testStartProcessInstanceByIdAfterReboot.
// Test for a bug: when the process engine is rebooted the
// cache is cleaned and the deployed process definition is
// removed from the process cache. This led to problems because
// the id wasnt fetched from the DB after a redeploy.
@Test
public void testStartProcessInstanceByIdAfterReboot() {
// In case this test is run in a test suite, previous engines might
// have been initialized and cached. First we close the
// existing process engines to make sure that the db is clean
// and that there are no existing process engines involved.
ProcessEngines.destroy();
// Creating the DB schema (without building a process engine)
ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
processEngineConfiguration.setProcessEngineName("reboot-test-schema");
processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();
// Create process engine and deploy test process
ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
processEngine.getRepositoryService().createDeployment().addClasspathResource("org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml").deploy();
// verify existence of process definition
List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
assertEquals(1, processDefinitions.size());
// Start a new Process instance
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
String processInstanceId = processInstance.getId();
assertNotNull(processInstance);
// Close the process engine
processEngine.close();
assertNotNull(processEngine.getRuntimeService());
// Reboot the process engine
processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.camunda.bpm.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
// Check if the existing process instance is still alive
processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNotNull(processInstance);
// Complete the task. That will end the process instance
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery().list().get(0);
taskService.complete(task.getId());
// Check if the process instance has really ended. This means that the process definition has
// re-loaded into the process definition cache
processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNull(processInstance);
// Extra check to see if a new process instance can be started as well
processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
assertNotNull(processInstance);
// close the process engine
processEngine.close();
// Cleanup schema
schemaProcessEngine.close();
}
use of org.camunda.bpm.engine.TaskService in project camunda-bpm-platform by camunda.
the class RepositoryServiceTest method testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
// Setup both process engines
ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema").setDatabaseSchemaUpdate(org.camunda.bpm.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
RepositoryService repositoryService1 = processEngine1.getRepositoryService();
ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.camunda.bpm.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(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/camunda/bpm/engine/test/api/repository/RepositoryServiceTest.testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.v1.bpmn20.xml").deploy().getId();
// Start process instance on second engine
String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
runtimeService2.startProcessInstanceById(processDefinitionId);
Task task = taskService2.createTaskQuery().singleResult();
assertEquals("original task", task.getName());
// Delete the deployment on second process engine
repositoryService2.deleteDeployment(deploymentId, true);
assertEquals(0, repositoryService2.createDeploymentQuery().count());
assertEquals(0, runtimeService2.createProcessInstanceQuery().count());
// 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/camunda/bpm/engine/test/api/repository/RepositoryServiceTest.testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.v2.bpmn20.xml").deploy().getId();
// Start process instance on second process engine -> must use revised process definition
processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
runtimeService2.startProcessInstanceByKey("oneTaskProcess");
task = taskService2.createTaskQuery().singleResult();
assertEquals("revised task", task.getName());
// cleanup
repositoryService1.deleteDeployment(deploymentId, true);
processEngine1.close();
processEngine2.close();
}
use of org.camunda.bpm.engine.TaskService in project camunda-bpm-platform by camunda.
the class CompleteProcessWithUserTaskTest method testCompleteProcessWithUserTask.
@Test
@ScenarioUnderTest("init.1")
public void testCompleteProcessWithUserTask() {
// given an already started process instance
ProcessInstance oldInstance = rule.processInstance();
Assert.assertNotNull(oldInstance);
// which waits on an user task
TaskService taskService = rule.getTaskService();
Task userTask = taskService.createTaskQuery().processInstanceId(oldInstance.getId()).singleResult();
Assert.assertNotNull(userTask);
// when completing the user task
taskService.complete(userTask.getId());
// then there exists no more tasks
// and the process instance is also completed
Assert.assertEquals(0, rule.taskQuery().count());
rule.assertScenarioEnded();
}
use of org.camunda.bpm.engine.TaskService in project camunda-bpm-platform by camunda.
the class DemoDataGenerator method createUsers.
public void createUsers(ProcessEngine engine) {
final IdentityService identityService = engine.getIdentityService();
if (identityService.isReadOnly()) {
LOGGER.info("Identity service provider is Read Only, not creating any demo users.");
return;
}
User singleResult = identityService.createUserQuery().userId("demo").singleResult();
if (singleResult != null) {
return;
}
LOGGER.info("Generating demo data for invoice showcase");
User user = identityService.newUser("demo");
user.setFirstName("Demo");
user.setLastName("Demo");
user.setPassword("demo");
user.setEmail("demo@camunda.org");
identityService.saveUser(user);
User user2 = identityService.newUser("john");
user2.setFirstName("John");
user2.setLastName("Doe");
user2.setPassword("john");
user2.setEmail("john@camunda.org");
identityService.saveUser(user2);
User user3 = identityService.newUser("mary");
user3.setFirstName("Mary");
user3.setLastName("Anne");
user3.setPassword("mary");
user3.setEmail("mary@camunda.org");
identityService.saveUser(user3);
User user4 = identityService.newUser("peter");
user4.setFirstName("Peter");
user4.setLastName("Meter");
user4.setPassword("peter");
user4.setEmail("peter@camunda.org");
identityService.saveUser(user4);
Group salesGroup = identityService.newGroup("sales");
salesGroup.setName("Sales");
salesGroup.setType("WORKFLOW");
identityService.saveGroup(salesGroup);
Group accountingGroup = identityService.newGroup("accounting");
accountingGroup.setName("Accounting");
accountingGroup.setType("WORKFLOW");
identityService.saveGroup(accountingGroup);
Group managementGroup = identityService.newGroup("management");
managementGroup.setName("Management");
managementGroup.setType("WORKFLOW");
identityService.saveGroup(managementGroup);
final AuthorizationService authorizationService = engine.getAuthorizationService();
// create group
if (identityService.createGroupQuery().groupId(Groups.CAMUNDA_ADMIN).count() == 0) {
Group camundaAdminGroup = identityService.newGroup(Groups.CAMUNDA_ADMIN);
camundaAdminGroup.setName("camunda BPM Administrators");
camundaAdminGroup.setType(Groups.GROUP_TYPE_SYSTEM);
identityService.saveGroup(camundaAdminGroup);
}
// create ADMIN authorizations on all built-in resources
for (Resource resource : Resources.values()) {
if (authorizationService.createAuthorizationQuery().groupIdIn(Groups.CAMUNDA_ADMIN).resourceType(resource).resourceId(ANY).count() == 0) {
AuthorizationEntity userAdminAuth = new AuthorizationEntity(AUTH_TYPE_GRANT);
userAdminAuth.setGroupId(Groups.CAMUNDA_ADMIN);
userAdminAuth.setResource(resource);
userAdminAuth.setResourceId(ANY);
userAdminAuth.addPermission(ALL);
authorizationService.saveAuthorization(userAdminAuth);
}
}
identityService.createMembership("demo", "sales");
identityService.createMembership("demo", "accounting");
identityService.createMembership("demo", "management");
identityService.createMembership("demo", "camunda-admin");
identityService.createMembership("john", "sales");
identityService.createMembership("mary", "accounting");
identityService.createMembership("peter", "management");
// authorize groups for tasklist only:
Authorization salesTasklistAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
salesTasklistAuth.setGroupId("sales");
salesTasklistAuth.addPermission(ACCESS);
salesTasklistAuth.setResourceId("tasklist");
salesTasklistAuth.setResource(APPLICATION);
authorizationService.saveAuthorization(salesTasklistAuth);
Authorization salesReadProcessDefinition = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
salesReadProcessDefinition.setGroupId("sales");
salesReadProcessDefinition.addPermission(Permissions.READ);
salesReadProcessDefinition.addPermission(Permissions.READ_HISTORY);
salesReadProcessDefinition.setResource(Resources.PROCESS_DEFINITION);
// restrict to invoice process definition only
salesReadProcessDefinition.setResourceId("invoice");
authorizationService.saveAuthorization(salesReadProcessDefinition);
Authorization accountingTasklistAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
accountingTasklistAuth.setGroupId("accounting");
accountingTasklistAuth.addPermission(ACCESS);
accountingTasklistAuth.setResourceId("tasklist");
accountingTasklistAuth.setResource(APPLICATION);
authorizationService.saveAuthorization(accountingTasklistAuth);
Authorization accountingReadProcessDefinition = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
accountingReadProcessDefinition.setGroupId("accounting");
accountingReadProcessDefinition.addPermission(Permissions.READ);
accountingReadProcessDefinition.addPermission(Permissions.READ_HISTORY);
accountingReadProcessDefinition.setResource(Resources.PROCESS_DEFINITION);
// restrict to invoice process definition only
accountingReadProcessDefinition.setResourceId("invoice");
authorizationService.saveAuthorization(accountingReadProcessDefinition);
Authorization managementTasklistAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
managementTasklistAuth.setGroupId("management");
managementTasklistAuth.addPermission(ACCESS);
managementTasklistAuth.setResourceId("tasklist");
managementTasklistAuth.setResource(APPLICATION);
authorizationService.saveAuthorization(managementTasklistAuth);
Authorization managementReadProcessDefinition = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
managementReadProcessDefinition.setGroupId("management");
managementReadProcessDefinition.addPermission(Permissions.READ);
managementReadProcessDefinition.addPermission(Permissions.READ_HISTORY);
managementReadProcessDefinition.setResource(Resources.PROCESS_DEFINITION);
// restrict to invoice process definition only
managementReadProcessDefinition.setResourceId("invoice");
authorizationService.saveAuthorization(managementReadProcessDefinition);
Authorization salesDemoAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
salesDemoAuth.setGroupId("sales");
salesDemoAuth.setResource(USER);
salesDemoAuth.setResourceId("demo");
salesDemoAuth.addPermission(READ);
authorizationService.saveAuthorization(salesDemoAuth);
Authorization salesJohnAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
salesJohnAuth.setGroupId("sales");
salesJohnAuth.setResource(USER);
salesJohnAuth.setResourceId("john");
salesJohnAuth.addPermission(READ);
authorizationService.saveAuthorization(salesJohnAuth);
Authorization manDemoAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
manDemoAuth.setGroupId("management");
manDemoAuth.setResource(USER);
manDemoAuth.setResourceId("demo");
manDemoAuth.addPermission(READ);
authorizationService.saveAuthorization(manDemoAuth);
Authorization manPeterAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
manPeterAuth.setGroupId("management");
manPeterAuth.setResource(USER);
manPeterAuth.setResourceId("peter");
manPeterAuth.addPermission(READ);
authorizationService.saveAuthorization(manPeterAuth);
Authorization accDemoAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
accDemoAuth.setGroupId("accounting");
accDemoAuth.setResource(USER);
accDemoAuth.setResourceId("demo");
accDemoAuth.addPermission(READ);
authorizationService.saveAuthorization(accDemoAuth);
Authorization accMaryAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
accMaryAuth.setGroupId("accounting");
accMaryAuth.setResource(USER);
accMaryAuth.setResourceId("mary");
accMaryAuth.addPermission(READ);
authorizationService.saveAuthorization(accMaryAuth);
Authorization taskMaryAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
taskMaryAuth.setUserId("mary");
taskMaryAuth.setResource(TASK);
taskMaryAuth.setResourceId(ANY);
taskMaryAuth.addPermission(READ);
taskMaryAuth.addPermission(UPDATE);
authorizationService.saveAuthorization(taskMaryAuth);
// create default filters
FilterService filterService = engine.getFilterService();
Map<String, Object> filterProperties = new HashMap<String, Object>();
filterProperties.put("description", "Tasks assigned to me");
filterProperties.put("priority", -10);
addVariables(filterProperties);
TaskService taskService = engine.getTaskService();
TaskQuery query = taskService.createTaskQuery().taskAssigneeExpression("${currentUser()}");
Filter myTasksFilter = filterService.newTaskFilter().setName("My Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(myTasksFilter);
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to my Groups");
filterProperties.put("priority", -5);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskCandidateGroupInExpression("${currentUserGroups()}").taskUnassigned();
Filter groupTasksFilter = filterService.newTaskFilter().setName("My Group Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(groupTasksFilter);
// global read authorizations for these filters
Authorization globalMyTaskFilterRead = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
globalMyTaskFilterRead.setResource(FILTER);
globalMyTaskFilterRead.setResourceId(myTasksFilter.getId());
globalMyTaskFilterRead.addPermission(READ);
authorizationService.saveAuthorization(globalMyTaskFilterRead);
Authorization globalGroupFilterRead = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);
globalGroupFilterRead.setResource(FILTER);
globalGroupFilterRead.setResourceId(groupTasksFilter.getId());
globalGroupFilterRead.addPermission(READ);
authorizationService.saveAuthorization(globalGroupFilterRead);
// management filter
filterProperties.clear();
filterProperties.put("description", "Tasks for Group Accounting");
filterProperties.put("priority", -3);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskCandidateGroupIn(Arrays.asList("accounting")).taskUnassigned();
Filter candidateGroupTasksFilter = filterService.newTaskFilter().setName("Accounting").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(candidateGroupTasksFilter);
Authorization managementGroupFilterRead = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
managementGroupFilterRead.setResource(FILTER);
managementGroupFilterRead.setResourceId(candidateGroupTasksFilter.getId());
managementGroupFilterRead.addPermission(READ);
managementGroupFilterRead.setGroupId("accounting");
authorizationService.saveAuthorization(managementGroupFilterRead);
// john's tasks
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to John");
filterProperties.put("priority", -1);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskAssignee("john");
Filter johnsTasksFilter = filterService.newTaskFilter().setName("John's Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(johnsTasksFilter);
// mary's tasks
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to Mary");
filterProperties.put("priority", -1);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskAssignee("mary");
Filter marysTasksFilter = filterService.newTaskFilter().setName("Mary's Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(marysTasksFilter);
// peter's tasks
filterProperties.clear();
filterProperties.put("description", "Tasks assigned to Peter");
filterProperties.put("priority", -1);
addVariables(filterProperties);
query = taskService.createTaskQuery().taskAssignee("peter");
Filter petersTasksFilter = filterService.newTaskFilter().setName("Peter's Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(petersTasksFilter);
// all tasks
filterProperties.clear();
filterProperties.put("description", "All Tasks - Not recommended to be used in production :)");
filterProperties.put("priority", 10);
addVariables(filterProperties);
query = taskService.createTaskQuery();
Filter allTasksFilter = filterService.newTaskFilter().setName("All Tasks").setProperties(filterProperties).setOwner("demo").setQuery(query);
filterService.saveFilter(allTasksFilter);
}
Aggregations