[ 
https://issues.apache.org/jira/browse/OLINGO-414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15301945#comment-15301945
 ] 

Santosh kumar edited comment on OLINGO-414 at 5/26/16 11:06 AM:
----------------------------------------------------------------

Hi All,
I was able to debug the issue and identify the root cause. The issue seems to 
be in ODataExpressionParser.java class ( of olingo-odata2-jpa-processor-core 
module) of Olingo Library. The method that I had to modify for the fix is given 
below.

- private static String getPropertyName(final CommonExpression whereExpression)
                    throws EdmException, ODataJPARuntimeException {
             EdmTyped edmProperty = ((PropertyExpression) 
whereExpression).getEdmProperty();
             
             if (edmProperty instanceof EdmNavigationProperty) { throw
               ODataJPARuntimeException.throwException(ODataJPARuntimeException.
               FILTER_ON_NAVIGATION_NOT_SUPPORTED, null); 
                }          
                 String name = "";
              EdmMapping mapping =null;
             
                //  Rest of the code.
       }

In the above code, when we see NavigationProperty, instead of throwing an 
exception, we could simply return internal name or name of the navigation 
property depending on below condition (navigation property could have a 
customized name, like in my case SiblingEntity is the customized name. URL is 
given below)

if (edmProperty instanceof EdmNavigationProperty) {
                    EdmNavigationProperty 
edmNavigationProperty=(EdmNavigationProperty) edmProperty;
                    mapping= edmNavigationProperty.getMapping();
                    if (mapping != null) {
                           return mapping.getInternalName();
                    }
             return  edmNavigationProperty.getName();
             }

Post fix I could test is succesfully from my application and also JUnit in 
Olingo library . Below is the JPQL Statement and the SQL query generated by 
Olingo and eclipse link respectively (for my application).

 JPQL : SELECT E1 FROM SalesOrderType E1 WHERE 
(E1.salesOrderInfo.isActiveEntity IS null) ORDER BY E1.activeSalesOrderID , 
E1.salesOrderDraftUUID

 SQL:
SELECT t0."ActiveSalesOrderID", t0."SalesOrderDraftUUID", t0."ApprovalComment", 
t0."Approved", t0."BillingStatus", t0."BusinessPartnerID", 
t0."CreationDateTime", t0."CreationUserName", t0."CurrencyCode", 
t0."DeliveryStatus", t0."DraftAdministrativeDataUUID", t0."GrossAmount", 
t0."HasActiveEntity", t0."HasDraftEntity", t0."IsActiveEntity", 
t0."LastChangedDateTime", t0."LastChangedUserName", t0."LifecycleStatus", 
t0."LogNumber", t0."NetAmount", t0."OpportunityID", t0."SalesOrderID", 
t0."TaxAmount", t0."UXBUSINESSPARTNERID", t0."UXDELETABLEENTITY", 
t0."UXUPDATABLEENTITY" FROM "SCHEMA"."SALESORDER" t0, " SCHEMA "."SALESORDER" 
t1 WHERE ((t1."IsActiveEntity" IS NULL) AND ((t1."SalesOrderDraftUUID" = 
t0."SalesOrderDraftUUID") AND (t1."ActiveSalesOrderID" = 
t0."ActiveSalesOrderID"))) ORDER BY t0."ActiveSalesOrderID", 
t0."SalesOrderDraftUUID"")

The URL for the scenario is : 
https://localhost:9443/draftinfrastructure/salesorder.svc/SalesOrderTypes?$skip=0&$top=50&$filter=(SiblingEntity/IsActiveEntity
 eq null).

SiblingEntity is the navigation property in this url and IsActiveEntity is the 
property inside sibling entity which is of type SalesOrderEntity.

I don't think there is any issue related to JPQL in Olingo or SQL in Eclipse 
link (or any JPA for that matter). 
 Let me know what you think? 

Thanks and Regards,
Santosh



was (Author: santosh kumar):
Hi All,
I was able to debug the issue and identify the root cause. The issue seems to 
be in ODataExpressionParser.java class ( of olingo-odata2-jpa-processor-core 
module) of Olingo Library. The method that I had to modify for the fix is given 
below.

