Search in sources :

Example 26 with MemberOfSite

use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.

the class EnterpriseWorkflowTestApi method startReviewPooledProcess.

/**
 * Start a review pooled process through the public REST-API.
 */
@SuppressWarnings("unchecked")
protected ProcessInfo startReviewPooledProcess(final RequestContext requestContext) throws PublicApiException {
    org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiReviewPooled").singleResult();
    ProcessesClient processesClient = publicApiClient.processesClient();
    final JSONObject createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionId", processDefinition.getId());
    final JSONObject variablesObject = new JSONObject();
    variablesObject.put("bpm_priority", 1);
    variablesObject.put("bpm_workflowDueDate", ISO8601DateFormat.format(new Date()));
    variablesObject.put("wf_notifyMe", Boolean.FALSE);
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            List<MemberOfSite> memberships = getTestFixture().getNetwork(requestContext.getNetworkId()).getSiteMemberships(requestContext.getRunAsUser());
            assertTrue(memberships.size() > 0);
            MemberOfSite memberOfSite = memberships.get(0);
            String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name();
            variablesObject.put("bpm_groupAssignee", group);
            return null;
        }
    }, requestContext.getRunAsUser(), requestContext.getNetworkId());
    createProcessObject.put("variables", variablesObject);
    return processesClient.createProcess(createProcessObject.toJSONString());
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) Date(java.util.Date) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) List(java.util.List)

Example 27 with MemberOfSite

use of org.alfresco.rest.api.tests.client.data.MemberOfSite 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)

Aggregations

MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)27 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)14 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)12 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)12 Test (org.junit.Test)11 LinkedList (java.util.LinkedList)8 ArrayList (java.util.ArrayList)7 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)7 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)7 JSONObject (org.json.simple.JSONObject)7 Task (org.activiti.engine.task.Task)6 Sites (org.alfresco.rest.api.tests.client.PublicApiClient.Sites)5 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)5 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)5 List (java.util.List)4 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 HashMap (java.util.HashMap)3 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)3 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)3