This tutorial will guide you on how to expose an RDF datasource as a data service using WSO2 Data Services Serverthe Create New Data Service wizard. To demonstrate this feature, we will use a sample RDF file that is shipped with WSO2 DSS EI by default. Given below are the details of this datasource:
The RDF file (Movies.rdf
), stored in the <DSS<EI_HOME>/samples/data-services/resources/
folder contains data about some popular movies. Each movie data has the following sub elements: "title", "director", "year", "genre" and "actor".
...
See the following topics for instructions:
Table of Contents
...
Start the Create New Data Service wizard
Now, let's start creating the data service from scratch:
Log in to the management console of DSS using WSO2 EI using the following URL on your browser: "https://10.100.5.65:9443localhost:8243/carbon/".
Click Create under the under Data Service menu to to open the Create Data Service window.
Enter RDF as the data service name as shown below. Leave the default values for the other fields.
Click Next to go to the Datasources screen.
Add
...
an RDF file as the datasource
You can add an RDF file as the datasource as explained below.
- Click Add New Datasource and enter values as shown below.
- Follow the instructions below to fill the datasource details.
- Datasource ID: Enter RDF as the ID for the datasource.
- Datasource Type: Select RDF as the datasource type from the list. You can then specify the location of your RDF file: ./samples/data-services/resources/Movies.rdf
- RDF File Location: Enter the path to the RDF file. In this tutorial we are using a sample RDF file that is shipped with your product. The file location is ./samples/data-services/resources/Movies.rdf.
- Save the datasource.
- Click Next to go to the Queries screen.
Define a query for the datasource
Now let's start writing a query for getting data from the Movies.
rdf file. The query will specify the data that should be fetched by this query, and the format that should be used to display data when the query is invoked.
...
- Click Add New Input Mapping to start creating the input mapping.
- We will create an input mapping for 'genre', which will allow us to query for data based on the genre of the movie. Enter the values as shown below.
- The new input mapping will be listed as shown below.
Info |
---|
Find out more about defining Input Mappings in WSO2 DSS. |
Create output mapping
Now let's specify output mappings to specify how the data fetched from the query should be displayed. We will create output mappings for all the types of data in the RDF file: title, director, year, genre and actor. Follow the steps given below.
- In the Output type field, specify the format in which the query results should be presented. You can select XML, JSON or RDF. We will use XML for this tutorial.
- In the Grouped by element field, specify a grouping for all the output mappings. This will be the XML element that will group the query result. Enter Movies in this field.
- In the Row Name field, specify the XML element that should group each individual result. Enter Movie in this field.
- Click Add New Output Mapping to start creating the output mapping for the title column. Enter values as shown below:
- Click Add to save the output mapping. You will now have one output mapping listed for the GetMoviesbyGenre query as shown below.
Now, add the following output mappings:
Mapping Type Element Name Datasource Type Datasource Column Name Parameter Type Schema Type Element director Column director SCALAR string Element year Column year SCALAR string Element genre Column genre SCALAR string Element actor Column actor SCALAR string
Info |
---|
Find out more about defining Output Mappings in WSO2 DSS. |
Define an operation to invoke the query
Follow the steps given below.
- Once you have defined the query, click Next to go to the Operations screen.
- Click Add New Operation and enter the following values:
- Operation Name: Enter GetMoviesbyGenre as the operation name.
- Query ID: Select the GetMoviesbyGenre query in this field.
- Save the operation.
Finish creating the data service
Once you have defined the operation, click Finish to complete the data service creation process. You will now be taken to the Deployed Services screen, which shows all the data services deployed on the server.
...
Invoking your data service
You can try the data service you created by using the TryIt tool that is in your product by default.
...