Discussion:
[jboss-user] [jBPM] - setActorID for Swimlane in JBPM5
Aditya Gaurav
2013-02-26 09:49:25 UTC
Permalink
Aditya Gaurav [https://community.jboss.org/people/e3aa3b] created the discussion

"setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/799559#799559

--------------------------------------------------------------
Hi,

How can we dynamically set the actor ID for a Swimlane in JBPM5? Following snippet doesnt persist the information:

=====================
ProcessInstance pi = ksession.startProcess("com.sample.evaluation1");
                              Process p = pi.getProcess();
                              WorkflowProcess wfp = (WorkflowProcess)p;

                              WorkflowProcessInstance wfpi = (WorkflowProcessInstance)pi;
                              SwimlaneContextInstance slci = (SwimlaneContextInstance)wfpi.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);

                              SwimlaneContext sc = slci.getSwimlaneContext();
                              Swimlane s1 = sc.getSwimlane("SL1");

                              s1.setActorId("krisv");
=====================

Do I need to follow above calls with a persistence call to save the session or something? Any pointers will be really helpful.


Thanks
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799559#799559]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-02-26 18:32:02 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/799691#799691

--------------------------------------------------------------
yes, I believe you need to enclose it with Command so it will be executed within transaction and it's status will be persisted. Otherwise you simply change it on a process instance snapshot that is already disconnected and thus does not persist it's state.

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799691#799691]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Aditya Gaurav
2013-02-26 18:58:06 UTC
Permalink
Aditya Gaurav [https://community.jboss.org/people/e3aa3b] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/799706#799706

--------------------------------------------------------------
Thanks Maciej.

By 'Command' do you mean the invocation: ksession.startProcess(<Process_Name>,<params>)? Can you pls refer me to a snippet which maybe helpful in figuring out this problem?

I noticed that in JBPM3 version, there was a way to save the session. A related post in that version: http://web.archiveorange.com/archive/v/AVypsdDazttvKCv1Kk9q http://web.archiveorange.com/archive/v/AVypsdDazttvKCv1Kk9q

Is there a similar approach possible for JBPM5?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799706#799706]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-02-26 19:08:53 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/799709#799709

--------------------------------------------------------------
here is how you could define command and execute it on ksession so it gets executed within transaction
ksession.execute(new GenericCommand<Void>() {
 
    public Vold execute(Context context) {
 
        StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
 
        org.jbpm.process.instance.ProcessInstance processInstance = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(piId);
 
       
          // put your logic here
    }
 
});

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799709#799709]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Aditya Gaurav
2013-02-27 07:53:08 UTC
Permalink
Aditya Gaurav [https://community.jboss.org/people/e3aa3b] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/799798#799798

--------------------------------------------------------------
Hi Maciej,

I tried below, but it still is not able to persist the change:

<code>

GenericCommand<Void> genericCommand = new GenericCommand<Void>(){
                                        public Void execute(Context context){

                                                  System.out.println("inside execute");
                                                  StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
                                                  ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
                                                  WorkflowProcessInstance wfpi = (WorkflowProcessInstance)processInstance;
                                                  SwimlaneContextInstance slci = (SwimlaneContextInstance)wfpi.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);

                                                  SwimlaneContext sc = slci.getSwimlaneContext();

                                                  Swimlane s1 = sc.getSwimlane("SL1");
                                                  Swimlane s2 = sc.getSwimlane("SL2");

                                                  s1.setActorId("krisv");
                                                  s2.setActorId("mary");

                                                  //slci.setActorId("SL1", "krisv");
                                                  //slci.setActorId("SL2", "mary");

                                                  return null;

                                        }
                              };

                              ksession.execute(genericCommand);

</code>
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799798#799798]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-02-28 17:26:09 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800121#800121

--------------------------------------------------------------
could you provide bit more details on what you try to do and when do you change the actor on swimlane. Preferably process with test case so I could easily investigate it.

Cheers
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800121#800121]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Aditya Gaurav
2013-02-28 17:45:07 UTC
Permalink
Aditya Gaurav [https://community.jboss.org/people/e3aa3b] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800125#800125

--------------------------------------------------------------
Hi Maciej,

I am currently trying to work out a POC where I can change the actor on a Swimlane after the process has been started. i.e.

===

|
|
|
| final ProcessInstance pi = ksession.startProcess("com.sample.evaluation1"); |

===

And then:

GenericCommand<Void> genericCommand = new GenericCommand<Void>(){
public Void execute(Context context){

                                                  System.out.println("inside execute");
                                                  StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
                                                  ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
                                                  WorkflowProcessInstance wfpi = (WorkflowProcessInstance)processInstance;
                                                  SwimlaneContextInstance slci = (SwimlaneContextInstance)wfpi.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);

                                                  SwimlaneContext sc = slci.getSwimlaneContext();

                                                  Swimlane s1 = sc.getSwimlane("SL1");
                                                  Swimlane s2 = sc.getSwimlane("SL2");

                                                  s1.setActorId("krisv");
                                                  s2.setActorId("mary");

//                                                  WorkflowProcessInstanceUpgrader.upgradeProcessInstance(ksession, processInstance.getId(), "com.sample.evaluation1", null);

                                                  //slci.setActorId("SL1", "krisv");
                                                  //slci.setActorId("SL2", "mary");

                                                  return null;

                                        }
                              };

ksession.execute(genericCommand);
================================


The intention is that we should be able to dynamically modify/set the actor ID (using setActorID method of Swimlane class).


Thanks
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800125#800125]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-02-28 18:38:39 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800138#800138

--------------------------------------------------------------
just gave it a try on master, https://github.com/droolsjbpm/jbpm/blob/master/jbpm-test/src/test/java/org/jbpm/ProcessPersistenceHumanTaskOnLaneTest.java here is a test case that uses swimlanes and I added following code to check and change actorId on the swimlane and it worked fine, it was saved. To give that  atry on that test case just replace line 56 with this code


     ksession.execute(new GenericCommand<Void>(){
            public Void execute(Context context){
                KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
                ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
 
                WorkflowProcessInstance wfpi = (WorkflowProcessInstance)pi;
                SwimlaneContextInstance slci = (SwimlaneContextInstance)wfpi.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
       
                SwimlaneContext sc = slci.getSwimlaneContext();
       
                Swimlane sl = sc.getSwimlane("MyLane");
                System.out.println("Before: Current actor id is " + sl.getActorId());
                return null;
            }});
       
        GenericCommand<Void> genericCommand = new GenericCommand<Void>(){
            public Void execute(Context context){
                KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
                ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
 
                WorkflowProcessInstance wfpi = (WorkflowProcessInstance)pi;
                SwimlaneContextInstance slci = (SwimlaneContextInstance)wfpi.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
       
                SwimlaneContext sc = slci.getSwimlaneContext();
       
                Swimlane sl = sc.getSwimlane("MyLane");
                System.out.println("Command: Current actor id is " + sl.getActorId());
                sl.setActorId("mary");
               
                return null;
            }
        };
        ksession.execute(genericCommand);
        // simulating a system restart
        ksession = restoreSession(ksession, true);
       
        ksession.execute(new GenericCommand<Void>(){
            public Void execute(Context context){
                KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
                ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
 
                WorkflowProcessInstance wfpi = (WorkflowProcessInstance)pi;
                SwimlaneContextInstance slci = (SwimlaneContextInstance)wfpi.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
       
                SwimlaneContext sc = slci.getSwimlaneContext();
       
                Swimlane sl = sc.getSwimlane("MyLane");
                System.out.println("After: Current actor id is " + sl.getActorId());
                return null;
            }});
 

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800138#800138]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Aditya Gaurav
2013-02-28 19:03:10 UTC
Permalink
Aditya Gaurav [https://community.jboss.org/people/e3aa3b] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800143#800143

--------------------------------------------------------------
Thanks Maciej,

If I try above example, the actor ID for the swimlane gets printed fine.

However, the task in that Swimlane still doesnt show up in the user queue. i.e. if I set the actor ID to 'mary', the task still doesnt show up in mary's queue. Infact, I dont see the task anywhere (it's not present in any of the configured user's queue).
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800143#800143]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-03-01 13:32:35 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800294#800294

--------------------------------------------------------------
first of all why do you want to set it manually? swimlane will ensure that all tasks will be assigned to the same actor who was assigner to the first task. So no need to manage that yourself.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800294#800294]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Aditya Gaurav
2013-03-01 13:44:49 UTC
Permalink
Aditya Gaurav [https://community.jboss.org/people/e3aa3b] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800295#800295

--------------------------------------------------------------
Hi Maciej,

The issue that I am facing is that actor is not assigned even the first time. i.e. when the process gets started, the task is not assigned to anyone (since the actor ID and group ID is not set and the same is not passed as a parameter to the start Process). Hence even though the Process gets started, it doesnt show up in any user's queue.

To summarize, I want that the task should show up in a user (say Mary's queue) for tasks belonging to Swimlane1 and to another user's queue (say krisv's queue) for tasks belonging to Swimlane2.

One of the ways to do that is by using process variable and then setting them before Process instantiation and things work fine in that case. However, if I dont follow Process Variable approach and would like to dynamically assign the Swimlane to an actor using (setActorID API), the task doesn't show up in any user's queue (even though I have set it using setActorID API to krisv/mary).


Thanks
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800295#800295]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-03-01 14:08:09 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800301#800301

--------------------------------------------------------------
I believe that you try to set something on swimlane after task was created and thus change on swimlane does not affect the task any more. What I would suggest here is to assign that to a group, then one of the actors claim it and subsequent tasks will get automatically assigned to the same user. This is how swimlane is used on runtime.

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800301#800301]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Aditya Gaurav
2013-03-01 16:53:50 UTC
Permalink
Aditya Gaurav [https://community.jboss.org/people/e3aa3b] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/800340#800340

--------------------------------------------------------------
Thanks Maciej. Yes, that's one possible way to do it.

Under what scenario(s) is setActorID API useful?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800340#800340]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Gareth Edwards
2013-04-06 14:46:03 UTC
Permalink
Gareth Edwards [https://community.jboss.org/people/garethed] created the discussion

"Re: setActorID for Swimlane in JBPM5"

To view the discussion, visit: https://community.jboss.org/message/806831#806831

--------------------------------------------------------------
Hi,

Do swimlanes work with groups?

I have a task that is available to two groups. I would like all tasks in the workflow assigined to the the user that claims the first task.
No actor is specified in the tasks, just groups.

Gareth.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/806831#806831]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...