ALF-9385. Separation of taggingService from Blog CannedQueries.

Initial implementation provides separate 'findTaggedBlogPosts' method and removes taggingService from the CQs.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28816 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2011-07-05 18:00:21 +00:00
parent 38e82ebe68
commit 7901f5ce66
7 changed files with 101 additions and 38 deletions

View File

@@ -81,6 +81,7 @@
<property name="contentService" ref="ContentService"/> <property name="contentService" ref="ContentService"/>
<property name="nodeService" ref="NodeService"/> <property name="nodeService" ref="NodeService"/>
<property name="permissionService" ref="PermissionService"/> <property name="permissionService" ref="PermissionService"/>
<property name="searchService" ref="SearchService"/>
<property name="draftBlogPostsCannedQueryFactory" ref="getDraftBlogPostsCannedQueryFactory"/> <property name="draftBlogPostsCannedQueryFactory" ref="getDraftBlogPostsCannedQueryFactory"/>
<property name="publishedBlogPostsCannedQueryFactory" ref="getPublishedBlogPostsCannedQueryFactory"/> <property name="publishedBlogPostsCannedQueryFactory" ref="getPublishedBlogPostsCannedQueryFactory"/>
@@ -117,7 +118,6 @@
<bean name="getDraftsAndPublishedBlogPostsCannedQueryFactory" parent="parentBlogPostsCannedQueryFactory" <bean name="getDraftsAndPublishedBlogPostsCannedQueryFactory" parent="parentBlogPostsCannedQueryFactory"
class="org.alfresco.repo.blog.cannedqueries.DraftsAndPublishedBlogPostsCannedQueryFactory"> class="org.alfresco.repo.blog.cannedqueries.DraftsAndPublishedBlogPostsCannedQueryFactory">
<property name="methodSecurity" ref="BlogService_security_getMyDraftsAndAllPublished"/> <property name="methodSecurity" ref="BlogService_security_getMyDraftsAndAllPublished"/>
<property name="taggingService" ref="TaggingService"/>
</bean> </bean>
<!-- Blog Integration Service (Integration with external blog hosting sites) --> <!-- Blog Integration Service (Integration with external blog hosting sites) -->

View File

