use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method createProcessInfo.
protected ProcessInfo createProcessInfo(HistoricProcessInstance processInstance) {
ProcessInfo processInfo = new ProcessInfo(processInstance);
ProcessDefinition definitionEntity = activitiProcessEngine.getRepositoryService().getProcessDefinition(processInstance.getProcessDefinitionId());
processInfo.setProcessDefinitionKey(getLocalProcessDefinitionKey(definitionEntity.getKey()));
return processInfo;
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method getProcesses.
@Override
public CollectionWithPagingInfo<ProcessInfo> getProcesses(Parameters parameters) {
Paging paging = parameters.getPaging();
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(PROCESS_COLLECTION_EQUALS_QUERY_PROPERTIES, null);
propertyWalker.setSupportedGreaterThanParameters(PROCESS_COLLECTION_GREATERTHAN_QUERY_PROPERTIES);
propertyWalker.setSupportedLessThanParameters(PROCESS_COLLECTION_LESSTHAN_QUERY_PROPERTIES);
propertyWalker.enableVariablesSupport(namespaceService, dictionaryService);
if (parameters.getQuery() != null) {
QueryHelper.walk(parameters.getQuery(), propertyWalker);
}
String status = propertyWalker.getProperty("status", WhereClauseParser.EQUALS);
String processDefinitionId = propertyWalker.getProperty("processDefinitionId", WhereClauseParser.EQUALS);
String businessKey = propertyWalker.getProperty("businessKey", WhereClauseParser.EQUALS);
String processDefinitionKey = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.EQUALS);
String startUserId = propertyWalker.getProperty("startUserId", WhereClauseParser.EQUALS);
Date startedAtGreaterThan = propertyWalker.getProperty("startedAt", WhereClauseParser.GREATERTHAN, Date.class);
Date startedAtLessThan = propertyWalker.getProperty("startedAt", WhereClauseParser.LESSTHAN, Date.class);
Date endedAtGreaterThan = propertyWalker.getProperty("endedAt", WhereClauseParser.GREATERTHAN, Date.class);
Date endedAtLessThan = propertyWalker.getProperty("endedAt", WhereClauseParser.LESSTHAN, Date.class);
Boolean includeVariables = propertyWalker.getProperty("includeVariables", WhereClauseParser.EQUALS, Boolean.class);
if (status != null && PROCESS_STATUS_LIST.contains(status) == false) {
throw new InvalidArgumentException("Invalid status parameter: " + status);
}
List<SortColumn> sortList = parameters.getSorting();
SortColumn sortColumn = null;
if (sortList != null && sortList.size() > 0) {
if (sortList.size() != 1) {
throw new InvalidArgumentException("Only one order by parameter is supported");
}
sortColumn = sortList.get(0);
}
final HistoricProcessInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery();
if (processDefinitionId != null)
query.processDefinitionId(processDefinitionId);
if (businessKey != null)
query.processInstanceBusinessKey(businessKey);
if (processDefinitionKey != null) {
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
if (processDefinitionKey.startsWith("@" + TenantUtil.getCurrentDomain() + "@")) {
query.processDefinitionKey(processDefinitionKey);
} else {
query.processDefinitionKey("@" + TenantUtil.getCurrentDomain() + "@" + processDefinitionKey);
}
} else {
query.processDefinitionKey(processDefinitionKey);
}
}
if (startUserId != null)
query.startedBy(startUserId);
if (startedAtGreaterThan != null)
query.startedAfter(startedAtGreaterThan);
if (startedAtLessThan != null)
query.startedBefore(startedAtLessThan);
if (endedAtGreaterThan != null)
query.finishedAfter(endedAtGreaterThan);
if (endedAtLessThan != null)
query.finishedBefore(endedAtLessThan);
if (status == null || PROCESS_STATUS_ACTIVE.equals(status)) {
query.unfinished();
} else if (PROCESS_STATUS_COMPLETED.equals(status)) {
query.finished();
query.notDeleted();
} else if (PROCESS_STATUS_DELETED.equals(status)) {
query.deleted();
}
if (includeVariables != null && includeVariables) {
query.includeProcessVariables();
}
List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
if (variableProperties != null) {
for (QueryVariableHolder queryVariableHolder : variableProperties) {
if (queryVariableHolder.getOperator() == WhereClauseParser.EQUALS) {
query.variableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHAN) {
query.variableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHANOREQUALS) {
query.variableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHAN) {
query.variableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHANOREQUALS) {
query.variableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.MATCHES) {
if (queryVariableHolder.getPropertyValue() instanceof String == false) {
throw new InvalidArgumentException("the matches operator can only be used with a String value for property " + queryVariableHolder.getPropertyName());
}
if (((String) queryVariableHolder.getPropertyValue()).startsWith("(?i)")) {
query.variableValueLikeIgnoreCase(queryVariableHolder.getPropertyName(), ((String) queryVariableHolder.getPropertyValue()).substring("(?i)".length()).toLowerCase());
} else {
query.variableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
}
} else if (queryVariableHolder.getOperator() == WhereClauseParser.NEGATION) {
query.variableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else {
throw new InvalidArgumentException("variable " + queryVariableHolder.getPropertyName() + " can only be used with an =, >, >=, <=, <, not, matches comparison type");
}
}
}
if (authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
// Admin is allowed to read all processes in the current tenant
if (tenantService.isEnabled()) {
query.variableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
} else {
// If non-admin user, involvement in the process is required (either owner, assignee or externally involved).
query.involvedUser(AuthenticationUtil.getRunAsUser());
}
if (sortColumn != null) {
if (PROCESS_COLLECTION_SORT_PROPERTIES.contains(sortColumn.column)) {
if ("processDefinitionId".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessDefinitionId();
} else if ("id".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceId();
} else if ("businessKey".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceBusinessKey();
} else if ("startedAt".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceStartTime();
} else if ("endedAt".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceEndTime();
} else if ("durationInMillis".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceDuration();
}
} else {
throw new InvalidArgumentException("sort " + sortColumn.column + " is not supported, supported items are " + Arrays.toString(PROCESS_COLLECTION_SORT_PROPERTIES.toArray()));
}
if (sortColumn.asc) {
query.asc();
} else {
query.desc();
}
} else {
query.orderByProcessInstanceStartTime().desc();
}
List<HistoricProcessInstance> processInstances = query.listPage(paging.getSkipCount(), paging.getMaxItems());
int totalCount = (int) query.count();
List<ProcessInfo> page = new ArrayList<ProcessInfo>(processInstances.size());
Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
for (HistoricProcessInstance processInstance : processInstances) {
ProcessInfo processInfo = createProcessInfo(processInstance);
if (includeVariables != null && includeVariables) {
if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId()) == false) {
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processInfo.getProcessDefinitionId());
if (startFormData != null) {
String formKey = startFormData.getFormKey();
definitionTypeMap.put(processInfo.getProcessDefinitionId(), getWorkflowFactory().getTaskFullTypeDefinition(formKey, true));
}
}
if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId())) {
// Convert raw variables to Variable objects
List<Variable> resultingVariables = restVariableHelper.getVariables(processInstance.getProcessVariables(), definitionTypeMap.get(processInfo.getProcessDefinitionId()));
processInfo.setProcessVariables(resultingVariables);
}
}
page.add(processInfo);
}
return CollectionWithPagingInfo.asPaged(paging, page, (page.size() + paging.getSkipCount()) < totalCount, totalCount);
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testSetOutcome.
@Test
@SuppressWarnings("unchecked")
public void testSetOutcome() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInf = startReviewPooledProcess(requestContext);
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInf.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
activitiProcessEngine.getTaskService().saveTask(task);
Map<String, String> params = new HashMap<String, String>();
params.put("select", "state,variables");
HttpResponse response = tasksClient.update("tasks", task.getId(), null, null, "{\"state\":\"completed\",\"variables\":[{\"name\":\"wf_reviewOutcome\",\"value\":\"Approve\",\"scope\":\"local\"},{\"name\":\"bpm_comment\",\"value\":\"approved by me\",\"scope\":\"local\"}]}", params, "Failed to update task", 200);
HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(task.getId()).includeProcessVariables().includeTaskLocalVariables().singleResult();
String outcome = (String) historyTask.getTaskLocalVariables().get("bpm_outcome");
assertEquals("Approve", outcome);
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskVariablesReview.
@Test
public void testGetTaskVariablesReview() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInstance = startParallelReviewProcess(requestContext);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).taskAssignee(requestContext.getRunAsUser()).singleResult();
assertNotNull(task);
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject variables = tasksClient.findTaskVariables(task.getId());
assertNotNull(variables);
JSONObject list = (JSONObject) variables.get("list");
assertNotNull(list);
JSONArray entries = (JSONArray) list.get("entries");
assertNotNull(entries);
// Check pagination object for size
JSONObject pagination = (JSONObject) list.get("pagination");
assertNotNull(pagination);
assertEquals(42L, pagination.get("count"));
assertEquals(42L, pagination.get("totalItems"));
assertEquals(0L, pagination.get("skipCount"));
assertFalse((Boolean) pagination.get("hasMoreItems"));
} finally {
cleanupProcessInstance(processInstance.getId());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo 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());
}
}
Aggregations