Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Log in to the management console using the following URL on your browser:  "https://localhost:8243/carbon/".
  2. Click Create under Data Service menu to  to open the Create Data Service window.
  3. Enter CustomTabularDataService as the data service name.
  4. When you get to the Add New Datasource screen, enter CustomTabular as the datasource ID.
  5. Select Custom Data Source as the datasource type. 
  6. Select Custom Tabular Data Source.
  7. In the Custom Data Source Class field, enter the following interface: org.wso2.carbon.dataservices.core.custom.datasource.InMemoryDataSource
  8. Click Add New Property to enter properties that will identify the data in the datasource.

    PropertyValue
    inmemory_datasource_schema
    {Users:[ID,Name]}
    inmemory_datasource_records
    {Users:[["1","Will Smith"],["2","Denzel Washington"]]
  9. The new datasource will now be listed as shown below.

  10. Click Add New Query to start defining a query. We will write a query to find and display all users in the datasource.

    1. In the Query ID field, enter getAllUsers.
    2. In the Datasource field, select the CustomTabular datasource that you created in the previous step.

    3. In the SQL field, enter a query:

      Code Block
      SELECT ID,Name FROM Users
    4. Now let's specify output mappings for the data. We will create output mappings for the following data:  ID and Name
      1. 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.
      2. 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 Users in this field. 
      3. In the Row Name field, specify the XML element that should group each individual result.  Enter User in this field.
      4. Click Add New Output Mapping to start creating the output mapping for the ID field. Enter values as shown below:
      5. Click Add to save the output mapping. 
      6. Now, add another output mapping for the Name column.

      7. You will now have the following output mappings listed for the getAllUsers query:

  11. Click Add New Operation to open the following screen.
  12. In the Operation Name field, enter 'getAllUsersOp'.
  13. In the Query ID field, select getAllUsers from the list.
  14. Save the operation.
  15. 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.

...

  1. Click Create under Data Service menu to  to open the Create Data Service window.
  2. Enter CustomQueryDataService as the data service name.
  3. When you get to the Add New Datasource screen, enter CustomQuery as the datasource ID.
  4. Select Custom Data Source as the datasource type. 
  5. Select Custom Query Data Source.
  6. In the Custom Data Source Class field, enter the following interface: org.wso2.carbon.dataservices.core.custom.datasource.EchoDataSource.
  7. Click Add New Property to enter properties that will identify the data in the datasource.

    PropertyValue
    prop1
    prop_value1
    prop2
    prop_value2

    Code Block
    <property name="prop1">prop_value1</property>
    <property name="prop2">prop_value2</property>
  8. The new datasource will be listed as shown below.

  9. Click Add New Query to start defining a query. We will write a query to find and display all users in the datasource.

    1. In the Query ID field, enter getValues.
    2. In the Datasource field, select the CustomQuery datasource that you created in the previous step.

    3. In the Expression field, enter a query:

      Code Block
      column1,column2;R1C1 :param1,R1C2 :param2;R2C1 :param1,R2C2 :param2
    4. Now let's specify input mappings to enter data. We will create input mappings for the fields given in the expression above:  Column1 and Column2
      1. Click Add New Input Mapping to open the respective screen.
      2. Define a mapping for column 1 as shown below.
      3. Click Add to save the mapping.
      4. Add another input mapping for column 2. You will now have two input mappings for the two columns as shown below.
    5. Now let's specify output mappings, which will determine how the result from your query will be presented when the query is invoked. The sample datasource we are using contains the following columns: Column 1 and Column 2. We will create an output mapping for each of these columns. 
      1. 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.
      2. In the Grouped by element field, specify a grouping for all the output mappings. We will enter Rows.
      3. In the Row Name field, specify the XML element that will be used to display an individual value. We will enter Row.
      4. Click Add New Output Mapping to start creating the output mapping for column. Enter values as shown below.
      5.  Click Add to save the output mapping.
      6. You will now have two output mappings created as shown below.
  10. Click Add New Operation to open the Add New Operation screen.
  11. In the Operation Name field, enter 'getValuesOp'.
  12. In the Query ID field, select getValues from the list. 
  13. Save the operation.
  14. 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. 

...

  1. Go to the Deployed Services screen.
  2. Click the Try this service link for the CustomQueryDataService data service. The TryIt Tool will open with the data service.
  3. Select the getValuesOp operation.
  4. Enter any values for the input parameters as shown below.

    Code Block
    <!--Exactly 1 occurrence-->
          <xs:column1 xmlns:xs="http://ws.wso2.org/dataservice">1</xs:column1>
          <!--Exactly 1 occurrence-->
          <xs:column2 xmlns:xs="http://ws.wso2.org/dataservice">2</xs:column2>column2
  5. Click Send to see the result:

    Code Block
    <Rows xmlns="http://ws.wso2.org/dataservice">
       <Row>
          <C1>R1C1 :param1</C1>
          <C2>R1C2 :param2</C2>
       </Row>
       <Row>
          <C1>R2C1 :param1</C1>
          <C2>R2C2 :param2</C2>
       </Row>
    </Rows>