use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskItems.
@Test
public void testGetTaskItems() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
RequestContext otherContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
// Create test-document and add to package
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
ProcessInfo processInfo = startAdhocProcess(requestContext, docNodeRefs);
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
assertNotNull(task);
activitiProcessEngine.getTaskService().setAssignee(task.getId(), null);
try {
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject itemsJSON = tasksClient.findTaskItems(task.getId());
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);
// get with admin
publicApiClient.setRequestContext(adminContext);
itemsJSON = tasksClient.findTaskItems(task.getId());
assertNotNull(itemsJSON);
entriesJSON = (JSONArray) itemsJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
// get with non involved user
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.findTaskItems(task.getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
// get with candidate user
activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherContext.getRunAsUser());
publicApiClient.setRequestContext(otherContext);
itemsJSON = tasksClient.findTaskItems(task.getId());
assertNotNull(itemsJSON);
entriesJSON = (JSONArray) itemsJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
// get with user from candidate group with no assignee
List<MemberOfSite> memberships = getTestFixture().getNetwork(otherContext.getNetworkId()).getSiteMemberships(otherContext.getRunAsUser());
assertTrue(memberships.size() > 0);
MemberOfSite memberOfSite = memberships.get(0);
String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name();
activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherContext.getRunAsUser());
activitiProcessEngine.getTaskService().addCandidateGroup(task.getId(), group);
publicApiClient.setRequestContext(otherContext);
itemsJSON = tasksClient.findTaskItems(task.getId());
assertNotNull(itemsJSON);
entriesJSON = (JSONArray) itemsJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
// get with user from candidate group with assignee
activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
try {
tasksClient.findTaskItems(task.getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
// invalid task id
publicApiClient.setRequestContext(requestContext);
try {
tasksClient.findTaskItems("fakeid");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// get items from completed task with initiator
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);
itemsJSON = tasksClient.findTaskItems(task.getId());
assertNotNull(itemsJSON);
entriesJSON = (JSONArray) itemsJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
// get items from completed task with user from candidate group
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.findTaskItems(task.getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processInfo.getId());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testUpdateTaskMnt13276.
@Test
@SuppressWarnings("unchecked")
public void testUpdateTaskMnt13276() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String initiatorId = requestContext.getRunAsUser();
ProcessInfo processInfo = startReviewPooledProcess(requestContext);
// create test users
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>();
String temp = "_" + System.currentTimeMillis();
persons.add(currentNetwork.createUser(new PersonInfo("user0", "user0", "user0" + temp, "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
persons.add(currentNetwork.createUser(new PersonInfo("user1", "user1", "user1" + temp, "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
persons.add(currentNetwork.createUser(new PersonInfo("user2", "user2", "user2" + temp, "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
return persons;
}
}, false, true);
final MemberOfSite memberOfSite = currentNetwork.getSiteMemberships(initiatorId).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);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
// Updating the task by user in group
JSONObject taskBody = new JSONObject();
taskBody.put("name", "Updated name by user in group");
List<String> selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "name" }));
requestContext.setRunAsUser(persons.get(0).getId());
JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("Updated name by user in group", result.get("name"));
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
assertNotNull(task);
assertEquals("Updated name by user in group", task.getName());
// Updating the task by user not in group
try {
taskBody.put("name", "Updated name by user not in group");
requestContext.setRunAsUser(persons.get(2).getId());
tasksClient.updateTask(task.getId(), taskBody, selectedFields);
fail("User not from group should not see items.");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Permission was denied", expected.getHttpResponse());
}
// claim task
TaskService taskService = activitiProcessEngine.getTaskService();
task = taskService.createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
taskService.setAssignee(task.getId(), persons.get(1).getId());
// Updating by user in group for claimed task by another user
try {
taskBody = new JSONObject();
taskBody.put("name", "Updated name by user in group for claimed task");
selectedFields.addAll(Arrays.asList(new String[] { "name" }));
requestContext.setRunAsUser(persons.get(0).getId());
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
fail("User from group should not see items for claimed task by another user.");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Permission was denied", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processInfo.getId());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo 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.model.ProcessInfo 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.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testCreateProcessInstanceWithItems.
@Test
public void testCreateProcessInstanceWithItems() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
assertNotNull(processRest);
final Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
assertEquals(1, variables.get("bpm_priority"));
final ActivitiScriptNode packageScriptNode = (ActivitiScriptNode) variables.get("bpm_package");
assertNotNull(packageScriptNode);
final Map<String, FavouriteDocument> documentMap = new HashMap<>();
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
for (ChildAssociationRef childAssociationRef : documentList) {
FavouriteDocument doc = getTestFixture().getRepoService().getDocument(requestContext.getNetworkId(), childAssociationRef.getChildRef());
documentMap.put(doc.getName(), doc);
}
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processRest.getId()).singleResult();
assertEquals(requestContext.getRunAsUser(), task.getAssignee());
activitiProcessEngine.getTaskService().complete(task.getId());
final Task task2 = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processRest.getId()).singleResult();
assertEquals(requestContext.getRunAsUser(), task2.getAssignee());
activitiProcessEngine.getTaskService().complete(task2.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
assertEquals(2, documentMap.size());
assertTrue(documentMap.containsKey("Test Doc1"));
FavouriteDocument doc = documentMap.get("Test Doc1");
assertEquals("Test Doc1", doc.getName());
assertEquals("Test Doc1 Title", doc.getTitle());
assertTrue(documentMap.containsKey("Test Doc2"));
doc = documentMap.get("Test Doc2");
assertEquals("Test Doc2", doc.getName());
assertEquals("Test Doc2 Title", doc.getTitle());
cleanupProcessInstance(processRest.getId());
}
Aggregations