cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Function Imports to OData Services

Former Member
0 Kudos

Hello,

I try to add a Function Import in my OData service but it doesn't appear in the &metadata, so I can't access it.

I am following this tutorial : https://olingo.apache.org/doc/odata2/tutorials/jpafunctionimport.html

So, I have created a class wich contains the logic part :


public class MobileAppService {

  @EdmFunctionImport(name = "GetApiValidity",

            returnType = @ReturnType(type = Type.SIMPLE, isCollection = false),

            httpMethod = HttpMethod.GET)

  public int getApiValidity( ) {

       return 123;

  }

}

Another class to register the annotated Java methods :


public class LucEdmExtension implements JPAEdmExtension {

  @Override

  public void extendWithOperation(JPAEdmSchemaView view) {

       view.registerOperations(MobileAppService.class, null);

  }

}

Finally I have registered this last class in the ODataJPAContext :


@Override

  public ODataJPAContext initializeODataJPAContext()

                 throws ODataJPARuntimeException {

       ODataJPAContext oDataJPAContext = this.getODataJPAContext();

       try {

            EntityManagerFactory emf = Utility.getEntityManagerFactory();

            oDataJPAContext.setEntityManagerFactory(emf);

            oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);

            oDataJPAContext.setJPAEdmExtension(new LucEdmExtension());

            return oDataJPAContext;

       } catch (Exception e) {

            throw new RuntimeException(e);

       }

  }

As far as I know, it should be enough to get this kind of metadata :


<EntityContainer Name="ODataEntityContainer" m:IsDefaultEntityContainer="true">

    . . .

     <FunctionImport Name="GetApiValidity" ReturnType=""Edm.Int32"" m:HttpMethod="GET"></FunctionImport>

     . . .

</EntityContainer>

But I have nothing related with Function Import... Could you please help me ?

I am using a class of type EdmProvider to configure all other services, should I add something in this class for the Function Import ?

I am using OData 2.0 version.

Thanks a lot,

François

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

When I don't use the EdmProvider object to define all other services, the function import is detected and proposed in the metadata.

Can't we use both EdmProvider and Function Import ?

I really think I should add something in the EdmProvider class but I can't figure out what.

Any help would be appreciated

François

Former Member
0 Kudos

Hello Francois,

Yes you cannot mix JPA Edm Provider with Edm Providers. In case if you are using Edm providers to generate the OData service then you have use the Edm Provider APIs to add function imports to the service metadata.

JPA edm providers are used for transforming JPA entities into OData services. It uses Edm Annotations to transform Java methods to function imports.

I hope this answers your query.

Thanks

Kind Regards

Chandan

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Chandan,

you are right we can't mix both methods. I've completed my EdmProvider class to define the function import (using method getFunctionImport) and I've implemented the logic in my ODataSingleProcessor class (using method executeFunctionImport).

It works fine. Thanks for your help.

Regards

François