ALF-10429 / ALF-10413 - Start to refactor the blog service to match the other new services, as a precursor to fixing the paging bug

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31166 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-10-12 13:01:23 +00:00
parent df96dd8e68
commit 33289cbe68
10 changed files with 295 additions and 46 deletions

View File

@@ -0,0 +1,77 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.blog;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* An implementation of a {@link BlogPostInfo}
*
* @author Nick Burch (based on the existing webscript conrollers in the REST API)
* @since 4.0
*/
public class BlogPostInfoImpl implements BlogPostInfo
{
private final NodeRef nodeRef;
private final String systemName;
public BlogPostInfoImpl(NodeRef nodeRef, String systemName)
{
this.nodeRef = nodeRef;
this.systemName = systemName;
}
/**
* Gets the NodeRef representing this blog-post.
*/
@Override
public NodeRef getNodeRef()
{
return nodeRef;
}
@Override
public NodeRef getContainerNodeRef()
{
//return containerNodeRef; // TODO
return null;
}
/**
* Gets the {@link ContentModel#PROP_NAME cm:name} of the blog post.
* @return
*/
@Override
public String getSystemName()
{
return systemName;
}
/**
* @return the Title of the blog post.
*/
public String getTitle()
{
// TODO
return null;
}
}

View File

@@ -37,6 +37,7 @@ import org.alfresco.repo.blog.cannedqueries.GetBlogPostsCannedQueryFactory;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.search.impl.lucene.LuceneUtils;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
@@ -145,7 +146,16 @@ public class BlogServiceImpl implements BlogService
return nodeService.getProperty(blogPostNode, ContentModel.PROP_PUBLISHED) == null;
}
@Override
public BlogPostInfo createBlogPost(String siteShortName, String blogTitle,
String blogContent, boolean isDraft)
{
// TODO Implement
return null;
}
@Override
public BlogPostInfo createBlogPost(NodeRef blogContainerNode, String blogTitle,
String blogContent, boolean isDraft)
{
@@ -177,7 +187,37 @@ public class BlogServiceImpl implements BlogService
setOrUpdateReleasedAndUpdatedDates(postNode.getChildRef());
}
return new BlogPostInfo(postNode.getChildRef(), nodeName);
return new BlogPostInfoImpl(postNode.getChildRef(), nodeName);
}
@Override
public BlogPostInfo updateBlogPost(BlogPostInfo post) {
if (post.getNodeRef() == null)
{
throw new IllegalArgumentException("Can't update a post that was never persisted, call create instead");
}
// TODO Implement
return null;
}
@Override
public void deleteBlogPost(BlogPostInfo post) {
if (post.getNodeRef() == null)
{
throw new IllegalArgumentException("Can't delete a post that was never persisted");
}
nodeService.deleteNode(post.getNodeRef());
}
@Override
public PagingResults<BlogPostInfo> getDrafts(String siteShortName,
String username, PagingRequest pagingReq)
{
// TODO Implement
return null;
}
@Override
@@ -194,6 +234,15 @@ public class BlogServiceImpl implements BlogService
CannedQueryResults<BlogPostInfo> results = cq.execute();
return results;
}
@Override
public PagingResults<BlogPostInfo> getPublishedExternally(
String siteShortName, PagingRequest pagingReq)
{
// TODO Implement
return null;
}
@Override
public PagingResults<BlogPostInfo> getPublishedExternally(NodeRef blogContainerNode, PagingRequest pagingReq)
{
@@ -209,6 +258,14 @@ public class BlogServiceImpl implements BlogService
return results;
}
@Override
public PagingResults<BlogPostInfo> getPublished(String siteShortName,
Date fromDate, Date toDate, String byUser, PagingRequest pagingReq)
{
// TODO Implement
return null;
}
@Override
public PagingResults<BlogPostInfo> getPublished(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, PagingRequest pagingReq)
{
@@ -280,6 +337,14 @@ public class BlogServiceImpl implements BlogService
}
}
@Override
public PagingResults<BlogPostInfo> findBlogPosts(String siteShortName,
RangedDateProperty dateRange, String tag, PagingRequest pagingReq)
{
// TODO Implement
return null;
}
@Override
public PagingResults<BlogPostInfo> findBlogPosts(NodeRef blogContainerNode, RangedDateProperty dateRange, String tag, PagingRequest pagingReq)
{
@@ -321,7 +386,7 @@ public class BlogServiceImpl implements BlogService
List<BlogPostInfo> blogPostInfos = new ArrayList<BlogPostInfo>(nodeRefs.size());
for (NodeRef nodeRef : nodeRefs)
{
blogPostInfos.add(new BlogPostInfo(nodeRef, (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME)));
blogPostInfos.add(new BlogPostInfoImpl(nodeRef, (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME)));
}
return blogPostInfos;
}

