3

I see there is documentation that describes using annotations with Olingo for Odata v2: https://olingo.apache.org/doc/odata2/tutorials/AnnotationProcessorExtension.html

So for example, instead of manually creating a provider that details all the EDM metadata, I'd like to add annotations to my model and have a generic EDM provider to generate all the meta data. And similarly for the data provider. It would like something like this:

@EdmEntityType
@EdmEntitySet
public class Car {
  @EdmKey
  @EdmProperty
  private String id;
  @EdmProperty
  private String model;
  @EdmNavigationProperty
  private Manufacturer manufacturer;
}

Is there similar functionality for Olingo Odata4? I couldn't find any examples and searching didn't seen the annotations defined in their source code. As I recall this approach works with other frameworks, .Nets web API, SDL Odata, Olingo Odata2, etc.

Update: I ended up using SDL Odata instead which also supports Odata v4 and has notations. For an example look here: https://github.com/sdl/odata-example

Here is what a model looks like in Scala:

@EdmEntity(namespace = "SDL.OData.Example", key = Array("id"), containerName = "SDLExample")
@EdmEntitySet
case class Person (
  @(EdmProperty @field)(name="id",       nullable = false) var personId: String,
  @(EdmProperty @field)(name="firstName",nullable = false) var firstName: String,
  @(EdmProperty @field)(name="lastName", nullable = false) var lastName: String,
  @(EdmProperty @field)(name="age",      nullable = false) var age: Int
)
Mike
  • 791
  • 8
  • 18

1 Answers1

4

There is currently no documentation on this topic. I would suggest you look at the Olingo TechSvc module which is used in their integration tests. There you can see how the annotations are set for an EntitySet: https://github.com/apache/olingo-odata4/blob/2e24ffd1d3c343fdec45f8dbf0398783a0a86f3f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java#L179

Basically you use the classes you can find in the org.apache.olingo.commons.api.edm.annotation package and add instances of those clases to you CsdlProvider elements which you want to be annotated.

chrisam
  • 553
  • 2
  • 4
  • I got a chance to stare at the above code you mentioned, but I'm not familiar enough with Olingo to understand enough of what it's doing in order to come up with my own example. I assume I need to make my own custom EDM provider, similar to EdmTechProvider since that was just created for testing. It seems like a bit of work for something I had expected to work out of the box but perhaps I am missing something? – Mike Jul 28 '16 at 18:45
  • 1
    Sorry it seems I misunderstood your question. I thought you were talking about OData annotations which are elements within the metadata XML. There is currently no Java Annotation mechanism which results in a working OData service for OData V4. – chrisam Jul 29 '16 at 08:03
  • Are semantics of annotations, e.g. ``Core.Permissions`` read-only mode, enforced? From my tests, it looks like they are not. – Michael Jess Jan 10 '17 at 12:48