use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestActivities method testPersonActivities.
@Test
public void testPersonActivities() throws Exception {
People peopleProxy = publicApiClient.people();
// Test with default tenant domain. see ALF-20448
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person5.getId(), null, false, true);
return activities;
}
}, person5.getId(), defaultNetwork.getId());
for (Activity activity : expectedActivities) {
if (activity.getSiteId() == null) {
fail("SiteId should present in user-joined activity.");
}
}
{
int skipCount = 0;
int maxItems = expectedActivities.size();
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(defaultNetwork.getId(), person5.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person5.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
}
// Test Case cloud-2204
// Test case cloud-1500
// Test Case cloud-2216
// paging
// Test Case cloud-1500
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
{
int skipCount = 2;
int maxItems = expectedActivities.size() - 2;
assertTrue(maxItems > 0);
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
// "-me-" user
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(org.alfresco.rest.api.People.DEFAULT_USER, params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
}
// unknown user - 404
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
peopleProxy.getActivities(GUID.generate(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown site - 404
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("siteId", GUID.generate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(GUID.generate(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// user from another network - 404
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
peopleProxy.getActivities(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// another user from the same network - 403
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
peopleProxy.getActivities(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
try {
List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
assertTrue(activities.size() > 0);
Activity activity = activities.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.remove("people", person1.getId(), "activities", String.valueOf(activity.getId()), "Unable to DELETE a person activity");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1500
// other user activities
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> expectedActivities = repoService.getActivities(person1.getId(), null, true, false);
return expectedActivities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.others));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
// all activities with siteId exclusion
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> expectedActivities = repoService.getActivities(person1.getId(), testSite.getSiteId(), false, false);
return expectedActivities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("siteId", testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
// all activities with siteId exclusion, unknown site id
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
Map<String, String> params = createParams(paging, null);
params.put("siteId", GUID.generate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown person id
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
Map<String, String> params = createParams(paging, null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(GUID.generate(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid who parameter
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
Map<String, String> params = createParams(paging, null);
params.put("who", GUID.generate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1970
// Not allowed methods
// try
// {
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.create("people", person1.getId(), "activities", null, null, "Unable to POST to person activities");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.update("people", person1.getId(), "activities", null, null, "Unable to PUT person activities");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.remove("people", person1.getId(), "activities", null, "Unable to DELETE person activities");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>()
// {
// @Override
// public List<Activity> doWork() throws Exception
// {
// List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
// return activities;
// }
// }, person1.getId(), network1.getId());
// assertTrue(activities.size() > 0);
// Activity activity = activities.get(0);
//
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.create("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to POST to a person activity");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>()
// {
// @Override
// public List<Activity> doWork() throws Exception
// {
// List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
// return activities;
// }
// }, person1.getId(), network1.getId());
// assertTrue(activities.size() > 0);
// Activity activity = activities.get(0);
//
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.update("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to PUT a person activity");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
// Test Case cloud-1970
// not allowed methods
{
List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, false);
return activities;
}
}, person1.getId(), network1.getId());
assertTrue(activities.size() > 0);
Activity activity = activities.get(0);
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.create("people", person1.getId(), "activities", null, null, "Unable to POST to activities");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.create("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to POST to an activity");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.update("people", person1.getId(), "activities", null, null, "Unable to PUT activities");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.update("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to PUT an activity");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.remove("people", person1.getId(), "activities", null, "Unable to DELETE activities");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.remove("people", person1.getId(), "activities", String.valueOf(activity.getId()), "Unable to DELETE an activity");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testUpdateTaskVariablesExplicitTyped.
@Test
@SuppressWarnings("unchecked")
public void testUpdateTaskVariablesExplicitTyped() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
Map<String, Object> actualLocalVariables = activitiProcessEngine.getTaskService().getVariablesLocal(task.getId());
Map<String, Object> actualGlobalVariables = activitiProcessEngine.getRuntimeService().getVariables(processInstance.getId());
assertEquals(5, actualGlobalVariables.size());
assertEquals(8, actualLocalVariables.size());
// Set a new global value that is NOT present in the model with type given
JSONObject variableBody = new JSONObject();
variableBody.put("name", "newVariable");
variableBody.put("value", 1234L);
variableBody.put("type", "d:long");
variableBody.put("scope", "global");
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject resultEntry = tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
assertNotNull(resultEntry);
JSONObject result = (JSONObject) resultEntry.get("entry");
assertEquals("newVariable", result.get("name"));
assertEquals(1234L, result.get("value"));
assertEquals("d:long", result.get("type"));
assertEquals("global", result.get("scope"));
assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processInstance.getId(), "newVariable"));
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testDeleteTaskItem.
@Test
@SuppressWarnings("unchecked")
public void testDeleteTaskItem() 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();
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item as admin
JSONObject createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
JSONObject result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
JSONObject itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
publicApiClient.setRequestContext(adminContext);
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with candidate user
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPerson);
publicApiClient.setRequestContext(otherContext);
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with not involved user
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherPerson);
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
// delete item 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);
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with user from candidate group with assignee
activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
publicApiClient.setRequestContext(requestContext);
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
publicApiClient.setRequestContext(requestContext);
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// invalid task id
publicApiClient.setRequestContext(requestContext);
try {
tasksClient.deleteTaskItem("fakeid", docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// invalid item id
try {
tasksClient.deleteTaskItem(task.getId(), "fakeid");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item from completed task
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
activitiProcessEngine.getTaskService().complete(task.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processInfo.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testTaskStateTransitions.
@Test
@SuppressWarnings("unchecked")
public void testTaskStateTransitions() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInstance = startAdhocProcess(requestContext, null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
// Unclaimed to claimed
JSONObject taskBody = new JSONObject();
taskBody.put("state", "claimed");
List<String> selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "state", "assignee" }));
JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("claimed", result.get("state"));
// claimed to unclaimed
taskBody = new JSONObject();
taskBody.put("state", "unclaimed");
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("unclaimed", result.get("state"));
} finally {
cleanupProcessInstance(processInstance.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskVariablesAuthentication.
@Test
public void testGetTaskVariablesAuthentication() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String initiator = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
// Start process by one user and try to access the task variables as the task assignee instead of the process
// initiator to see if the assignee is authorized to get the task
ProcessInstance processInstance = startAdhocProcess(initiator, requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
TasksClient tasksClient = publicApiClient.tasksClient();
// Try accessing task variables when NOT involved in the task
try {
tasksClient.findTaskVariables(task.getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Permission was denied", expected.getHttpResponse());
}
// Set assignee, task variables should be accessible now
activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
JSONObject jsonObject = tasksClient.findTaskVariables(task.getId());
assertNotNull(jsonObject);
// Fetching task variables as admin should be possible
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
jsonObject = tasksClient.findTaskVariables(task.getId());
assertNotNull(jsonObject);
// Fetching the task variables as a admin from another tenant shouldn't be possible
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
try {
tasksClient.findTaskVariables(task.getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Permission was denied", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processInstance);
}
}
Aggregations