use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testCreateProcessInstanceWithId.
@Test
@SuppressWarnings("unchecked")
public void testCreateProcessInstanceWithId() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionId", processDefinition.getId());
final JSONObject variablesObject = new JSONObject();
variablesObject.put("bpm_dueDate", ISO8601DateFormat.format(new Date()));
variablesObject.put("bpm_priority", 1);
variablesObject.put("bpm_description", "test description");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
createProcessObject.put("variables", variablesObject);
ProcessInfo processRest = processesClient.createProcess(createProcessObject.toJSONString());
assertNotNull(processRest);
assertNotNull(processRest.getId());
HistoricProcessInstance processInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processRest.getId()).singleResult();
assertEquals(processInstance.getId(), processRest.getId());
assertEquals(processInstance.getStartActivityId(), processRest.getStartActivityId());
assertEquals(processInstance.getStartUserId(), processRest.getStartUserId());
assertEquals(processInstance.getStartTime(), processRest.getStartedAt());
assertEquals(processInstance.getProcessDefinitionId(), processRest.getProcessDefinitionId());
assertEquals("activitiAdhoc", processRest.getProcessDefinitionKey());
assertNull(processRest.getBusinessKey());
assertNull(processRest.getDeleteReason());
assertNull(processRest.getDurationInMs());
assertNull(processRest.getEndActivityId());
assertNull(processRest.getEndedAt());
assertNull(processRest.getSuperProcessInstanceId());
Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
assertEquals("test description", variables.get("bpm_description"));
assertEquals(1, variables.get("bpm_priority"));
cleanupProcessInstance(processRest.getId());
// Test same create method with an admin user
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
processRest = processesClient.createProcess(createProcessObject.toJSONString());
assertNotNull(processRest);
variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
assertEquals("test description", variables.get("bpm_description"));
assertEquals(1, variables.get("bpm_priority"));
cleanupProcessInstance(processRest.getId());
// Try with unexisting process definition ID
publicApiClient.setRequestContext(requestContext);
createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionId", "unexisting");
try {
processesClient.createProcess(createProcessObject.toJSONString());
fail();
} catch (PublicApiException e) {
// Exception expected because of wrong process definition id
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
assertErrorSummary("No workflow definition could be found with id 'unexisting'.", e.getHttpResponse());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstanceById.
@Test
public void testGetProcessInstanceById() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
ProcessesClient processesClient = publicApiClient.processesClient();
final ProcessInfo process = startAdhocProcess(requestContext, null);
try {
ProcessInfo processInfo = processesClient.findProcessById(process.getId());
assertNotNull(processInfo);
final Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processInfo.getId());
assertEquals(1, variables.get("bpm_priority"));
HistoricProcessInstance processInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processInfo.getId()).singleResult();
assertNotNull(processInfo.getId());
assertEquals(processInstance.getId(), processInfo.getId());
assertNotNull(processInfo.getStartActivityId());
assertEquals(processInstance.getStartActivityId(), processInfo.getStartActivityId());
assertNotNull(processInfo.getStartUserId());
assertEquals(processInstance.getStartUserId(), processInfo.getStartUserId());
assertNotNull(processInfo.getStartedAt());
assertEquals(processInstance.getStartTime(), processInfo.getStartedAt());
assertNotNull(processInfo.getProcessDefinitionId());
assertEquals(processInstance.getProcessDefinitionId(), processInfo.getProcessDefinitionId());
assertNotNull(processInfo.getProcessDefinitionKey());
assertEquals("activitiAdhoc", processInfo.getProcessDefinitionKey());
assertNull(processInfo.getBusinessKey());
assertNull(processInfo.getDeleteReason());
assertNull(processInfo.getDurationInMs());
assertNull(processInfo.getEndActivityId());
assertNull(processInfo.getEndedAt());
assertNull(processInfo.getSuperProcessInstanceId());
assertFalse(processInfo.isCompleted());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
// now complete the process and see if ending info is available in the REST response
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(process.getId()).singleResult();
activitiProcessEngine.getTaskService().complete(task.getId());
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(process.getId()).singleResult();
activitiProcessEngine.getTaskService().complete(task.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
processInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processInfo.getId()).singleResult();
processInfo = processesClient.findProcessById(processInfo.getId());
assertNotNull(processInfo.getId());
assertEquals(processInstance.getId(), processInfo.getId());
assertNotNull(processInfo.getStartActivityId());
assertEquals(processInstance.getStartActivityId(), processInfo.getStartActivityId());
assertNotNull(processInfo.getStartUserId());
assertEquals(processInstance.getStartUserId(), processInfo.getStartUserId());
assertNotNull(processInfo.getStartedAt());
assertEquals(processInstance.getStartTime(), processInfo.getStartedAt());
assertNotNull(processInfo.getProcessDefinitionId());
assertEquals(processInstance.getProcessDefinitionId(), processInfo.getProcessDefinitionId());
assertNotNull(processInfo.getProcessDefinitionKey());
assertEquals("activitiAdhoc", processInfo.getProcessDefinitionKey());
assertNull(processInfo.getBusinessKey());
assertNull(processInfo.getDeleteReason());
assertNotNull(processInfo.getDurationInMs());
assertEquals(processInstance.getDurationInMillis(), processInfo.getDurationInMs());
assertNotNull(processInfo.getEndActivityId());
assertEquals(processInstance.getEndActivityId(), processInfo.getEndActivityId());
assertNotNull(processInfo.getEndedAt());
assertEquals(processInstance.getEndTime(), processInfo.getEndedAt());
assertNull(processInfo.getSuperProcessInstanceId());
assertTrue(processInfo.isCompleted());
} finally {
cleanupProcessInstance(process.getId());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstancesWithDifferentProcessDefs.
@Test
public void testGetProcessInstancesWithDifferentProcessDefs() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
final ProcessInfo process2 = startParallelReviewProcess(requestContext);
final ProcessInfo process3 = startReviewPooledProcess(requestContext);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
Map<String, String> paramMap = new HashMap<String, String>();
ListResponse<ProcessInfo> processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
// include process variables as well
paramMap = new HashMap<String, String>();
paramMap.put("where", "(includeVariables=true)");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
} finally {
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstancesWithSorting.
@Test
public void testGetProcessInstancesWithSorting() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo process1 = startAdhocProcess(requestContext, null, "akey");
final ProcessInfo process2 = startAdhocProcess(requestContext, null, "bkey");
final ProcessInfo process3 = startAdhocProcess(requestContext, null, "aakey");
try {
// sort on business key ascending
ProcessesClient processesClient = publicApiClient.processesClient();
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("orderBy", "businessKey ASC");
ListResponse<ProcessInfo> processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
assertEquals(process3.getId(), processList.getList().get(0).getId());
assertEquals(process1.getId(), processList.getList().get(1).getId());
assertEquals(process2.getId(), processList.getList().get(2).getId());
// sort on business key descending
paramMap.put("orderBy", "businessKey DESC");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
assertEquals(process2.getId(), processList.getList().get(0).getId());
assertEquals(process1.getId(), processList.getList().get(1).getId());
assertEquals(process3.getId(), processList.getList().get(2).getId());
paramMap.put("orderBy", "startedAt ASC");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
paramMap.put("orderBy", "endedAt ASC");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
paramMap.put("orderBy", "durationInMillis ASC");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
// sort on more than 1.
paramMap.put("orderBy", "startedAt, endedAt");
try {
processList = processesClient.getProcesses(paramMap);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
// sort on non existing key
paramMap.put("orderBy", "businessKey2 ASC");
try {
processList = processesClient.getProcesses(paramMap);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
// sort on non existing sort order
try {
paramMap.put("orderBy", "businessKey ASC2");
processList = processesClient.getProcesses(paramMap);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
}
}
Aggregations