You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Ryan Summerskill <ry...@veritasprime.com> on 2016/04/09 18:29:45 UTC

How to get property attributes for EntityType

I'm building a java service that accesses OData information. I'm using
olingo to parse all my returned json. If I pull the metadata I can see that
my properties have custom attributes under all of my EntityTypes. I'm
trying to access these attributes. I can currently access all the
properties but all I can seem to get is the key, value pairs.

*for(Entry<String, Object> prop : entry.getProperties().entrySet())*

Steeping through in Eclipse I can see that the EntityType object has parsed
these attributes and is storing them in a hashmap. Any idea how to get at
this using Olingo? Last resort would be to side process the metadata xml
again but I really really don't want to do that.

I've also seen in debugger that the call

*entitySet.getEntityType().getProperty("createdBy")*

contains a *SimpleProperty property* variable that contains all my
attribute annotations. Again can't figure out how to get access (both
hacking and googleing). sigh :\

Thanks for any help you can give,
-Ryan S.

-- 
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify the system manager. 
This message contains confidential information and is intended only for the 
individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail. Please notify the sender 
immediately by e-mail if you have received this e-mail by mistake and 
delete this e-mail from your system. If you are not the intended recipient 
you are notified that disclosing, copying, distributing or taking any 
action in reliance on the contents of this information is strictly 
prohibited.

Re: How to get property attributes for EntityType

Posted by Ryan Summerskill <ry...@veritasprime.com>.
Michael,

Thank you very much. When I was hacking around in the debugger I tried this
but saw that after casting to the EdmProperty the annotations variable was
null so I didn't pursue those function calls any further. Lesson learned
again and again, never assume. :)

I see now it is loaded on the call to getAnnotations().

Thanks Again!
Ryan S.


On Tue, Apr 12, 2016 at 1:07 AM, Bolz, Michael <mi...@sap.com> wrote:

