diff --git a/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java b/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java index e06eef38d9..fe31d14c81 100644 --- a/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java +++ b/source/java/org/alfresco/repo/node/getchildren/GetChildrenCannedQuery.java @@ -414,6 +414,10 @@ public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions(); cannedQueryRegistry.setStorageType(CannedQueryFactory.class); @@ -142,6 +151,11 @@ public class GetChildrenCannedQueryTest extends TestCase getChildrenCannedQueryFactory.afterPropertiesSet(); + fiveStarRatingScheme = ratingService.getRatingScheme("fiveStarRatingScheme"); + assertNotNull(fiveStarRatingScheme); + likesRatingScheme = ratingService.getRatingScheme("likesRatingScheme"); + assertNotNull(likesRatingScheme); + if (! setupTestData) { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); @@ -429,10 +443,63 @@ public class GetChildrenCannedQueryTest extends TestCase } } + private float getFiveStarRating() + { + float rating = random.nextFloat() * (fiveStarRatingScheme.getMaxRating() - fiveStarRatingScheme.getMinRating()) + fiveStarRatingScheme.getMinRating(); + assertTrue("Five star rating is out of range: " + rating, (rating >= fiveStarRatingScheme.getMinRating() && rating <= fiveStarRatingScheme.getMaxRating())); + return rating; + } + public void testPropertySorting() throws Exception { NodeRef parentNodeRef = repositoryHelper.getCompanyHome(); + NodeRef nodeRef1 = null; + NodeRef nodeRef2 = null; + NodeRef nodeRef3 = null; + NodeRef nodeRef4 = null; + NodeRef nodeRef5 = null; + NodeRef nodeRef6 = null; + NodeRef nodeRef7 = null; + NodeRef nodeRef8 = null; + NodeRef nodeRef9 = null; + NodeRef nodeRef10 = null; + // Create some nodes with integer properties on which to sort, in this case cm:fiveStarRatingScheme and cm:likesRatingScheme + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + try + { + nodeRef1 = createContent(parentNodeRef, "rating1", ContentModel.TYPE_CONTENT); + nodeRef2 = createContent(parentNodeRef, "rating2", ContentModel.TYPE_CONTENT); + nodeRef3 = createContent(parentNodeRef, "rating3", ContentModel.TYPE_CONTENT); + nodeRef4 = createContent(parentNodeRef, "rating4", ContentModel.TYPE_CONTENT); + nodeRef5 = createContent(parentNodeRef, "rating5", ContentModel.TYPE_CONTENT); + + nodeRef6 = createContent(parentNodeRef, "rating6", ContentModel.TYPE_CONTENT); + nodeRef7 = createContent(parentNodeRef, "rating7", ContentModel.TYPE_CONTENT); + nodeRef8 = createContent(parentNodeRef, "rating8", ContentModel.TYPE_CONTENT); + nodeRef9 = createContent(parentNodeRef, "rating9", ContentModel.TYPE_CONTENT); + nodeRef10 = createContent(parentNodeRef, "rating10", ContentModel.TYPE_CONTENT); + } + finally + { + AuthenticationUtil.popAuthentication(); + } + + // apply some ratings to these nodes + ratingService.applyRating(nodeRef1, getFiveStarRating(), "fiveStarRatingScheme"); + ratingService.applyRating(nodeRef2, getFiveStarRating(), "fiveStarRatingScheme"); + ratingService.applyRating(nodeRef3, getFiveStarRating(), "fiveStarRatingScheme"); + ratingService.applyRating(nodeRef4, getFiveStarRating(), "fiveStarRatingScheme"); + ratingService.applyRating(nodeRef5, getFiveStarRating(), "fiveStarRatingScheme"); + + ratingService.applyRating(nodeRef6, 1.0f, "likesRatingScheme"); + ratingService.applyRating(nodeRef7, 1.0f, "likesRatingScheme"); + ratingService.applyRating(nodeRef8, 1.0f, "likesRatingScheme"); + ratingService.applyRating(nodeRef9, 1.0f, "likesRatingScheme"); + ratingService.applyRating(nodeRef10, 1.0f, "likesRatingScheme"); + + // do children canned query PagingResults results = list(parentNodeRef, -1, -1, 0); List sortQNames = new ArrayList(3); @@ -449,8 +516,10 @@ public class GetChildrenCannedQueryTest extends TestCase sortQNames.add(GetChildrenCannedQuery.SORT_QNAME_CONTENT_SIZE); sortQNames.add(GetChildrenCannedQuery.SORT_QNAME_CONTENT_MIMETYPE); sortQNames.add(GetChildrenCannedQuery.SORT_QNAME_NODE_TYPE); - - // TODO pending merge to HEAD: sortQNames.add(ContentModel... cm:likesRatingSchemeCount ...); + + // Add in the ratings properties on which to sort + sortQNames.add(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "fiveStarRatingSchemeCount")); + sortQNames.add(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "likesRatingSchemeCount")); // sort with one prop for (QName sortQName : sortQNames) @@ -833,6 +902,10 @@ public class GetChildrenCannedQueryTest extends TestCase { result = ((Long)val).compareTo((Long)prevVal); } + else if (val instanceof Integer) + { + result = ((Integer)val).compareTo((Integer)prevVal); + } else if (val instanceof QName) { result = ((QName)val).compareTo((QName)prevVal);