2 Replies Latest reply on Apr 15, 2015 11:29 AM by awizenm

    How to register user and group dynamically in jBPM 6.2?

    awizenm

      Hi all,

       

      In jBPM 5 to register a user you would do this like that (from user guide 5.4 Chapter 13):

       

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.task");
      
      TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
      
      TaskServiceSession taskSession = taskService.createSession();
      
      // now register new users and groups
      
      taskSession.addUser(new User("krisv"));
      
      taskSession.addGroup(new Group("developers"));
      
      
      
      
      
      

       

       

      I want to flexible create and handle new user at the runtime.

       

      How to register user and group dynamically in jBPM 6.2?

        • 1. Re: How to register user and group dynamically in jBPM 6.2?
          awizenm

          I assume a new user should find his way to the OrganizationalEntity table. But how?

           

          Is there a way to create and persist the UserImpl directly - as User is now an interface?

           

          Does jBPM 6 support dynamic user creation and handling at all?

          • 2. Re: How to register user and group dynamically in jBPM 6.2?
            awizenm

            ok, playing around directly with UserImpl is not a good idea.

             

            Registering a user (adding a user) to the task seems also to be an obsolete concept in jBPM 6.2.

             

            The solution to my problem is indeed adding the bpmn2:potentialOwner element to bpmn2 like in the Evaluation.bpmn example. Then passing arbitrary user as a parameter on process start in Java code.

             

            However, to be able to give the task to any user I had to use my own simple UserGroupCallback in the test class:

             

            Here is the constructor:

             

            public MyJbpmJUnitBaseTestCase(boolean arg0, boolean arg1) {
                super(arg0, arg1);
                userGroupCallback = new UserGroupCallback() {
            
                    @Override
                    public List<String> getGroupsForUser(String userId, List<String> groupIds, List<String> allExistingGroupIds) {
                        List<String> groups = new ArrayList<String>();
                        groups.add("myGroup");
                        return groups;
                    }
            
                    @Override
                    public boolean existsUser(String userId) {
                        return true;
                    }
            
                    @Override
                    public boolean existsGroup(String groupId) {
                        return true;
                    }
                };
            }