RESTful API
Using weather REST API ..
Use Case - Weather API
Accurate weather information and forecasts are essential elements in critical decision-making scenarios. Both enterprises and individual consumers rely on current and future weather patterns to run their daily operations and manage risks successfully.
As such, the increased demand for accurate weather information has pushed the developer community to invest in building reliable weather apps.
So in this workshop we're going to:
use a weather API.
pull the data into PDI.
display dataset in a CDE dashboard - Pentaho Server service.

The following section is for Reference only.
The CDE has been activated.
You may require to create an Openweathermap account.
Follow the steps outlined below to activate CDE and test the API call with Postman.

To activate the Community Dashboard Editor (CDE) plugin, you will need to change the configuration of several .xml files in the Pentaho solutions folder as described below. Verify that you have the appropriate permissions to read, write, and execute commands in the specified directories in the instructions.
Ensure the Pentaho Server is stopped.
Uncomment the following lines:
/opt/pentaho/server/pentaho-server/pentaho-solutions/system/pentaho-cdf-dd/plugin.xml
Locate the following two commented blocks in this file and remove the comment tags from these blocks.
Save.
Uncomment the following lines:
/opt/pentaho/server/pentaho-server/pentaho-solutions/system/pentaho-cdf-dd/settings.xml
Locate the block at end of the file, 'Defining the new-toolbar-button' and remove the comments tags from this block
Locate the block at end of the file, 'Defining the new-toolbar-button' and remove the comments tags from this block.
Save.
Save your changes.
Restart the Pentaho Server.
Community Dashboard Editor (CDE)
To verify CDE is activated, do the following.
Log on to the Pentaho User Console.
From the Home page, click the Create New button.
From the menu that displays, select the New CDE Dashboard option. You can now begin creating your first CDE dashboard.

Sign up for a free Openweather account.
Once registered, generate an API key.

Read the API documentation for deployment - Geocoding
q
required
City name, state code (only for the US) and country code divided by comma. Please use ISO 3166 country codes.
appid
required
Your unique API key (you can always find it on your account page under the "API key" tab)
limit
optional
Number of the locations in the API response (up to 5 results can be returned in the API response)
Example
Postman is an API platform for building and using APIs.
Sign up - for free - & download Postman.
You can also install Postman as a VS Extension or from Snap.
Once logged into your account you can test your API weather call and test the output of various parameters.

The new 'One Call' API requires the location latitude & logitude.
This method usues a deprecated Geocoding API to resolve city, state, country - ISO 3166.
https://api.openweathermap.org/data/2.5/weather?
q=
{city name}
london
{state code}
England
{country code}
GB
appid
{API key}

Optional Params
Edit the query to set the mode & units.
mode
Possible values are xml and html. If you don't use the mode parameter format is JSON by default.
units
Units of measurement. standard, metric and imperial units are available. If you do not use the units parameter, standard units will be applied by default.
lang
You can use this parameter to get the output in your language.
x
Resources
REST API documentation API information for building custom solutions of Pentaho products.
CDF API Pentaho Data Integration and Analytics CDF API documentation.
Pentaho Data Integration and Analytics Platform JavaScript API.
The CDE is a Pentaho service.
x
x

Weather API
Start Pentaho Pro Suite.
Open the following transformation in Pentaho Data Integration.
~/Workshop--Data-Integration/Labs/Module 7 - Workflows/API/tr_weather_cda.ktr
Browse through the following steps.
As you already know, Kettle variables can be used in Jobs and Transformations wherever you see a dollar sign. There is one more way to use variables—getting their values as fields of your stream. For this, you have to use the Get Variables step.
With the Get Variables step, you can get the value for one or more variables. The kind of variable can be any of the Kettle variables types you just learned the variables defined in the kettle.properties file, internal variables, for example, ${user.dir}, named parameters, or other Kettle variables.
Double-click on the step to view settings.

The variables & default values are pulled from 'Named Parameters' set in the Transformation properties.

The REST Client transformation step enables you to consume RESTfull services.
For a simple http GET request you can also use: http client step.
Double-click on the step to view settings.

Based on the openweathermap API documentation:
• the URL calls the service to return the weather data based on:
${city}=London
${country}=GB
${units}=metric
${mode}=xml
• 'response' is return to the 'results' data stream field.
• the fields are 'mapped' in the fileds tab.

This step provides the ability to read data from any type of XML file using XPath specifications.
For further details: Get data from XML
Double-click on the step to view settings.

The response from the API call - results - is the data source.
Click on the 'Content' tab.

To determine the XPath, you will need to copy and paste a snippet of the API call.
The root is: /current

Click on Fields tab.

The Row Normaliser step converts the columns of an input stream into rows. You can use this step to normalize repeating groups of columns.
Double-click on the step to view settings.

The Select values step can perform all the following actions on fields in the PDI data stream:
• Select values
• Remove values
• Rename values
• Change data types
• Configure length and precision of values
x
x
x
Community Data Access (CDA) allows you to gather and combine data from several data sources into a single structure, which you can then use in dashboards. Driven by the need to unify access to the Pentaho data layer, CDA was developed to create an abstraction layer between a CTools dashboard and the physical connections to different databases.
CDA has three main objectives:
Combine data from several sources
Ensure security while accessing the data (avoiding, for instance, SQL injection problems)
Ease data exports
View the following CDA file.
~/Workshop--Data-Integration/
x
x
Define a connection to the 'Pentaho' Repository.

Create a folder: Public / weather
x
x
x
x
Last updated
Was this helpful?