- private static String getPropertyName(final CommonExpression whereExpression)
                    throws EdmException, ODataJPARuntimeException {
             EdmTyped edmProperty = ((PropertyExpression) 
whereExpression).getEdmProperty();
             
             if (edmProperty instanceof EdmNavigationProperty) { throw
               ODataJPARuntimeException.throwException(ODataJPARuntimeException.
               FILTER_ON_NAVIGATION_NOT_SUPPORTED, null); 
                }          
                 String name = "";
              EdmMapping mapping =null;
             
                //  Rest of the code.
       }

In the above code, when we see NavigationProperty, instead of throwing an 
exception, we could simply return internal name or name of the navigation 
property depending on below condition (navigation property could have a 
customized name, like in my case SiblingEntity is the customized name. URL is 
given below)

if (edmProperty instanceof EdmNavigationProperty) {
                    EdmNavigationProperty 
edmNavigationProperty=(EdmNavigationProperty) edmProperty;
                    mapping= edmNavigationProperty.getMapping();
                    if (mapping != null) {
                           return mapping.getInternalName();
                    }
             return  edmNavigationProperty.getName();
             }

Also I have written a JUnit to test this functionality. Below is the JPQL 
Statement and the SQL query generated by Olingo and eclipse link respectively.

 JPQL : SELECT E1 FROM SalesOrderType E1 WHERE 
(E1.salesOrderInfo.isActiveEntity IS null) ORDER BY E1.activeSalesOrderID , 
E1.salesOrderDraftUUID

 SQL:
SELECT t0."ActiveSalesOrderID", t0."SalesOrderDraftUUID", t0."ApprovalComment", 
t0."Approved", t0."BillingStatus", t0."BusinessPartnerID", 
t0."CreationDateTime", t0."CreationUserName", t0."CurrencyCode", 
t0."DeliveryStatus", t0."DraftAdministrativeDataUUID", t0."GrossAmount", 
t0."HasActiveEntity", t0."HasDraftEntity", t0."IsActiveEntity", 
t0."LastChangedDateTime", t0."LastChangedUserName", t0."LifecycleStatus", 
t0."LogNumber", t0."NetAmount", t0."OpportunityID", t0."SalesOrderID", 
t0."TaxAmount", t0."UXBUSINESSPARTNERID", t0."UXDELETABLEENTITY", 
t0."UXUPDATABLEENTITY" FROM "SCHEMA"."SALESORDER" t0, " SCHEMA "."SALESORDER" 
t1 WHERE ((t1."IsActiveEntity" IS NULL) AND ((t1."SalesOrderDraftUUID" = 
t0."SalesOrderDraftUUID") AND (t1."ActiveSalesOrderID" = 
t0."ActiveSalesOrderID"))) ORDER BY t0."ActiveSalesOrderID", 
t0."SalesOrderDraftUUID"")

The URL for the scenario is : 
https://localhost:9443/draftinfrastructure/salesorder.svc/SalesOrderTypes?$skip=0&$top=50&$filter=(SiblingEntity/IsActiveEntity
 eq null).

SiblingEntity is the navigation property in this url and IsActiveEntity is the 
property inside sibling entity which is of type SalesOrderEntity.

I don't think there is any issue related to JPQL in Olingo or SQL in Eclipse 
link (or any JPA for that matter).
 Let me know what you think? 

Thanks and Regards,
Santosh


> Cannot Filter on Navigation Property
> ------------------------------------
>
>                 Key: OLINGO-414
>                 URL: https://issues.apache.org/jira/browse/OLINGO-414
>             Project: Olingo
>          Issue Type: Bug
>          Components: odata2-jpa
>    Affects Versions: V2 2.0.0
>            Reporter: Simon Carroll
>         Attachments: olingo-414-exception.diff, olingo-414-patch.diff
>
>
> We are receiving an error when we try to filter on a navigation property.  In 
> our solution we have a Notification entity and a User entity, we would like 
> to retrieve a specific Notification but only if it is linked to the 
> requesting user.  This would involve an ODATA request which filters on both 
> the UserId and the NotificationId.  An example of the URL we are invoking is:
> dspplatform.svc/Notifications?$filter=NotificationId%20eq%204%20and%20UserDetails/UserId%20eq%202
> This returns the following error:
> org.apache.olingo.odata2.core.edm.provider.EdmNavigationPropertyImplProv 
> cannot be cast to org.apache.olingo.odata2.api.edm.EdmProperty
> Can you please advise on how to perform filters on a Navigation property as 
> we need this as part of our core functionality?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to