SLN Spotlight_SAP Labs India: adding custom annotation and labels to metadata
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.
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());
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.
Now when you check the metadata before annotation addition,
Now below metadata shows after adding annotation at entity level by implementing the JPAEdmExtension class
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.