> Hi Ryan,
>
> sorry, I think I misunderstood your use case.
>
> Indeed it is a little bit confusing because the EdmEntityType
> “getProperty” returns a “EdmType” instead of an “EdmProperty”
> and this “EdmType” does not inherit the “EdmAnnotatable” interface.
> However in your case you can cast the “EdmTyped” to a “EdmProperty” and
> then access the annotations via the “getAnnotations(..)” method.
> Below I pasted a short code snippet:
>
> EdmTyped tempProperty = EntityProvider.readMetadata(metadataXml, false)
>     .getEntityType(NAMESPACE, "Employee")
>     .getProperty("EmployeeId");
> EdmProperty property = (EdmProperty) tempProperty;
>
> EdmAnnotations annotations = property.getAnnotations();
> EdmAnnotationAttribute attribute =
> annotations.getAnnotationAttribute("nameOfAnnotation", "namespaceOfAnnotation");
> System.out.println(attribute.getName() + " -> " + attribute.getText());
>
>
> Hope I have understood your use case now and I could help you  ;o)
>
> Best Regards, Michael
>
>
> On 11 Apr 2016, at 20:35, Ryan Summerskill <
> ryan.summerskill@veritasprime.com> wrote:
>
> I have attached an excerpt of my metadata below. You'll be able to see the
> property's attributes that I'm trying to gain access to.
>
> I have cached the Edm metadata object so that I'm only requesting the
> metadata once from the site (and have access to it at the time that I'm
> processing my OData entry). Sounds like what you are saying is that I'll
> have to side process the xml to get access to the attributes, or is there a
> way to gain access using the Edm object?
>
> Thanks,
> Ryan S.
>
>
>
> ​
> *Ryan Summerskill*
> * Prime Solutions Manager **| Principal Software Engineer*
> *Direct: 913.484.7195 <913.484.7195>* *|* *E-mail:** ryan.summerskill@veritasprime.com
> <ry...@veritasprime.com>*
>
>
> * <http://www.linkedin.com/pub/ryan-summerskill/7/97/424>*
> * <http://www.veritasprime.com/>*
>
>
> On Mon, Apr 11, 2016 at 2:27 AM, Bolz, Michael <mi...@sap.com>
> wrote:
>
>> Hello Ryan,
>>
>> Can you please provide the Olingo version which you use?
>> Furthermore it would be helpful if you could share your metadata document
>> (EDMX).
>>
>> As far as I understand your use case it is not possible to access the
>> additional custom properties defined with the EDM
>> while you process the result of an OData (data) request on a resource.
>> So for your use case it would be necessary that you do a metadata request
>> and cache those metadata information
>> so that you do not need a second metadata request while you process the
>> result of an OData (data) request on a resource.
>>
>> Kind Regards,
>> Michael
>>
>>
>>
>> On 09 Apr 2016, at 18:29, Ryan Summerskill <
>> ryan.summerskill@veritasprime.com> wrote:
>>
>> I'm building a java service that accesses OData information. I'm using
>> olingo to parse all my returned json. If I pull the metadata I can see that
>> my properties have custom attributes under all of my EntityTypes. I'm
>> trying to access these attributes. I can currently access all the
>> properties but all I can seem to get is the key, value pairs.
>>
>> *for(Entry<String, Object> prop : entry.getProperties().entrySet())*
>>
>> Steeping through in Eclipse I can see that the EntityType object has
>> parsed these attributes and is storing them in a hashmap. Any idea how to
>> get at this using Olingo? Last resort would be to side process the metadata
>> xml again but I really really don't want to do that.
>>
>> I've also seen in debugger that the call
>>
>> *entitySet.getEntityType().getProperty("createdBy")*
>>
>> contains a *SimpleProperty property* variable that contains all my
>> attribute annotations. Again can't figure out how to get access (both
>> hacking and googleing). sigh :\
>>
>> Thanks for any help you can give,
>> -Ryan S.
>>
>> This email and any files transmitted with it are confidential and
>> intended solely for the use of the individual or entity to whom they are
>> addressed. If you have received this email in error please notify the
>> system manager. This message contains confidential information and is
>> intended only for the individual named. If you are not the named addressee
>> you should not disseminate, distribute or copy this e-mail. Please notify
>> the sender immediately by e-mail if you have received this e-mail by
>> mistake and delete this e-mail from your system. If you are not the
>> intended recipient you are notified that disclosing, copying, distributing
>> or taking any action in reliance on the contents of this information is
>> strictly prohibited.
>>
>>
>>
>
> This email and any files transmitted with it are confidential and intended
> solely for the use of the individual or entity to whom they are addressed.
> If you have received this email in error please notify the system manager.
> This message contains confidential information and is intended only for the
> individual named. If you are not the named addressee you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately by e-mail if you have received this e-mail by mistake and
> delete this e-mail from your system. If you are not the intended recipient
> you are notified that disclosing, copying, distributing or taking any
> action in reliance on the contents of this information is strictly
> prohibited.<example.txt>
>
>
>

-- 
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify the system manager. 
This message contains confidential information and is intended only for the 
individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail. Please notify the sender 
immediately by e-mail if you have received this e-mail by mistake and 
delete this e-mail from your system. If you are not the intended recipient 
you are notified that disclosing, copying, distributing or taking any 
action in reliance on the contents of this information is strictly 
prohibited.

Re: How to get property attributes for EntityType

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

sorry, I think I misunderstood your use case.

Indeed it is a little bit confusing because the EdmEntityType “getProperty” returns a “EdmType” instead of an “EdmProperty” 
and this “EdmType” does not inherit the “EdmAnnotatable” interface.
However in your case you can cast the “EdmTyped” to a “EdmProperty” and then access the annotations via the “getAnnotations(..)” method.
Below I pasted a short code snippet:

