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

Directory schemas must allow references declared with xs:simpleType/xs:list

    XMLWordPrintable

    Details

    • Tags:
    • Sprint:
      nxFG 10.10.1
    • Story Points:
      3

      Description

      When a directory field is used as a reference but has a schema based on xs:simpleType/xs:list, we observe failures.

      The problem is that most references in Nuxeo are declared through nxs:stringList which is actually a xs:complexType/xs:sequence and is therefore backed by a List<String>, whereas a xs:simpleType/xs:list is backed by a String[]. So generic code that expects to cast to List<String> when getting references will fail.


      Original report:

      I customised the user schema and added relations with documents, simple and multivalued.
      Whenever we express the relation between documents and the user with a stringList (base.xsd, same as groups) in the user schema, the user is saves properly and the relations too.
      When we add a document resolver to help us with the interface, we have a ClassCast exception String array cannot be cast to List of String =>

      java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List

      at org.nuxeo.ecm.directory.BaseSession.createEntry(BaseSession.java:381)
      at org.nuxeo.ecm.directory.BaseSession.createEntry(BaseSession.java:357)
      at org.nuxeo.ecm.platform.usermanager.UserManagerImpl.createUser(UserManagerImpl.java:1208)
      at org.nuxeo.ecm.platform.usermanager.UserManagerImpl.createUser(UserManagerImpl.java:862)
      at org.nuxeo.directory.test.TestDirectorySecurityDefault.adminCanCreateEntry(TestDirectorySecurityDefault.java:90)
      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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.nuxeo.runtime.test.runner.FeaturesRunner$BeforeMethodRunStatement.evaluate(FeaturesRunner.java:285)

      This is how we expressed the relations:

      <xs:element name="whateverProperty">
          <xs:simpleType>
            <xs:list>
              <xs:simpleType>
                <xs:restriction base="xs:string" ref:resolver="documentResolver" ref:store="id"/>
              </xs:simpleType>
            </xs:list>
          </xs:simpleType>
        </xs:element>
      

      This is the inserseReference setting in the user directory:

              <inverseReference field="whateverProperty"
                                directory="testIdDirectory"
                                dualReferenceField="whateverPropertyMembers"/>
      

      This is the directory we reference:

       <directory name="testIdDirectory" extends="template-directory">
            <schema>intIdSchema</schema>
            <idField>id</idField>
            <autoincrementIdField>false</autoincrementIdField>
            <createTablePolicy>always</createTablePolicy>
            <references>
              <reference field="whateverPropertyMembers"
                         directory="userDirectory"
                         name="user2whateverProperty"
                         source="whateverPropertyId"
                         target="userId"/>
            </references>
          </directory>
      

      I fixed it by patching the class BaseSession (nuxeo-platform-directory-api): String[] -> List<String>.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 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 - 3 hours
                3h

                  PagerDuty

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