5 Replies Latest reply on Nov 19, 2013 4:53 AM by Yogesh Gupta

    How to integrate a Web Application with JBPM?

    srikanthan ramanathan Newbie

      Hi,

       

      Hope you all are doing fine. i need a quick favour from you guys. We are planning to use JBPM as an BPM engine. But, unfortunately I don’t have any knowledge on JBMP. So, I would like to clarify with you guys. The queries are given below:

       

      The proposed architecture

      1. 1. The architecture is à Our JBoss based Web App will call JBPM thru java call.
      2. 2. And we will not use JBPM user interface (GUI) but we use our Bboss application’s UI.
      3. 3. From the JBoss UI’s button click (Submit/Approve etc), JBoss app calls JBPM to
        1. a. create workflow process instance.
        2. b. Move process instance from one stage to another stage.
      4. 4. Meaning, we have Maker/Checker (Authorization) functionality exists. When Maker user submits the transaction in Jboss UI, the JBPM process (workflow) will be called and instance will be created for the Checker user(s) for the transaction approval. The Checker can either “Approve” the transaction (OR) he can “Reject” it back to the Maker user.
      5. 5. So, it is kind of Jboss driven JBPM Maker/Check Approval process. We are using the JBPM just for STATE MANAGEMENT.

       

      Queries

      1. 1. How do I call BPM process (best way of doing it) from my Web application?
        1. a. How to do thru plain java call?
        2. b. How to do thru web-service call?
      2. 2. When maker submits the transaction, he will get an option (popup window) to select the eligible Checker user’s names in the Web Application. When Maker chooses the Checker names and submit the transaction, the BPM should create a process instance only for the chosen Checker users.
      3. 3. Do we have dynamic role support in JBMP? The role’s corresponding user/group details should be picked up from database. The Role details will be kept in Web Application database; the JBPM will have to connect to Web application database to get the role details.
      4. 4. Can I fetch all the process instances/To-Do list (for example, waiting for approval) that belong to one user/group (OR) set of users by making java call to BPM engine from MY Web application?
      5. 5. Also, we have a scenario, in which there are multiple user groups to be part of approval process. Like, “minimum 2 people from Group G1” and “minimum 3 people from Group G2” should approve the process instance.

       

      Could you please clarify it? That would be nice.

      Have a wonderful day

        • 1. Re: How to integrate a Web Application with JBPM?
          Lingaiah Sundari Newbie

          I am also looking for the web application interaction  with jbpm and drools  - > any sample  web application  ( jsf, jpa, spring, hibernate , jsp or servlet .... ).

           

          Please let me know the references to get into more details , I have tried but not succeeded to find out the references ...

           

          -Regards,

          Lingaiah

          • 2. Re: How to integrate a Web Application with JBPM?
            Lingaiah Sundari Newbie

            Hi Srikanthan,

             

                 I have done the web application  interaction with JBPM. In our example It was covered around 70% of your requirement.

             

                 We can have the helper class to call the JBPM process or with in the servlet we can have the call to JBPM process. And also covered Human tasks and actions .

             

                

                 sample code (Servlet) :

             

                

            protected

            void processRequest(HttpServletRequest request, HttpServletResponse response)

             

            throws ServletException, IOException {

             

            response.setContentType(

            "text/html;charset=UTF-8");

            PrintWriter out = response.getWriter();

             

             

            try {

            String action = request.getParameter(

            "action");

             

             

            if (action.equals("CreateProcess")) {

             

            UserTransaction ut = (UserTransaction)

            new InitialContext().lookup( "java:comp/UserTransaction" );

            ut.begin();

             

             

            //StatefulKnowledgeSession ksession = JbpmAPIUtil.getSession();

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

            // JPAWorkingMemoryDbLogger logger =

             

            new JPAWorkingMemoryDbLogger (ksession

            );

             

             

            /*Map<String, Object> params = new HashMap<String, Object>();

            params.put("priority", "High");

            params.put("modelNumber", "123");

            params.put("quantity", "66"); */

            KnowledgeRuntimeLoggerFactory.newConsoleLogger(

            ksession

            );

             

             

            ksession.getWorkItemManager().registerWorkItemHandler("Log", new

            SystemOutWorkItemHandler());

             

             

            ksession

            .getWorkItemManager().registerWorkItemHandler(

             

            "Email", new EmailWorkItemHandler("20.139.68.11","86400","lsundari","Shiva@2012"

            ));

             

             

            //ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());

             

            CustomerProfile customerProfile =

            new CustomerProfile(request.getParameter("fName"),request.getParameter("lName"),Integer.parseInt(request.getParameter("age")),Integer.parseInt(request.getParameter("aLimit")),Integer.parseInt(request.getParameter("mSalary")),request.getParameter("eMail"),"TODO","TODO"

            );

            Map<String, Object> params =

            new

            HashMap<String, Object>();

            params.put(

            "customerProfile"

            , customerProfile);

            params.put(

            "employee", "lingaiah"

            );

            params.put(

            "reason", "CC Review Process"

            );

             

             

             

             

            ksession.startProcess("com.sample.bpmn.creditcardissueprocess"

            ,params);

            Thread.sleep(200);

             

            ksession

            .fireAllRules();

            Thread.sleep(200);

            ut.commit();

             

            //logger.dispose();

             

            request.setAttribute(

            "processVariable"

            , processInstanceVarible());

            request.setAttribute(

            "message", "Process Created!"

            );

            request.setAttribute(

            "processList"

            , processInstances());

             

             

            RequestDispatcher rD = request.getRequestDispatcher(

            "adminuser.jsp"

            );

            rD.forward(request, response);

            }

             

            else if(action.equals("listtasks"

            )) {

            String user = request.getParameter(

            "user"

            );

             

             

            //UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );

             

            /*

            * Get all the task assigned to 'user'

            */

             

            java.util.List<TaskSummary> tasks = JbpmAPIUtil.getAssignedTasks(user);

            TaskSummary task =

            null

            ;

             

             

            BlockingTaskOperationResponseHandler responseHandler =

            null

            ;

            ContentData contentData =

            null

            ;

            Map data =

            new

            HashMap();

             

             

            for

            (TaskSummary taskSummary : tasks) {

            System.

            out.println(taskSummary.getId() + " : "

            + taskSummary.getActualOwner());

            }

             

            request.setAttribute(

            "tasks"

            ,tasks);

            request.setAttribute(

            "user"

            ,user);

             

            request.setAttribute(

            "processList"

            , processInstances());

            request.setAttribute(

            "processVariable"

            , processInstanceVarible());

            RequestDispatcher rD = request.getRequestDispatcher(

            "taskrequest.jsp"

            );

            rD.forward(request, response);

             

            }

             

             

            else if(action.equals("Submit"

            )) {

             

            UserTransaction ut = (UserTransaction)

            new InitialContext().lookup( "java:comp/UserTransaction"

            );

            ut.begin();

            String user = request.getParameter(

            "user"

            );

             

            /*

            * Get all the task assigned to 'user'

            */

            CustomerProfile data =

            new

            CustomerProfile();

             

            /*data.put("priority",request.getParameter("priority"));

            data.put("modelNumber",request.getParameter("modelNumber"));

            data.put("quantity",request.getParameter("quantity"));*/

            data.setfName(request.getParameter(

            "fName"

            ));

            data.setlName(request.getParameter(

            "lName"

            ));

            data.setAppliedLimit(Integer.parseInt(request.getParameter(

            "aLimit"

            )));

            data.setMonthlySalary(Integer.parseInt(request.getParameter(

            "mSalary"

            )));

            data.seteMail(request.getParameter(

            "eMail"

            ));

            System.

            out.println("lingarao : "+request.getParameter("reviewStatus"

            ));

            data.setReviewStatus(request.getParameter(

            "reviewStatus"

            ));

             

            Long processId =

            new Long((String)request.getParameter("processId"

            ));

             

            // StatefulKnowledgeSession ksession = JbpmAPIUtil.getSession();

             

             

            // JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger (ksession);

             

             

            // processInstaceLogger = new JPAProcessInstanceDbLog (ksession.getEnvironment());

             

            WorkflowProcessInstance process = (WorkflowProcessInstance)

            ksession

            .getProcessInstance(processId);

            ((CustomerProfile)process.getVariable(

            "customerProfile")).setReviewStatus(request.getParameter("reviewStatus"

            ));;

             

            if((request.getParameter("reviewStatus").equalsIgnoreCase("Accepted"

            ))){

            ((CustomerProfile)process.getVariable(

            "customerProfile")).setCardIssueStatus(" Accepted by manual process , submitted to CC fulfillment process."

            );

            }

            else

            {

            ((CustomerProfile)process.getVariable(

            "customerProfile")).setCardIssueStatus(" Rejeected by manual process , sent status email"

            );

            }

             

            long taskId = new Long(request.getParameter("taskId"

            )).longValue();

            String taskStatus = request.getParameter(

            "taskStatus"

            );

             

             

            if (!taskStatus.equals("Completed"

            ))

            JbpmAPIUtil.completeTask(taskId, data, user);

             

             

            // request.setAttribute("processList", processInstances());

            ut.commit();

             

            //logger.dispose();

             

            //processInstaceLogger.dispose();

             

             

            //request.setAttribute("tasks",tasks);

            request.setAttribute(

            "processVariable"

            , processInstanceVarible());

            RequestDispatcher rD = request.getRequestDispatcher(

            "index.jsp"

            );

            rD.forward(request, response);

            }

             

            else if(action.equals("taskinit"

            )){

             

             

            request.setAttribute(

            "taskId",request.getParameter("taskId"

            ));

            request.setAttribute(

            "taskStatus",request.getParameter("taskStatus"

            ));

            request.setAttribute(

            "user",request.getParameter("user"

            ));

            request.setAttribute(

            "processId",request.getParameter("processId"

            ));

             

            request.setAttribute(

            "processVariable"

            , processInstanceVarible());

             

            // request.setAttribute("processList", processInstances());

            RequestDispatcher rD = request.getRequestDispatcher(

            "initialrequest.jsp"

            );

            rD.forward(request, response);

            }

            }

            catch

            (Exception e){

            out.println(

            "Error:"

            + e.getMessage().toString());

            }

             

            finally

            {

            out.close();

            }

             

            -Regards,

            Lingaiah.S

            • 3. Re: How to integrate a Web Application with JBPM?
              jamunas Newbie

              Thanks Lingaiah for this very good information , We are exactly looking for this solution, I am going to try this and get back to you.

               

              Jamuna S

              • 4. Re: How to integrate a Web Application with JBPM?
                Pascal S Newbie

                Hi,

                 

                i have posted a answer to this thread. I think it could interest you too.

                https://community.jboss.org/message/753645#753645

                • 5. Re: How to integrate a Web Application with JBPM?
                  Yogesh Gupta Newbie

                  Hi Pascal,
                  Have you implemented workflow monitor same as provided in jbpm-console.??
                  Please guide me or share some relevant things so that I can take help form that.

                   

                  Thanks in advance.