Search code examples
javaodataolingo

How to get property attributes for EntityType using Olingo


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 :\


Solution

  • After talking with the guys on the olingo user group I have a solution. The code snippet

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

    Returns an EdmTyped object. This can be cast to a EdmProperty in which the annotations and attributes are available for lookup.

    EdmProperty prop = (EdmProperty)entitySet.getEntityType().getProperty("createdBy")
    for(EdmAnnotationAttribute attr : property.getAnnotations().getAnnotationAttributes())
    {
        attr contains your info
    }
    

    I didn't try this earlier as when I looked in the debugger after casting to EdmProperty annotations variable was null. Lesson learned again and again, never assume. :)

    Annotations are loaded at the time of the call to prop.getAnnotations()