use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessItem.
@Test
public void testDeleteProcessItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
try {
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
// Delete the item
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
// Fetching the item should result in 404
try {
publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: " + docNodeRefs[0].getId() + " was not found", expected.getHttpResponse());
}
// Deleting the item again should give an error
try {
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Expected not found");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessTasks.
@Test
public void testGetProcessTasks() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
RequestContext otherPersonContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
Map<String, String> paramMap = new HashMap<String, String>();
JSONObject tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
JSONArray entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
JSONObject taskJSONObject = (JSONObject) ((JSONObject) entriesJSON.get(0)).get("entry");
assertNotNull(taskJSONObject.get("id"));
assertEquals(process1.getId(), taskJSONObject.get("processId"));
assertEquals(process1.getProcessDefinitionId(), taskJSONObject.get("processDefinitionId"));
assertEquals("adhocTask", taskJSONObject.get("activityDefinitionId"));
assertEquals("Adhoc Task", taskJSONObject.get("name"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("assignee"));
assertEquals(2l, taskJSONObject.get("priority"));
assertEquals("wf:adhocTask", taskJSONObject.get("formResourceKey"));
assertNull(taskJSONObject.get("endedAt"));
assertNull(taskJSONObject.get("durationInMs"));
paramMap = new HashMap<String, String>();
paramMap.put("status", "active");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
paramMap = new HashMap<String, String>();
paramMap.put("status", "completed");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 0);
paramMap = new HashMap<String, String>();
try {
processesClient.getTasks("fakeid", paramMap);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: fakeid was not found", expected.getHttpResponse());
}
// get tasks with admin from the same tenant as the process initiator
publicApiClient.setRequestContext(adminContext);
paramMap = new HashMap<String, String>();
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
// get tasks with admin from another tenant as the process initiator
publicApiClient.setRequestContext(otherContext);
paramMap = new HashMap<String, String>();
try {
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
// get task with other not-involved person
publicApiClient.setRequestContext(otherPersonContext);
paramMap = new HashMap<String, String>();
try {
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
// involve other person and get task
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(process1.getId()).singleResult();
activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPersonContext.getRunAsUser());
publicApiClient.setRequestContext(otherPersonContext);
paramMap = new HashMap<String, String>();
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
// complete task and get tasks
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
activitiProcessEngine.getTaskService().complete(task.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
publicApiClient.setRequestContext(requestContext);
paramMap = new HashMap<String, String>();
paramMap.put("status", "any");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
publicApiClient.setRequestContext(otherPersonContext);
paramMap = new HashMap<String, String>();
paramMap.put("status", "any");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
} finally {
cleanupProcessInstance(process1.getId());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class EnterpriseWorkflowTestApi method startAdhocProcess.
/**
* Start an adhoc-process with possible business key through the public REST-API.
*/
@SuppressWarnings("unchecked")
protected ProcessInfo startAdhocProcess(final RequestContext requestContext, NodeRef[] documentRefs, String businessKey) throws PublicApiException {
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
ProcessesClient processesClient = publicApiClient.processesClient();
final JSONObject createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionId", processDefinition.getId());
if (businessKey != null) {
createProcessObject.put("businessKey", businessKey);
}
final JSONObject variablesObject = new JSONObject();
variablesObject.put("bpm_priority", 1);
variablesObject.put("wf_notifyMe", Boolean.FALSE);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
if (documentRefs != null && documentRefs.length > 0) {
final JSONArray itemsObject = new JSONArray();
for (NodeRef nodeRef : documentRefs) {
itemsObject.add(nodeRef.getId());
}
createProcessObject.put("items", itemsObject);
}
createProcessObject.put("variables", variablesObject);
return processesClient.createProcess(createProcessObject.toJSONString());
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class EnterpriseWorkflowTestApi method startParallelReviewProcess.
/**
* Start a review pooled process through the public REST-API.
*/
@SuppressWarnings("unchecked")
protected ProcessInfo startParallelReviewProcess(final RequestContext requestContext) throws PublicApiException {
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiParallelReview").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("wf_notifyMe", Boolean.FALSE);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
JSONArray assigneeArray = new JSONArray();
assigneeArray.add(requestContext.getRunAsUser());
TestPerson otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId());
assigneeArray.add(otherPerson.getId());
variablesObject.put("bpm_assignees", assigneeArray);
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
createProcessObject.put("variables", variablesObject);
return processesClient.createProcess(createProcessObject.toJSONString());
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method getProcessImage.
@Test
public void getProcessImage() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo processRest = startAdhocProcess(requestContext, null);
HttpResponse response = publicApiClient.processesClient().getImage(processRest.getId());
assertEquals(200, response.getStatusCode());
cleanupProcessInstance(processRest.getId());
try {
response = publicApiClient.processesClient().getImage("fakeId");
fail("Exception expected");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
}
Aggregations