From b3b9c36a08b01bb01bdadba05a89d42297cdb256 Mon Sep 17 00:00:00 2001 From: Neil McErlean Date: Tue, 28 Jun 2011 15:50:29 +0000 Subject: [PATCH] ALF-8969 Deleting some duplicate classes from Blog CannedQueries. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28674 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- ...ndPublishedBlogPostsCannedQueryParams.java | 76 ------- ...raftsAndPublishedBlogPostsCannedQuery.java | 174 --------------- ...dPublishedBlogPostsCannedQueryFactory.java | 158 -------------- .../repo/blog/GetBlogPostsCannedQuery.java | 184 ---------------- .../blog/GetBlogPostsCannedQueryFactory.java | 206 ------------------ .../blog/GetBlogPostsCannedQueryParams.java | 94 -------- .../repo/blog/PropertyBasedComparator.java | 71 ------ 7 files changed, 963 deletions(-) delete mode 100644 source/java/org/alfresco/repo/blog/DraftAndPublishedBlogPostsCannedQueryParams.java delete mode 100644 source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQuery.java delete mode 100644 source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQueryFactory.java delete mode 100644 source/java/org/alfresco/repo/blog/GetBlogPostsCannedQuery.java delete mode 100644 source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryFactory.java delete mode 100644 source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryParams.java delete mode 100644 source/java/org/alfresco/repo/blog/PropertyBasedComparator.java diff --git a/source/java/org/alfresco/repo/blog/DraftAndPublishedBlogPostsCannedQueryParams.java b/source/java/org/alfresco/repo/blog/DraftAndPublishedBlogPostsCannedQueryParams.java deleted file mode 100644 index 10e2d4bc39..0000000000 --- a/source/java/org/alfresco/repo/blog/DraftAndPublishedBlogPostsCannedQueryParams.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.blog; - -import java.util.Date; - -import org.alfresco.service.cmr.repository.NodeRef; - -/** - * Parameters for {@link DraftsAndPublishedBlogPostsCannedQuery}. - * - * @author Neil Mc Erlean - * @since 4.0 - */ -public class DraftAndPublishedBlogPostsCannedQueryParams -{ - private final NodeRef blogContainerNode; - private final String cmCreator; - private final Date createdFromDate; - private final Date createdToDate; - private final String tag; - - public DraftAndPublishedBlogPostsCannedQueryParams(NodeRef blogContainerNodeRef, - String cmCreator, - Date createdFromDate, - Date createdToDate, - String tag) - { - this.blogContainerNode = blogContainerNodeRef; - this.cmCreator = cmCreator; - this.createdFromDate = createdFromDate; - this.createdToDate = createdToDate; - this.tag = tag; - } - - public NodeRef getBlogContainerNode() - { - return blogContainerNode; - } - - public String getCmCreator() - { - return cmCreator; - } - - public Date getCreatedFromDate() - { - return createdFromDate; - } - - public Date getCreatedToDate() - { - return createdToDate; - } - - public String getTag() - { - return tag; - } -} diff --git a/source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQuery.java b/source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQuery.java deleted file mode 100644 index 6272c7e64e..0000000000 --- a/source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQuery.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.blog; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.alfresco.model.ContentModel; -import org.alfresco.query.CannedQuery; -import org.alfresco.query.CannedQueryParameters; -import org.alfresco.query.CannedQuerySortDetails.SortOrder; -import org.alfresco.repo.blog.BlogService.BlogPostInfo; -import org.alfresco.repo.security.permissions.impl.acegi.AbstractCannedQueryPermissions; -import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.tagging.TaggingService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.Pair; - -/** - * This is a {@link CannedQuery} for the rather particular 'get my drafts and all published' blog-post query. - * - * @author Neil Mc Erlean - * @since 4.0 - * - * @see BlogService#getMyDraftsAndAllPublished(NodeRef, Date, Date, String, org.alfresco.query.PagingRequest) - */ -public class DraftsAndPublishedBlogPostsCannedQuery extends AbstractCannedQueryPermissions -{ - private final NodeService rawNodeService; - private final TaggingService taggingService; - - public DraftsAndPublishedBlogPostsCannedQuery( - NodeService rawNodeService, - TaggingService taggingService, - MethodSecurityInterceptor methodSecurityInterceptor, - Object methodService, - String methodName, - CannedQueryParameters params, - String queryExecutionId) - { - super(params, queryExecutionId, methodSecurityInterceptor, methodService, methodName); - this.rawNodeService = rawNodeService; - this.taggingService = taggingService; - } - - @Override - protected List queryAndFilter(CannedQueryParameters parameters) - { - Object paramBeanObj = parameters.getParameterBean(); - if (paramBeanObj == null) - throw new NullPointerException("Null GetBlogPosts query params"); - - DraftAndPublishedBlogPostsCannedQueryParams paramBean = (DraftAndPublishedBlogPostsCannedQueryParams) paramBeanObj; - - String requestedTag = paramBean.getTag(); - Date createdFromDate = paramBean.getCreatedFromDate(); - Date createdToDate = paramBean.getCreatedToDate(); - - List childAssocs = getAllBlogNodes(paramBean.getBlogContainerNode()); - - List filteredNodeRefs = new ArrayList(); - for (ChildAssociationRef chAssRef : childAssocs) - { - NodeRef nextBlogNode = chAssRef.getChildRef(); - - // Is this next node in the list to be included in the results? - boolean nextNodeIsAcceptable = true; - - // Return all published Blog Posts - if (rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_PUBLISHED) != null) - { - // Intentionally empty - } - else - { - // We're relying on cm:published being null below i.e. we are dealing with draft blog posts. - if (!rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_CREATOR).equals(paramBean.getCmCreator())) - { - nextNodeIsAcceptable = false; - } - } - - // Only return blogs created within the specified dates - Date actualCreatedDate = (Date) rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_CREATED); - if (actualCreatedDate != null) - { - if (createdFromDate != null && actualCreatedDate.before(createdFromDate)) - { - nextNodeIsAcceptable = false; - } - if (createdToDate != null && actualCreatedDate.after(createdToDate)) - { - nextNodeIsAcceptable = false; - } - } - - // Only return blog posts tagged with the specified tag string. - if (requestedTag != null && !taggingService.getTags(nextBlogNode).contains(requestedTag)) - { - nextNodeIsAcceptable = false; - } - - - if (nextNodeIsAcceptable) - { - filteredNodeRefs.add(new BlogPostInfo(nextBlogNode, (String)rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_NAME))); - } - } - - List> sortPairs = parameters.getSortDetails().getSortPairs(); - // For now, the BlogService only sorts by a single property. - if (sortPairs != null && !sortPairs.isEmpty()) - { - Pair sortPair = sortPairs.get(0); - - QName sortProperty = (QName) sortPair.getFirst(); - final PropertyBasedComparator createdDateComparator = new PropertyBasedComparator(sortProperty, rawNodeService); - - if (sortPair.getSecond() == SortOrder.DESCENDING) - { - Collections.sort(filteredNodeRefs, Collections.reverseOrder(createdDateComparator)); - } - } - - - return filteredNodeRefs; - } - - private List getAllBlogNodes(NodeRef containerNode) - { - final Set childNodeTypes = new HashSet(); - childNodeTypes.add(ContentModel.TYPE_CONTENT); - - // This will, of course, retrieve all the blog posts which may be a very long list. - List childAssocs = rawNodeService.getChildAssocs(containerNode, childNodeTypes); - return childAssocs; - } - - @Override - protected boolean isApplyPostQuerySorting() - { - // No post-query sorting. It's done within the queryAndFilter() method above. - return false; - } - - @Override - protected boolean isApplyPostQueryPermissions() - { - return true; - } -} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQueryFactory.java b/source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQueryFactory.java deleted file mode 100644 index d3fb11ff66..0000000000 --- a/source/java/org/alfresco/repo/blog/DraftsAndPublishedBlogPostsCannedQueryFactory.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.blog; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.alfresco.model.ContentModel; -import org.alfresco.query.AbstractCannedQueryFactory; -import org.alfresco.query.CannedQuery; -import org.alfresco.query.CannedQueryFactory; -import org.alfresco.query.CannedQueryPageDetails; -import org.alfresco.query.CannedQueryParameters; -import org.alfresco.query.CannedQuerySortDetails; -import org.alfresco.query.PagingRequest; -import org.alfresco.query.CannedQuerySortDetails.SortOrder; -import org.alfresco.repo.blog.BlogService.BlogPostInfo; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.tagging.TaggingService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.Pair; -import org.alfresco.util.ParameterCheck; -import org.alfresco.util.PropertyCheck; - -/** - * A {@link CannedQueryFactory} for the creation of {@link DraftsAndPublishedBlogPostsCannedQuery}s. - * - * Currently, this is implemented using calls to lower-level services, notably the {@link NodeService} rather - * than database queries. This may change in the future. - * - * @since 4.0 - * @author Neil Mc Erlean. - */ -public class DraftsAndPublishedBlogPostsCannedQueryFactory extends AbstractCannedQueryFactory -{ - private MethodSecurityInterceptor methodSecurityInterceptor; - private String methodName; - private Object methodService; - private NodeService rawNodeService; - private TaggingService taggingService; - - public void setRawNodeService(NodeService nodeService) - { - this.rawNodeService = nodeService; - } - - public void setTaggingService(TaggingService taggingService) - { - this.taggingService = taggingService; - } - - public void setMethodSecurityInterceptor(MethodSecurityInterceptor methodSecurityInterceptor) - { - this.methodSecurityInterceptor = methodSecurityInterceptor; - } - - public void setMethodName(String methodName) - { - this.methodName = methodName; - } - - public void setMethodService(Object methodService) - { - this.methodService = methodService; - } - - @Override - public CannedQuery getCannedQuery(CannedQueryParameters parameters) - { - // if not passed in (TODO or not in future cache) then generate a new query execution id - String queryExecutionId = (parameters.getQueryExecutionId() == null ? super.getQueryExecutionId(parameters) : parameters.getQueryExecutionId()); - - final DraftsAndPublishedBlogPostsCannedQuery cq = new DraftsAndPublishedBlogPostsCannedQuery(rawNodeService, taggingService, - methodSecurityInterceptor, methodService, methodName, - parameters, queryExecutionId); - return (CannedQuery) cq; - } - - public CannedQuery getCannedQuery(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, String tag, PagingRequest pagingReq) - { - ParameterCheck.mandatory("blogContainerNode", blogContainerNode); - ParameterCheck.mandatory("pagingReq", pagingReq); - - int requestTotalCountMax = pagingReq.getRequestTotalCountMax(); - - //FIXME Need tenant service like for GetChildren? - DraftAndPublishedBlogPostsCannedQueryParams paramBean = new DraftAndPublishedBlogPostsCannedQueryParams(blogContainerNode, - byUser, - fromDate, toDate, tag); - - CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq); - CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING); - - // create query params holder - CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, AuthenticationUtil.getRunAsUser(), requestTotalCountMax, pagingReq.getQueryExecutionId()); - - // return canned query instance - return getCannedQuery(params); -} - - private CannedQuerySortDetails createCQSortDetails(QName sortProp, SortOrder sortOrder) - { - CannedQuerySortDetails cqsd = null; - List> sortPairs = new ArrayList>(); - sortPairs.add(new Pair(sortProp, sortOrder)); - cqsd = new CannedQuerySortDetails(sortPairs); - return cqsd; - } - - private CannedQueryPageDetails createCQPageDetails(PagingRequest pagingReq) - { - int skipCount = pagingReq.getSkipCount(); - if (skipCount == -1) - { - skipCount = CannedQueryPageDetails.DEFAULT_SKIP_RESULTS; - } - - int maxItems = pagingReq.getMaxItems(); - if (maxItems == -1) - { - maxItems = CannedQueryPageDetails.DEFAULT_PAGE_SIZE; - } - - // page details - CannedQueryPageDetails cqpd = new CannedQueryPageDetails(skipCount, maxItems, CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT); - return cqpd; - } - - @Override - public void afterPropertiesSet() throws Exception - { - super.afterPropertiesSet(); - - PropertyCheck.mandatory(this, "methodSecurityInterceptor", methodSecurityInterceptor); - PropertyCheck.mandatory(this, "methodService", methodService); - PropertyCheck.mandatory(this, "methodName", methodName); - } -} diff --git a/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQuery.java b/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQuery.java deleted file mode 100644 index f6881d7a63..0000000000 --- a/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQuery.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.blog; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.alfresco.model.ContentModel; -import org.alfresco.query.CannedQuery; -import org.alfresco.query.CannedQueryParameters; -import org.alfresco.query.CannedQuerySortDetails.SortOrder; -import org.alfresco.repo.blog.BlogService.BlogPostInfo; -import org.alfresco.repo.security.permissions.impl.acegi.AbstractCannedQueryPermissions; -import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.Pair; - -/** - * This class provides support for several {@link CannedQuery canned queries} used by the - * {@link BlogService}. - * - * @author Neil Mc Erlean - * @since 4.0 - */ -public class GetBlogPostsCannedQuery extends AbstractCannedQueryPermissions -{ - /* - * This must be the small n nodeService, not the big N NodeService. See below. - */ - private final NodeService rawNodeService; - - public GetBlogPostsCannedQuery( - NodeService rawNodeService, - MethodSecurityInterceptor methodSecurityInterceptor, - Object methodService, - String methodName, - CannedQueryParameters params, - String queryExecutionId) - { - super(params, queryExecutionId, methodSecurityInterceptor, methodService, methodName); - this.rawNodeService = rawNodeService; - } - - @Override - protected List queryAndFilter(CannedQueryParameters parameters) - { - Object paramBeanObj = parameters.getParameterBean(); - if (paramBeanObj == null) - throw new NullPointerException("Null GetBlogPosts query params"); - - GetBlogPostsCannedQueryParams paramBean = (GetBlogPostsCannedQueryParams) paramBeanObj; - String requestedCreator = paramBean.getCmCreator(); - boolean isPublished = paramBean.getIsPublished(); - Date publishedFromDate = paramBean.getPublishedFromDate(); - Date publishedToDate = paramBean.getPublishedToDate(); - List requiredAspects = paramBean.getRequiredAspects(); - - // Retrieve all blog-post nodes under the blogContainer root. This could potentially - // be a long list of NodeRefs and it is possible that future optimisation towards DB queries - // would avoid the retrieval of potentially long lists like this. - // It is however important to retrieve the full list of relevant nodes before any sorting - // is applied. Otherwise it would be possible to have nodes that were not retrieved, which after sorting - // could be at the front of this list. - // For that reason, we must use the small n nodeService, and not the large N NodeService, because the - // latter truncates results. - List childAssocs = getAllBlogNodes(paramBean.getBlogContainerNode()); - - List filteredNodeRefs = new ArrayList(); - for (ChildAssociationRef chAssRef : childAssocs) - { - // Is the nextBlogPostNode going to be included or not? - boolean nextNodeIsAcceptable = true; - - NodeRef nextBlogNode = chAssRef.getChildRef(); - - // Only return blog-posts whose cm:published status matches that requested. - final boolean nextBlogNodeIsPublished = rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_PUBLISHED) != null; - if (nextBlogNodeIsPublished != isPublished) - { - nextNodeIsAcceptable = false; - } - - // Only return blog posts whose creator matches the given username, if there is one. - if (requestedCreator != null && !rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_CREATOR).equals(requestedCreator)) - { - nextNodeIsAcceptable = false; - } - - // Only return blogs published within the specified dates - Date actualPublishedDate = (Date) rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_PUBLISHED); - if (actualPublishedDate != null) - { - if (publishedFromDate != null && actualPublishedDate.before(publishedFromDate)) - { - nextNodeIsAcceptable = false; - } - if (publishedToDate != null && actualPublishedDate.after(publishedToDate)) - { - nextNodeIsAcceptable = false; - } - } - - // Only those with the required aspects. - for (QName aspect : requiredAspects) - { - if (!rawNodeService.hasAspect(nextBlogNode, aspect)) - { - nextNodeIsAcceptable = false; - } - } - - // If all the above conditions are true... - if (nextNodeIsAcceptable) - { - filteredNodeRefs.add(new BlogPostInfo(nextBlogNode, (String)rawNodeService.getProperty(nextBlogNode, ContentModel.PROP_NAME))); - } - } - - List> sortPairs = parameters.getSortDetails().getSortPairs(); - - // For now, the BlogService only sorts by a single property. - if (sortPairs != null && !sortPairs.isEmpty()) - { - Pair sortPair = sortPairs.get(0); - - QName sortProperty = (QName) sortPair.getFirst(); - final PropertyBasedComparator createdDateComparator = new PropertyBasedComparator(sortProperty, rawNodeService); - - if (sortPair.getSecond() == SortOrder.DESCENDING) - { - Collections.sort(filteredNodeRefs, Collections.reverseOrder(createdDateComparator)); - } - } - - return filteredNodeRefs; - } - - private List getAllBlogNodes(NodeRef containerNode) - { - final Set childNodeTypes = new HashSet(); - childNodeTypes.add(ContentModel.TYPE_CONTENT); - - // This will, of course, retrieve all the blog posts which may be a very long list. - List childAssocs = rawNodeService.getChildAssocs(containerNode, childNodeTypes); - return childAssocs; - } - - - @Override - protected boolean isApplyPostQuerySorting() - { - // No post-query sorting. It's done within the queryAndFilter() method above. - return false; - } - - @Override - protected boolean isApplyPostQueryPermissions() - { - return true; - } -} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryFactory.java b/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryFactory.java deleted file mode 100644 index f557f0963c..0000000000 --- a/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryFactory.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.blog; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import org.alfresco.model.BlogIntegrationModel; -import org.alfresco.model.ContentModel; -import org.alfresco.query.AbstractCannedQueryFactory; -import org.alfresco.query.CannedQuery; -import org.alfresco.query.CannedQueryFactory; -import org.alfresco.query.CannedQueryPageDetails; -import org.alfresco.query.CannedQueryParameters; -import org.alfresco.query.CannedQuerySortDetails; -import org.alfresco.query.PagingRequest; -import org.alfresco.query.CannedQuerySortDetails.SortOrder; -import org.alfresco.repo.blog.BlogService.BlogPostInfo; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.Pair; -import org.alfresco.util.ParameterCheck; -import org.alfresco.util.PropertyCheck; - -/** - * A {@link CannedQueryFactory} for various queries relating to {@link BlogPostInfo blog-posts}. - * Currently, this is implemented using calls to lower-level services, notably the {@link NodeService} rather - * than database queries. This may change in the future. - * - * @author Neil Mc Erlean. - * @since 4.0 - * - * @see BlogService#getDrafts(NodeRef, String, PagingRequest) - * @see BlogService#getPublished(NodeRef, Date, Date, String, PagingRequest) - */ -public class GetBlogPostsCannedQueryFactory extends AbstractCannedQueryFactory -{ - private MethodSecurityInterceptor methodSecurityInterceptor; - private String methodName; - private Object methodService; - private NodeService rawNodeService; - - public void setRawNodeService(NodeService nodeService) - { - this.rawNodeService = nodeService; - } - - public void setMethodSecurityInterceptor(MethodSecurityInterceptor methodSecurityInterceptor) - { - this.methodSecurityInterceptor = methodSecurityInterceptor; - } - - public void setMethodName(String methodName) - { - this.methodName = methodName; - } - - public void setMethodService(Object methodService) - { - this.methodService = methodService; - } - - @Override - public CannedQuery getCannedQuery(CannedQueryParameters parameters) - { - String queryExecutionId = (parameters.getQueryExecutionId() == null ? super.getQueryExecutionId(parameters) : parameters.getQueryExecutionId()); - - final GetBlogPostsCannedQuery cq = new GetBlogPostsCannedQuery(rawNodeService, methodSecurityInterceptor, methodService, methodName, parameters, queryExecutionId); - return (CannedQuery) cq; - } - - public CannedQuery getGetDraftsCannedQuery(NodeRef blogContainerNode, String username, PagingRequest pagingReq) - { - ParameterCheck.mandatory("blogContainerNode", blogContainerNode); - ParameterCheck.mandatory("pagingReq", pagingReq); - - int requestTotalCountMax = pagingReq.getRequestTotalCountMax(); - - //FIXME Need tenant service like for GetChildren? - boolean isPublished = false; - List requiredAspects = null; - GetBlogPostsCannedQueryParams paramBean = new GetBlogPostsCannedQueryParams(blogContainerNode, - username, - isPublished, - null, null, - requiredAspects); - - CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq); - CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_CREATED, SortOrder.DESCENDING); - - // create query params holder - CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, AuthenticationUtil.getRunAsUser(), requestTotalCountMax, pagingReq.getQueryExecutionId()); - - // return canned query instance - return getCannedQuery(params); - } - - public CannedQuery getGetPublishedExternallyCannedQuery(NodeRef blogContainerNode, PagingRequest pagingReq) - { - ParameterCheck.mandatory("blogContainerNode", blogContainerNode); - ParameterCheck.mandatory("pagingReq", pagingReq); - - int requestTotalCountMax = pagingReq.getRequestTotalCountMax(); - - boolean isPublished = true; - List requiredAspects = Arrays.asList(new QName[]{BlogIntegrationModel.ASPECT_BLOG_POST}); - GetBlogPostsCannedQueryParams paramBean = new GetBlogPostsCannedQueryParams(blogContainerNode, - null, - isPublished, - null, null, - requiredAspects); - - CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq); - CannedQuerySortDetails cqsd = createCQSortDetails(BlogIntegrationModel.PROP_POSTED, SortOrder.DESCENDING); - - // create query params holder - CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, AuthenticationUtil.getRunAsUser(), requestTotalCountMax, pagingReq.getQueryExecutionId()); - - // return canned query instance - return getCannedQuery(params); - } - - public CannedQuery getGetPublishedCannedQuery(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, PagingRequest pagingReq) - { - ParameterCheck.mandatory("blogContainerNode", blogContainerNode); - ParameterCheck.mandatory("pagingReq", pagingReq); - - int requestTotalCountMax = pagingReq.getRequestTotalCountMax(); - - boolean isPublished = true; - List requiredAspects = null; - GetBlogPostsCannedQueryParams paramBean = new GetBlogPostsCannedQueryParams(blogContainerNode, - byUser, - isPublished, - fromDate, toDate, - requiredAspects); - - CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq); - CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING); - - // create query params holder - CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, AuthenticationUtil.getRunAsUser(), requestTotalCountMax, pagingReq.getQueryExecutionId()); - - // return canned query instance - return getCannedQuery(params); - } - - private CannedQuerySortDetails createCQSortDetails(QName sortProp, SortOrder sortOrder) - { - CannedQuerySortDetails cqsd = null; - List> sortPairs = new ArrayList>(); - sortPairs.add(new Pair(sortProp, sortOrder)); - cqsd = new CannedQuerySortDetails(sortPairs); - return cqsd; - } - - private CannedQueryPageDetails createCQPageDetails(PagingRequest pagingReq) - { - int skipCount = pagingReq.getSkipCount(); - if (skipCount == -1) - { - skipCount = CannedQueryPageDetails.DEFAULT_SKIP_RESULTS; - } - - int maxItems = pagingReq.getMaxItems(); - if (maxItems == -1) - { - maxItems = CannedQueryPageDetails.DEFAULT_PAGE_SIZE; - } - - // page details - CannedQueryPageDetails cqpd = new CannedQueryPageDetails(skipCount, maxItems, CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT); - return cqpd; - } - - @Override - public void afterPropertiesSet() throws Exception - { - super.afterPropertiesSet(); - - PropertyCheck.mandatory(this, "methodSecurityInterceptor", methodSecurityInterceptor); - PropertyCheck.mandatory(this, "methodService", methodService); - PropertyCheck.mandatory(this, "methodName", methodName); - } -} diff --git a/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryParams.java b/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryParams.java deleted file mode 100644 index 9f2edcfcea..0000000000 --- a/source/java/org/alfresco/repo/blog/GetBlogPostsCannedQueryParams.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.blog; - -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.QName; - -/** - * Parameter objects for {@link GetBlogPostsCannedQuery}. - * - * @author Neil Mc Erlean - * @since 4.0 - */ -public class GetBlogPostsCannedQueryParams -{ - private final NodeRef blogContainerNode; - private final String cmCreator; - /** - * true means the blog-posts should be cm:published, false means they should not. - */ - private final boolean isPublished; - private final Date publishedFromDate; - private final Date publishedToDate; - private final List requiredAspects; - - public GetBlogPostsCannedQueryParams(NodeRef blogContainerNodeRef, - String cmCreator, - boolean isPublished, - Date publishedFromDate, - Date publishedToDate, - List requiredAspects) - { - this.blogContainerNode = blogContainerNodeRef; - this.cmCreator = cmCreator; - this.isPublished = isPublished; - this.publishedFromDate = publishedFromDate; - this.publishedToDate = publishedToDate; - if (requiredAspects == null) - { - requiredAspects = Collections.emptyList(); - } - this.requiredAspects = requiredAspects; - } - - public NodeRef getBlogContainerNode() - { - return blogContainerNode; - } - - public String getCmCreator() - { - return cmCreator; - } - - public boolean getIsPublished() - { - return this.isPublished; - } - - public Date getPublishedFromDate() - { - return publishedFromDate; - } - - public Date getPublishedToDate() - { - return publishedToDate; - } - - public List getRequiredAspects() - { - return Collections.unmodifiableList(this.requiredAspects); - } -} diff --git a/source/java/org/alfresco/repo/blog/PropertyBasedComparator.java b/source/java/org/alfresco/repo/blog/PropertyBasedComparator.java deleted file mode 100644 index c9ec9b9f80..0000000000 --- a/source/java/org/alfresco/repo/blog/PropertyBasedComparator.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.blog; - -import java.util.Comparator; - -import org.alfresco.repo.blog.BlogService.BlogPostInfo; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.namespace.QName; - -/** - * Utility class to sort {@link BlogPostInfo}s on the basis of a Comparable property. - * Comparisons of two null properties are considered 'equal' by this comparator. - * Comparisons involving one null and one non-null property will return the null property as - * being 'before' the non-null property. - * - * Note that it is the responsibility of the calling code to ensure that the specified - * property values actually implement Comparable themselves. - */ -class PropertyBasedComparator implements Comparator -{ - private QName comparableProperty; - private NodeService nodeService; - - public PropertyBasedComparator(QName comparableProperty, NodeService nodeService) - { - this.comparableProperty = comparableProperty; - this.nodeService = nodeService; - } - - @SuppressWarnings("unchecked") - @Override - public int compare(BlogPostInfo nr1, BlogPostInfo nr2) - { - Comparable prop1 = (Comparable) nodeService.getProperty(nr1.getNodeRef(), comparableProperty); - Comparable prop2 = (Comparable) nodeService.getProperty(nr2.getNodeRef(), comparableProperty); - - if (prop1 == null && prop2 == null) - { - return 0; - } - else if (prop1 == null && prop2 != null) - { - return -1; - } - else if (prop1 != null && prop2 == null) - { - return 1; - } - else - { - return prop1.compareTo(prop2); - } - } -} \ No newline at end of file