11-01-2018 02:00 PM
Hi! I'm working on an automation chain in studio, and I'm running into an issue on trying to recursively apply a RunDocumentOperation operation to each document returned from a query.
The general structure is I have this contextual user action, when pressed, it will query documents that were modified within a set date range. For each of these modified documents, I'd like to run a specific automation chain (the same one for each document). So my starter chain looks like this:
Automation Chain Name: ac_find_modified
- Repository.Query:
query: "SELECT * FROM Document WHERE dc:modified BETWEEN DATE '2018-10-10' AND DATE '2018-10-15'"
language: NXQL
sortOrder: ASC
- RunDocumentOperation:
id: my_test_chain
isolate: "false"
rollbackGlobalOnError: "false"
What happens is that the query operation returns a DocumentList type, which I believed was okay to perform the RunDocumentOperation (according to the solution from this: https://answers.nuxeo.com/general/q/ae6a0c4c46f24bb3a317a075f056d95f/How-to-recursivly-apply-an-auto... )
However what I observed is after the query search, it would proceed to run the first document of the results through the "my_test_chain" automation chain and finish. However after finishing, it errors with the following
****** end sub chain ******
at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:238)
at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:97)
at org.nuxeo.ecm.automation.jsf.OperationActionBean.runOperation(OperationActionBean.java:94)
at org.nuxeo.ecm.automation.jsf.OperationActionBean.doOperation(OperationActionBean.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
.....
.....
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.nuxeo.ecm.automation.OperationException: Failed to invoke operation RunDocumentOperation with aliases [Context.RunDocumentOperation]
at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:189)
at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:130)
at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:116)
at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:133)
at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:116)
at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:214)
... 105 more
Caused by: java.lang.ClassCastException: org.nuxeo.ecm.core.api.impl.DocumentModelListImpl cannot be cast to org.nuxeo.ecm.core.api.DocumentModel
at org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain.run(RunDocumentChain.java:95)
at org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain.run(RunDocumentChain.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:171)
at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:177)
... 110 more
If it helps, the header of the automation chain traceback in the logs was:
****** chain ******
Name: ac_find_modified
Exception: OperationException
Caught error: Failed to invoke operation RunDocumentOperation with aliases [Context.RunDocumentOperation]
Caused by: java.lang.ClassCastException: org.nuxeo.ecm.core.api.impl.DocumentModelListImpl cannot be cast to org.nuxeo.ecm.core.api.DocumentModel
****** Hierarchy calls ******
org.nuxeo.ecm.automation.core.operations.services.query.DocumentPaginatedQuery
org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain
I just wanted to make sure this is the procedure to perform if you simply want to apply one automation chain to every document returned from a query. I'm kinda confused on why it actually processes the first element, but procedures to error after the first run? Another note is that the "my_test_chain" does start with Context.FetchDocument , which I was wondering maybe that is responsible since the error complains about casting a DocumentList to a Document and it is expecting a Document. However I read the description and said:
"Fetch the input of the context as a document or list of documents. The document will become the input for the next operation."
So it sounds like it should accept a list as well. So is it actually the RunDocumentOperation from my "ac_find_modified" chain?
11-28-2018 02:37 PM
Generally using an automation script is more appropriate for iterating through lists of documents.
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.