use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testCreateProcessInstanceForParallelReview.
@Test
public void testCreateProcessInstanceForParallelReview() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo processInfo = startParallelReviewProcess(requestContext);
assertNotNull(processInfo);
assertNotNull(processInfo.getId());
cleanupProcessInstance(processInfo.getId());
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessItems.
@Test
public void testGetProcessItems() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject itemsJSON = processesClient.findProcessItems(newProcessInstanceId);
assertNotNull(itemsJSON);
JSONArray entriesJSON = (JSONArray) itemsJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
boolean doc1Found = false;
boolean doc2Found = false;
for (Object entryObject : entriesJSON) {
JSONObject entryObjectJSON = (JSONObject) entryObject;
JSONObject entryJSON = (JSONObject) entryObjectJSON.get("entry");
if (entryJSON.get("name").equals("Test Doc1")) {
doc1Found = true;
assertEquals(docNodeRefs[0].getId(), entryJSON.get("id"));
assertEquals("Test Doc1", entryJSON.get("name"));
assertEquals("Test Doc1 Title", entryJSON.get("title"));
assertEquals("Test Doc1 Description", entryJSON.get("description"));
assertNotNull(entryJSON.get("createdAt"));
assertEquals(requestContext.getRunAsUser(), entryJSON.get("createdBy"));
assertNotNull(entryJSON.get("modifiedAt"));
assertEquals(requestContext.getRunAsUser(), entryJSON.get("modifiedBy"));
assertNotNull(entryJSON.get("size"));
assertNotNull(entryJSON.get("mimeType"));
} else {
doc2Found = true;
assertEquals(docNodeRefs[1].getId(), entryJSON.get("id"));
assertEquals("Test Doc2", entryJSON.get("name"));
assertEquals("Test Doc2 Title", entryJSON.get("title"));
assertEquals("Test Doc2 Description", entryJSON.get("description"));
assertNotNull(entryJSON.get("createdAt"));
assertEquals(requestContext.getRunAsUser(), entryJSON.get("createdBy"));
assertNotNull(entryJSON.get("modifiedAt"));
assertEquals(requestContext.getRunAsUser(), entryJSON.get("modifiedBy"));
assertNotNull(entryJSON.get("size"));
assertNotNull(entryJSON.get("mimeType"));
}
}
assertTrue(doc1Found);
assertTrue(doc2Found);
cleanupProcessInstance(processRest.getId());
try {
processesClient.findProcessItems("fakeid");
fail("Exception expected");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo 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.model.ProcessInfo 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.model.ProcessInfo 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());
}
}
Aggregations