Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-12432

DocumentReference/SpaceReference.compareTo() don't work with Nested Spaces

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 7.2-milestone-2
    • Fix Version/s: 7.3-milestone-1
    • Component/s: Model
    • Labels:
    • Tests:
      Unit
    • Difficulty:
      Unknown
    • Documentation:
      N/A
    • Documentation in Release Notes:
      N/A
    • Similar issues:

      Description

      Before Nested Spaces, we had a constant hierarchy level in Document or Space References: wiki, space and page.

      With Nested Spaces, this hierarchy is variable and the default implementation of the compare method performed in EntityReference.compare is no longer appropriate, since that generic implementation works by comparing depth and only for references of equal depth and of the same type is the name compared.

      A problematic example is:
      ["A.B", "X.Y", "A.B.C"] is considered sorted (using only length) instead of the expected result:
      ["A.B", "A.B.C", "X.Y"]

      The problem is even more evident when it comes to wikis:
      ["a:A.B", "b:X.Y", "a:A.D", "b:A.B.B", "a:A.B.C"] is considered sorted instead of the expected:
      ["a:A.B", "a:A.B.C", "a:A.D", "b:A.B.B", "b:X.Y"]

      The conclusion is that we need specific implementations for DocumentReference and SpaceReference that understand what it is they are sorting. Some improvements to the generic EntityReference implementation could be done, for example when comparing a SpaceReference to a DocumentReference, since it is not very useful to compare them only by length.

      Workaround: Until this is properly implemented, if you know you are sorting a list/array of DocumentReferences only or of SpaceReferences only, then you can have a custom comparator that compares the serialized string references to produce the expected result.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                enygma Eduard Moraru
                Reporter:
                enygma Eduard Moraru
              • Votes:
                0 Vote for this issue
                Watchers:
                1 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 - 1 hour
                  1h