Search in sources :

Example 36 with TaskService

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

the class ProcessDefinitionCacheTest 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 wasn't fetched from the DB after a redeploy.
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").setAsyncExecutorActivate(false).buildProcessEngine();
    processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy();
    // verify existence of process definition
    List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
    assertThat(processDefinitions).hasSize(1);
    // Start a new Process instance
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    String processInstanceId = processInstance.getId();
    assertThat(processInstance).isNotNull();
    // Close the process engine
    processEngine.close();
    assertThat(processEngine.getRuntimeService()).isNotNull();
    // Reboot the process engine
    processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();
    // Check if the existing process instance is still alive
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    assertThat(processInstance).isNotNull();
    // 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();
    assertThat(processInstance).isNull();
    // Extra check to see if a new process instance can be started as well
    processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    assertThat(processInstance).isNotNull();
    // close the process engine
    processEngine.close();
    // Cleanup schema
    schemaProcessEngine.close();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) TaskService(org.activiti.engine.TaskService) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) StandaloneInMemProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 37 with TaskService

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

the class ProcessWorkflowApiTest method testMNT12382.

@Test
public void testMNT12382() throws Exception {
    currentNetwork = getTestFixture().getRandomNetwork();
    TestPerson initiator = currentNetwork.getPeople().get(0);
    RequestContext requestContext = new RequestContext(currentNetwork.getId(), initiator.getId());
    publicApiClient.setRequestContext(requestContext);
    ProcessInfo processInfo = startReviewPooledProcess(requestContext);
    final List<TestPerson> persons = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<List<TestPerson>>() {

        @SuppressWarnings("synthetic-access")
        public List<TestPerson> execute() throws Throwable {
            ArrayList<TestPerson> persons = new ArrayList<TestPerson>();
            persons.add(currentNetwork.createUser(new PersonInfo("Maxim0", "Bobyleu0", "maxim0.bobyleu0", "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
            persons.add(currentNetwork.createUser(new PersonInfo("Maxim1", "Bobyleu1", "maxim1.bobyleu1", "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
            persons.add(currentNetwork.createUser(new PersonInfo("Maxim2", "Bobyleu2", "maxim2.bobyleu2", "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
            return persons;
        }
    }, false, true);
    final MemberOfSite memberOfSite = currentNetwork.getSiteMemberships(initiator.getId()).get(0);
    // startReviewPooledProcess() uses initiator's site id and role name for construct bpm_groupAssignee, thus we need appropriate things for created users
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    TestSite initiatorSite = (TestSite) memberOfSite.getSite();
                    initiatorSite.inviteToSite(persons.get(0).getId(), memberOfSite.getRole());
                    initiatorSite.inviteToSite(persons.get(1).getId(), memberOfSite.getRole());
                    // this user wouldn't be in group
                    initiatorSite.inviteToSite(persons.get(2).getId(), SiteRole.SiteConsumer == memberOfSite.getRole() ? SiteRole.SiteCollaborator : SiteRole.SiteConsumer);
                    return null;
                }
            }, AuthenticationUtil.getAdminUserName(), currentNetwork.getId());
            return null;
        }
    }, false, true);
    String processId = processInfo.getId();
    // getting process items by workflow initiator
    ProcessesClient processesClient = publicApiClient.processesClient();
    JSONObject initiatorItems = processesClient.findProcessItems(processId);
    // getting unclaimed process items by user in group
    requestContext = new RequestContext(currentNetwork.getId(), persons.get(0).getId());
    publicApiClient.setRequestContext(requestContext);
    JSONObject items1 = processesClient.findProcessItems(processId);
    assertEquals(initiatorItems.toJSONString(), items1.toJSONString());
    // getting unclaimed process items by user not in group
    requestContext = new RequestContext(currentNetwork.getId(), persons.get(2).getId());
    publicApiClient.setRequestContext(requestContext);
    try {
        JSONObject items2 = processesClient.findProcessItems(processId);
        fail("User not from group should not see items.");
    } catch (PublicApiException e) {
        // expected
        assertEquals(403, e.getHttpResponse().getStatusCode());
    }
    // claim task
    TaskService taskService = activitiProcessEngine.getTaskService();
    Task task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
    TestPerson assignee = persons.get(1);
    taskService.setAssignee(task.getId(), assignee.getId());
    // getting claimed process items by assignee
    requestContext = new RequestContext(currentNetwork.getId(), assignee.getId());
    publicApiClient.setRequestContext(requestContext);
    JSONObject items3 = processesClient.findProcessItems(processId);
    assertEquals(initiatorItems.toJSONString(), items3.toJSONString());
    // getting claimed process items by user in group
    requestContext = new RequestContext(currentNetwork.getId(), persons.get(0).getId());
    publicApiClient.setRequestContext(requestContext);
    try {
        JSONObject items4 = processesClient.findProcessItems(processId);
        fail("User from group should not see items for claimed task by another user.");
    } catch (PublicApiException e) {
        // expected
        assertEquals(403, e.getHttpResponse().getStatusCode());
    } finally {
        cleanupProcessInstance(processId);
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Task(org.activiti.engine.task.Task) PersonInfo(org.alfresco.rest.api.tests.PersonInfo) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) TaskService(org.activiti.engine.TaskService) ArrayList(java.util.ArrayList) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Test(org.junit.Test)

Example 38 with TaskService

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

the class TaskWorkflowApiTest method testUpdateTaskMnt13276.

@Test
@SuppressWarnings("unchecked")
public void testUpdateTaskMnt13276() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    String initiatorId = requestContext.getRunAsUser();
    ProcessInfo processInfo = startReviewPooledProcess(requestContext);
    // create test users
    final List<TestPerson> persons = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<List<TestPerson>>() {

        @SuppressWarnings("synthetic-access")
        public List<TestPerson> execute() throws Throwable {
            ArrayList<TestPerson> persons = new ArrayList<TestPerson>();
            String temp = "_" + System.currentTimeMillis();
            persons.add(currentNetwork.createUser(new PersonInfo("user0", "user0", "user0" + temp, "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
            persons.add(currentNetwork.createUser(new PersonInfo("user1", "user1", "user1" + temp, "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
            persons.add(currentNetwork.createUser(new PersonInfo("user2", "user2", "user2" + temp, "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
            return persons;
        }
    }, false, true);
    final MemberOfSite memberOfSite = currentNetwork.getSiteMemberships(initiatorId).get(0);
    // startReviewPooledProcess() uses initiator's site id and role name for construct bpm_groupAssignee, thus we need appropriate things for created users
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    TestSite initiatorSite = (TestSite) memberOfSite.getSite();
                    initiatorSite.inviteToSite(persons.get(0).getId(), memberOfSite.getRole());
                    initiatorSite.inviteToSite(persons.get(1).getId(), memberOfSite.getRole());
                    // this user wouldn't be in group
                    initiatorSite.inviteToSite(persons.get(2).getId(), SiteRole.SiteConsumer == memberOfSite.getRole() ? SiteRole.SiteCollaborator : SiteRole.SiteConsumer);
                    return null;
                }
            }, AuthenticationUtil.getAdminUserName(), currentNetwork.getId());
            return null;
        }
    }, false, true);
    try {
        Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
        TasksClient tasksClient = publicApiClient.tasksClient();
        // Updating the task by user in group
        JSONObject taskBody = new JSONObject();
        taskBody.put("name", "Updated name by user in group");
        List<String> selectedFields = new ArrayList<String>();
        selectedFields.addAll(Arrays.asList(new String[] { "name" }));
        requestContext.setRunAsUser(persons.get(0).getId());
        JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
        assertEquals("Updated name by user in group", result.get("name"));
        task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
        assertNotNull(task);
        assertEquals("Updated name by user in group", task.getName());
        // Updating the task by user not in group
        try {
            taskBody.put("name", "Updated name by user not in group");
            requestContext.setRunAsUser(persons.get(2).getId());
            tasksClient.updateTask(task.getId(), taskBody, selectedFields);
            fail("User not from group should not see items.");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Permission was denied", expected.getHttpResponse());
        }
        // claim task
        TaskService taskService = activitiProcessEngine.getTaskService();
        task = taskService.createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
        taskService.setAssignee(task.getId(), persons.get(1).getId());
        // Updating by user in group for claimed task by another user
        try {
            taskBody = new JSONObject();
            taskBody.put("name", "Updated name by user in group for claimed task");
            selectedFields.addAll(Arrays.asList(new String[] { "name" }));
            requestContext.setRunAsUser(persons.get(0).getId());
            result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
            fail("User from group should not see items for claimed task by another user.");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Permission was denied", expected.getHttpResponse());
        }
    } finally {
        cleanupProcessInstance(processInfo.getId());
    }
}
Also used : Task(org.activiti.engine.task.Task) PersonInfo(org.alfresco.rest.api.tests.PersonInfo) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) TaskService(org.activiti.engine.TaskService) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ArrayList(java.util.ArrayList) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) List(java.util.List) ArrayList(java.util.ArrayList) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) 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