com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Working with REST Tasks

BPMN REST tasks allow you to invoke REST endpoints within your BPMN processes. You can achieve this by adding a REST Task and handling the REST invocation part in a process implementation. This tutorial simulates a scenario, in which you access a REST endpoint of a Health Care Service via a REST Task to retrieve information of a patient appointment, and approve it based on the date as an administrator.

Before you begin,

  • Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:
    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.6.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.6.0\
    Ubuntu/usr/lib/wso2/EnterpriseIntegrator/6.6.0
    CentOS/usr/lib64/EnterpriseIntegrator/6.6.0
  • Select the relevant WSO2 Integration Studio based on your operating system and download it from here.
    The path to this folder is referred to as <EI_TOOLING> throughout this tutorial.

    Getting an error message? See the troubleshooting tips given under Installing WSO2 Integration Studio.

Starting the back-end service

Download and start the back-end service:

  1. Download the JAR file of the back-end service.
  2. Open a terminal and navigate to the location where your saved the back-end service.

  3. Execute the following command to start the service:

    java -jar Hospital-Service-JDK11-2.0.0.jar

The Healthcare service is now active and you can start sending requests to the service.

Sending the request to the backend service

Follow the steps below to send the request to the backend service. This creates the appointment of the patient.

  1. Send a request to the Backend service by entering the below details using a REST Client (e.g., Postman).

    In the Payload, set the appointment_date to a date, which is minimum one day after today's date. For example, in the below payload, it is assumes that today's date is 2018-08-14 so that 2018-08-16 is set as the appointment_date.

    HTTP MethodRequest URLPayload
    POST http://localhost:9090/grandoaks/categories/surgery/reserve

    {
    "patient": {
    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "johndoe@gmail.com"
    },
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "appointment_date": "2018-08-16"
    }

Creating the BPMN artifacts

Follow the steps below to create the BPMN artifacts including the REST Task,

  1. Create a new BPMN project named RestTaskBPMN. For instructions, see Creating a BPMN Project.
  2. Create a BPMN Diagram named RestTask.bpmn. For instructions, see Creating the BPMN Diagram.
  3. Click anywhere on the canvas, go to the Properties tab, and fill in the following details:
    Id               : restTask
    Name         : REST Task Process
    Namespace http://wso2.org/bpmn/rest Task
  4. To implement the order approval process, drag and drop a Start Event element, a REST Task element, a User Task element and an End Event element to the canvas. 

    You view the  Create connection  option when you hover the mouse pointer on  an  artifact. Click on the arrow, drag it and drop it on the artifact to which you want to connect it.

Configuring the Start Event

Select the  Properties  tab of the Start Event, click  Form ,   click  New ,   update the following and click  OK.

IdNameTypeRequiredReadableWritable
patientName Name of the PatientstringTrueTrueTrue
appointmentNoAppointment NumberlongTrueTrueTrue


You view both fields added to the form as shown below.


Configuring the REST Task

  1. Select the  Properties  tab of the REST Task, click  General  and enter the  Name  as  Get Appointment
  2. In the Properties tab of the REST Task, click Main config and update the following: 

    Service URLhttp://localhost:9090/healthcare/appointments/validity/${appointmentNo}
    HTTP methodGET
    Output Variable MappingsnoOfDays:$.status

    Important!

    Be sure to use only one parameter (Output Variable Mappings parameter or the Output Variable Name parameter) to specify the variable mappings.

     More information on the properties of the REST Task

    After adding the REST Task to your BPMN Diagram, you can configure the below Properties appropriately, as explained below.

    Field NameString ValueRequired/Optional
    Service URL 

    URL of the target endpoint.


    Optional

    You can give this instead of the Service Reference (EPR).

    BasicAuth UsernameUsername if the endpoints are securedRequired
    BasicAuth PasswordPassword for the username aboveRequired
    Service Reference (EPR)

    Registry resource path of the endpoint reference.


    Optional

    You can give this instead of the Service URL.

    HTTP MethodHTTP method (GET. POST, PUT or DELETE)Required
    Input PayloadRequest payloadOptional
    Output Variable name

    Name of the variable to save the response.

    Important!

    Be sure to use only one parameter (Output Variable Mappings parameter or the Output Variable Name parameter) to specify the variable mappings.

    Optional
    Output Variable Mappings

    Variable mappings to map JSON response content into multiple variables. 

    var2:customer.name,var3:item.price
    Optional
    Transport headers

    Header values in the format

    {"headerName1":"headerValue1","headerName2":"header Value2"}
    Optional

    Configuring the HTTP client

    The above REST task is bundled with an HTTP client by default. You can edit its configurations in the <EI_HOME>/wso2/business-process/conf/activiti.xml file as shown in the example below.

    <bean id="restClientConfiguration">
            <property name="maxTotalConnections" value="200"/>
            <property name="maxConnectionsPerRoute" value="200"/>
            <property name="connectionTimeout" value="12000"/>
            <property name="socketTimeout" value="12000"/>
    </bean>

Configuring the User Task

  1. Select the Properties tab of the User Task, click General and enter the Name as Confirm Appointment
  2. Click  Properties , click  Main config    and give admin as the Assignee.  

  3. In the  Properties  tab click  Form , click  New  and add the following.

    IdNameTypeReadableWritableRequired
    approveCancellationDo You Approve the
    Appointment Cancellation Request?
    enumTrueFalseTrue

    Click New next to Form values and add the following:

    IdName
    approveApprove
    rejectReject

  4. In the Properties tab click Form, click New and add the following.

    IdNameTypeVariableReadableWritableRequired
    noOfDaysNumber of DayslongnoOfDaysTrueFalseTrue

    You view the fields added to the Form of the User Task as shown below.

  5. Press Ctrl+S to save all your artifacts.

Deploying the artifacts

  1. For instructions on creating the deployable artifacts, see Creating the deployable archive.
  2. For instructions on deploying them, see Deploying BPMN artifacts.

Testing the output

  1. Log in to the BPMN-explorer at https://localhost:9445/bpmn-explorer  using  admin  for both the username and password.
  2. Click PROCESSES in the top menu, and click the Start option of the REST Task Process.
  3. Enter a value for the Name of the Patient and Appointment Number and click Start. This creates a Claimable Task.

    You need to enter the Appointment Number you received in the response of the service invocation above.

  4. Click TASKS in the top menu, and then click Claimable Tasks
  5. Click on the new  Claimable Task .

    You should not approve the appointment if the Number of days is less than one.



    You view the Appointment Number you entered before and the Number of Days retrieved as 1, which means you can approve it since it is one day ahead from today.

  6. Click Complete Task, to approve the appointment.
  7. Click  TASKS  →  COMPLETED TASKS  to view the completed task.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.