From 6901888160ab1dec7ddb10cc38d83f272ad47511 Mon Sep 17 00:00:00 2001 From: Will Abson Date: Wed, 25 Jun 2014 15:32:15 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud) 71614: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 71278: Merged V4.1-BUG-FIX (4.1.9) to V4.2-BUG-FIX (4.2.3) 70686: Merged DEV to V4.1-BUG-FIX (4.1.9) 70361: MNT-11120: FileFolderService.list does not order properly - Check next sort properties if current are null for both nodes. - Add unit test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74703 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../getchildren/GetChildrenCannedQuery.java | 9 +- .../filefolder/FileFolderServiceImplTest.java | 100 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java b/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java index 7ab70540f1..f5a68c83d1 100644 --- a/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java +++ b/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java @@ -405,7 +405,14 @@ public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions 1) + { + return compareImpl(node1In, node2In, sortProps.subList(1, sortProps.size())); + } + else + { + return (pv2 == null ? 0 : -1); + } } else if (pv2 == null) { diff --git a/source/test-java/org/alfresco/repo/model/filefolder/FileFolderServiceImplTest.java b/source/test-java/org/alfresco/repo/model/filefolder/FileFolderServiceImplTest.java index f025cc9840..16a8a224d8 100644 --- a/source/test-java/org/alfresco/repo/model/filefolder/FileFolderServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/model/filefolder/FileFolderServiceImplTest.java @@ -24,10 +24,12 @@ import java.io.OutputStream; import java.io.Reader; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.Map.Entry; import javax.transaction.Status; import javax.transaction.UserTransaction; @@ -1635,4 +1637,102 @@ public class FileFolderServiceImplTest extends TestCase assertFalse(copyInfo.getName().contains("(Working Copy)")); assertTrue(copyInfo.getName().substring(0, copyExtIndex).startsWith(checkedOutName.substring(0, origExtIndex))); } + + public void testSortingCustomFields() + { + // Test sorting based on MNT-11120 + QName customPropA = QName.createQName(ContentModel.USER_MODEL_URI, "a"); + QName customPropB = QName.createQName(ContentModel.USER_MODEL_URI, "b"); + + HashMap> customProps = new HashMap>(); + customProps.put("A-foo", new Pair(customPropA, "foo")); + customProps.put("A-bar", new Pair(customPropA, "bar")); + customProps.put("A-null", new Pair(customPropA, null)); + customProps.put("B-biz", new Pair(customPropB, "biz")); + customProps.put("B-baz", new Pair(customPropB, "baz")); + customProps.put("B-null", new Pair(customPropB, null)); + + NodeRef nodeRef = fileFolderService.create(workingRootNodeRef, "" + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef(); + NodeRef parentTestRef = fileFolderService.create(nodeRef, "parent", ContentModel.TYPE_CONTENT).getNodeRef(); + for (Entry> entry : customProps.entrySet()) + { + NodeRef child = fileFolderService.create(parentTestRef, entry.getKey(), ContentModel.TYPE_CONTENT).getNodeRef(); + nodeService.setProperty(child, entry.getValue().getFirst(), entry.getValue().getSecond()); + } + + List> sortProps = new ArrayList>(); + + PagingRequest pagingRequest = new PagingRequest(100, null); + + // {("user:a", true),("user:b", true")} + sortProps.clear(); + sortProps.add(new Pair(customPropA, true)); + sortProps.add(new Pair(customPropB, true)); + PagingResults results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + List pageRes = results.getPage(); + String[] expectedNames = new String[] { "A-null", "B-null", "B-baz", "B-biz", "A-bar", "A-foo" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // {("user:a", false),("user:b", true")} + sortProps.clear(); + sortProps.add(new Pair(customPropA, false)); + sortProps.add(new Pair(customPropB, true)); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "A-foo", "A-bar", "A-null", "B-null", "B-baz", "B-biz" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // {(\"user:a", true),("user:b", false")} + sortProps.clear(); + sortProps.add(new Pair(customPropA, true)); + sortProps.add(new Pair(customPropB, false)); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "B-biz", "B-baz", "A-null", "B-null", "A-bar", "A-foo" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // {(\"user:a", false),("user:b", false")} + sortProps.clear(); + sortProps.add(new Pair(customPropA, false)); + sortProps.add(new Pair(customPropB, false)); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "A-foo", "A-bar", "B-biz", "B-baz", "A-null", "B-null" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // {(\"user:b", true),("user:a", true")} + sortProps.clear(); + sortProps.add(new Pair(customPropB, true)); + sortProps.add(new Pair(customPropA, true)); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "A-null", "B-null", "A-bar", "A-foo", "B-baz", "B-biz" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // {("user:b", false),("user:a", true")} + sortProps.clear(); + sortProps.add(new Pair(customPropB, false)); + sortProps.add(new Pair(customPropA, true)); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "B-biz", "B-baz", "A-null", "B-null", "A-bar", "A-foo" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // {("user:b", true),("user:a", false")} + sortProps.clear(); + sortProps.add(new Pair(customPropB, true)); + sortProps.add(new Pair(customPropA, false)); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "A-foo", "A-bar", "A-null", "B-null", "B-baz", "B-biz" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // {("user:b", false),("user:a", false")} + sortProps.clear(); + sortProps.add(new Pair(customPropB, false)); + sortProps.add(new Pair(customPropA, false)); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "B-biz", "B-baz", "A-foo", "A-bar", "A-null", "B-null" }; + checkFileList(pageRes, 6, 0, expectedNames); + + // no sort + sortProps.clear(); + results = fileFolderService.list(parentTestRef, true, false, null, sortProps, pagingRequest); + expectedNames = new String[] { "B-null", "A-foo", "A-bar", "B-baz", "A-null", "B-biz" }; + checkFileList(pageRes, 6, 0, expectedNames); + } }