Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-25211

Whitelist NuxeoException for automation scripting usage

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Detail
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 10.2
    • Component/s: Automation

      Description

      Use case

      • As a developer building an application based on Web UI, I want to be sure the content of a document creation / edit form is validated server-side so that my content integrity is ensured.

      Example: make sure that my end date property for a Contract document type is ulterior to my start date property (see NXDOC-1578 ).

      Currently I can easily validate the form client side, but have no way to configure the same check server-side using Studio.

      • I can add an event handler on document creation / modification
      • I can bind it to an automation script

      But the script cannot throw a NuxeoException if the rule is not ok.
      I would like to do the following to complete my use case:

      throw new NuxeoException("End date must be ulterior to start date", 400);
      

      WHAT HAPPENS CURRENTLY

      • Whitelist NuxeoException using an XML extension
          <require>org.nuxeo.automation.scripting.classfilter</require>
          <extension target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent" point="classFilter">
            <classFilter>
              <allow>org.nuxeo.ecm.core.api.NuxeoException</allow>
            </classFilter>
          </extension>
        
      • Create an automation script with the following content:
        function run(input, params) {
          throw new org.nuxeo.ecm.core.api.NuxeoException("FooBar3000");
        }
        
      • Associate it to an event handler on about to create and before doc modification
      • Save, deploy and create a new doc

      =>

      ****** chain ******
      Name: javascript.bla
      Exception: OperationException
      Caught error: Failed to invoke operation javascript.bla
      Caused by: org.nuxeo.ecm.automation.OperationException: Failed to invoke operation javascript.bla
      ****** Hierarchy calls ******
          org.nuxeo.automation.scripting.internals.ScriptingOperationImpl
      
              at org.nuxeo.ecm.automation.core.trace.TracerFactory.onTrace(TracerFactory.java:198)
              at org.nuxeo.ecm.automation.core.trace.Tracer.popContext(Tracer.java:73)
              at org.nuxeo.ecm.automation.core.trace.Tracer.onChainExit(Tracer.java:86)
              at org.nuxeo.ecm.automation.core.impl.OperationChainCompiler$CompiledChainImpl.lambda$invoke$0(OperationChainCompiler.java:227)
              ... 138 more
      Caused by: java.lang.reflect.UndeclaredThrowableException
          at com.sun.proxy.$Proxy168.run(Unknown Source)
          at org.nuxeo.automation.scripting.internals.ScriptingOperationImpl.run(ScriptingOperationImpl.java:66)
          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:170)
          at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:175)
          ... 140 more
      Caused by: java.lang.reflect.InvocationTargetException
          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.automation.scripting.internals.AutomationScriptingServiceImpl$Bridge$1.invoke(AutomationScriptingServiceImpl.java:111)
          ... 148 more
      Caused by: <eval>:2:2 org.nuxeo.ecm.core.api.NuxeoException: FooBar3000
          at jdk.nashorn.internal.runtime.ECMAException.create(ECMAException.java:113)
          at jdk.nashorn.internal.scripts.Script$Recompilation$4$28AA$\^eval\_.run(<eval>:2)
          at org.nuxeo.automation.scripting.internals.ScriptingOperationImpl$Runnable$$NashornJavaAdapter.run(Unknown Source)
          ... 153 more
      Caused by: org.nuxeo.ecm.core.api.NuxeoException: FooBar3000
          ... 155 more
      

      TODO

      • Whitelist NuxeoException usage following the same pattern as NXP-25020 by default in Nuxeo Platform

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 20 minutes
                  20m

                    PagerDuty

                    Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.