@@ -102,7 +102,6 @@ public interface BlogService
* @param blogContainerNode the container node for blog posts (under the site). * @param blogContainerNode the container node for blog posts (under the site).
* @param fromDate an inclusive date limit for the results (more recent than). * @param fromDate an inclusive date limit for the results (more recent than).
* @param toDate an inclusive date limit for the results (before). * @param toDate an inclusive date limit for the results (before).
* @param tag if specified, only returns posts tagged with this tag.
* @param pagingReq an object defining the paging parameters for the result set. * @param pagingReq an object defining the paging parameters for the result set.
* *
* @return a {@link PagingResults} object containing some or all of the results (subject to paging). * @return a {@link PagingResults} object containing some or all of the results (subject to paging).
@@ -111,8 +110,20 @@ public interface BlogService
* *
* @deprecated This method is a domain-specific query used by the Blog REST API and is not considered suitable for general use. * @deprecated This method is a domain-specific query used by the Blog REST API and is not considered suitable for general use.
*/ */
PagingResults<BlogPostInfo> getMyDraftsAndAllPublished(NodeRef blogContainerNode, Date fromDate, Date toDate, PagingResults<BlogPostInfo> getMyDraftsAndAllPublished(NodeRef blogContainerNode, Date fromDate, Date toDate, PagingRequest pagingReq);
String tag, PagingRequest pagingReq);
/**
* Finds blog posts by the specified user tagged with the given tag string.
*
* @param blogContainerNode the container node for blog posts (under the site).
* @param tag tag string.
* @param pagingReq an object defining the paging parameters for the result set.
*
* @return a {@link PagingResults} object containing some or all of the results (subject to paging).
*
* @see SiteService#getContainer(String, String) to retrieve the blogContainerNode
*/
PagingResults<BlogPostInfo> findTaggedBlogPosts(NodeRef blogContainerNode, String tag, PagingRequest pagingReq);
/** /**
* Returns true if the specified blog-post node is a 'draft' blog post. * Returns true if the specified blog-post node is a 'draft' blog post.

View File

@@ -19,8 +19,10 @@
package org.alfresco.repo.blog; package org.alfresco.repo.blog;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
@@ -39,9 +41,14 @@ import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO9075;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
import org.alfresco.util.registry.NamedObjectRegistry; import org.alfresco.util.registry.NamedObjectRegistry;
@@ -69,6 +76,7 @@ public class BlogServiceImpl implements BlogService
private ContentService contentService; private ContentService contentService;
private NodeService nodeService; private NodeService nodeService;
private PermissionService permissionService; private PermissionService permissionService;
private SearchService searchService;
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory<BlogPostInfo>> cannedQueryRegistry) public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory<BlogPostInfo>> cannedQueryRegistry)
{ {
@@ -110,6 +118,11 @@ public class BlogServiceImpl implements BlogService
this.permissionService = permissionService; this.permissionService = permissionService;
} }
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
@Override @Override
public boolean isDraftBlogPost(NodeRef blogPostNode) public boolean isDraftBlogPost(NodeRef blogPostNode)
{ {
@@ -199,7 +212,7 @@ public class BlogServiceImpl implements BlogService
* @deprecated * @deprecated
*/ */
@Override @Override
public PagingResults<BlogPostInfo> getMyDraftsAndAllPublished(NodeRef blogContainerNode, Date createdFrom, Date createdTo, String tag, PagingRequest pagingReq) public PagingResults<BlogPostInfo> getMyDraftsAndAllPublished(NodeRef blogContainerNode, Date createdFrom, Date createdTo, PagingRequest pagingReq)
{ {
ParameterCheck.mandatory("blogContainerNode", blogContainerNode); ParameterCheck.mandatory("blogContainerNode", blogContainerNode);
ParameterCheck.mandatory("pagingReq", pagingReq); ParameterCheck.mandatory("pagingReq", pagingReq);
@@ -207,7 +220,7 @@ public class BlogServiceImpl implements BlogService
// get canned query // get canned query
pagingReq.setRequestTotalCountMax(MAX_QUERY_ENTRY_COUNT); pagingReq.setRequestTotalCountMax(MAX_QUERY_ENTRY_COUNT);
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser(); String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
DraftsAndPublishedBlogPostsCannedQuery cq = (DraftsAndPublishedBlogPostsCannedQuery)draftsAndPublishedBlogPostsCannedQueryFactory.getCannedQuery(blogContainerNode, createdFrom, createdTo, currentUser, tag, pagingReq); DraftsAndPublishedBlogPostsCannedQuery cq = (DraftsAndPublishedBlogPostsCannedQuery)draftsAndPublishedBlogPostsCannedQueryFactory.getCannedQuery(blogContainerNode, createdFrom, createdTo, currentUser, pagingReq);
// execute canned query // execute canned query
CannedQueryResults<BlogPostInfo> results = cq.execute(); CannedQueryResults<BlogPostInfo> results = cq.execute();
@@ -250,4 +263,70 @@ public class BlogServiceImpl implements BlogService
nodeService.setProperty(blogPostNode, ContentModel.PROP_UPDATED, new Date()); nodeService.setProperty(blogPostNode, ContentModel.PROP_UPDATED, new Date());
} }
} }
@Override
public PagingResults<BlogPostInfo> findTaggedBlogPosts(
NodeRef blogContainerNode, String tag, PagingRequest pagingReq)
{
StringBuilder luceneQuery = new StringBuilder();
luceneQuery.append("+TYPE:\"").append(ContentModel.TYPE_CONTENT).append("\" ")
.append("+PARENT:\"").append(blogContainerNode.toString()).append("\" ")
.append("+PATH:\"/cm:taggable/cm:").append(ISO9075.encode(tag)).append("/member\"");
SearchParameters sp = new SearchParameters();
sp.addStore(blogContainerNode.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(luceneQuery.toString());
sp.addSort(ContentModel.PROP_PUBLISHED.toString(), false);
ResultSet luceneResults = null;
PagingResults<BlogPostInfo> results = null;
try
{
luceneResults = searchService.query(sp);
final ResultSet finalLuceneResults = luceneResults;
results = new PagingResults<BlogPostInfo>()
{
@Override
public List<BlogPostInfo> getPage()
{
List<NodeRef> nodeRefs = finalLuceneResults.getNodeRefs();
List<BlogPostInfo> blogPostInfos = new ArrayList<BlogPostInfo>(nodeRefs.size());
for (NodeRef nodeRef : nodeRefs)
{
blogPostInfos.add(new BlogPostInfo(nodeRef, (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME)));
}
return blogPostInfos;
}
@Override
public String getQueryExecutionId()
{
return null;
}
@Override
public Pair<Integer, Integer> getTotalResultCount()
{
int size = finalLuceneResults.getNodeRefs().size();
//FIXME Impl
return new Pair<Integer, Integer>(size, size);
}
@Override
public boolean hasMoreItems()
{
return finalLuceneResults.hasMore();
}
};
}
finally
{
if (luceneResults != null) luceneResults.close();
}
return results;
}
} }

