09-06-2012 09:27 AM
I want to specify into my Nuxeo studio a form with a suggestion box mapped on a Single/Multiple Document suggestion. All work well, but I want to filter the suggestions returned to fetch only a specific kind of documents or path.
How can I do that ?
09-06-2012 09:33 AM
Dear Me,
So you must have into your form definition (in creation or edition) a single or multiple Document suggestion widget. You have into this widget a field called "document page provider name". Here you will specify the filter.
Today you can't specify the filter directly in studio, waiting that, you can go to:
_
<extension target="org.nuxeo.ecm.platform.query.api.PageProviderService"
point="providers">
<coreQueryPageProvider name="ListeDiffusion">
<pattern quoteParameters="false" escapeParameters="true">
SELECT * FROM MyDocument WHERE ecm:fulltext LIKE '?*' AND ecm:mixinType !=
'HiddenInNavigation' AND ecm:isCheckedInVersion = 0 AND
ecm:currentLifeCycleState != 'deleted'
</pattern>
<!-- sort column="dc:title" ascending="true" / sort by fulltext relevance -->
<pageSize>5</pageSize>
</coreQueryPageProvider>
</extension>
You will recognize the NXQL syntax. With your large knowledge on this language, I think you have enough to what you want.
09-06-2012 09:33 AM
Dear Me,
So you must have into your form definition (in creation or edition) a single or multiple Document suggestion widget. You have into this widget a field called "document page provider name". Here you will specify the filter.
Today you can't specify the filter directly in studio, waiting that, you can go to:
_
<extension target="org.nuxeo.ecm.platform.query.api.PageProviderService"
point="providers">
<coreQueryPageProvider name="ListeDiffusion">
<pattern quoteParameters="false" escapeParameters="true">
SELECT * FROM MyDocument WHERE ecm:fulltext LIKE '?*' AND ecm:mixinType !=
'HiddenInNavigation' AND ecm:isCheckedInVersion = 0 AND
ecm:currentLifeCycleState != 'deleted'
</pattern>
<!-- sort column="dc:title" ascending="true" / sort by fulltext relevance -->
<pageSize>5</pageSize>
</coreQueryPageProvider>
</extension>
You will recognize the NXQL syntax. With your large knowledge on this language, I think you have enough to what you want.
05-23-2014 05:03 AM
Thank you for this insight.
I have a "Single document suggestion" widget and have declared my own "Page Provider" in Studio, and would like to specify a NXQL which only returns Nuxeo documents located at a certain path related to the current document: is it possible, and if yes, how do I express that, please? I've read that the "Page Provider" cannot use EL expression and that it is up to the caller to provide parameters, hence my question is what and how does the "Single document suggestion" transmit parameters to the "Page Provider" declared through the "pageProviderName" attribute?
Thank you for your support. Regards.
05-31-2014 03:48 AM
In your page provider, you can add an other question mark, and build the EL accordingly. Because yes, in this context - and at least with Nuxeo 5.9.3 as I could test right away - it works. So for example, say I am in a Folderish document and want to limit the search to any children/grand-children, etc., here is the PageProvider (XML extension to use in Studio):
<extension target="org.nuxeo.ecm.platform.query.api.PageProviderService"
point="providers">
<coreQueryPageProvider name="pageProviderWithStartsWith">
<pattern quoteParameters="false" escapeParameters="true">
SELECT * FROM Document WHERE dc:title ILIKE '?%' AND ecm:mixinType !=
'HiddenInNavigation' AND ecm:isCheckedInVersion = 0 AND
ecm:currentLifeCycleState != 'deleted' AND ecm:path STARTSWITH "?"
</pattern>
<parameter>#{currentDocument.path}</parameter>
<!-- sort column="dc:title" ascending="true" / sort by fulltext relevance -->
<pageSize>5</pageSize>
</coreQueryPageProvider>
</extension>
Notice...
AND ecm:path STARTSWITH "?"
...and:
<parameter>#{currentDocument.path}</parameter>
06-03-2014 03:37 PM
Thank you @ThibArg for your answer.
I understand that the "parameter" XML node enables to express parameters that can be used within the page provider NXQL query. Your example is interesting, but I would like to state in the NXQL request that I only want the documents with start with the current document grand-parent. I tried with the following syntax :
<parameter>#{documentManager.getDocument(documentManager.getDocument(currentDocument.getParentRef()).getParentRef()).getPathAsString()}</parameter>
which does not work (I get exceptions in the logs). Would you have any idea how on to achieve that, please?
Thank you for your help.
06-03-2014 05:02 PM
This expression...
#{documentManager.getParentDocument(currentDocument.parentRef).path}
...will work (works actually), because documentManager.getParentDocument()
returns the parent document of the ref. passed as parameter, and it receives the ref. of the parent of the current document (currentDocument.parentRef
). So this expression is basically "get the parent of the ref. of the parent" <=> "get the grand parent":
#{documentManager.getParentDocument(currentDocument.parentRef).path}
|----------------------------------|-------------------------|
| ? | ? ? |
| Grand parent | Cur. doc Parent |
06-04-2014 04:45 AM
Thank you @ThibArg for answering so quickly. I guess that the recipe you are proposing works on a very recent version of Nuxeo, because I get the same exception, while attempting to run it on Nuxeo v5.8:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
at org.nuxeo.ecm.platform.query.nxql.NXQLQueryBuilder.getQuery(NXQLQueryBuilder.java:213)
at org.nuxeo.ecm.platform.query.nxql.CoreQueryDocumentPageProvider.buildQuery(CoreQueryDocumentPageProvider.java:204)
at org.nuxeo.ecm.platform.query.nxql.CoreQueryDocumentPageProvider.getCurrentPage(CoreQueryDocumentPageProvider.java:91)
at org.nuxeo.ecm.automation.core.util.PaginablePageProvider.<init>(PaginablePageProvider.java:34)
at org.nuxeo.ecm.automation.jaxrs.io.documents.PaginableDocumentModelListImpl.<init>(PaginableDocumentModelListImpl.java:46)
at org.nuxeo.ecm.automation.core.operations.services.DocumentPageProviderOperation.run(DocumentPageProviderOperation.java:182)
at sun.reflect.GeneratedMethodAccessor938.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:135)
at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:149)
... 97 more
Or do you think that I missed something, please?
06-04-2014 10:25 AM
Please stop using this as a forum, it's not a forum. There should be a single Question at the top and one or more Answers. The rest should be comments or edits to the question to clarify it.
06-04-2014 10:35 AM
Hi,
The IndexOutOfBound error is thrown because the number of ? in the Query does not match the number of parameters you give.
Probably you specify 2 parameters in the PageProvider but have only 1 ? in the NXQL Query.
Concerning the way you can retrieve the path, I would expect that you can use the fact that the path attribute of the DocumentModel is not a String but a Path object
=> something like #{currentDocument.getPath().removeLastSegments(2)}
should work
Tiry
06-04-2014 01:14 PM
Here is the XML extension I added in Studio:
<extension target="org.nuxeo.ecm.platform.query.api.PageProviderService"
point="providers">
<coreQueryPageProvider name="pageProviderWithStartsWith">
<pattern quoteParameters="false" escapeParameters="true">
SELECT * FROM Document WHERE dc:title ILIKE '?%' AND ecm:mixinType !=
'HiddenInNavigation' AND ecm:isCheckedInVersion = 0 AND
ecm:currentLifeCycleState != 'deleted' AND ecm:path STARTSWITH '?'
</pattern>
<parameter>#{documentManager.getParentDocument(currentDocument.parentRef).path}</parameter>
<pageSize>5</pageSize>
</coreQueryPageProvider>
</extension>
So we have the first parameter...
[...] dc:title ILIKE '?%' [...]
...which uses what the user is entering in the suggestion widget.
Notice: it must be the first parameter (can't be the second, third, ...)
Then, the second parameter is the path to query:
[...] AND ecm:path STARTSWITH '?'
And so far, the #{documentManager.getParentDocument(currentDocument.parentRef).path}
expression also works in 5.8. I tested with the latest 5.8, HF 14.
I did test Thierry's expression(#{currentDocument.getPath().removeLastSegments(2)}
) and it also works like a charm. Could even be seen as more elegant, cool! 🙂
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.