Skip to main content

Exposing integration by using a data type

Archived

11 Tasks

20 mins

Pega Platform 8.3.1
Visible to: All users
Advanced Pega Platform 8.3.1 English
This content is now archived and is no longer updated. Progress is not calculated. Pega Cloud instances are disabled, and badges are no longer awarded.

Scenario

Front Stage needs to know if the probability of precipitation equals or exceeds 40 percent during the an event. At present, the weather forecast queries a data transorm. Front Stage now wants to query a true weather forecast service the day before an event.

The forecast is performed for the location where the event is being held, as opposed to the user's browser location. Given that the role of the user is Facility Coordinator, assume the browser user is in close proximity to the event.

The following table provides the credentials you need to complete the exercise.

Role Operator ID Password
Administrator Admin@Booking rules

 

Using the existing data class FSG-Data-Precipitation-Forecast, simulate a weather forecast service query that returns the probability of precipitation for each day of an event.

Create and interface a data page to pull the weather forecast. The parameters when querying the service are:

  • StartDate
  • EndDate
  • Latitude
  • Longitude

The response is a list of pages where each page resembles the FSG-Data-Precipitation class.

{ "forecast":[ { "Date":"20170731" ,"Probability":"35" ,"Unit":"Percent" }, { "Date":"20170801" ,"Probability":"40" ,"Unit":"Percent" } ] }

Enable geolocation at the case type level and portal level. When enabled, the pxRequestor system page contains the following location fields:

  • pxRequestor.pyLatitude
  • pxRequestor.pyLongitude

