1 2 Previous Next 17 Replies Latest reply: Oct 13, 2011 8:41 PM by Ming Nguyen RSS

    Assign role, group to Human Task when initiated

    Ming Nguyen
      Hi all,
      Currently, when user login to BPM and create new task instance, i can get roles and groups of that user by programming. I want to assign roles of user to that task instance dynamically when user click SUBMIT button (Because i want to restrict users belong role are able to do this task, each user belong to a role and group can do it).

      Somebody help?

      Thanks.
        • 1. Re: Assign role, group to Human Task when initiated
          Ravi Jegga
          Hi Ming
          1. If you want to intercept any Actions from a Task like Save, Submit, Approve, Reject etc, you can create your own class like MyAppTaskValidationCallback that implements oracle.bpel.services.workflow.task.ITaskValidationCallback and in this overwrite one method named validateTaskOperation(bunch of parameters). See APIs for this.

          In this method, you can get the action performed on the task. Also you can get the complete Payload of the Task including your custom payload and the standard Task Payload stuff like History, Attachments, Comments etc. You can write some simple XML Parser utility methods to get and set attributes in the Payload xsd schema. So in your case, in this method, get Roles, Groups of the logged in user. Check the action performed. If he is not allowed to do that operation, throw the error from this method. Else continue with your logic. To begin with create java class like above, add this code snippet and just explore the data.

          Now, just curious. If your requirement is really to control the actions based on User Role/Groups, did you try to use the out of box functionality and avoid this custom logic. Say for BPM Applications, we have Swimlanes / Roles. Only users belonging to that Role, can work on that Tasks. Try to use out of box stuff as much as possible, unless you really need custom assignment logic.

          Thanks
          Ravi Jegga

          Just giving the code snippet to get an idea. But do refer the online APIs for more information.
          public void validateTaskOperation(ITaskValidationCallback.TaskAction taskAction, IWorkflowContext iWorkflowContext, Task task, Map<String, Object> parameters, Locale locale, List<String> errors) {
          try {
            Element taskPayload = task.getPayloadAsElement(); 
            String taskTitle;
            String taskOutcome;
            SystemAttributesType taskSystemAttributes = task.getSystemAttributes();          
          
            taskTitle = task.getTitle();
          
            System.out.println("MyAppTaskValidationCallback::validateTaskOperation() Begin For TaskTitle: " + taskTitle + " -> TaskAction: " + taskAction + " -> Parameters:\n" + parameters);
          
            if(taskAction == TaskAction.ACQUIRE) {
                System.out.println("Inside ACQUIRE");
                //parameters.put("AcquiredBy", iWorkflowContext.getUser());
            } else if(taskAction == TaskAction.OUTCOME_UPDATE) {
              System.out.println("Inside OUTCOME_UPDATE");
            }
          } catch (Exception anException) {
            anException.printStackTrace();
          }
          }
          • 2. Re: Assign role, group to Human Task when initiated
            769088
            Hi Ravi,
            you opened me a world.
            It's a week I try to understand how to act on information of a task.
            Thanks a lot.
                 
            The java class must be hooked by the ' Events ' tab of the Task ?

            Regards.
            • 3. Re: Assign role, group to Human Task when initiated
              Ravi Jegga
              Hi
              Yes, open your .task file in the JDeveloper. On left side select Events section. And on right side, in the bottom section, in Validation Callback give fully qualified name of your class like com.a.b.c.MyAppTaskValidationCallback. I used only this event. I have not used other Comments, Attachments and anything in the top section also which is specific to action. But this Validation does get called for all the Actions and so this is more Generic I would say.

              Thanks
              Ravi Jegga
              • 4. Re: Assign role, group to Human Task when initiated
                Ming Nguyen
                Hi Ravi,

                Your answer is very very useful for me. Thank you for your reply.
                I think my problem is resolved :).

                Thanks & Regards.
                • 5. Re: Assign role, group to Human Task when initiated
                  769088
                  Hi all,
                  I'm trying to figure out how to pass the list of documents from one task to another (this works only if attachments are included in a task of type initiator).
                  I hope that the data object of type binary serve to this.

                  Thanks a lot.
                  • 6. Re: Assign role, group to Human Task when initiated
                    Ming Nguyen
                    Hi Ravi,

                    I have just tried as your guide, but it seems does not working. I created a class validation callback called CreateTaskValidationCallback and register in Task Events (give full qualified name is com.bvh.event.CreateTaskValidationCallback). So, when i check this task action on Workspace, it does not working also. I can not see any change.

                    Do you know why ?

                    Thanks & Regards.
                    • 7. Re: Assign role, group to Human Task when initiated
                      David Read-Oracle
                      There may be another approach to meeting your requirement. If I understand, you want to take the role and/or group membership of the person that initiates the process and make that set of roles/groups the criteria for subsequent assignment? If that's true, then I assume the submitting user has a broader set of roles than the swim-lane role that let them launch the process in the first place, but at the same time that set of roles can serve to restrict who can perform subsequent tasks.

                      If that's still all true you could try this ...

                      1. Have the task payload for the initiator task include a list of strings, which would hold the the list of roles. You wouldn't bind that visibly to the form, but populate that list from from a backing bean using the code you already have.
                      2. In the output data association store that list as a process data object.
                      3. Then in subsequent human tasks, pass that list as part of the payload, and have the participant list built "By Expression" referencing the task payload.

                      A last question is whether your code for getting roles/groups is specialized or just a lookup in LDAP? There are xpath functions that can do that directly from within the BPM process. Unfortunately those aren't currently exposed in JDev. If you just need to get the list of roles from LDAP that may be possible.
                      • 8. Re: Assign role, group to Human Task when initiated
                        Ming Nguyen
                        Hi David,

                        I describe my problem:

                        My project is developed for A parent company and many branches (equivalent groups). All company have some roles ( 3 - 5 roles). My purpose is able to restrict users belong to role and group to manipulate with their task. Each user belong to one branch can only do owner task instance, users belong to other branches cannot visible and manipulate to that task.
                        (users can have the same role).

                        So, I want to assign task dynamically when user create new task instance.

                        Thanks.
                        • 9. Re: Assign role, group to Human Task when initiated
                          Ravi Jegga
                          Hi Ming
                          1. To begin with, please check your log files and the file that contains your soa_server outputs. Like if you start soa_server in a normal window without redirect to any log files or nohup, check those log files. This should give an idea.

                          2. You already created the callback class. Do not include any of your custom import classes other then the ones that you need for the method I gave earlier. Just add System.out.println and see if they get printed in the log files.

                          3. I hope you created this class within your workflow project itself. NOW the reason for above stuff is, if you have any imports that refer your other custom classes from other project, you should have those dependent JARs inside the SCA-INF/lib folder of your workflow project. The general practice is, we deplloy the workflow project as SCA JAR File. We deploy all the rest of the stuff like other jars, UI projects, models etc as one big EAR at application level. So this means your Workflow JAR should have all dependent JARs under SCA-INf/lib folder for any class that you refer in your custom Validation class.

                          conclusion, in your custom validation class, just import only required classes and just add System.out.printlns. Deploy your Taskforms. One more thing by the way if you use older versions of BPM Suite like 11.3 and older. We faced a werid problem sometimes the changes made to workflow project are NOT picked up. The only solution was to undeploy everything. Stop the servers. Clean cache, tmp folders from soa_server and restart server and redeploy the workflow project. This is not an issue in latest BPM 11.4. But for older versions, this is a bug if I am not wrong and there may be a Patch also for this issue.

                          I have same code on my side in BPM 11.4 and my ValidationClass does gets called anytime I work on any Task like Instantiate, Save, Submit etc etc.

                          Thanks
                          Ravi Jegga
                          • 10. Re: Assign role, group to Human Task when initiated
                            Ming Nguyen
                            Hi Ravi,
                            I'm using Jdev 11.4. That's right as your prediction. I have checked the server log, my workflow project has referenced to other project and maybe that's is the reason occurs error.
                            Now my class Validation Callback does gets called anytime. By the way, I have one issue related this. Let's see my function :
                            {{{
                            public void validateTaskOperation(ITaskValidationCallback.TaskAction taskAction,
                            IWorkflowContext iWorkflowContext,
                            Task task, Map<String, Object> map,
                            Locale locale, List<String> list) {
                            try {
                            if (taskAction == TaskAction.OUTCOME_UPDATE) {
                            // Get group
                            String groupName = "";
                            List<BPMGroup> listGroup;
                            List<BPMUser> listUser =
                            bpmClient.searchUsers("name", iWorkflowContext.getUser());
                            if (listUser != null) {
                            BPMUser user = listUser.get(0);
                            listGroup = user.getGroups(true);
                            BPMGroup group = listGroup.get(0);
                            groupName = group.getName();
                            task.setOwnerGroup(groupName);

                            // Update Task instance
                            IWorkflowServiceClient wfSvcClient;
                            ITaskQueryService queryService;
                            ITaskService taskService;
                            IWorkflowContext wfContext;

                            String contextStr = ADFWorklistBeanUtil.getWorklistContextId();
                            wfSvcClient = WorkflowService.getWorkflowServiceClient();
                            queryService = wfSvcClient.getTaskQueryService();
                            wfContext = queryService.getWorkflowContext(contextStr);

                            taskService = wfSvcClient.getTaskService();
                            taskService.updateTask(wfContext, task);
                            }
                            }

                            } catch (Exception anException) {
                            anException.printStackTrace();
                            }

                            }
                            }}}

                            As you can see in the code above, i want to update "ownerGroup" attribute to the Task instance before assign to next step. But the code update task has error. Do you know the reason for this?

                            Thanks for your answer. It's very easy to understand and useful for me.

                            Regards.

                            Edited by: Ming Nguyen on May 6, 2011 9:51 AM
                            • 11. Re: Assign role, group to Human Task when initiated
                              Ravi Jegga
                              Hi Ming
                              I am glad your original issue is resolved and now your Callback handler gets called for every Task Action.

                              Coming to your latest question, its related to using the APIs of Workflow and Tasks. I have not used the setOwnerGroup attribute in particular. But I set my payload elements using Binding Iterators. I will look into your code snippet and try it on my side.

                              Thanks
                              Ravi Jegga
                              • 12. Re: Assign role, group to Human Task when initiated
                                Ming Nguyen
                                Thanks Ravi,
                                You are really kind-hearted man :). So if you have any other idea or solution for this, please advise me.

                                Best Regards.
                                • 13. Re: Assign role, group to Human Task when initiated
                                  Ming Nguyen
                                  Hi Ravi,

                                  Can you send me your sample code using Binding Iterator to update Task Payload ?

                                  Thanks & Regards.
                                  • 14. Re: Assign role, group to Human Task when initiated
                                    846241
                                    hi,can u provide me with the code i have the same requirements.
                                    Thanks
                                    1 2 Previous Next