You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@olingo.apache.org by RATISH BANSAL <ra...@gmail.com> on 2019/01/21 14:42:50 UTC

Need help to parse annotations from EdmEntitySet using Olingo / ODATA 4

Hello,

Sorry for the trouble, I was not sure whether this is the right group ask
this question about Olingo usage.

I am facing problem in parsing annotations from EdmEntitySet using Olingo /
ODATA 4.
Suppose I have below entity set defined in odata service

*<EntitySet Name="Photos"
EntityType="Microsoft.OData.SampleService.Models.TripPin.Photo">*
* <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Photos"/>*
* <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">*
* <Record>*
* <PropertyValue Property="Searchable" Bool="true"/>*
* <PropertyValue Property="UnsupportedExpressions">*
* <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>*
* </PropertyValue>*
* </Record>*
* </Annotation>*
* <Annotation
Term="Org.OData.Capabilities.V1.InsertRestrictions">...</Annotation>*
*</EntitySet>*

I am able to get this entity from the entity container but I also want to
capture the annotations defined with it. For example in this case I want to
know what are various *SearchRestrictions *on this entity set.
Can somebody please help to solve the problem.

Thanks & Regards
Ratish Bansal

Re: Need help to parse annotations from EdmEntitySet using Olingo / ODATA 4

Posted by RATISH BANSAL <ra...@gmail.com>.
Thanks for the reply Archana.

I am using Olingo Java client library for parsing the metadata.
The issue I am facing is exactly the same mentioned in *[0] *, and for
which commit has already been made under JIRA* [1].*

*To summarize the issue briefly:* Once we get the annotations by using
entity.getAnnotations() we are not able to get further information from the
annotation like term,qualifier, property etc because all their getters
return null.
Based on the explanation written in the comments at [0] *"In the $metadata
document reference above Annotations are there, but there are no
definitions of Term, thus you are seeing the nulls. One could argue that
these are "core" vocabularies they need to be always available with
whatever $metadata document, which I agree as they are put forward by the
OData Specification. However, right now, Olingo client side library does
not automatically add these vocabularies into the Edm object does not have
any of these "core" terms."*

Even after the fix I am facing difficulty in reading these entity set
annotations.
From the fix my understanding is that we should use new readMetadata() API
that takes metadata file and vocabulary xml content and return us the Edm
instance.

*Something like this:*

*List<InputStream> streams = new ArrayList<InputStream>();*
*streams.add(getClass().getResourceAsStream("VOC_Core.xml"));*
*final Edm edm =
client.getReader().readMetadata(getClass().getResourceAsStream("edmxWithCoreAnnotation.xml"),streams);*

But my use case is to *read metadata from Url with authentication *as
well.Please find below my sample code

*EdmMetadataRequest request =
client.getRetrieveRequestFactory().getMetadataRequest(serviceUrl);*
*ODataRetrieveResponse<Edm> response = (ODataRetrieveResponse<Edm>)
OdataRequestUtil.executeRequest(request, authDetails); *
*//execute Request method just set authentication headers and then call
request.execute()*
*edm = response.getBody();*

Can you please point how should I change my code to use the new introduced
readMetadata() API or something thing else to make my use case work.

 *[0]* *https://issues.apache.org/jira/browse/OLINGO-983
<https://issues.apache.org/jira/browse/OLINGO-983>*
 *[1]* *https://issues.apache.org/jira/browse/OLINGO-1062
<https://issues.apache.org/jira/browse/OLINGO-1062>*

Thanks & Regards
Ratish Bansal

On Tue, Jan 22, 2019 at 11:50 AM Rai, Archana <ar...@sap.com> wrote:

> Hi Ratish,
>
> Once you get the entity you can call apis like:
>
> entity.getAnnotations() to get the list of declared annotations.
>
> Thanks,
> Archana
>
> -----Original Message-----
> From: RATISH BANSAL <ra...@gmail.com>
> Sent: Monday, January 21, 2019 8:13 PM
> To: dev@olingo.apache.org
> Subject: Need help to parse annotations from EdmEntitySet using Olingo /
> ODATA 4
>
> Hello,
>
> Sorry for the trouble, I was not sure whether this is the right group ask
> this question about Olingo usage.
>
> I am facing problem in parsing annotations from EdmEntitySet using Olingo /
> ODATA 4.
> Suppose I have below entity set defined in odata service
>
> *<EntitySet Name="Photos"
> EntityType="Microsoft.OData.SampleService.Models.TripPin.Photo">*
> * <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Photos"/>*
> * <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">*
> * <Record>*
> * <PropertyValue Property="Searchable" Bool="true"/>*
> * <PropertyValue Property="UnsupportedExpressions">*
> *
> <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>*
> * </PropertyValue>*
> * </Record>*
> * </Annotation>*
> * <Annotation
> Term="Org.OData.Capabilities.V1.InsertRestrictions">...</Annotation>*
> *</EntitySet>*
>
> I am able to get this entity from the entity container but I also want to
> capture the annotations defined with it. For example in this case I want to
> know what are various *SearchRestrictions *on this entity set.
> Can somebody please help to solve the problem.
>
> Thanks & Regards
> Ratish Bansal
>

RE: Need help to parse annotations from EdmEntitySet using Olingo / ODATA 4

Posted by "Rai, Archana" <ar...@sap.com>.
Hi Ratish,

Once you get the entity you can call apis like:

entity.getAnnotations() to get the list of declared annotations.

Thanks,
Archana

-----Original Message-----
From: RATISH BANSAL <ra...@gmail.com> 
Sent: Monday, January 21, 2019 8:13 PM
To: dev@olingo.apache.org
Subject: Need help to parse annotations from EdmEntitySet using Olingo / ODATA 4

Hello,

Sorry for the trouble, I was not sure whether this is the right group ask
this question about Olingo usage.

I am facing problem in parsing annotations from EdmEntitySet using Olingo /
ODATA 4.
Suppose I have below entity set defined in odata service

*<EntitySet Name="Photos"
EntityType="Microsoft.OData.SampleService.Models.TripPin.Photo">*
* <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Photos"/>*
* <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">*
* <Record>*
* <PropertyValue Property="Searchable" Bool="true"/>*
* <PropertyValue Property="UnsupportedExpressions">*
* <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>*
* </PropertyValue>*
* </Record>*
* </Annotation>*
* <Annotation
Term="Org.OData.Capabilities.V1.InsertRestrictions">...</Annotation>*
*</EntitySet>*

I am able to get this entity from the entity container but I also want to
capture the annotations defined with it. For example in this case I want to
know what are various *SearchRestrictions *on this entity set.
Can somebody please help to solve the problem.

Thanks & Regards
Ratish Bansal