mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9367. Added new/improved Unit Tests in area of tagged blogposts and sorted result sets.
Also fixed a bug-ette whereby for 'get all' blogposts, the drafts at the end where sorted the wrong way. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29071 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -85,10 +85,15 @@ public abstract class AbstractBlogPostsCannedQueryFactory extends AbstractCanned
|
||||
|
||||
protected CannedQuerySortDetails createCQSortDetails(QName sortProp, SortOrder sortOrder)
|
||||
{
|
||||
CannedQuerySortDetails cqsd = null;
|
||||
List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>();
|
||||
sortPairs.add(new Pair<QName, SortOrder>(sortProp, sortOrder));
|
||||
cqsd = new CannedQuerySortDetails(sortPairs);
|
||||
List<Pair<? extends Object, SortOrder>> singlePair = new ArrayList<Pair<? extends Object, SortOrder>>(1);
|
||||
singlePair.add(new Pair<QName, SortOrder>(sortProp, sortOrder));
|
||||
|
||||
return this.createCQSortDetails(singlePair);
|
||||
}
|
||||
|
||||
protected CannedQuerySortDetails createCQSortDetails(List<Pair<? extends Object, SortOrder>> sortPairs)
|
||||
{
|
||||
CannedQuerySortDetails cqsd = new CannedQuerySortDetails(sortPairs);
|
||||
return cqsd;
|
||||
}
|
||||
|
||||
|
@@ -137,17 +137,17 @@ public class DraftsAndPublishedBlogPostsCannedQuery extends AbstractCannedQueryP
|
||||
}
|
||||
|
||||
List<Pair<? extends Object, SortOrder>> sortPairs = parameters.getSortDetails().getSortPairs();
|
||||
// For now, the BlogService only sorts by a single property.
|
||||
if (sortPairs != null && !sortPairs.isEmpty())
|
||||
{
|
||||
Pair<? extends Object, SortOrder> sortPair = sortPairs.get(0);
|
||||
|
||||
QName sortProperty = (QName) sortPair.getFirst();
|
||||
final PropertyBasedComparator comparator = new PropertyBasedComparator(sortProperty);
|
||||
|
||||
if (sortPair.getSecond() == SortOrder.DESCENDING)
|
||||
for (Pair<? extends Object, SortOrder> sortPair : sortPairs)
|
||||
{
|
||||
Collections.sort(filtered, Collections.reverseOrder(comparator));
|
||||
QName sortProperty = (QName) sortPair.getFirst();
|
||||
final PropertyBasedComparator comparator = new PropertyBasedComparator(sortProperty);
|
||||
|
||||
if (sortPair.getSecond() == SortOrder.DESCENDING)
|
||||
{
|
||||
Collections.sort(filtered, Collections.reverseOrder(comparator));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,9 @@
|
||||
*/
|
||||
package org.alfresco.repo.blog.cannedqueries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.CannedQuery;
|
||||
@@ -30,6 +32,8 @@ import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
@@ -67,7 +71,15 @@ public class DraftsAndPublishedBlogPostsCannedQueryFactory extends AbstractBlogP
|
||||
fromDate, toDate);
|
||||
|
||||
CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
|
||||
CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING);
|
||||
|
||||
List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(2);
|
||||
|
||||
// Sort by created then published. We want a list of all published (most recently published first),
|
||||
// followed by all unpublished (most recently created first)
|
||||
sortPairs.add(new Pair<QName, SortOrder>(ContentModel.PROP_CREATED, SortOrder.DESCENDING));
|
||||
sortPairs.add(new Pair<QName, SortOrder>(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING));
|
||||
|
||||
CannedQuerySortDetails cqsd = createCQSortDetails(sortPairs);
|
||||
|
||||
// create query params holder
|
||||
CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingReq.getQueryExecutionId());
|
||||
|
Reference in New Issue
Block a user