如何获取控制器中流程实例的ID? [英] How to get the ID of the process instance in the controller?

查看:358
本文介绍了如何获取控制器中流程实例的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的环境:


Alfresco Share v5.2.d(r134641-b15,Aikau 1.0.101.3,Spring Surf
5.2.d,Spring WebScripts 6.13,Freemarker 2.3.20-alfresco修补,Rhino 1.7R4-alfresco修补,Yui 2.9.0-alfresco-20141223)

Alfresco Share v5.2.d (r134641-b15, Aikau 1.0.101.3, Spring Surf 5.2.d, Spring WebScripts 6.13, Freemarker 2.3.20-alfresco-patched, Rhino 1.7R4-alfresco-patched, Yui 2.9.0-alfresco-20141223)

Alfresco社区v5.2.0(r134428-b13)模式10005

Alfresco Community v5.2.0 (r134428-b13) schema 10005

启动工作流程时,我可以分配执行者-用户列表谁将参与业务流程。我需要获取所有这些用户的列表,并将其显示在reviewTask屏幕中。

When I start the workflow, I can assign executors - the list of users who will participate in the business process. I need to get a list of all those users and display this list in the reviewTask screen.

要显示此数据,我具有自定义FreeMarker模板。从这个模板中,我将调用我的Web脚本。

To display this data I have the custom FreeMarker template. From this template I'll call my Web Script.

要通过REST与存储库进行交互,我使用了Web脚本框架MVC-执行接收逻辑的控制器

To interact with the repository through REST I use the Web Script Framework MVC - the controller that executes the logic of receiving the list of users and FreeMarker template for the JSON response.

已向我提供了好主意,以及如何实现。但是我遇到了一些问题。

I've been offered the great idea, how it can be done. But I faced with some problem.

可以说,我启动了多个业务流程实例。在工作流控制台中,我可以看到以下内容:

Let's say, I launched multiple instances of the business process. In the Workflow Console I can see the following:

id: activiti$1801 , desc: DESCRIPTION_1 , start date: Sun Mar 12 19:19:09 GST 2017 , def: activiti$activitiParallelReview v1
id: activiti$2005 , desc: DESCRIPTION_2 , start date: Sun Mar 12 20:11:57 GST 2017 , def: activiti$activitiParallelReview v1
id: activiti$2138 , desc: DESCRIPTION_3 , start date: Sun Mar 12 20:12:55 GST 2017 , def: activiti$activitiParallelReview v1

因此,我有三个ID:

activiti$1801
activiti$2005
activiti$2138

这些ID仅在Workflow Console中对我可用。

These IDs are available for me only in the Workflow Console.

如何在控制器中获取这些标识符?

How can I get these identifiers in the controller?

例如,我可以编写一个将被Activiti调用的类吗?假设,

Can I, for example, write a class that will be called by Activiti? Let's say,

public class SomeListener implements TaskListener {
...
    @Override
    public void notify(DelegateTask task) {
        ...
        String taskId = task.getId();
        ...
    }
}   

然后将其附加到

这是正确的方法吗?..

Is this the right way?..

我将非常感谢您提供的信息。谢谢大家。

I would be very grateful for the information. Thanks to all.

我写了一个实现 ExecutionListener 接口。然后在从 mswf:submitParallelReviewTask mswf:activitiReviewTask 的过渡中将其添加为侦听器。

I wrote a class that implements the ExecutionListener interface. Then added it as a listener on the transition from mswf:submitParallelReviewTask to mswf:activitiReviewTask.

我需要的所有属性,我可以在这里找到(感谢 Gagravarr answer ):

All the properties that I need, I can get here (Thank to Gagravarr for his answer):

public class PropertiesReceiver implements ExecutionListener {
    private static final long serialVersionUID = 1L;
    private static Log logger = LogFactory.getLog(PropertiesReceiver.class);

    @Override
    public void notify(DelegateExecution delegateExecution) throws Exception {
        // TODO Auto-generated method stub
        String processInstanceId = delegateExecution.getProcessInstanceId();
        logger.debug("processInstanceId == " + processInstanceId);

        ActivitiScriptNodeList assignees = 
                (ActivitiScriptNodeList) delegateExecution.getVariable("bpm_assignees"); 
        for (ActivitiScriptNode personNode : assignees) {
            String username = (String) personNode.getProperties().get("cm:userName");
            logger.debug("username == " + username);
        }
    }
}

alfrescotomcat-stdout.2017- 03-13.log:

alfrescotomcat-stdout.2017-03-13.log:

...
2017-03-13 11:03:12,244  DEBUG [mswf.bpm.PropertiesReceiver] [http-apr-8080-exec-3] processInstanceId == 26205
2017-03-13 11:03:12,248  DEBUG [mswf.bpm.PropertiesReceiver] [http-apr-8080-exec-3] username == first
2017-03-13 11:03:12,250  DEBUG [mswf.bpm.PropertiesReceiver] [http-apr-8080-exec-3] username == second
...

但这是一个单独的项目,打包在AMP文件中。

But this is a separate project, packaged in an AMP file.

确定,另一种方式。我可以在 ScriptExecutionListener

Ok, another way. I can get the id of the process instance in ScriptExecutionListener:

execution.getProcessInstanceId();

然后调用从共享端获取Alfresco REST API 以检索我需要的所有信息(感谢

And call the Alfresco REST API from the Share side to retrieve all the information that I need (Thanks to Martin Ehe).

例如,此调用允许获取所有执行者:

For example, this call allows to get all the executors:

http://localhost:8080/alfresco/api/-default-/public/workflow/versions/1/processes/26205/variables

,其中 26205 == id 流程实例。

但是我应该在哪里保存此ID以便从共享访问它?我可以向工作流程模型添加方面吗?是否正确?..

But where should I save this ID to access it from Share? Can I add aspect to the workflow model and whether it's right?..

推荐答案

请尝试一下。

public JSONObject test(String userName) {


        JSONObject allTasks = new JSONObject();

        companyHome = repository.getCompanyHome();
        try {
            List<WorkflowTask> wft=serviceRegistry.getWorkflowService().getAssignedTasks(userName,WorkflowTaskState.IN_PROGRESS );

                JSONArray ja = new JSONArray();
                System.out.println("WF sizes = "+wft.size());
                for (WorkflowTask  temp : wft) {
                    JSONObject userWFDetails = new JSONObject();

                    userWFDetails.put("taskId", temp.getId());
                    userWFDetails.put("taskDesc", temp.getDescription());
                    userWFDetails.put("wfInstanceId", temp.getPath().getInstance().getId());

                    System.out.println("wf tasks-"+temp);
                    System.out.println("task id-"+temp.getId());
                    System.out.println("wf instance id-"+temp.getPath().getInstance().getId());
                    System.out.println("wf path id-"+temp.getPath().getId());
                    ja.put(userWFDetails);
                }           
                allTasks.put("userTasksDetails", ja);
            } catch (Exception e) {
            e.printStackTrace();
        }
        return allTasks;
    }

通过您的用户名。您将获得所有用户任务详细信息。 JSON格式的工作流程实例详细信息。

pass your userName. and you will get all the user task details. workflow instance details in json format.

这篇关于如何获取控制器中流程实例的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