use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testCreateProcessInstanceForPooledReview.
@Test
public void testCreateProcessInstanceForPooledReview() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo processInfo = startReviewPooledProcess(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 testUpdateProcessVariableWithWrongType.
@SuppressWarnings("unchecked")
@Test
public void testUpdateProcessVariableWithWrongType() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processRest = startParallelReviewProcess(requestContext);
try {
assertNotNull(processRest);
String processId = processRest.getId();
// Update an existing variable with wrong type
JSONObject variableJson = new JSONObject();
variableJson.put("name", "wf_requiredApprovePercent");
variableJson.put("value", 55.99);
variableJson.put("type", "d:double");
try {
publicApiClient.processesClient().updateVariable(processId, "wf_requiredApprovePercent", variableJson);
fail("Exception expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
variableJson = new JSONObject();
variableJson.put("name", "wf_requiredApprovePercent");
variableJson.put("value", 55.99);
variableJson.put("type", "d:int");
JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "wf_requiredApprovePercent", variableJson);
assertNotNull(resultEntry);
JSONObject result = (JSONObject) resultEntry.get("entry");
assertEquals("wf_requiredApprovePercent", result.get("name"));
assertEquals(55l, result.get("value"));
assertEquals("d:int", result.get("type"));
assertEquals(55, activitiProcessEngine.getRuntimeService().getVariable(processId, "wf_requiredApprovePercent"));
JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processId);
assertNotNull(processvariables);
// Add process variables to map for easy lookup
Map<String, JSONObject> variablesByName = new HashMap<String, JSONObject>();
JSONObject entry = null;
JSONArray entries = (JSONArray) processvariables.get("entries");
assertNotNull(entries);
for (int i = 0; i < entries.size(); i++) {
entry = (JSONObject) entries.get(i);
assertNotNull(entry);
entry = (JSONObject) entry.get("entry");
assertNotNull(entry);
variablesByName.put((String) entry.get("name"), entry);
}
JSONObject approvePercentObject = variablesByName.get("wf_requiredApprovePercent");
assertNotNull(approvePercentObject);
assertEquals(55l, approvePercentObject.get("value"));
assertEquals("d:int", approvePercentObject.get("type"));
// set a new variable
variableJson = new JSONObject();
variableJson.put("name", "testVariable");
variableJson.put("value", "text");
variableJson.put("type", "d:text");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "testVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("testVariable", result.get("name"));
assertEquals("text", result.get("value"));
assertEquals("d:text", result.get("type"));
assertEquals("text", activitiProcessEngine.getRuntimeService().getVariable(processId, "testVariable"));
// change the variable value and type (should be working because no content model type)
variableJson = new JSONObject();
variableJson.put("name", "testVariable");
variableJson.put("value", 123);
variableJson.put("type", "d:int");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "testVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("testVariable", result.get("name"));
assertEquals(123l, result.get("value"));
assertEquals("d:int", result.get("type"));
assertEquals(123, activitiProcessEngine.getRuntimeService().getVariable(processId, "testVariable"));
// change the variable value for a list of noderefs (bpm_assignees)
final JSONObject updateAssigneesJson = new JSONObject();
updateAssigneesJson.put("name", "bpm_assignees");
updateAssigneesJson.put("type", "d:noderef");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
JSONArray assigneeArray = new JSONArray();
assigneeArray.add(requestContext.getRunAsUser());
updateAssigneesJson.put("value", assigneeArray);
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
resultEntry = publicApiClient.processesClient().updateVariable(processId, "bpm_assignees", updateAssigneesJson);
assertNotNull(resultEntry);
final JSONObject updateAssigneeResult = (JSONObject) resultEntry.get("entry");
assertEquals("bpm_assignees", updateAssigneeResult.get("name"));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
JSONArray assigneeArray = (JSONArray) updateAssigneeResult.get("value");
assertNotNull(assigneeArray);
assertEquals(1, assigneeArray.size());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
assertEquals("d:noderef", updateAssigneeResult.get("type"));
// update the bpm_assignees with a single entry, should result in an error
final JSONObject updateAssigneeJson = new JSONObject();
updateAssigneeJson.put("name", "bpm_assignees");
updateAssigneeJson.put("type", "d:noderef");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
updateAssigneeJson.put("value", requestContext.getRunAsUser());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
try {
publicApiClient.processesClient().updateVariable(processId, "bpm_assignees", updateAssigneeJson);
fail("Exception expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
// change the variable value with a non-existing person
variableJson = new JSONObject();
variableJson.put("name", "bpm_assignees");
JSONArray assigneeArray = new JSONArray();
assigneeArray.add("nonExistingPerson");
variableJson.put("value", assigneeArray);
variableJson.put("type", "d:noderef");
try {
publicApiClient.processesClient().updateVariable(processId, "bpm_assignees", variableJson);
fail("Exception expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testUpdateInitiatorAndGetProcessVariables.
// MNT-17918
@SuppressWarnings("unchecked")
@Test
public void testUpdateInitiatorAndGetProcessVariables() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
String processId = processRest.getId();
// Update initiator variable to "admin"
JSONObject variableJson = new JSONObject();
variableJson.put("name", "initiator");
variableJson.put("type", "d:noderef");
NodeRef personRef = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
String assignee = adminContext.getRunAsUser();
NodeRef personRef = getPersonNodeRef(assignee).getNodeRef();
variableJson.put("value", personRef.toString());
return personRef;
}
}, adminContext.getRunAsUser(), adminContext.getNetworkId());
JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "initiator", variableJson);
assertNotNull(resultEntry);
final JSONObject updateInitiatorResult = (JSONObject) resultEntry.get("entry");
assertEquals("initiator", updateInitiatorResult.get("name"));
assertEquals("d:noderef", updateInitiatorResult.get("type"));
assertNotNull("Variable value should be returned", updateInitiatorResult.get("value"));
assertEquals(personRef.getId(), updateInitiatorResult.get("value"));
// Get process variables after updating "initiator"
publicApiClient.setRequestContext(adminContext);
resultEntry = publicApiClient.processesClient().getProcessvariables(processId);
assertNotNull(resultEntry);
validateVariableField(resultEntry, "initiator", adminContext.getRunAsUser());
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessItem.
@Test
public void testGetProcessItem() 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 itemJSON = processesClient.findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
assertNotNull(itemJSON);
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
assertEquals("Test Doc1", itemJSON.get("name"));
assertEquals("Test Doc1 Title", itemJSON.get("title"));
assertEquals("Test Doc1 Description", itemJSON.get("description"));
assertNotNull(itemJSON.get("createdAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("createdBy"));
assertNotNull(itemJSON.get("modifiedAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("modifiedBy"));
assertNotNull(itemJSON.get("size"));
assertNotNull(itemJSON.get("mimeType"));
cleanupProcessInstance(processRest.getId());
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstancesWithPaging.
@Test
public void testGetProcessInstancesWithPaging() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
final ProcessInfo process2 = startAdhocProcess(requestContext, null);
final ProcessInfo process3 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
// Test with existing processDefinitionId
Map<String, String> params = new HashMap<String, String>();
params.put("processDefinitionId", process1.getProcessDefinitionId());
JSONObject processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
JSONObject paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
JSONArray jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(3, jsonEntries.size());
// Test with existing processDefinitionId and max items
params.clear();
params.put("maxItems", "2");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(2, jsonEntries.size());
// Test with existing processDefinitionId and skip count
params.clear();
params.put("skipCount", "1");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(1l, paginationJSON.get("skipCount"));
// MNT-10977: Workflow process retrieval returns incorrect hasMoreItems value
// Repository must answer 'false' for 'hasMoreItems' since the total number of items is 3, 2 items are requested and 1 is skipped
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(2, jsonEntries.size());
// Test with existing processDefinitionId and max items and skip count
params.clear();
params.put("maxItems", "3");
params.put("skipCount", "2");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(1l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
// MNT-10977: Workflow process retrieval returns incorrect hasMoreItems value
// Repository must answer 'false' for 'hasMoreItems' since the total number of items is 3 and 2 items are skipped
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(1, jsonEntries.size());
} finally {
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
}
}
Aggregations