问题
I have two transition named "approved" and "reject" at the lastest step of my workflow, but i want to controll the workflow action from my portlet.
Anybody know How to Perform workflow transition programmatically in liferay ?
回答1:
my current code
JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(id);
getPermissionChecker().init(u.getUser(), true);
WorkflowInstanceLink wil= WorkflowInstanceLinkLocalServiceUtil.getWorkflowInstanceLink(companyId, journalArticle.getGroupId(), JournalArticle.class.getName(), journalArticle.getId());
WorkflowInstance workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance(companyId, wil.getWorkflowInstanceId());
Map<String, Serializable> workflowContext = workflowInstance.getWorkflowContext();
List<Integer> logTypes_assign = new ArrayList<Integer>();
logTypes_assign.add(WorkflowLog.TASK_ASSIGN);
List<WorkflowLog> workflowLogs_assign = WorkflowLogManagerUtil.getWorkflowLogsByWorkflowInstance(companyId, wil.getWorkflowInstanceId(), logTypes_assign, QueryUtil.ALL_POS, QueryUtil.ALL_POS, WorkflowComparatorFactoryUtil.getLogCreateDateComparator(true));
//WorkflowPermissionUtil.hasPermission(permissionChecker, groupId, className, classPK, actionId);
if(workflowLogs_assign.size() > 0){
long taskId = workflowLogs_assign.get(workflowLogs_assign.size()-1).getWorkflowTaskId();
WorkflowTask task = WorkflowTaskManagerUtil.getWorkflowTask(companyId, taskId);
_log.info("task : "+task.getName());
WorkflowTask nextTask = WorkflowTaskManagerUtil.assignWorkflowTaskToUser(companyId, userId, task.getWorkflowTaskId(), userId, "auto assign", task.getDueDate(), workflowContext);
WorkflowTaskManagerUtil.completeWorkflowTask(companyId, userId, nextTask.getWorkflowTaskId(), "next task transition name", "next task name", workflowContext);
}
回答2:
workflowInstance1 = WorkflowInstanceManagerUtil.signalWorkflowInstance(service.getCompanyId(), user.getUserId(),
workflowInstanceId, transitionNAME, workflowInstance.getWorkflowContext());
来源:https://stackoverflow.com/questions/15672441/perform-workflow-transition-programmatically-in-liferay