Use any weather URL for the simulated weather service (for example, http://weatherforecast.com). Develop a UI to display the request parameters. The REST response contains as many elements as the number of days the event is held. Post-process the response to identify the first day where the probability of precipitation equals or exceeds 40 percent.

Detailed Tasks

1 Detailed steps

To complete the assignment, you will:

  1. Create a new RainForecast REST Connector.
  2. Create a new D_ForecastService data page.
  3. Configure the new D_ForecastService data page to use the REST Connector.
  4. Create a Simulation Activity as the Web Service is not available.
  5. Configure the RainForecast REST Connector to use the simulation activity.
  6. Enable Geolocation tracking to capture the location of the operator.
  7. Create and configure a ForecastService property to use the new D_Forecast data page.
  8. Modify the Weather case life cycle to conditionally make precipitation preparations.

2 Create a new RainForecast REST Connector

  1. From the DEV Studio menu, select Configure > Integration > Connectors > Create REST integration to start the New REST Integration wizard.
  2. On the Connection form, enter the following values.
    Description Value
    Name Rain Forecast
    Endpoint URL http://weatherforecast.com
    Query string parameters

    StartDate
    EndDate
    Latitude
    Longitude

    When you are finished, the completed tab will look like the following image.

    Rest Integration

     

  3. Advance to the Resource methods form. in the Name field, enter Forecast . Use the default GET method as shown in the following image.
    Resource method

     

  4. Advance to the Data model form. Save the example response text to a file. Click + Add a file to add the text file as shown in the following image.
    Data model

     

  5. Advance to the Review form. Change the parent class to FSG-Int. Change the generated class to FSG-Int-RainForecast. Do not generate a Data layer and select Skip (I'll do it later). When finished, the form will look like the following image.
    Review

     

  6. Click Create to complete REST integration.

3 Create a new D_ForecastService data page

  1. In the Data Explorer, expand Forecast and select the Forecast data page (D_Forecast).
  2. Click Save As to save the D_Forecast data page to a new D_ForecastService. Enter the following values:
    Field Value
    Label Forecast Service
    Identifier D_ForecastService
    Apply to FSG-Data-Precipitation-Forecast
    Add to ruleset Weather
  3. Click Create and open to create the new D_ForecastService data page.
  4. In the Parameters tab of the D_ForecastService data page, delete the pyGUID parameter.
  5.  In the Parameters tab of the D_ForecastService data page, add the following Required Yes, In/Out In parameters:
    • StartDate (String)
    • EndDate (String)
    • Latitude (Decimal)
    • Longitude (Decimal)

4 Configure the new D_ForecastService data page to use the new RainForecast REST Connector

  1. In the Data sources section in the Definition tab of the D_ForecastService data page, update the following values:
    Field Value
    Source Connector
    Type REST
    Name Forecast
    Request Data Transform ForecastRequestGET
    Response Data Transform ForecastResponseGET
  2. Select the Parameters link under Request Data Transform and enable the Pass current parameter page check box in the Parameters for ForecastRequestGET dialog.
  3. Select the Parameters link under Response Data Transform. In the Parameters for ForecastResponseGET dialog, enable the Pass current parameter page check box.
    1. Create the Request Data Transform ForecastRequestGET using Add to ruleset RainForecast.
    2. On the Parameters tab, require the same parameters as the D_ForecastListService data page.
    3. On the Definition tab, select ActionUpdate Page for Target.request.query_GET and Set the properties as shown in the following image.
      Forecast request get

       

    4. Create the Response Data Transform ForecastResponseGET using Add to ruleset RainForecast. Click Create and open and then Save to create and save the auto-generated ForecastResponseGET data transform.
    5. Save the D_ForecastListService data page.

5 Create a simulation activity for the RainForecast REST connector

Simulate the Forecast REST connector to return as many FSG-Int-RainForecast-Forecast pages as there are days between StartDate and EndDate inclusive by doing the following:

  1. Create an activity within the FSG-Int-RainForecast-ForecastAPI class and RainForecast ruleset named SimulateRainForecast.
  2. In the activity Parameters tab, define an Out parameter NumDays (Integer), an In parameter StartDateTime (Date Time), and an In parameter EndDateTime (Date Time). The completed tab should look like the following:
    SimulateRainForecast

     

  3. In the Steps tab for activity step 1, enter Property-Set Param.NumDays = @DateTime.DateTimeDifference (Param.StartDateTime, Param.EndDateTime, "D").
  4. For activity step 2, enter Repeat For loop, Minimum Value = 0, Max Value = Param.NumDays, Increment = 1. Property-Set the following:
    • .response_GET.forecast(<APPEND>).Date = @DateTime.addToDate( .request.query_GET.StartDate,param.pyForEachCount,0,0,0)
    • .response_GET.forecast(<LAST>).Probability = 40
    • .response_GET.forecast(<LAST>).Unit = “Percent"

    The completed Steps tab should look like the following:

    SimulateRainForecast activity

     

  5. Save the activity for getting the forecast information.

6 Configure the RainForecast REST Connector to use the simulation activity

  1. Open the Forecast REST connector record, click the Simulations button and add the SimulateRainForecast activity.
  2. Click one or both context radio buttons (Global and User Session)

    The completed Simulations dialog should look like the following.

    Simulation

     

  3. Click Submit to save your forecast simulation.
  4. Return to the ForecastResponseGET response data transform and implement as the following:
    1. In the Parameters tab, delete parameter pyGUID and add the following In parameters:
      • StartDate (String)
      • EndDate (String)
      • Latitude (Decimal)
      • Longitude (Decimal)
    2. In the Definition tab, update step 1 as follows:

       

      Field Value
      Action Append To
      Target Primary.pxResults
      Relation each page in
      Source DataSource.response_GET.forecast
    3. Click Save to save the updated data transform.
  5. Create a Post load processing activity for the D_ForecastService data page named PostRainForecastProc using Add to ruleset Weather.
  6. In the Security tab of the activity, set the PostRainForecastProc Activity type = Load Data Page.
  7. In the Pages and Classes tab, declare a Page name D_ForecastService.pxResults using Class FSG-Data-Precipitation-Forecast.
  8. In the Parameters tab, define an Out parameter Name IndexToSave using Data type Integer with Default value 0.
  9. In the Steps tab, do the following:
    1. In step 1, enter Property-Set where Param.IndexToSave = 0.
    2. In step 2, set Loop Repeat to For each embedded page in Step page D_ForecastService.pxResults capturing the first index where Probability >= 40%. To configure the loop, do the following:
      1. Use MethodProperty-Set where Param.IndexToSave = Param.pyForEachCount.
      2. Click When and set the condition to Enable conditions before this action with When .Probability>=40 if true Continue Whens if false Exit Iteration.
    3. In step 3, use Method Exit-Activity and set When to Enable conditions before this action with When Param.IndexToSave==0 if true Exit Activity if false Skip Step.
    4. In step 4, use Method Page-Copy to CopyFrom D_ForecastService.pxResults (param.IndexToSave) to CopyInto D_ForecastService.
    5. In step 5, use Method Property-Set with Step page D_ForecastService.pxResults(param.IndexToSave) to set Primary.Date = .Date, Primary.Probability = .Probability, and Primary.Unit = .Unit.

      The completed Steps tab should look like the following.

      Post rain forecast proc

       

7 Enable Geolocation tracking and capture the location of the operator.

  1. From the Cases Explorer, open the Weather case type .
  2. On the Settings tab in the General section, enable Enable geolocation tracking.
  3. Create Whenever Used declare expressions for the (FSG-Booking-Work-Weather) Weather.Latitude and Weather.Longitude properties in the Weather ruleset:
    1. (FSG-Booking-Work-Weather) .Weather.Latitude = pxRequestor.pyLatitude
    2. (FSG-Booking-Work-Weather) .Weather.Longitude = pxRequestor.pyLongitude

8 Create and configure a ForecastService property to use the new D_Forecast data page

  1. Copy the (FSG-Booking-Work-Weather) Forecast property to (FSG-Booking-Work-Weather) ForecastService.
  2. For the new ForcastService property, change Data access from Refer to a data page to Copy from a data page. Change the Data Page to D_ForecastService. Configure the parameter as shown below:
    Forecast service

     

9 Modify the Weather case life cycle to conditionally prepare for precipitation

  1. In APP Studio, open the Weather case type from the Cases Explorer.
  2. Change the Start process (otherwise skip) to Custom condition.
  3. For the Prepare for Weather process in the Preparing stage, use a When condition.
  4. Next to the condition field, click the gear icon to add the condition as shown in the following image. If .Forecast_service is not displayed, configure the condition as Rain probability is 40 or greater.
    Weather stages
  5. Save the life cycle to generate the When rule.
  6. In DEV Studio modify the generated when rule to use .ForecastService.Probability or the Forecast.Probability as shown in the following image.
    Prepare for weather when

     

10 Verify your work

  1. Create an Event case and advance the case to where child cases are spun off.
  2. Select Begin for a Weather Case.
  3. If the case is paused at the Wait for Day before Event step, click Yes (continue). If necessary, click Begin.
    Weather case

     

    The Get Weather Forecast view is displayed.

11 Solution Download



Available in the following mission:

We'd prefer it if you saw us at our best.

Pega Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice