2023 Aug 07 6:10 AM - last edited on 2023 Aug 11 3:50 PM by thomas_jung
(Check out the SAP Developer Challenge - APIs blog post for everything you need to know about the challenge to which this task relates!)
In this task you'll move from the public Northwind service to a simple version powered by CAP, and explore data with an OData operation and some system query options.
The OASIS curated Northwind service is great, but it's also sometimes useful to have one's own version. There's an extremely simplified version of the classic Northwind service, called Northbreeze (get it?) at https://developer-challenge.cfapps.eu10.hana.ondemand.com/odata/v4/northbreeze.
This Northbreeze service is powered by the SAP Cloud Application Programming Model (CAP) and offers four entity sets:
(Well there's technically a fifth, TotalProducts, but that's just a calculation projection on the count of products).
The reason for running our own version of Northwind is that we can modify and extend it as we see fit, plus being based on CAP, we can learn about and experiment with CAP's rich support for serving OData APIs.
In this task you'll start to become familiar with the data offered.
Specifically for this task, you'll need to become familiar with the Products data. To do that, have a look at the Northbreeze service's metadata document at https://developer-challenge.cfapps.eu10.hana.ondemand.com/odata/v4/northbreeze/$metadata.
Identify the EntityContainer element that describes the entity sets available, in the form of EntitySet elements, and find the element describing the entity set with the name Products, which should look like this:
<EntitySet Name="Products" EntityType="Northbreeze.Products"> <NavigationPropertyBinding Path="Category" Target="Categories"/> <NavigationPropertyBinding Path="Supplier" Target="Suppliers"/> </EntitySet>
You can see that this entity set is a collection of Northbreeze.Products entity types. The 'Northbreeze' part is essentially the namespace, generated based on the service name. Follow the trail to the Products entity type, which will be an element outside the EntityContainer element, but still within the Northbreeze-namespaced Schema element.
The Products entity type should look like this:
<EntityType Name="Products"> <Key> <PropertyRef Name="ProductID"/> </Key> <Property Name="ProductID" Type="Edm.Int32" Nullable="false"/> <Property Name="ProductName" Type="Edm.String"/> <Property Name="QuantityPerUnit" Type="Edm.String"/> <Property Name="UnitPrice" Type="Edm.Decimal" Scale="variable"/> <NavigationProperty Name="Category" Type="Northbreeze.Categories" Partner="Products"> <ReferentialConstraint Property="Category_CategoryID" ReferencedProperty="CategoryID"/> </NavigationProperty> <Property Name="Category_CategoryID" Type="Edm.Int32"/> <NavigationProperty Name="Supplier" Type="Northbreeze.Suppliers" Partner="Products"> <ReferentialConstraint Property="Supplier_SupplierID" ReferencedProperty="SupplierID"/> </NavigationProperty> <Property Name="Supplier_SupplierID" Type="Edm.Int32"/> <Property Name="UnitsInStock" Type="Edm.Int32"/> <Property Name="UnitsOnOrder" Type="Edm.Int32"/> <Property Name="ReorderLevel" Type="Edm.Int32"/> <Property Name="Discontinued" Type="Edm.Boolean"/> </EntityType>
Amongst other things, you can see that a product has an ID (ProductID), a name (ProductName), a count of the number of units currently in stock (UnitsInStock) and a boolean that is used to indicate whether or not a product is discontinued (Discontinued).
Request the first few products to see data for these and the other properties, via https://developer-challenge.cfapps.eu10.hana.ondemand.com/odata/v4/northbreeze/Products?$top=5. You should see something like this:
{ "@odata.context": "$metadata#Products", "value": [ { "ProductID": 1, "ProductName": "Chai", "QuantityPerUnit": "10 boxes x 20 bags", "UnitPrice": 18, "Category_CategoryID": 1, "Supplier_SupplierID": 1, "UnitsInStock": 39, "UnitsOnOrder": 0, "ReorderLevel": 10, "Discontinued": false }, { "ProductID": 2, "ProductName": "Chang", "QuantityPerUnit": "24 - 12 oz bottles", "UnitPrice": 19, "Category_CategoryID": 1, "Supplier_SupplierID": 1, "UnitsInStock": 17, "UnitsOnOrder": 40, "ReorderLevel": 25, "Discontinued": false }, { "ProductID": 3, "ProductName": "Aniseed Syrup", "QuantityPerUnit": "12 - 550 ml bottles", "UnitPrice": 10, "Category_CategoryID": 2, "Supplier_SupplierID": 1, "UnitsInStock": 13, "UnitsOnOrder": 70, "ReorderLevel": 25, "Discontinued": false }, { "ProductID": 4, "ProductName": "Chef Anton's Cajun Seasoning", "QuantityPerUnit": "48 - 6 oz jars", "UnitPrice": 22, "Category_CategoryID": 2, "Supplier_SupplierID": 2, "UnitsInStock": 53, "UnitsOnOrder": 0, "ReorderLevel": 0, "Discontinued": false }, { "ProductID": 5, "ProductName": "Chef Anton's Gumbo Mix", "QuantityPerUnit": "36 boxes", "UnitPrice": 21.35, "Category_CategoryID": 2, "Supplier_SupplierID": 2, "UnitsInStock": 0, "UnitsOnOrder": 0, "ReorderLevel": 0, "Discontinued": true } ] }
Your task is to calculate the total stock quantity (i.e. the total units in stock) for all current products, i.e. products that are not been marked as discontinued. The result of this calculation should be a number.
Once you have calculated the number, which should be an integer, you should hash it and post the hash as a new reply to this discussion thread, as described in Task 0 - Learn to share your task results and in a similar way to how you've done this in the previous task.
Like all tasks in this challenge, you are free to approach this one however you see fit. One way would be to request all the products (https://developer-challenge.cfapps.eu10.hana.ondemand.com/odata/v4/northbreeze/Products) and manually sum the values of the relevant UnitsInStock properties.
But where's the fun in that?
How about requesting the entire products entity set in your favorite language and obtaining result by parsing the response and using that language to make the calculation?
You could also use OData's $filter system query option to first reduce the entity set result to only those products that have the value false for the Discontinued property.
And what about the $count facility, which in OData V4 is now a system query option as well something you can append to a resource path?
This would also be a good opportunity to take your first steps exploring some great new OData V4 features supported by CAP, such as data aggregation.
How did you approach this task? If you used a programming language, which one did you use, and how did you do it? If you used an $apply based data aggregation feature, what was it, and was was your experience using it?
2023 Aug 15 12:05 PM
2023 Aug 15 12:39 PM
2023 Aug 15 3:25 PM
2023 Aug 15 10:38 PM - edited 2023 Aug 16 10:14 PM
2023 Aug 16 2:38 AM
2023 Aug 16 11:37 AM
2023 Aug 16 5:43 PM
2023 Aug 16 11:30 PM
2023 Aug 17 6:48 AM
2023 Aug 17 11:59 AM
2023 Aug 17 12:01 PM
Doing it with postman where the response of the request is processed directly with test. Great to test out some basic postman functions like Runner where several calls can be combined (first the task then the translation to hash)
2023 Aug 23 7:19 AM
Nice one @cinemandre ! Yes, while I'm a `curl` person always, Postman has its place and is very powerful.
2023 Aug 17 1:27 PM
2023 Aug 17 2:34 PM
2023 Aug 17 11:10 PM
2023 Aug 18 3:22 PM
2023 Aug 18 6:50 PM
2023 Aug 20 12:19 PM
2023 Aug 21 3:09 AM
2023 Aug 21 9:04 AM
2023 Aug 21 4:43 PM
2023 Aug 21 9:21 PM
2023 Aug 21 9:22 PM
2023 Aug 23 7:19 AM
2023 Aug 22 7:43 AM
2023 Aug 22 7:59 AM
2023 Aug 22 12:53 PM
2023 Aug 23 12:17 PM
2023 Aug 23 1:16 PM
2023 Aug 23 4:53 PM
2023 Aug 23 6:15 PM - edited 2023 Aug 29 1:17 AM
My approach:
1. lazy approach: using postman with apply, filter `Discontinued` then aggregate the `UnitsInStock`
2. user approach: using excel to retrieve the Odata then pivot the table data
I prefer to use excel since Microsoft just announced to combine my favorite programming language python and excel haha.
Announcing Python in Excel (microsoft.com)
PS: I'm not sure how long does it take to work on ABAP as there are many steps to do, for instance, define destination, trust setting, certificate then, write a bunch of code to receive the response and aggregate.
2023 Aug 24 5:08 AM - last edited on 2023 Aug 24 9:01 AM by Former Member
2023 Aug 27 5:12 PM
@Former Member and @lehuynhnam - you might want to check the instructions in Task 0 as to how you should post your hash answer 🙂
2023 Aug 24 1:44 PM
2023 Aug 24 3:22 PM
2023 Aug 27 1:56 PM
2023 Aug 27 3:32 PM
2023 Aug 29 1:00 AM
2023 Aug 29 1:18 AM
2023 Aug 29 3:16 AM