Skip to content

How to get Annotation tag with term and String #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Boltzmann opened this issue Jul 22, 2022 · 1 comment
Closed

How to get Annotation tag with term and String #153

Boltzmann opened this issue Jul 22, 2022 · 1 comment

Comments

@Boltzmann
Copy link
Contributor

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 <Annotation> <String>Description Test</String> </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
Copy link
Contributor Author

#37 (comment) 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");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant