...
Log in to the management console using the following URL on your browser: "https://localhost:8243/carbon/.
Click Create under the under Data Service menu to to open the Create Data Service windowwindow.
Enter Excel as the data service name as shown below. Leave the default values for the other fields.
Click Next to go to the Datasources screen.
...
- Click Add New Datasource to open the following screen.
- Follow the instructions below to fill the datasource details.
In the Datasource Id field, enter Excel as the value.
In the Datasource Type field, specify the type of datasource for which the data service is created. Select Excel from the list. You will now get the following screen:
In the Excel URL field, specify the path to your Excel file. In this tutorial, we are using a sample excel file that is stored in the following location of your product pack:
./samples/data-services/resources/Products.xls
.
The Use Query Mode option allows you to write queries for the datasource in two different ways.Anchor use_query_mode use_query_mode Non-Query mode: Allows you to directly expose the contents of the excel file as a service.
Query mode: Allows you to query the Excel file in SQL-like manner, and expose the results as a service.
Note See the next section on writing queries for more information on how the query mode affects how you query data in the excel sheet.
- Save the datasource.
- Click Next to go to the Queries screen.
...
- Click Add New Query to open the Add New Query screen.
- Enter Q1 as the query id in the Query ID field.
In the Datasource field, select the datasource for which you are going to write a query. Select the Excel datasource that you created previously.
- You can directly specify the details of the spreadsheet as shown below.
- Define Output Mapping: Now, let's specify how the data fetched from the datasource should be displayed in the output. The sample Excel datasource we we are using contains three columns: ID, Model and Classification. We will create an output mapping for each of these columns.
- 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 Products in this field.
- In the Row Name field, specify the XML element that should group each individual result. Enter Enter Product in this field.
- Click Add New Output Mapping to start creating the output mapping for the ID column. Enter values as shown below:
- Click Add to save the output mapping.
Create output mappings for the remaining columns given below.
Mapping Type Element Name Datasource Type Datasource Column Name Parameter Type Schema Type Element Model Column Model SCALAR string Element Classification Column Classification SCALAR string Info Find out more about defining Output Mappings.
- Click Next to go to the Operations screen.
...
- Click Add New Query to open the Add New Query screen.
- Enter Q1 as the query id in the Query ID field.
In the Datasource field, select the datasource for which you are going to write a query. Select the Excel datasource that you created previously.
Specify an SQL query to insert data into the spreadsheet.
Code Block INSERT INTO sheet1 (ID, Model, Classification) VALUES(?,?,?)
- Define Input Mapping: You need to create input mappings for the ID, Model and Classification columns specified in the above SQL statement. These input mapping parameters will be used for inserting data into the relevant columns. Click Click Generate Input Mapping, and default input mappings will be generated for all the fields that you have specified in your SQL statement as shown below.
Info Find out more about defining Input Mappings.
Click Next to go to the Operations screenscreen.
Defining operations to invoke the query
...
Once you have defined the operation, click Finish to 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.
...