Friday, April 5, 2013

Integrate BPM workflow with a UI in External system


         Many of us are wondering on how to create a BPM Application with User I in an external system. REST API is the first thing that comes to our mind. Create an instance using REST API url and then fetch task ids available for a particular instance using REST API url again and perform the operation on the screen in External system and complete the task by passing the inputs using REST URL. This is the first approach that many of us get to our mind, on seeing the above statement

There is another, yet simple approach came to us when we have this problem in front of us.

Using combination of External Activity, REST API and Message event.

          In the BPD, whenever there is a human interaction needed, place an external activity and attach an intermediate message event to the External activity. Here external activity is just a fool proof activity, to

create the task and make the token wait on that activity until some action happens on the UI related to that task. When user performs an action in the UI, Ext system should capture all inputs and create an XML and send it to BPM by invoking a human service in BPM via REST API URL. This service will in turn parse the input xml and invoke UCA to trigger the intermediate message event attached to the external activity in the BPD which will close the task and move the token to the next activity.

Below diagram shows the high level representation of the above approach.


Following are high level of executing the process using the above approach.
  • Login to the external system; fill up the details in the form which acts as a starting step of the application. The external system should invoke the Human service in BPM via REST API call or webservice call, which will trigger an instance in BPM for the Process using UCA.
  • BPM should then update the instance id and workflow status corresponding to the data in database.
  • When “User A”, logs in to the External system, all the instances will be listed to him and he can select an instance an open the screen corresponding to the task and submits it. System then captures the data entered by user in the screen, formats the input structure and sends it to the BPM via REST API call. BPM will then parse input XML to get the data and triggers the intermediate message event corresponding to the task in the intended instance, to pass the data and close the task and move the token to the next activity. BPM should update the workflow status before moving to the next task and hence forth. In this way BPM and external system will be in sync in terms of moving workflow from one status to another.
       A separate article is posted on how to call REST API url from a java system.
       Below shown is the sample BPD.
 

Please Share if there are any other simple procedures to do this. Hope this helps.



