Previous post https://blogs.sap.com/2017/10/26/using-a-third-party-library-with-sapui5-application-sap-hana-cloud-development-scenario-part-2/

Testing Odata Service :

In this part we have to validate our Odata service befor building the Front End application.

For this i will use Advanced Rest Client ( chrome Extension ). Create a new Request put the url to call Event Entity and added the “$top” parameter to the url to select just the first two events from the whole list.

If you are not familiar with Odata you can see this blog https://blogs.sap.com/2016/02/08/odata-everything-that-you-need-to-know-part-1/

This is the final set up we need to use GET operation and i added X-Csrf-Token = Fetch to use the result in the next operation

https://mdcpXXXXXXtrial.hanatrial.ondemand.com/Calendar/services/BookingEBC.xsodata/Events?$top=2

<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <feed xml:base="https://mdcpXXXXXXtrial.hanatrial.ondemand.com:443/Calendar/services/BookingEBC.xsodata/"> <title type="text">Events</title> <id>https://mdcpXXXXXXtrial.hanatrial.ondemand.com:443/Calendar/services/BookingEBC.xsodata/Events</id> <author> <name /> </author> <link title="Events" href="Events" /> <entry> <id>https://mdcpXXXXXXtrial.hanatrial.ondemand.com:443/Calendar/services/BookingEBC.xsodata/Events('00065ec7-9051-4798-a321-7dfc4eec09c9')</id> <title type="text" /> <author> <name /> </author> <link title="Events" href="Events('00065ec7-9051-4798-a321-7dfc4eec09c9')" /> <category term="Calendar.services.BookingEBC.EventsType" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:ID m:type="Edm.String">00065ec7-9051-4798-a321-7dfc4eec09c9</d:ID> <d:TITLE m:type="Edm.String">Empty Task TEST</d:TITLE> <d:START_DATE m:type="Edm.String">2017-05-11T09:00</d:START_DATE> <d:END_DATE m:type="Edm.String">2017-05-11T10:30</d:END_DATE> <d:COLOR m:type="Edm.String">#77DD77</d:COLOR> <d:STATUS m:type="Edm.String">F</d:STATUS> <d:DESCRIPTION m:type="Edm.String">6f9137f3-092a-408b-9385-549ed7116ffb</d:DESCRIPTION> <d:YEAR m:type="Edm.Int32">2017</d:YEAR> <d:MONTH m:type="Edm.Int32">5</d:MONTH> <d:DAY m:type="Edm.Int32">11</d:DAY> <d:OWNERID m:type="Edm.String">ONGABI</d:OWNERID> <d:CUST_COSTCENTER m:type="Edm.String" /> <d:SREP_COSTCENTER m:type="Edm.String" /> </m:properties> </content> </entry> <entry> <id>https://mdcpXXXXXXtrial.hanatrial.ondemand.com:443/Calendar/services/BookingEBC.xsodata/Events('001e0529-8218-4a40-ad20-d7374516c38a')</id> <title type="text" /> <author> <name /> </author> <link title="Events" href="Events('001e0529-8218-4a40-ad20-d7374516c38a')" /> <category term="Calendar.services.BookingEBC.EventsType" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:ID m:type="Edm.String">001e0529-8218-4a40-ad20-d7374516c38a</d:ID> <d:TITLE m:type="Edm.String">Empty Task</d:TITLE> <d:START_DATE m:type="Edm.String">2017-08-17T11:00</d:START_DATE> <d:END_DATE m:type="Edm.String">2017-08-17T12:30</d:END_DATE> <d:COLOR m:type="Edm.String">#77DD77</d:COLOR> <d:STATUS m:type="Edm.String">F</d:STATUS> <d:DESCRIPTION m:type="Edm.String">6f9137f3-092a-408b-9385-549ed7116ffb</d:DESCRIPTION> <d:YEAR m:type="Edm.Int32">2017</d:YEAR> <d:MONTH m:type="Edm.Int32">8</d:MONTH> <d:DAY m:type="Edm.Int32">17</d:DAY> <d:OWNERID m:type="Edm.String" /> <d:CUST_COSTCENTER m:type="Edm.String" /> <d:SREP_COSTCENTER m:type="Edm.String" /> </m:properties> </content> </entry> </feed>

If the call is executed correctly we should see a result similar to my XML. Pick one ID to check the GetDetail_Entity method by changing the URL.

https://mdcpXXXXXXtrial.hanatrial.ondemand.com/Calendar/services/BookingEBC.xsodata/Events(‘001e0529-8218-4a40-ad20-d7374516c38a’)?$format=json

{ "d": { "__metadata": { "type": "Calendar.services.BookingEBC.EventsType", "uri": "https://mdcp601643trial.hanatrial.ondemand.com:443/Calendar/services/BookingEBC.xsodata/Events('001e0529-8218-4a40-ad20-d7374516c38a')" }, "ID": "001e0529-8218-4a40-ad20-d7374516c38a", "TITLE": "Empty Task", "START_DATE": "2017-08-17T11:00", "END_DATE": "2017-08-17T12:30", "COLOR": "#77DD77", "STATUS": "F", "DESCRIPTION": "6f9137f3-092a-408b-9385-549ed7116ffb", "YEAR": 2017, "MONTH": 8, "DAY": 17, "OWNERID": " ", "CUST_COSTCENTER": " ", "SREP_COSTCENTER": " " } }

Back to Advanced Rest Client, copy the X-CSRF-TOKEN value and use it to send a PUT operation to modify the Event Content

Change the X-Csrf-Token value and the Request type and URL

https://mdcpXXXXXXtrial.hanatrial.ondemand.com/Calendar/services/BookingEBC.xsodata/Events(‘001e0529-8218-4a40-ad20-d7374516c38a’)

Change the body by putting the same JSON result from the GET operation request and modify some value and Execute the request.

Final JSON

{ "__metadata": { "type": "Calendar.services.BookingEBC.EventsType", "uri": "https://mdcpXXXXXXtrial.hanatrial.ondemand.com:443/Calendar/services/BookingEBC.xsodata/Events('001e0529-8218-4a40-ad20-d7374516c38a')" }, "ID": "001e0529-8218-4a40-ad20-d7374516c38a", "TITLE": "Empty Task Test", "START_DATE": "2017-08-17T11:00", "END_DATE": "2017-08-17T12:30", "COLOR": "#77DD77", "STATUS": "F", "DESCRIPTION": "6f9137f3-092a-408b-9385-549ed7116ffb", "YEAR": 2017, "MONTH": 8, "DAY": 17, "OWNERID": "ONGABI", "CUST_COSTCENTER": " ", "SREP_COSTCENTER": " " }

Change the operation from PUT to GET on the Advanced Rest and check the result

https://mdcpXXXXXXtrial.hanatrial.ondemand.com/Calendar/services/BookingEBC.xsodata/Events(‘001e0529-8218-4a40-ad20-d7374516c38a’)

The response should be like this.

Conslusion :

The Odata service is now ready and we can start the UI part in the next article.

 

Next Post => https://blogs.sap.com/2017/11/07/using-a-third-party-library-with-sapui5-application-sap-cloud-development-scenario-part-4/

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !