Hi
I need to dynamically filter the results of a REST query based on the actual user is calling it, but it seems REST queries do not support predefined parameters like :session$userId.
Is it currently possible, or do I have to override the underlying QueriesControllerManager bean to automatically add this param before running the actual query?
import com.haulmont.restapi.config.RestQueriesConfiguration;
import org.dom4j.Element;
public class CustomRestQueriesConfiguration extends RestQueriesConfiguration {
@Override
protected void loadConfig(Element rootElem) {
super.loadConfig(rootElem);
// add predefined parameters if needed in loaded queries
for (QueryInfo query : queries) {
if (query.getJpql().contains(":session$userId")) {
query.getParams().add(new QueryParamInfo("session$userId", "java.util.UUID"));
}
}
}
}
that’s it, you are now able to use :session$userId parameter without passing it explicitly, and without defining it in params collection (remember that a client can always pass that parameter explicitly, but you’re overriding it with put, cause params are a Map).
In the meantime I changed my post by including an overridden RestQueriesConfiguration, so there’s no need to explicitly add the parameter to the params collection in rest-queries.xml.