> EdmTyped tempProperty = EntityProvider.readMetadata(metadataXml, false)
>     .getEntityType(NAMESPACE, "Employee")
>     .getProperty("EmployeeId");
> EdmProperty property = (EdmProperty) tempProperty;
> EdmAnnotations annotations = property.getAnnotations();
> EdmAnnotationAttribute attribute = annotations.getAnnotationAttribute("nameOfAnnotation", "namespaceOfAnnotation");
> System.out.println(attribute.getName() + " -> " + attribute.getText());

Hope I have understood your use case now and I could help you  ;o)

Best Regards, Michael


> On 11 Apr 2016, at 20:35, Ryan Summerskill <ry...@veritasprime.com> wrote:
> 
> I have attached an excerpt of my metadata below. You'll be able to see the property's attributes that I'm trying to gain access to. 
> 
> I have cached the Edm metadata object so that I'm only requesting the metadata once from the site (and have access to it at the time that I'm processing my OData entry). Sounds like what you are saying is that I'll have to side process the xml to get access to the attributes, or is there a way to gain access using the Edm object?
> 
> Thanks, 
> Ryan S.
> 
> 
> 
> ​Ryan Summerskill 
> Prime Solutions Manager | Principal Software Engineer
> Direct: 913.484.7195 | E-mail: ryan.summerskill@veritasprime.com <ma...@veritasprime.com>
>  <http://www.linkedin.com/pub/ryan-summerskill/7/97/424>
> 
>  <http://www.veritasprime.com/>
> 
> 
> On Mon, Apr 11, 2016 at 2:27 AM, Bolz, Michael <michael.bolz@sap.com <ma...@sap.com>> wrote:
> Hello Ryan,
> 
> Can you please provide the Olingo version which you use?
> Furthermore it would be helpful if you could share your metadata document (EDMX).
> 
> As far as I understand your use case it is not possible to access the additional custom properties defined with the EDM 
> while you process the result of an OData (data) request on a resource.
> So for your use case it would be necessary that you do a metadata request and cache those metadata information
> so that you do not need a second metadata request while you process the result of an OData (data) request on a resource.
> 
> Kind Regards,
> Michael
> 
> 
> 
>> On 09 Apr 2016, at 18:29, Ryan Summerskill <ryan.summerskill@veritasprime.com <ma...@veritasprime.com>> wrote:
>> 
>> I'm building a java service that accesses OData information. I'm using olingo to parse all my returned json. If I pull the metadata I can see that my properties have custom attributes under all of my EntityTypes. I'm trying to access these attributes. I can currently access all the properties but all I can seem to get is the key, value pairs.
>> 
>> for(Entry<String, Object> prop : entry.getProperties().entrySet())
>> Steeping through in Eclipse I can see that the EntityType object has parsed these attributes and is storing them in a hashmap. Any idea how to get at this using Olingo? Last resort would be to side process the metadata xml again but I really really don't want to do that.
>> 
>> I've also seen in debugger that the call
>> 
>> entitySet.getEntityType().getProperty("createdBy")
>> contains a SimpleProperty property variable that contains all my attribute annotations. Again can't figure out how to get access (both hacking and googleing). sigh :\
>> 
>> 
>> Thanks for any help you can give,
>> -Ryan S.
>> 
>> This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
> 
> 
> 
> This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.<example.txt>


Re: How to get property attributes for EntityType

Posted by Ryan Summerskill <ry...@veritasprime.com>.
I have attached an excerpt of my metadata below. You'll be able to see the
property's attributes that I'm trying to gain access to.

I have cached the Edm metadata object so that I'm only requesting the
metadata once from the site (and have access to it at the time that I'm
processing my OData entry). Sounds like what you are saying is that I'll
have to side process the xml to get access to the attributes, or is there a
way to gain access using the Edm object?

Thanks,
Ryan S.



​
*Ryan Summerskill*
* Prime Solutions Manager **| Principal Software Engineer*
*Direct: 913.484.7195* *|* *E-mail:** ryan.summerskill@veritasprime.com
<ry...@veritasprime.com>*


* <http://www.linkedin.com/pub/ryan-summerskill/7/97/424>*
* <http://www.veritasprime.com/>*


