I'm using the JPATypedQuery visitor to fetch data from the database based on
the FIQL query. 
My Entity called 'DocumentRequest' has a property 'suppliercode' with getter
and setters.

I capture the Searchcondition from the SearchContext like this:
SearchCondition<DocumentRequest> condition =
searchContext.getCondition(DocumentRequest.class);

and then pass it to the DAO layer to fetch it using the query visitor in
some generic method like this:
                SearchConditionVisitor<T, TypedQuery&lt;T>> visitor = new
JPATypedQueryVisitor(em, getType());
                if (filter != null) {
                        filter.accept(visitor);
                        TypedQuery<T> query = visitor.getQuery();
                        return query.getResultList();
                }               

This is all working fine if my query syntax & properties are correct.
But I'm getting inconsistent behaviour when I pass something else then
'suppliercode'.

1) If I pass a query like this: ?_s=suPPlierCode==abc
So property name exists, but casing is different, then I get this: 
Unable to locate Attribute with the the given name [suPPlierCode] on this
ManagedType [com.xxx.DocumentRequest]; 
nested exception is java.lang.IllegalArgumentException: Unable to locate
Attribute with the the given name [suPPlierCode] on this ManagedType
[com.xxx.DocumentRequest]
And this error comes from the JPATypeqQueryVistor:
        at
org.hibernate.jpa.internal.metamodel.AbstractManagedType.checkNotNull(AbstractManagedType.java:128)
        at
org.hibernate.jpa.internal.metamodel.AbstractManagedType.getAttribute(AbstractManagedType.java:113)
        at
org.hibernate.jpa.criteria.path.AbstractFromImpl.locateAttributeInternal(AbstractFromImpl.java:116)
        at
org.hibernate.jpa.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:204)
        at
org.hibernate.jpa.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:177)
        at
org.apache.cxf.jaxrs.ext.search.jpa.AbstractJPATypedQueryVisitor.getNextPath(AbstractJPATypedQueryVisitor.java:306)
        
        
2) If I pass a query like this: ?_s=suppliercooooooooode==abc
so non-existing property I get this:
org.apache.cxf.jaxrs.ext.search.PropertyNotFoundException
        at
org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionParser.getTypeInfo(AbstractSearchConditionParser.java:90)
        
And that happens when I try to get the condition from the searchContext
        SearchCondition<DocumentRequest> condition =
searchContext.getCondition(DocumentRequest.class);
        
        
Actually I would expect that it would behave the same in both cases, since a
non existing property is passed.
And in both cases I would like to send some error message back to the client
telling him that an incorrect FIQL query was passed to the system (send a
HTTP BAD Request back or something lik that).

So, is there a way to validate the FIQL query against the properties of a
POJO before actually passing it to the QueryVisitor?


        



--
View this message in context: 
http://cxf.547215.n5.nabble.com/FIQL-query-validation-tp5762439.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to