Skip to Content

This is the continuation of previous blog (blog series), In this blog series will be explaining about adding custom annotation and labels into ODATA metadata, but in Olingo 2.0 anytype of Aggregation is not possible.

 

Introduction   

In order to add new annotation into the metadata to any of the Entity class or calculation view then, we have to extend the JPAEdmExtension class and create a Java class by implementing the interface org.apache.olingo.odata2.jpa.processor.api.model to register the annotated Java methods. Below metadata of Employee and Orders Entity class info, before the annotation addition you need to include below set of code in SampleCustomOdataJpaServiceFactory class,

  • oDataJPAContext.setJPAEdmExtension((JPAEdmExtension) new CustomAnnotationProcessor());

 

/wp-content/uploads/2016/10/17_1042960.png

And in CustomAnnotationProcessor class override the extendJPAEdmSchema method as shown below, In below sample code I have just added the generic annotation on all the columns, if required you  can added different annotation for different columns as well as for class level also.

 

/wp-content/uploads/2016/10/18_1042964.png

 

 

Now when you check the metadata before annotation addition,

 

/wp-content/uploads/2016/10/19_1042965.png

 

 

Now below metadata shows after adding annotation at entity level by implementing the JPAEdmExtension class

/wp-content/uploads/2016/10/20_1042966.png

 

In this blog it has been explained that how custom annotation can be added in columns metadata of ODATA.

In next blog .i.e. Part4, how JPA mapping can be redefined.

 

 

 

 

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Treasa PA

    Hi Rajnish,

    I’m also trying out the sap annotations. In the code snippet for adding annotation to the entity properties, the value for prefix of the attribute is set as “sap”, and the value for name is set as “sap:label”. However in the metadata, it gets displayed as “sap:label”. Is the prefix value ignored even though it is set?

    Kind Regards,
    Treasa PA

    (0) 
    1. Rajnish Tiwari Post author

      Hi Treasa,

      Its not ignored, if prefix is not added as sap then value can not to be set as sap:label. i was facing some issue in adding the tags so i have to set prefix as “sap” and label as “sap:label”

      Moreover it expects that before : (colon) whatever value we are adding the same value has to added in prefix also.

      Thanks,
      Rajnish

      (0) 

Leave a Reply