Hi

Right now you can control it like this, it is captured in
http://cxf.apache.org/docs/jax-rs-search.html#JAX-RSSearch-Capturingthequeries, and the follow up sections, but I guess it would help to have a table...

- register ExceptionMapper<PropertyNotFoundException> and let the client know about it in a more readable way - set "search.lax.property.match" - so if the property can not be matched then it would be ignored - use a property map, example, "code":"supplierCode" - that can minimize the typo effect and besides I think it is a good practice to avoid, when possible to have clients use aliases to simplify the future Java bean updates (example, 'supplierCode' property will be renamed somehow in the future, etc, while the client still users 'code')

However dealing with the typos in a more positive way is interesting, I guess may be I can introduce an interface like PropertyNameConverter, which will be given the current object and the property name and the converter will have an option to adapt something like 'suPPlierCode' to 'supplierCode', etc

I'll have a look a bit later, will let you know
Thanks Sergey

On 30/10/15 16:45, Diether wrote:
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.



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to