use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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());
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessInstanceById.
@Test
public void testDeleteProcessInstanceById() 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);
ProcessesClient processesClient = publicApiClient.processesClient();
// delete with user starting the process instance
ProcessInfo process = startAdhocProcess(requestContext, null);
try {
processesClient.deleteProcessById(process.getId());
// Check if the process was actually deleted
assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
assertNotNull(deletedInstance);
assertNotNull(deletedInstance.getEndTime());
assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
try {
processesClient.deleteProcessById(process.getId());
fail("expected exeception");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(process.getId());
}
// delete with admin in same network as the user starting the process instance
process = startAdhocProcess(requestContext, null);
try {
publicApiClient.setRequestContext(adminContext);
processesClient.deleteProcessById(process.getId());
// Check if the process was actually deleted
assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
assertNotNull(deletedInstance);
assertNotNull(deletedInstance.getEndTime());
assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
} finally {
cleanupProcessInstance(process.getId());
}
// delete with admin from other network as the user starting the process instance
process = startAdhocProcess(requestContext, null);
try {
publicApiClient.setRequestContext(otherContext);
processesClient.deleteProcessById(process.getId());
fail("Expect permission exception");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
} 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 testCreateProcessInstanceWithKey.
@Test
@SuppressWarnings("unchecked")
public void testCreateProcessInstanceWithKey() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionKey", "activitiAdhoc");
final JSONObject variablesObject = new JSONObject();
variablesObject.put("bpm_dueDate", "2013-09-30T00:00:00.000+0300");
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);
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());
// Test create process with wrong key
publicApiClient.setRequestContext(requestContext);
createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionKey", "activitiAdhoc2");
try {
processRest = processesClient.createProcess(createProcessObject.toJSONString());
fail();
} catch (PublicApiException e) {
// Exception expected because of wrong process definition key
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
assertErrorSummary("No workflow definition could be found with key 'activitiAdhoc2'.", e.getHttpResponse());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstanceByIdUnexisting.
@Test
public void testGetProcessInstanceByIdUnexisting() throws Exception {
initApiClientWithTestUser();
ProcessesClient processesClient = publicApiClient.processesClient();
try {
processesClient.findProcessById("unexisting");
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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());
}
}
Aggregations