View File

@@ -40,8 +40,8 @@ import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteModel;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService;
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService.RangedDateProperty;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;

View File

@@ -26,7 +26,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.query.CannedQuerySortDetails;
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
import org.alfresco.repo.query.AbstractQNameAwareCannedQueryFactory;
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;

View File

@@ -27,12 +27,13 @@ import java.util.List;
import org.alfresco.query.CannedQuery;
import org.alfresco.query.CannedQueryParameters;
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
import org.alfresco.repo.blog.BlogPostInfoImpl;
import org.alfresco.repo.blog.cannedqueries.AbstractBlogPostsCannedQueryFactory.BlogEntityComparator;
import org.alfresco.repo.domain.query.CannedQueryDAO;
import org.alfresco.repo.security.permissions.impl.acegi.AbstractCannedQueryPermissions;
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService;
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
@@ -156,7 +157,7 @@ public class DraftsAndPublishedBlogPostsCannedQuery extends AbstractCannedQueryP
List<BlogPostInfo> blogPostInfos = new ArrayList<BlogPostInfo>(filtered.size());
for (BlogEntity result : filtered)
{
blogPostInfos.add(new BlogPostInfo(result.getNodeRef(), result.getName()));
blogPostInfos.add(new BlogPostInfoImpl(result.getNodeRef(), result.getName()));
}
if (start != null)

View File

@@ -29,7 +29,7 @@ import org.alfresco.query.CannedQueryPageDetails;
import org.alfresco.query.CannedQueryParameters;
import org.alfresco.query.CannedQuerySortDetails;
import org.alfresco.query.PagingRequest;
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;

View File

@@ -27,13 +27,14 @@ import java.util.List;
import org.alfresco.query.CannedQuery;
import org.alfresco.query.CannedQueryParameters;
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
import org.alfresco.repo.blog.BlogPostInfoImpl;
import org.alfresco.repo.blog.cannedqueries.AbstractBlogPostsCannedQueryFactory.BlogEntityComparator;
import org.alfresco.repo.domain.node.AuditablePropertiesEntity;
import org.alfresco.repo.domain.query.CannedQueryDAO;
import org.alfresco.repo.security.permissions.impl.acegi.AbstractCannedQueryPermissions;
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService;
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
@@ -153,7 +154,7 @@ public class GetBlogPostsCannedQuery extends AbstractCannedQueryPermissions<Blog
List<BlogPostInfo> blogPostInfos = new ArrayList<BlogPostInfo>(filtered.size());
for (BlogEntity result : filtered)
{
blogPostInfos.add(new BlogPostInfo(result.getNodeRef(), result.getName()));
blogPostInfos.add(new BlogPostInfoImpl(result.getNodeRef(), result.getName()));
}
if (start != null)

View File

@@ -29,8 +29,8 @@ import org.alfresco.query.CannedQueryParameters;
import org.alfresco.query.CannedQuerySortDetails;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService;
import org.alfresco.service.cmr.blog.BlogService.BlogPostInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.ParameterCheck;

View File

@@ -0,0 +1,56 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.service.cmr.blog;
import java.io.Serializable;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This class represents a blog post in a blog.
*
* @author Neil Mc Erlean
* @since 4.0
*/
public interface BlogPostInfo extends Serializable, PermissionCheckValue
{
/**
* Gets the NodeRef representing this blog-post.
*/
NodeRef getNodeRef();
/**
* @return the NodeRef of the container this belongs to (Site or Otherwise)
*/
NodeRef getContainerNodeRef();
/**
* Gets the {@link ContentModel#PROP_NAME cm:name} of the blog post.
*/
String getSystemName();
/**
* @return the Title of the blog post.
*/
String getTitle();
// TODO Remaining fields
}

View File

