Monday 17 September 2018

Build database objects/services in HANA service using SAP WebIDE Full-Stack : Part 2

This blog is part of a blog series which shows to build HANA database artefacts using the SAP WebIDE Full-Stack and the new HANA service on Cloud Foundry.

Create Nodejs. Module


In this section, I am going to show how to create a nodejs module and add an OData service within it. This OData service will be used to expose the contents of the table/view modeled earlier.

Select the project “ProductsApp01” (created earlier) and use the context menu to create a “Node.js module”.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Provide the name of the module as “products01_js” and enable XSJS support before clicking on Finish

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Select the lib folder and use the context menu to create a new file with the name “products01.xsodata”

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Paste the below code into the xsodata file

service { 
"products01_db::catalog.product" as "Products"
keys ("Id");
}

Below is how your XSOData file would look like:

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Modify the yaml file by selecting the nodejs module and under “Requires” section, add two dependencies. This will enable the nodejs module to refer to the DB artefacts.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Build the nodejs module by selecting the folder and using the Build option in the context menu

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

You should see a success message in the log files..

Run the nodejs application using the menu option shown below.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

This will take few minutes. You will get a URL in the console as shown below.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Click on the URL and change it to refer the OData service as shown below

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Let’s deploy this application in our Cloud Foundry runtime. Select the root project folder and use the context menu to Build the project

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

In few minutes, you should be able to the successful build and  new folder would get created in your workspace with the .mtar file.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Deploy the mtar file to the Cloud Platform account using the context menu. When prompted for Cloud Foundry details – select your CF API Endpoint, Organization and space

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

This will take you few minutes to deploy the applications to your CF space.

Once the application has been deployed, navigate to your CF space and under Applications menu, you will be able to see one app for db module and another for js module. The products01_db app would be stopped by default and is only required for the creation of the DB artefacts. Also note there in another app with a long GUID. This app was created when you tried to test the nodejs module from within WebIDE. You can stop this app as its not required.  We will be using the app “products01_js” as it will provide the OData service.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Click on the js app to view the application URL.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

Modify the URL to call the OData service as shown below and open it in the browser.

{"d":{"results":[{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(101)","type":"default.ProductsType"},"Id":101,"name":"Notebook","supplierName":"IBM","category":"Computer","unitPrice":2300,"unitsInStock":34},{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(102)","type":"default.ProductsType"},"Id":102,"name":"Tablet","supplierName":"Samsung","category":"Computer","unitPrice":900,"unitsInStock":22},{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(103)","type":"default.ProductsType"},"Id":103,"name":"iPhone","supplierName":"Apple","category":"Phone","unitPrice":800,"unitsInStock":129},{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(105)","type":"default.ProductsType"},"Id":105,"name":"iPod","supplierName":"Apple","category":"Music","unitPrice":700,"unitsInStock":298}]}}

This should return the list of products. You can now use this URL with other SAP CP services or build a UI on top of it too.

SAP HANA Certification, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Tutorial and Material

No comments:

Post a Comment