My experience with HXE2 SP3 – Part3
hello readers, this is the 3rd post in my series of experiences while working with HXE2SP3. If you have read the other 2, thank you… if you have not, please check them out.
- Part 1 – installing HXE and adding a sapui5 module
- Part 2 – how to add a db module to my xsa project
In this section, I will explain how adding a nodejs module goes and some interesting learning I had while doing this. Thank you again for reading this far.
My steps:
- Add a new module to the existing project.
Let’s also enable XSJS for backwards compatibility in case we had an xsjs service before
And Yes you are right.. the new reference is automatically added to the mta.yaml file.
The package.json file contains the configuration for this nodejs module. Where is the entry point, and what other properties will be used in this module, such as scripts, versions, engines, etc.
The server.js file – is the entry point of our nodejs module.
From this file, we can create REST APIs that perform tasks in response to a request. Notice in our server.js file.. it redirects to the index.xsjs file… let’s examine what happens there… so let’s first build and then run our nodejs module
It was successfully built
Btw… while the nodejs module is starting.. we can go back to the cockpit and look in our development space.
After a few minutes… then the new service starts
We can also see the output in the webide console…
And then run the service to get the output from the xsjs service.
Woooooaaaaaahhhhh!!!
You may be wondering.. where is nodejs, where is xsjs.. what is all of the other code..
The best way to differentiate and know what code is being run, we can look into the file extensions..
xsjs – XSJS legacy XS services
js – this is the nodejs code.. you can also look into the different code function calls etc.
now that we have the example working, let’s add the UAA-service to make it more robust, also add the dbm module as a dependency to be able to call the db and extract data.
In your mta.yaml file, reopen the Requires section and add the following:
Now, in the app module… let’s add a reference to the nodejs module so that we can make calls from our UI app to the server side and even navigate from the browser (nodejs module). In the mta.yaml file, under the Requires section add the nodejs_api provider. * notice the provider and the resource types.
Then add the routes to the xs-app.json file.
Let me take a moment here and explain these routes…. As part of any SPA (client side) or even on the server side, there is route navigation… so we can easily get to our destination with a route. This is similar how REST APIs defines the entity we need to get to or a specific object within a collection, such as:
host:port/destination –> mainly seen on a SPA
host:port/destination/id –> seen at SPA to navigate to a specific object
host:port/entityCollection –>mainly seen on REST APIs
host:port/entityCollection/objectId –> mainly seen on REST APIs
*if you copied the code from the great tutorial from SAP… make sure modify the name of your nodejs module, in my case it is called nodejs
Further, in the server.js file… (entry point to our back end service, comment out the anonymous authentication) so we can test out the integration with that service
Re-build and re-run your web app module since that will now be our entry point.
If you do what I did….
- and ran the index.xsjs you will get unauthorized since we had modified the routes
- and ran the web app module and nav to the nodejs/index.xsjs file path you will get 404 not found… since the path will not match…. Finally you will realize that the route does make sense –
Hopefully you get it to run… and share the same feeling as me
Then try your other routes such as:
Or your odata service, however, if you didn’t specify a key on your view you may see an error like:
so then, I specified a key and re-built the project
And now
fine then XSA… … let’s add the $format flag
And the entity collections
From here on wards it should be simple for anyone already knowing odata… but if you do not.. here are some good rules
My next finding was that this is still odata v2 (nodejs and javascript) and apparently Java is the only runtime that supports odata v4.. so I will investigate further.
I went back to my hdbcds file… added the odata annotation, re-build the db module… re-run and looks like v2 still ? so let’s go build a Java module, why not.
by this point, I have created a new project, a ui5 module, a db module and a nodejs (xsjs compatibility mode) module. All the moving pieces feel like what’s happening on the east coast – jk – hope every one is doing ok in those areas.
Thank you again for reading this blog, please share your findings, experiences, and issues.
Hi Sergio,
These are interesting blogs and great to see your take on how your development experience went with SAP HANA, express edition SPS03.
Aside from the ones you mentioned in this blog series when creating each of these modules, were there any other significant things you experienced during development that you think could have been a better user experience?
Also, have you tried this on another environment besides a VM on your laptop, something like a cloud instance or container?
Excited to hear back.
Thanks,
-Annie
Hi Annie,
thank you for the comment. I have not tried the cloud or container instances but I will probably do that next to see and compare myself other alternatives.
As far as sgnificant changes are the tools primarily such as the mta graphical editor, the CDS graphical view... and the web Ide - this is in comparison with my experience on HANA 1 SP12. As far as UX improvements ... I am not sure if this would count as an improvement but having the cockpit and cockpit manager seems somewhat confusing on the naming of 2 tools... I think this would have been ok to keep on the same tool with a different set of permissions or roles, just from my personal opinion. I’ll think of others and let you know once I do a few more examples.
thank you again for your question and comment
Hi Sergio,
Thanks for your feedback here about your own user experience with the new version, and your take on the Cockpit tools.
Would be great to hear more about the other environments as well. Keep 'em coming...we're here to listen! 🙂
Cheers,
Annie
Greate blog Sergio, save us many hour of testing and struggle with bad documentation. Just wondering if you can explain how we can use a Odata connection in a SAPUI5 module. Any guidens will be appreciated.
Br
Petter
Thank you Petter...
in order to consume the web service from a ui5 application, you will need to be able to consume it (follow steps from above) then you can call the web service via an AJAX call from your UI5 application. In the UI5 SDK, the oData model has a read function that can do that, as shown here:
https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel/methods/read
if you decide to consume the odata model as a json model, that can also be done, https://sapui5.hana.ondemand.com/#/api/sap.ui.model.json.JSONModel/constructor
i also created a blog on how to consume odata services from a ui5 app on the SCP
https://blogs.sap.com/2016/05/26/using-hcp-to-develop-a-custom-fiori-app/
was this what you were looking for? let me know if you have additional questions. good luck!
Hi
Thanks for fast answer. I was hoping the I could use my Odata connection that I have created with the eclipse HANA modeler tool. And link that to a Entity set in the layout editor. Do you know how to use the enity set in the layout editor, is it possible to consume the odata connection I have created in HANA modeler.
I have not used it there, but... it looks like no Entities are defined yet.
Hi
I have tried to find a palse to add the Odata service URL, but have not manage to find the place. The Odata is up and runing and I can see the output in the browser. I have also made it possible to use the service as an anonyous user.
what i know is that when you create the app from a template.. you are able to set your odata end point there... then from your editor you should be able to see the Entity Sets... the configuration from the template gets saved in the manifest.json file (see those lines in my blog) and see if you can add it there in case you don't see a wizard... ill be checking the web ide and ill letu know if i find it