@@ -24,7 +24,6 @@ import org.alfresco.model.ContentModel;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.blog.BlogIntegrationService;
import org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.site.SiteService;
@@ -42,6 +41,20 @@ import org.alfresco.service.namespace.QName;
*/
public interface BlogService
{
/**
* Creates a new blog post in the specified site
*
* @param siteShortName the name of the site to add the post to.
* @param blogTitle the title of the blog post.
* @param blogContent text/html content of the blog post.
* @param isDraft <tt>true</tt> if the blog post is a draft post, else <tt>false</tt>.
*
* @return The {@link BlogPostInfo} of the newly created blog post.
*
* @see SiteService#getContainer(String, String) to retrieve the blogContainerNode
*/
BlogPostInfo createBlogPost(String siteShortName, String blogTitle, String blogContent, boolean isDraft);
/**
* Creates a new blog post within the specified container node.
*
@@ -56,6 +69,31 @@ public interface BlogService
*/
BlogPostInfo createBlogPost(NodeRef blogContainerNode, String blogTitle, String blogContent, boolean isDraft);
/**
* Updates an existing {@link BlogPostInfo} in the repository.
*
* @return The updated {@link BlogPostInfo}
*/
BlogPostInfo updateBlogPost(BlogPostInfo post);
/**
* Deletes an existing {@link BlogPostInfo} from the repository.
*/
void deleteBlogPost(BlogPostInfo post);
/**
* Gets the draft blog posts created by the specified user.
*
* @param siteShortName the name of the site to add the post to.
* @param username to limit results to blogs with this cm:creator. <tt>null</tt> means all users.
* @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> getDrafts(String siteShortName, String username, PagingRequest pagingReq);
/**
* Gets the draft blog posts created by the specified user.
*
@@ -69,6 +107,22 @@ public interface BlogService
*/
PagingResults<BlogPostInfo> getDrafts(NodeRef blogContainerNode, String username, PagingRequest pagingReq);
/**
* Gets the (internally, Alfresco-) published blog posts.
*
* @param siteShortName the name of the site to add the post to.
* @param fromDate an inclusive date limit for the results (more recent than).
* @param toDate an inclusive date limit for the results (before).
* @param byUser if not <tt>null</tt> limits results to posts by the specified user.
* if <tt>null</tt> results will be by all users.
* @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> getPublished(String siteShortName, Date fromDate, Date toDate, String byUser, PagingRequest pagingReq);
/**
* Gets the (internally, Alfresco-) published blog posts.
*
@@ -85,6 +139,18 @@ public interface BlogService
*/
PagingResults<BlogPostInfo> getPublished(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, PagingRequest pagingReq);
/**
* Gets blog posts published externally (i.e. to an external blog hosting site).
*
* @param siteShortName the name of the site to add the post to.
* @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> getPublishedExternally(String siteShortName, PagingRequest pagingReq);
/**
* Gets blog posts published externally (i.e. to an external blog hosting site).
*
@@ -113,6 +179,22 @@ public interface BlogService
*/
PagingResults<BlogPostInfo> getMyDraftsAndAllPublished(NodeRef blogContainerNode, Date fromDate, Date toDate, PagingRequest pagingReq);
/**
* Finds blog posts by the specified user tagged with the given tag string. This method allows date ranges to be applied to any valid
* {@link DataTypeDefinition#DATE} or {@link DataTypeDefinition#DATETIME} property. Examples include {@link ContentModel#PROP_CREATED} or
* {@link ContentModel#PROP_PUBLISHED}.
*
* @param siteShortName the name of the site to add the post to.
* @param dateRange a {@link RangedDateProperty} parameter object. Can be null.
* @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> findBlogPosts(String siteShortName, RangedDateProperty dateRange, String tag, PagingRequest pagingReq);
/**
* Finds blog posts by the specified user tagged with the given tag string. This method allows date ranges to be applied to any valid
* {@link DataTypeDefinition#DATE} or {@link DataTypeDefinition#DATETIME} property. Examples include {@link ContentModel#PROP_CREATED} or
@@ -134,44 +216,11 @@ public interface BlogService
*
* @param blogPostNode a NodeRef representing a blog-post.
* @return <tt>true</tt> if it is a draft post, else <tt>false</tt>.
*
* @deprecated Add this to the BlogPostInfo shortly
*/
boolean isDraftBlogPost(NodeRef blogPostNode);
/**
* A simple data object for storage of blog-related data.
*
* @author Neil Mc Erlean
* @since 4.0
*/
public class BlogPostInfo implements PermissionCheckValue
{
private final NodeRef nodeRef;
private final String name;
public BlogPostInfo(NodeRef nodeRef, String name)
{
this.nodeRef = nodeRef;
this.name = name;
}
/**
* Gets the NodeRef representing this blog-post.
*/
@Override
public NodeRef getNodeRef()
{
return nodeRef;
}
/**
* Gets the {@link ContentModel#PROP_NAME cm:name} of the blog post.
* @return
*/
public String getName()
{
return name;
}
}
/**
* A simple data object for expressing a date range search parameter.
*/