You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Ivan Lucas Vargas <xe...@gmail.com> on 2015/02/11 17:20:41 UTC

Metadata example for inserting master / detail entities

Hi,

Does someone can give me some example of one existing metadata that is
working when inserting new entities with a list of entities? Like
inserting, in one transaction, Order and OrderItems? I'm working with
breezejs for doing this interaction between client and server and I think
that maybe breeze is not building the data request as it should for
olingo...

tks

Re: Metadata example for inserting master / detail entities

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi,

sorry I missed your initial mail/question.
It would be nice if you create an Issue and add an example as well as the according metadata.
This way we can better track (and look into) the issue.

Kind regards,
Michael

> On 12 Feb 2015, at 13:09, Ivan Lucas Vargas <xe...@gmail.com> wrote:
> 
> Should I post a bug so?
> 
> On Thu Feb 12 2015 at 09:46:13 Bolz, Michael <michael.bolz@sap.com <ma...@sap.com>> wrote:
> Hi,
> 
> If I understand your use case your payload is nearly correct.
> In the first post the “Orders” entity is created and if you change the HTTP line into:
> > POST $1/OrderItems HTTP/1.1
> 
> The “OrderItems” entity is posted on the before created “Orders” entity.
> This all works as long as the according OData Service implementation support this.
> 
> Kind regards,
> Michael
> 
> 
>> On 12 Feb 2015, at 03:05, Ivan Lucas Vargas <xenevreu@gmail.com <ma...@gmail.com>> wrote:
>> 
>> Hi,
>> 
>> let me detail my question. I think it will clarify my doubt. I'm trying to insert one entity with a list of another entity in the same batch request. In my case, the post payload is:
>> 
>> --batch_98b2-5d17-73e4
>> Content-Type: multipart/mixed; boundary=changeset_3d94-0d7a-375d
>> 
>> --changeset_3d94-0d7a-375d
>> Content-Type: application/http
>> Content-Transfer-Encoding: binary
>> 
>> POST Orders HTTP/1.1
>> Content-ID: 1
>> DataServiceVersion: 2.0
>> Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
>> Content-Type: application/json
>> MaxDataServiceVersion: 3.0
>> 
>> {"OrderId":-1,"Customer":1}
>> --changeset_3d94-0d7a-375d
>> Content-Type: application/http
>> Content-Transfer-Encoding: binary
>> 
>> POST OrderItems HTTP/1.1
>> Content-ID: 2
>> DataServiceVersion: 2.0
>> Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
>> Content-Type: application/json
>> MaxDataServiceVersion: 3.0
>> 
>> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132}
>> --changeset_3d94-0d7a-375d--
>> 
>> --batch_98b2-5d17-73e4--
>> 
>> The idea here is to insert both entities. So, we have the OrderId: -1 and OrderItemId: -2. This way, olingo will understand and generate the ids based on the Oracle sequence mapped into the JPA entities. But, as far as I read till now, the second changeset should reference the first changeset, by using the $ in the POST. So, it should be:
>> 
>> POST OrderItems HTTP/1.1 (original) -> POST $1/OrderItems HTTP/1.1 (by referencing the content-id: 1 of the first changeset)
>> 
>> Is this understanding correct? If yes, the second question is: My payload needs to have the navigation link included? In this case, the payload sould be something like:
>> 
>> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132} (original) -> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132, OrderDetails: {url: __deferred}}
>> 
>> Is this understand also correct? Or by the navigation link olingo will understand that in the entity OrderItem, the property OrderId is a property link and will resolve this referenced request and will fill the attribute OrderItem.OrderId with the Order.OrderId that was already updated with the sequence value got from the entity resolution of the first changeset?
>> 
>> The navigation property for this relationship generated by the $metadata is:
>> <NavigationProperty Name="OrderDetails" Relationship="pu.Order_OrderItem" FromRole="OrderItem" ToRole="Order"/>
>> 
>> Thanks!
> 