View File

@@ -56,17 +56,14 @@ public class DraftsAndPublishedBlogPostsCannedQuery extends AbstractCannedQueryP
private static final String QUERY_SELECT_GET_BLOGS = "select_GetBlogsCannedQuery"; private static final String QUERY_SELECT_GET_BLOGS = "select_GetBlogsCannedQuery";
private final CannedQueryDAO cannedQueryDAO; private final CannedQueryDAO cannedQueryDAO;
private final TaggingService taggingService;
public DraftsAndPublishedBlogPostsCannedQuery( public DraftsAndPublishedBlogPostsCannedQuery(
CannedQueryDAO cannedQueryDAO, CannedQueryDAO cannedQueryDAO,
TaggingService taggingService,
MethodSecurityBean<BlogPostInfo> methodSecurity, MethodSecurityBean<BlogPostInfo> methodSecurity,
CannedQueryParameters params) CannedQueryParameters params)
{ {
super(params, methodSecurity); super(params, methodSecurity);
this.cannedQueryDAO = cannedQueryDAO; this.cannedQueryDAO = cannedQueryDAO;
this.taggingService = taggingService;
} }
@Override @Override
@@ -80,7 +77,6 @@ public class DraftsAndPublishedBlogPostsCannedQuery extends AbstractCannedQueryP
DraftsAndPublishedBlogPostsCannedQueryParams paramBean = (DraftsAndPublishedBlogPostsCannedQueryParams) paramBeanObj; DraftsAndPublishedBlogPostsCannedQueryParams paramBean = (DraftsAndPublishedBlogPostsCannedQueryParams) paramBeanObj;
String requestedCreator = paramBean.getCmCreator(); String requestedCreator = paramBean.getCmCreator();
String requestedTag = paramBean.getTag();
Date createdFromDate = paramBean.getCreatedFromDate(); Date createdFromDate = paramBean.getCreatedFromDate();
Date createdToDate = paramBean.getCreatedToDate(); Date createdToDate = paramBean.getCreatedToDate();
@@ -135,13 +131,6 @@ public class DraftsAndPublishedBlogPostsCannedQuery extends AbstractCannedQueryP
} }
} }
// TODO review use-case and either remove or push-down
// Only return blog posts tagged with the specified tag string.
if (requestedTag != null && !taggingService.getTags(result.getNode().getNodeRef()).contains(requestedTag))
{
nextNodeIsAcceptable = false;
}
if (nextNodeIsAcceptable) if (nextNodeIsAcceptable)
{ {
filtered.add(result); filtered.add(result);

View File

@@ -30,7 +30,6 @@ import org.alfresco.query.PagingRequest;
import org.alfresco.query.CannedQuerySortDetails.SortOrder; import org.alfresco.query.CannedQuerySortDetails.SortOrder;
import org.alfresco.repo.blog.BlogService.BlogPostInfo; import org.alfresco.repo.blog.BlogService.BlogPostInfo;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
/** /**
@@ -41,24 +40,17 @@ import org.alfresco.util.ParameterCheck;
*/ */
public class DraftsAndPublishedBlogPostsCannedQueryFactory extends AbstractBlogPostsCannedQueryFactory public class DraftsAndPublishedBlogPostsCannedQueryFactory extends AbstractBlogPostsCannedQueryFactory
{ {
private TaggingService taggingService;
public void setTaggingService(TaggingService taggingService)
{
this.taggingService = taggingService;
}
@Override @Override
public CannedQuery<BlogPostInfo> getCannedQuery(CannedQueryParameters parameters) public CannedQuery<BlogPostInfo> getCannedQuery(CannedQueryParameters parameters)
{ {
final DraftsAndPublishedBlogPostsCannedQuery cq = new DraftsAndPublishedBlogPostsCannedQuery( final DraftsAndPublishedBlogPostsCannedQuery cq = new DraftsAndPublishedBlogPostsCannedQuery(
cannedQueryDAO, taggingService, cannedQueryDAO,
methodSecurity, methodSecurity,
parameters); parameters);
return (CannedQuery<BlogPostInfo>) cq; return (CannedQuery<BlogPostInfo>) cq;
} }
public CannedQuery<BlogPostInfo> getCannedQuery(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, String tag, PagingRequest pagingReq) public CannedQuery<BlogPostInfo> getCannedQuery(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, PagingRequest pagingReq)
{ {
ParameterCheck.mandatory("blogContainerNode", blogContainerNode); ParameterCheck.mandatory("blogContainerNode", blogContainerNode);
ParameterCheck.mandatory("pagingReq", pagingReq); ParameterCheck.mandatory("pagingReq", pagingReq);
@@ -72,7 +64,7 @@ public class DraftsAndPublishedBlogPostsCannedQueryFactory extends AbstractBlogP
getQNameId(ContentModel.PROP_PUBLISHED), getQNameId(ContentModel.PROP_PUBLISHED),
getQNameId(ContentModel.TYPE_CONTENT), getQNameId(ContentModel.TYPE_CONTENT),
byUser, byUser,
fromDate, toDate, tag); fromDate, toDate);
CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq); CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING); CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_PUBLISHED, SortOrder.DESCENDING);

View File

@@ -31,7 +31,6 @@ public class DraftsAndPublishedBlogPostsCannedQueryParams extends BlogEntity
private final String cmCreator; private final String cmCreator;
private final Date createdFromDate; private final Date createdFromDate;
private final Date createdToDate; private final Date createdToDate;
private final String tag;
public DraftsAndPublishedBlogPostsCannedQueryParams(Long blogContainerNodeId, public DraftsAndPublishedBlogPostsCannedQueryParams(Long blogContainerNodeId,
Long nameQNameId, Long nameQNameId,
@@ -39,15 +38,13 @@ public class DraftsAndPublishedBlogPostsCannedQueryParams extends BlogEntity
Long contentTypeQNameId, Long contentTypeQNameId,
String cmCreator, String cmCreator,
Date createdFromDate, Date createdFromDate,
Date createdToDate, Date createdToDate)
String tag)
{ {
super(blogContainerNodeId, nameQNameId, publishedQNameId, contentTypeQNameId, null, null); super(blogContainerNodeId, nameQNameId, publishedQNameId, contentTypeQNameId, null, null);
this.cmCreator = cmCreator; this.cmCreator = cmCreator;
this.createdFromDate = createdFromDate; this.createdFromDate = createdFromDate;
this.createdToDate = createdToDate; this.createdToDate = createdToDate;
this.tag = tag;
} }
public String getCmCreator() public String getCmCreator()
@@ -64,9 +61,4 @@ public class DraftsAndPublishedBlogPostsCannedQueryParams extends BlogEntity
{ {
return createdToDate; return createdToDate;
} }
public String getTag()
{
return tag;
}
} }

View File

@@ -137,7 +137,7 @@ public interface ServiceRegistry
static final QName RENDITION_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "RenditionService"); static final QName RENDITION_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "RenditionService");
static final QName RATING_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "RatingService"); static final QName RATING_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "RatingService");
static final QName REPO_ADMIN_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "RepoAdminService"); static final QName REPO_ADMIN_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "RepoAdminService");
static final QName NODE_LOCATOR_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "NodeLocatorService"); static final QName NODE_LOCATOR_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "nodeLocatorService");
// WCM / AVM // WCM / AVM
static final QName AVM_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMService"); static final QName AVM_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMService");