on 07-27-2014 8:14 PM
Hi ,
I want to create an odata web service which would output a json which has attribute children.
Children can again have children.
E.g :
{
"chainid":1,
"docuid":1,
"backrefid":0,
"docnr":"4500005376",
"doctyp":"",
"name":"PurchaseOrder",
"username":"KRICK",
"docdate":"\/Date(1391040000000)\/",
"doctime":"PT00H00M00S",
"docyear":"0000",
"node":"",
"colorcode":"",
"tabname":"EKKO",
"awkey":"",
"awtyp":"",
"bukrs":"0001",
"image":"images/email_64.png",
"children": [
{
"chainid":1,
"docuid":2,
"backrefid":1,
"docnr":"5000004089",
"doctyp":"",
"name":"MM GoodsMvnt",
"username":"KRICK",
"docdate":"\/Date(1391040000000)\/",
"doctime":"PT10H44M35S",
"docyear":"2014",
"node":"",
"colorcode":"G",
"tabname":"MKPF",
"awkey":"",
"awtyp":"MKPF",
"bukrs":"",
"image":"images/email_64.png",
} ] }
Any idea on how to implement this using entity set or otherwise?
Thanks in advance.
Regards,
Sumant
Hello Sumant,
This would be possible using the Navigation property. Here are some steps to achieve the same
Step 1: Create ParentEntity and the ChildEntity.
Step 2: Establish an association between these two entities with cardinality 1:N
Step 3:Create a navigation from ParentEntity to ChildEntity using this association. Assume the Navigation property name is 'children'
Step 4: Implement the DPC logic to get the data.
Step 5: If you fire the URL http://host:port/namespace/servicename/ParentEntitySet?$expand=children & $format=json you get the desired data..
Regards,
Atanu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Atanu,
Thanks for your answer.
But my childentity can also have children.
So how do I create this relationship?
Establishing a parent to child 1:N would mean 1 parent with have N children.
E.g :
root:{
name: "root",
description: "root description",
child: {
name: "item1",
description: "item1 description",
child: {
name: "subitem1-1",
description: "subitem1-1 description",
child: {
name: "subsubitem1-1-1",
description: "subsubitem1-1-1 description",
}
}
}
}
Thanks & Regards,
Sumant
It is possible to drill down to children of children as well.For this the URL would look like
http://host:port/namespace/servicename/ParentEntitySet?$expand=<Navigation property name from ppaarreentt to children1>/<Navigation property name from children1 to children1' children>
Example at
http://services.odata.org/V3/OData/OData.svc/Categories?$expand=Products/Supplier
The main problem here is the terminology and way of thinking.
In OData there is no real parent/child hierarchy, this is being imposed by the way of thinking. This is a navigation and, as such, is not restricted to 'downwards' movement.
If you think in navigation terms, this becomes a recursion exercise.
Here is an analogy where the entities are of the same type: rail station network.
The "principal" entity is a Station. It has a navigation to an entityset called NextStations; this set contains any stations that are directly connected by a rail link.
A Station can be a terminus or a way station.
With this model you can move from Station to Station. You can make a one way trip or a two way trip. The trip can be linear from any via any to any, or it could be circular from origin via any to origin.
Once you move from one station to another, the state changes and a new navigation can be undertaken. The 'data rules' for every station are the same, it doesn't matter how far station foo is from station bar.
The model is simple yet useful. There is no need to define a whole network of stations in some complex model. A client consuming a service can overlay their own context on this - you could for example describe the London Tube system in this way, and a UI could come up with the well known map of this system.
Regards
Ron.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Currently I have taken two entities one as parent another child which have the same structure.
Every node which has a child is a parent.
A navigation property from parent to child with 1 : N.
Another navigation property from child to child 1 : N.
This seems to give me a json which is close to what is required in the UI though not exact.
But it looks like I have to work with that in the javascript.
Thanks all for your help.
Regards,
Sumant
Another approach:
As I understand you have parent and child of the same type. So I would suggest to create only one entity but associate with itself and create navigation to the same entity again (1:N). So that you can achieve deep children functionality.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Krishna,
Yes both the parent and child are of the same type.
But while creating the association type i need to reference the parentname of one entity to the name of another.
How do I write this association?
e.g : if I create
begin of item,
name type string,
description type string,
parentname type string,
enf of item.
and create an association like this for 1 : N cardinality ?
lo_association = model->create_association(
iv_association_name = 'item_items'
iv_left_type = 'item'
iv_right_type = 'item'
iv_right_card = cardinality_feed
iv_left_card = cardinality_entity ).
Regards,
Sumant
Hello Sumant,
Code is fine.
But i have never tried creating association between the same entities as you are trying now ( 1 to N ) and i do not know how GW supports that, so i cannot comment on behavior of the GW
Kindly fire the service to see metadata and see how GW responds to that. If any problem we can see later.
If at all there is any problem in model level ( not syntax errors ), you will be getting error ' Model Contains Error ' when GW tries to load the metadata once u add service in /iwfnd/maint_service.
Regards,
Ashwin
Hello Ashwin,
lo_association = model->create_association(
iv_association_name = 'item_items'
iv_left_type = 'item'
iv_right_type = 'item'
iv_right_card = 'N'
iv_left_card = '1').
lo_entity_type = model->get_entity_type( iv_entity_name = 'item' ).
lo_entity_type->create_navigation_property(
iv_property_name = 'children'
iv_association_name = 'item_items' ).
It throws an error "Resource not found for the segment children'.
Regards,
Sumant
Hello Sumant,
The code which u have written ( below code ) has to be changed.
You cannot create navigation with lo_entity_type referring to /iwbep/if_mgw_odata_entity_typ.
lo_entity_type->create_navigation_property(
iv_property_name = 'children'
iv_association_name = 'item_items' ).
Code will be like this :
lo_nav_property referring to /iwbep/if_mgw_odata_nav_prop.
lo_nav_property = lo_entity_type->create_navigation_property( iv_property_name = 'children'
iv_association_name = 'item_items' ).
Please make changes.
Regards,
Ashwin
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.