Search code examples
javaapacheodatametadataolingo

Olingo V4 Annotations not getting reflected in $metadata


I have implemented Odata V4 service using Olingo. I am trying to include
Aggregation.ApplySupported annotation to my service. However the annotation term value is blank in my $metadata document. Below is my code snippet

List<CsdlAnnotation> list = new ArrayList<CsdlAnnotation>();
CsdlAnnotation annotationAttribute = new CsdlAnnotation();
annotationAttribute.setTerm("Aggregation.ApplySupported");
annotationAttribute.setExpression(new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String, "true"));
list.add(annotationAttribute);
entityContainer.setAnnotations(list);

$metadata

<EntityContainer Name="myContainer">
   <!-- .....sets -->
  <Annotation>   <!-- term is blank -->
     <String>true</String>
  </Annotation>
</EntityContainer>

Can't figure out whats I am missing on. Thanks in advance.


Solution

  • You should override getTerm method in your provider.

    @Override
        public CsdlTerm getTerm(final FullQualifiedName termName) throws ODataException {
            return new CsdlTerm().setAppliesTo(Arrays.asList("EntityContainer"))
                    .setName("ApplySupported");
        }
    

    See example here: https://apache.googlesource.com/olingo-odata4/+/master/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java