Re: Metadata example for inserting master / detail entities

Posted by Ivan Lucas Vargas <xe...@gmail.com>.
Should I post a bug so?

On Thu Feb 12 2015 at 09:46:13 Bolz, Michael <mi...@sap.com> wrote:

> Hi,
>
> If I understand your use case your payload is nearly correct.
> In the first post the “Orders” entity is created and if you change the
> HTTP line into:
> > POST $1/OrderItems HTTP/1.1
>
> The “OrderItems” entity is posted on the before created “Orders” entity.
> This all works as long as the according OData Service implementation
> support this.
>
> Kind regards,
> Michael
>
>
> On 12 Feb 2015, at 03:05, Ivan Lucas Vargas <xe...@gmail.com> wrote:
>
> Hi,
>
> let me detail my question. I think it will clarify my doubt. I'm trying to
> insert one entity with a list of another entity in the same batch request.
> In my case, the post payload is:
>
> --batch_98b2-5d17-73e4
> Content-Type: multipart/mixed; boundary=changeset_3d94-0d7a-375d
>
> --changeset_3d94-0d7a-375d
> Content-Type: application/http
> Content-Transfer-Encoding: binary
>
> POST Orders HTTP/1.1
> Content-ID: 1
> DataServiceVersion: 2.0
> Accept: application/atomsvc+xml;q=0.8,
> application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
> Content-Type: application/json
> MaxDataServiceVersion: 3.0
>
> {"OrderId":-1,"Customer":1}
> --changeset_3d94-0d7a-375d
> Content-Type: application/http
> Content-Transfer-Encoding: binary
>
> POST OrderItems HTTP/1.1
> Content-ID: 2
> DataServiceVersion: 2.0
> Accept: application/atomsvc+xml;q=0.8,
> application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
> Content-Type: application/json
> MaxDataServiceVersion: 3.0
>
> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132}
> --changeset_3d94-0d7a-375d--
>
> --batch_98b2-5d17-73e4--
>
> The idea here is to insert both entities. So, we have the OrderId: -1 and
> OrderItemId: -2. This way, olingo will understand and generate the ids
> based on the Oracle sequence mapped into the JPA entities. But, as far as I
> read till now, the second changeset should reference the first changeset,
> by using the $ in the POST. So, it should be:
>
> POST OrderItems HTTP/1.1 (original) -> POST *$1/*OrderItems HTTP/1.1 (by
> referencing the content-id: 1 of the first changeset)
>
> Is this understanding correct? If yes, the second question is: My payload
> needs to have the navigation link included? In this case, the payload sould
> be something like:
>
> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132} (original)
> -> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132,* OrderDetails: {url:
> __deferred}*}
>
> Is this understand also correct? Or by the navigation link olingo will
> understand that in the entity OrderItem, the property OrderId is a property
> link and will resolve this referenced request and will fill the attribute
> OrderItem.OrderId with the Order.OrderId that was already updated with the
> sequence value got from the entity resolution of the first changeset?
>
> The navigation property for this relationship generated by the $metadata
> is:
> <NavigationProperty Name="OrderDetails" Relationship="pu.Order_OrderItem"
> FromRole="OrderItem" ToRole="Order"/>
>
> Thanks!
>
>
>

Re: Metadata example for inserting master / detail entities

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi,

If I understand your use case your payload is nearly correct.
In the first post the “Orders” entity is created and if you change the HTTP line into:
> POST $1/OrderItems HTTP/1.1

The “OrderItems” entity is posted on the before created “Orders” entity.
This all works as long as the according OData Service implementation support this.

Kind regards,
Michael

> On 12 Feb 2015, at 03:05, Ivan Lucas Vargas <xe...@gmail.com> wrote:
> 
> Hi,
> 
> let me detail my question. I think it will clarify my doubt. I'm trying to insert one entity with a list of another entity in the same batch request. In my case, the post payload is:
> 
> --batch_98b2-5d17-73e4
> Content-Type: multipart/mixed; boundary=changeset_3d94-0d7a-375d
> 
> --changeset_3d94-0d7a-375d
> Content-Type: application/http
> Content-Transfer-Encoding: binary
> 
> POST Orders HTTP/1.1
> Content-ID: 1
> DataServiceVersion: 2.0
> Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
> Content-Type: application/json
> MaxDataServiceVersion: 3.0
> 
> {"OrderId":-1,"Customer":1}
> --changeset_3d94-0d7a-375d
> Content-Type: application/http
> Content-Transfer-Encoding: binary
> 
> POST OrderItems HTTP/1.1
> Content-ID: 2
> DataServiceVersion: 2.0
> Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
> Content-Type: application/json
> MaxDataServiceVersion: 3.0
> 
> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132}
> --changeset_3d94-0d7a-375d--
> 
> --batch_98b2-5d17-73e4--
> 
> The idea here is to insert both entities. So, we have the OrderId: -1 and OrderItemId: -2. This way, olingo will understand and generate the ids based on the Oracle sequence mapped into the JPA entities. But, as far as I read till now, the second changeset should reference the first changeset, by using the $ in the POST. So, it should be:
> 
> POST OrderItems HTTP/1.1 (original) -> POST $1/OrderItems HTTP/1.1 (by referencing the content-id: 1 of the first changeset)
> 
> Is this understanding correct? If yes, the second question is: My payload needs to have the navigation link included? In this case, the payload sould be something like:
> 
> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132} (original) -> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132, OrderDetails: {url: __deferred}}
> 
> Is this understand also correct? Or by the navigation link olingo will understand that in the entity OrderItem, the property OrderId is a property link and will resolve this referenced request and will fill the attribute OrderItem.OrderId with the Order.OrderId that was already updated with the sequence value got from the entity resolution of the first changeset?
> 
> The navigation property for this relationship generated by the $metadata is:
> <NavigationProperty Name="OrderDetails" Relationship="pu.Order_OrderItem" FromRole="OrderItem" ToRole="Order"/>
> 
> Thanks!


Re: Metadata example for inserting master / detail entities

Posted by Ivan Lucas Vargas <xe...@gmail.com>.
Hi,

let me detail my question. I think it will clarify my doubt. I'm trying to
insert one entity with a list of another entity in the same batch request.
In my case, the post payload is:

--batch_98b2-5d17-73e4
Content-Type: multipart/mixed; boundary=changeset_3d94-0d7a-375d

--changeset_3d94-0d7a-375d
Content-Type: application/http
Content-Transfer-Encoding: binary

POST Orders HTTP/1.1
Content-ID: 1
DataServiceVersion: 2.0
Accept: application/atomsvc+xml;q=0.8,
application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
Content-Type: application/json
MaxDataServiceVersion: 3.0

{"OrderId":-1,"Customer":1}
--changeset_3d94-0d7a-375d
Content-Type: application/http
Content-Transfer-Encoding: binary

POST OrderItems HTTP/1.1
Content-ID: 2
DataServiceVersion: 2.0
Accept: application/atomsvc+xml;q=0.8,
application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
Content-Type: application/json
MaxDataServiceVersion: 3.0

{"OrdemItemId":-2,"OrderId":-1,"ProductId":132}
--changeset_3d94-0d7a-375d--

--batch_98b2-5d17-73e4--

The idea here is to insert both entities. So, we have the OrderId: -1 and
OrderItemId: -2. This way, olingo will understand and generate the ids
based on the Oracle sequence mapped into the JPA entities. But, as far as I
read till now, the second changeset should reference the first changeset,
by using the $ in the POST. So, it should be:

POST OrderItems HTTP/1.1 (original) -> POST *$1/*OrderItems HTTP/1.1 (by
referencing the content-id: 1 of the first changeset)

Is this understanding correct? If yes, the second question is: My payload
needs to have the navigation link included? In this case, the payload sould
be something like:

{"OrdemItemId":-2,"OrderId":-1,"ProductId":132} (original)
-> {"OrdemItemId":-2,"OrderId":-1,"ProductId":132,* OrderDetails: {url:
__deferred}*}

Is this understand also correct? Or by the navigation link olingo will
understand that in the entity OrderItem, the property OrderId is a property
link and will resolve this referenced request and will fill the attribute
OrderItem.OrderId with the Order.OrderId that was already updated with the
sequence value got from the entity resolution of the first changeset?

The navigation property for this relationship generated by the $metadata is:
<NavigationProperty Name="OrderDetails" Relationship="pu.Order_OrderItem"
FromRole="OrderItem" ToRole="Order"/>

Thanks!

On Wed Feb 11 2015 at 4:01:25 PM Ivan Lucas Vargas <xe...@gmail.com>
wrote:

> Ramesh,
>
> The breeze api along with datajs has one method called unwapInstance,
> which "cleans" the entity before sending the request. It will clean the
> entity with all other attributes and methods of breeze (like entityAspect,
> for example), but it also cleans the attributes for the relationship.
> Example:
>
> Orders/OrderItemsDetails (olingo metadata) becomes Orders only.
> OrderItems/OrderId - ok
> OrderItems/OrderDetails becomes OrderItems only.
>
> In other words, in the case above, should I send to olingo the POST
> request for OrderItem the OrderDetails too, or only the OerderItem.OrderId?
>
> On Wed Feb 11 2015 at 15:44:22 Ramesh Reddy <ra...@redhat.com> wrote:
>
>> The references should be already updated/resolved by the time you receive
>> the request on the server side. Individual payload inside the batch is
>> exactly same as if you would have done for a single request, like create
>> entity. Only the boundary and some header stuff is extra in that request.
>>
>> ------------------------------
>>
>> Hi Ramesh,
>>
>>        I've already tried this link, but I need to understand the payload
>> sent to the server. The scenario I'm having problems is exactly the
>> scenario described on item 2.2.1 of the link you provided, the referenced
>> requests. Unfortunatelly, the example does not show the payload sent to the
>> server...
>>
>> tks
>>
>> On Wed Feb 11 2015 at 14:32:22 Ramesh Reddy <ra...@redhat.com> wrote:
>>
>>> Look into batch request in OData. If this is V2 http://www.odata.org/
>>> documentation/odata-version-2-0/batch-processing
>>>
>>> Ramesh..
>>>
>>> ------------------------------
>>>
>>> Hi,
>>>
>>> Does someone can give me some example of one existing metadata that is
>>> working when inserting new entities with a list of entities? Like
>>> inserting, in one transaction, Order and OrderItems? I'm working with
>>> breezejs for doing this interaction between client and server and I think
>>> that maybe breeze is not building the data request as it should for
>>> olingo...
>>>
>>> tks
>>>
>>>
>>>
>>

Re: Metadata example for inserting master / detail entities

Posted by Ivan Lucas Vargas <xe...@gmail.com>.
Ramesh,

The breeze api along with datajs has one method called unwapInstance, which
"cleans" the entity before sending the request. It will clean the entity
with all other attributes and methods of breeze (like entityAspect, for
example), but it also cleans the attributes for the relationship. Example:

Orders/OrderItemsDetails (olingo metadata) becomes Orders only.
OrderItems/OrderId - ok
OrderItems/OrderDetails becomes OrderItems only.

In other words, in the case above, should I send to olingo the POST request
for OrderItem the OrderDetails too, or only the OerderItem.OrderId?

On Wed Feb 11 2015 at 15:44:22 Ramesh Reddy <ra...@redhat.com> wrote:

> The references should be already updated/resolved by the time you receive
> the request on the server side. Individual payload inside the batch is
> exactly same as if you would have done for a single request, like create
> entity. Only the boundary and some header stuff is extra in that request.
>
> ------------------------------
>
> Hi Ramesh,
>
>        I've already tried this link, but I need to understand the payload
> sent to the server. The scenario I'm having problems is exactly the
> scenario described on item 2.2.1 of the link you provided, the referenced
> requests. Unfortunatelly, the example does not show the payload sent to the
> server...
>
> tks
>
> On Wed Feb 11 2015 at 14:32:22 Ramesh Reddy <ra...@redhat.com> wrote:
>
>> Look into batch request in OData. If this is V2
>> http://www.odata.org/documentation/odata-version-2-0/batch-processing
>>
>> Ramesh..
>>
>> ------------------------------
>>
>> Hi,
>>
>> Does someone can give me some example of one existing metadata that is
>> working when inserting new entities with a list of entities? Like
>> inserting, in one transaction, Order and OrderItems? I'm working with
>> breezejs for doing this interaction between client and server and I think
>> that maybe breeze is not building the data request as it should for
>> olingo...
>>
>> tks
>>
>>
>>
>

Re: Metadata example for inserting master / detail entities

Posted by Ramesh Reddy <ra...@redhat.com>.
The references should be already updated/resolved by the time you receive the request on the server side. Individual payload inside the batch is exactly same as if you would have done for a single request, like create entity. Only the boundary and some header stuff is extra in that request. 

----- Original Message -----

> Hi Ramesh,

> I've already tried this link, but I need to understand the payload sent to
> the server. The scenario I'm having problems is exactly the scenario
> described on item 2.2.1 of the link you provided, the referenced requests.
> Unfortunatelly, the example does not show the payload sent to the server...

> tks

> On Wed Feb 11 2015 at 14:32:22 Ramesh Reddy < rareddy@redhat.com > wrote:

> > Look into batch request in OData. If this is V2
> > http://www.odata.org/documentation/odata-version-2-0/batch-processing
> 

> > Ramesh..
> 

> > > Hi,
> > 
> 

> > > Does someone can give me some example of one existing metadata that is
> > > working when inserting new entities with a list of entities? Like
> > > inserting,
> > > in one transaction, Order and OrderItems? I'm working with breezejs for
> > > doing this interaction between client and server and I think that maybe
> > > breeze is not building the data request as it should for olingo...
> > 
> 

> > > tks
> > 
> 

Re: Metadata example for inserting master / detail entities

Posted by Ivan Lucas Vargas <xe...@gmail.com>.
Hi Ramesh,

       I've already tried this link, but I need to understand the payload
sent to the server. The scenario I'm having problems is exactly the
scenario described on item 2.2.1 of the link you provided, the referenced
requests. Unfortunatelly, the example does not show the payload sent to the
server...

tks

On Wed Feb 11 2015 at 14:32:22 Ramesh Reddy <ra...@redhat.com> wrote:

> Look into batch request in OData. If this is V2
> http://www.odata.org/documentation/odata-version-2-0/batch-processing
>
> Ramesh..
>
> ------------------------------
>
> Hi,
>
> Does someone can give me some example of one existing metadata that is
> working when inserting new entities with a list of entities? Like
> inserting, in one transaction, Order and OrderItems? I'm working with
> breezejs for doing this interaction between client and server and I think
> that maybe breeze is not building the data request as it should for
> olingo...
>
> tks
>
>
>

Re: Metadata example for inserting master / detail entities

Posted by Ramesh Reddy <ra...@redhat.com>.
Look into batch request in OData. If this is V2 http://www.odata.org/documentation/odata-version-2-0/batch-processing 

Ramesh.. 

----- Original Message -----

> Hi,

> Does someone can give me some example of one existing metadata that is
> working when inserting new entities with a list of entities? Like inserting,
> in one transaction, Order and OrderItems? I'm working with breezejs for
> doing this interaction between client and server and I think that maybe
> breeze is not building the data request as it should for olingo...

> tks