On Mon, Apr 11, 2016 at 2:27 AM, Bolz, Michael <mi...@sap.com> wrote:

> Hello Ryan,
>
> Can you please provide the Olingo version which you use?
> Furthermore it would be helpful if you could share your metadata document
> (EDMX).
>
> As far as I understand your use case it is not possible to access the
> additional custom properties defined with the EDM
> while you process the result of an OData (data) request on a resource.
> So for your use case it would be necessary that you do a metadata request
> and cache those metadata information
> so that you do not need a second metadata request while you process the
> result of an OData (data) request on a resource.
>
> Kind Regards,
> Michael
>
>
>
> On 09 Apr 2016, at 18:29, Ryan Summerskill <
> ryan.summerskill@veritasprime.com> wrote:
>
> I'm building a java service that accesses OData information. I'm using
> olingo to parse all my returned json. If I pull the metadata I can see that
> my properties have custom attributes under all of my EntityTypes. I'm
> trying to access these attributes. I can currently access all the
> properties but all I can seem to get is the key, value pairs.
>
> *for(Entry<String, Object> prop : entry.getProperties().entrySet())*
>
> Steeping through in Eclipse I can see that the EntityType object has
> parsed these attributes and is storing them in a hashmap. Any idea how to
> get at this using Olingo? Last resort would be to side process the metadata
> xml again but I really really don't want to do that.
>
> I've also seen in debugger that the call
>
> *entitySet.getEntityType().getProperty("createdBy")*
>
> contains a *SimpleProperty property* variable that contains all my
> attribute annotations. Again can't figure out how to get access (both
> hacking and googleing). sigh :\
>
> Thanks for any help you can give,
> -Ryan S.
>
> This email and any files transmitted with it are confidential and intended
> solely for the use of the individual or entity to whom they are addressed.
> If you have received this email in error please notify the system manager.
> This message contains confidential information and is intended only for the
> individual named. If you are not the named addressee you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately by e-mail if you have received this e-mail by mistake and
> delete this e-mail from your system. If you are not the intended recipient
> you are notified that disclosing, copying, distributing or taking any
> action in reliance on the contents of this information is strictly
> prohibited.
>
>
>

-- 
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify the system manager. 
This message contains confidential information and is intended only for the 
individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail. Please notify the sender 
immediately by e-mail if you have received this e-mail by mistake and 
delete this e-mail from your system. If you are not the intended recipient 
you are notified that disclosing, copying, distributing or taking any 
action in reliance on the contents of this information is strictly 
prohibited.

Re: How to get property attributes for EntityType

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

Can you please provide the Olingo version which you use?
Furthermore it would be helpful if you could share your metadata document (EDMX).

As far as I understand your use case it is not possible to access the additional custom properties defined with the EDM 
while you process the result of an OData (data) request on a resource.
So for your use case it would be necessary that you do a metadata request and cache those metadata information
so that you do not need a second metadata request while you process the result of an OData (data) request on a resource.

Kind Regards,
Michael



> On 09 Apr 2016, at 18:29, Ryan Summerskill <ry...@veritasprime.com> wrote:
> 
> I'm building a java service that accesses OData information. I'm using olingo to parse all my returned json. If I pull the metadata I can see that my properties have custom attributes under all of my EntityTypes. I'm trying to access these attributes. I can currently access all the properties but all I can seem to get is the key, value pairs.
> 
> for(Entry<String, Object> prop : entry.getProperties().entrySet())
> Steeping through in Eclipse I can see that the EntityType object has parsed these attributes and is storing them in a hashmap. Any idea how to get at this using Olingo? Last resort would be to side process the metadata xml again but I really really don't want to do that.
> 
> I've also seen in debugger that the call
> 
> entitySet.getEntityType().getProperty("createdBy")
> contains a SimpleProperty property variable that contains all my attribute annotations. Again can't figure out how to get access (both hacking and googleing). sigh :\
> 
> 
> Thanks for any help you can give,
> -Ryan S.
> 
> This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.