SAP / olingo-jpa-processor-v4

The JPA Processor fills the gap between Olingo V4 and the database, by providing a mapping between JPA metadata and OData metadata, generating queries and supporting the entity manipulations.
Apache License 2.0
122 stars 76 forks source link

How to get Annotation tag with term and String #153

Closed Boltzmann closed 2 years ago

Boltzmann commented 2 years ago

Why does @EdmAnnotation(term = "Core.Description", constantExpression = @EdmAnnotation.ConstantExpression(type = CsdlConstantExpression.ConstantExpressionType.String, value = "Description Test")) result in the xml output of http://localhost:8080/Cases/V1.0/$metadata only in `

Description Test
                </Annotation>` - without the string "Term=Core.Description" in the Annotation tag?

I would expect it to behave similar to the qualifier parameter @EdmAnnotation(term = "Core.Description", qualifier = "Qualifier", constantExpression = @EdmAnnotation.ConstantExpression(type = CsdlConstantExpression.ConstantExpressionType.String, value = "Description Test")) that gives <Annotation Qualifier="Qualifier">. At the moment "term" does not matter at all.

Background: A GET http://localhost:8080/Cases/V1.0/$metadata of a project with Entity

package some.package.example;

import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmAnnotation;
import lombok.*;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;

import javax.persistence.*;

@Entity
@Table(name = "Example_case")
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ExampleEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @EdmAnnotation(term = "Core.Description", qualifier = "Qualifier",
            constantExpression = @EdmAnnotation.ConstantExpression(type = CsdlConstantExpression.ConstantExpressionType.String,
                    value = "Description Test"))
    @Column(name = "OrderNumber")
    private String order_nr;
}

gives

<?xml version='1.0' encoding='UTF-8'?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
    <edmx:DataServices>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Cases">
            <EntityType Name="ExampleEntity">
                <Key>
                    <PropertyRef Name="Id"/>
                </Key>
                <Property Name="Order_nr" Type="Edm.String" MaxLength="255">
                    <Annotation Qualifier="Qualifier">
                        <String>Description Test</String>
                    </Annotation>
                </Property>
                <Property Name="Id" Type="Edm.Int64"/>
            </EntityType>
            <EntityContainer Name="Cases">
                <EntitySet Name="ExampleEntities" EntityType="Cases.ExampleEntity"/>
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

I seek for a solution with an output off

<Annotation Term="Core.Description" String="Description Test"/>
Boltzmann commented 2 years ago

https://github.com/SAP/olingo-jpa-processor-v4/issues/37#issuecomment-375079043 helps:

It seems that an attribute of either Person.class or BusinessPartner.class has an annotation EdmAnnotation, which can be used to generate simple OData annotation, but corresponding definition of the OData annotations is missing.

...

[...] download Org.OData.Core.V1.xml, store it e.g. under /src/main/resources/annotations You create an extension of JPAEdmMetadataPostProcessor and override method provideReferences using the following code:

    String uri = "http://docs.oasisopen.org/odata/odata/v4.0/os/vocabularies/Org.OData.Core.V1.xml";
    IntermediateReferenceAccess reference = references.addReference(uri, "annotations/Org.OData.Core.V1.xml");
    reference.addInclude("Org.OData.Core.V1", "Core");