on 03-25-2016 2:22 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.