13 comments:

  1. Dear Pradeep,

    Would like to know if you can show any sample code for this please?

    Best
    Kevin

    ReplyDelete
  2. Sorry Chan. I do not have sample code with me in my machine now.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  3. Some questions about your article:

    1. What are the advantages of using message events on external activity instead of simply linking activities using arrows directly?

    I am trying to look for the differences between your described approach (use External Activity, REST API and Message event) and the one described in:

    Integrating a business process application in IBM Business Process Manager V7.5.1 and V8 with an external system using the REST API
    http://www.ibm.com/developerworks/websphere/library/techarticles/1202_olivieri/1202_olivieri.html

    Both your approach and Olivieri's appraoch (in above IBM article) use REST API to trigger process instances and finish the tasks (close tasks) in processes ("Task A" in your example). I can see that your approach uses message events on external activity, but I don't understand the advantages of using this.

    2. You mentioned:
    Login to the external system; fill up the details in the form which acts as a starting step of the application.

    (You should be talking about "Task A", right?) Does that mean the following?
    After users log into the external system, they go to a screen (via menu in external system for example), fill up the details, and click Submit button. After that, the system would kick start the process instance and finish "Task A" (close Task A).

    3. You mentioned the followings:
    The external system should invoke the Human service in BPM via REST API call or webservice call, which will trigger an instance in BPM for the Process using UCA.

    What is meant by "invoke the human service" and then "trigger BPM instance"? I thought technically we should trigger an instance first, and then finish the Human Service "Task A" (implemented as External Implementation) via REST API calls. Kindly advise if I have misunderstood the article.

    4. You mentioned the following:
    BPM should then update the instance id and workflow status corresponding to the data in database.

    (I assume you are talking about "Update workflow status to DB" step)
    Which database do you mean, the BPM DB, or the external DB?

    If you mean the external DB, I would also like to ask how you would handle transaction? In "Task A", after users have submitted the form and finished "Task A", DB changes should have been committed. What if some errors occur in "Update workflow status to DB" step? How to do transaction roll back? Please advise.

    5. You mentioned the followings:
    When “User A”, logs in to the External system................................ In this way BPM and external system will be in sync in terms of moving workflow from one status to another.

    I don't quite understand this part. Is this part talking about "Task A" and "Update workflow status to DB"?

    Once again, many many thanks in advanced for your attention.

    Best,
    Kevin

    ReplyDelete
    Replies
    1. Dear Kevin,

      1. Advantage in my approach is, you dont have keep track of task ids to close the tasks, You dont have to keep track of External activity Id in an external system. All that you need to do is invoke a URL with normal process data as input, all the task closing logic will be kept in BPM.
      Task will be closed using intermediate messages events attached to activities. Using the input data correlation ids have to be formatted.

      2.Before Task A is created, there should be an instance created. This is what I meant. By logging in to external portal, fill up the details and click on submit, then that system will have to invoke a service in BPM using Rest URL, which will inturn trigger an instance.

      3. "Human Service" Doesn't have to in an Task, it can also be a stand alone service.
      There is a restriction while invoking a service via REST API Call, the service has to Human service or Ajax Service. Please see the article about rest api in IBM site.
      Regarding "trigger BPM instance" , the service will call a start message event to create an instance and then "task A" will be created in that instance.

      4.Exception handling should be implemented in BPM to handle all this. I have give a deep thought about the exception handling yet.

      5.For each task, there should be certain workflow status to be maintained in order identify, which instance is at which state and who had to work on it. So when a user logs in to the external system portal, only the tasks intended for his action will be will visible to him/her based on the status of the request. This status has to be updated by BPM.

      Thanks,
      Pradeep

      Delete
  4. So, in my understanding, by using your described approach, an execution would be like this.:

    Assumption:
    1. The external system DB keeps track of certain workflow status for each task in BPM (such workflow status is updated by BPM workflows). So the external system can display the list of tasks for each user without accessing the BPM DB.
    2. In the external system, for each user, there is a Task List page which lists all the tasks (or instances) intended for that login user’s action only.


    User interaction and process execution:
    1. User A logins to the external system. He goes to “Task List” page. He sees no tasks there.
    2. Next, User A goes into a screen (via clicking a menu item or whatever). He fills up the details, and click submit button. The program then invokes a human service which in turn calls a start message event and that starts a process instance. When the process starts, it first updates certain workflow status corresponding to the data in external system database. Then the token goes to “Task A”. As a result, now there is a running instance with the token on activity “Task A”.
    3. Next, User A goes to the “Task List” again. He now sees there is a task called “Task A”. He sees the new task because the workflow status in external DB has already been updated by the process in BPM.
    4. User A clicks on “Task A” run icon and he goes into a screen responsible for “Task A” of the process. He fills up the details, clicks Submit button. The program then invokes a human service which in turn triggers the immediate event and move the token to the next activity “Update workflow status to DB”. Certain workflow status in external system DB is updated. The process continues. It moves the token to next activity “Task B”.
    5. User A refreshes the Task List page, and now he sees “Task A” is gone (or complete, or whatever depending on how it is implemented). Also, he sees a new task named “Task B”.

    Remarks:
    1. I am confused about the term “trigger an instance” so I haven’t used it for this time. Does it mean starting an instance (ie. Creating an instance), or simply triggering some events on an instance?

    Kindly advise if my description is correct. Million thanks.

    ReplyDelete
    Replies
    1. In point 5: User A will see the "Task B", if he is owner of the task.
      To make it more simple lets look it like this.
      1. A clerk creates request by entering some details which will create an instance and BPM will update the status for request as "pending Assi.Manager".
      2. Now if Assi.Manager logs in to portal and he sees "Task A" and he filled some details and submitted it. The program then invokes a human service which in turn triggers the immediate event and move the token to the next activity and Update workflow status as "Pending sr.manager" to DB. Now if Ass.Manager refreshes his task list, "Task A" is gone because it is completed.
      3. Now if sr.manager logs in and see his task list, "Task B" is available to him and he can work on it now.

      You got it right about the approach. And you are correct "trigger an instance" means create or start an instance.

      Delete
    2. 1. In your description above, how many activities does the process contain?

      In my understanding, it should contain 4 activities:
      - Update workflow status to DB 1(System)
      - Approve Request 1 (Assi.Manager)
      - Update workflow status to DB 2(System)
      - Approve Request 2 (Sr.Manager)

      It would NOT contain the following activity:
      - Create Request (Clerk)

      because the instance is only created after the clerk enters some details and clicks submit button.

      Correct me if wrong.

      2. My question about BPM integration comes up again.

      If we integrate BPM using this way, the external system DB actually stores all the requests and related status. We are loading requests for approval from our own DB.

      In our program, we may execute SQLs like the followings:
      For asst.manager:
      select * from REQUESTS where status='PENDING_FOR_ASST_MGR';
      For sr.manager:
      select * from REQUESTS where status='PENDING_FOR_SR_MGR';

      As you see, the external system DB stores everything. Then why would we still need BPM?

      If we move the logic of "updating workflow related status" to our own program, then the external system can do all the things. It seems that BPM is no longer needed.

      It seems we are only doing extra programming work if we choose to integrate BPM with our system. What are the advantages of using BPM here? This is a question asked by my project team members too. Grateful if you can give me some directions. Thanks.

      3. Another question. In your previous reply, you mentioned the followings:
      Task will be closed using intermediate messages events attached to activities. Using the input data correlation ids have to be formatted.

      I guess it is related to formatting the input data structure as mentioned in your article. But I don't quite understand this concept. Can you elaborate more on this?

      Delete
    3. 1. In your description above, how many activities does the process contain?

      In my understanding, it should contain 4 activities:
      - Update workflow status to DB 1(System)
      - Approve Request 1 (Assi.Manager)
      - Update workflow status to DB 2(System)
      - Approve Request 2 (Sr.Manager)

      It would NOT contain the following activity:
      - Create Request (Clerk)

      because the instance is only created after the clerk enters some details and clicks submit button.

      Correct me if wrong.

      2. My question about BPM integration comes up again.

      If we integrate BPM using this way, the external system DB actually stores all the requests and related status. We are loading requests for approval from our own DB.

      In our program, we may execute SQLs like the followings:
      For asst.manager:
      select * from REQUESTS where status='PENDING_FOR_ASST_MGR';
      For sr.manager:
      select * from REQUESTS where status='PENDING_FOR_SR_MGR';

      As you see, the external system DB stores everything. Then why would we still need BPM?

      If we move the logic of "updating workflow related status" to our own program, then the external system can do all the things. It seems that BPM is no longer needed.

      It seems we are only doing extra programming work if we choose to integrate BPM with our system. What are the advantages of using BPM here? This is a question asked by my project team members too. Grateful if you can give me some directions. Thanks.

      3. Another question. In your previous reply, you mentioned the followings:
      Task will be closed using intermediate messages events attached to activities. Using the input data correlation ids have to be formatted.

      I guess it is related to formatting the input data structure as mentioned in your article. But I don't quite understand this concept. Can you elaborate more on this?

      Delete
    4. Hi Pradeep, how are you? Just wish to see if you have any ideas about my questions above after some time.


      Reagrding question (1), my main concern is about whether the first step "Update workflow status to DB 1" exists or not. This is because in your BPD, there is no such step before Task A. But you say when the instance is being created, the workflow data in DB would be updated. So I wonder where this first update takes place?

      Or do you mean this first update takes place inside the UCA linked to the start message event?


      Regarding question (2), my main concern is that IBM BPM (IBPM) is already taking care of the workflow data for us. All those info is stored in the BPM DB. When User A logins to the external system, we can simply retrieve the list of tasks for User A via BPM API (eg. REST API or Web API). Of course, in order to do this, we would require IBPM's user registry to store the user info.

      But in your BPM integration approach, you store the workflow data in the external DB, and retrieve the list of tasks for users from the external DB directly. It seems that you are not using IBPM's built-in user registry as well. Correct me if I misunderstood your integration approach.

      I wonder why you don't depend on IBPM for doing this job for you but do the same job by yourself?


      Regarding question (3), I just don't understand what "formatted" means.


      Kindly enlighten me when you are available, many thanks in adv.

      Kevin

      Delete
    5. Hi kevin,
      Regarding question 1), An activity which updates the DB exists and it should update the external DB where the application data is maintained.

      Regarding question 2), your understanding is correct. Normally in any BPM project (in my experience) each step in the workflow will have a status associated with it and we have to update the status to application database(whether it is in BPM DB or External DB) for tracking purposes or reporting purpose or if u need to build a custom inbox for users etc.

      And in addition to that I don't think it is possible to use IBPM's built in repository for an external system unless you are integrating an external repository (like LDAP, AD etc) with IBPM (not sure just a thought).

      Regarding question 3). The word formatted is used just to say that you need to have or create a correlation id for the intermediate message event. for example : a correlation id can be IBPM's instance ID, or it can be your request id or case id which is unique for a particular request.

      Delete
  5. Hi Pradeep,

    I am in the same situation where my UI page is in .war file which is deployed on the was console and on the external system when user logs in they will have a link and once they click on link they will be routed to my jsp page. and on my jsp page I am trying to make REST API call to one of the Ajax service on my process app but in this step for the REST call it is asking for authentication again.. please suggest how to authenticate user to be able to make a REST API call, the user who logged on to the external portal is the user who has access to BPM via an active directory group.. Appreciate any help around it.

    Thanks
    Phanikumar.M

    ReplyDelete
  6. Hi Phani kumar,
    Thnaks for stopping by. This authentication can be done in two ways, 1. 1. since the web application and BPM both uses LDAP, you can probably get the logged in userid/password from LDAP or from Seesion of webapplication and provide the same to BPM Rest Call for Authentication.

    2. You can create a common user id which is used for BPM rest call authentication alone and provide that userid/password for all the rest call authentications irrespective who logged in to your web application.

    ReplyDelete