• Role Resolver: wkScirptRoleResolver

    By Christian Güdemann 1 decade ago

    Hello all,

    How do I acces the submitted "role" value in the script function in the evaluateRole event. I see that this is a methodbinding and the rolename is as object submitted, but how can I access this object.

     

    Thanks

    Christian

    • Patch for ScriptRoleResolver and ScriptIndentityResolver

      By Christian Güdemann 1 decade ago

      Hello All,

      could you please implement the following Patch to the ScriptResolver Class:

      The new elements in red:

      public IRoleResolver findRoleResolver(final FacesContext context) {
              final UIComponent uicCurrent = getComponent();
              return new AbstractRoleResolver() {
                  public String[] resolveRole(String requester, String role) throws WorkflowException {
                      if(evaluateRole!=null) {
                          if (evaluateRole instanceof MethodBindingEx) {
                              ((MethodBindingEx) evaluateRole)
                                      .setComponent(uicCurrent);
                              ((MethodBindingEx) evaluateRole)
                                      .setParamNames(s_roleName);
                          }


                          Object o = evaluateRole.invoke(context, new Object[]{extractRole(role)});
                          return toStringArray(o);
                      }
                      // Default is identity...
                      return new String[]{role};
                  }
                  private String[] toStringArray(Object o) {
                      if(o instanceof String[]) {
                          return (String[])o;
                      }
                      if(o instanceof Collection) {
                          Collection c = (Collection)o;
                          String[] a = new String[c.size()];
                          int i =0;
                          for(Iterator it=c.iterator(); it.hasNext(); ) {
                              String s = it.next().toString();
                              a[i++] = s;
                          }
                          return a;
                      }
                      if(o instanceof FBSValue) {
                          FBSValue v = (FBSValue)o;
                          String[] a = new String[v.getArrayLength()];
                          for(int i=0; i                         try {
                                  String s = v.getArrayElement(i).stringValue();
                                  a[i] = s;
                              } catch(InterpretException ex) {}
                          }
                          return a;
                      }
                      return new String[]{o.toString()};
                  }
              };
          }
          private static final String[] s_roleName = { "roleName" };// $NON-NLS-1$

      This makes the value of the roleName available as "roleName" on the SSJS side.

      Same effort for ScriptIdentityResolver Class:

          public IIdentityResolver findIdentityResolver(final FacesContext context) {
              final UIComponent uicCurrent = getComponent();
              return new AbstractIdentityResolver() {
                  public String nativeToWorkflow(String name)
                          throws WorkflowException {
                      if (nativeToWorkflow != null) {
                          if (nativeToWorkflow instanceof MethodBindingEx) {
                              ((MethodBindingEx) nativeToWorkflow)
                                      .setComponent(uicCurrent);
                              ((MethodBindingEx) nativeToWorkflow)
                                      .setParamNames(s_name);
                          }


                          return (String) nativeToWorkflow.invoke(context,
                                  new Object[] { name });
                      }
                      // Default is identity...
                      return name;
                  }

                  public String workflowToNative(String name)
                          throws WorkflowException {
                      if (nativeToWorkflow != null) {
                          if (nativeToWorkflow instanceof MethodBindingEx) {
                              ((MethodBindingEx) nativeToWorkflow)
                                      .setComponent(uicCurrent);
                              ((MethodBindingEx) nativeToWorkflow)
                                      .setParamNames(s_name);
                          }

                          return (String) workflowToNative.invoke(context,
                                  new Object[] { name });
                      }
                      // Default is identity...
                      return name;
                  }
              };
          }

          private static final String[] s_name = { "idName" };// $NON-NLS-1$

      • Thank you very much for you fix

        By Qian Liang 1 decade ago

        Thank you very much for you fix! We will include this in next release.