diff --git a/config/alfresco/blog-context.xml b/config/alfresco/blog-context.xml
index e30f3f6362..ccbea96f92 100644
--- a/config/alfresco/blog-context.xml
+++ b/config/alfresco/blog-context.xml
@@ -66,8 +66,11 @@
-
+
+
+
+
diff --git a/source/java/org/alfresco/repo/blog/BlogServiceImpl.java b/source/java/org/alfresco/repo/blog/BlogServiceImpl.java
index 98c0aafa1d..9554ac57e8 100644
--- a/source/java/org/alfresco/repo/blog/BlogServiceImpl.java
+++ b/source/java/org/alfresco/repo/blog/BlogServiceImpl.java
@@ -28,6 +28,7 @@ import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.query.CannedQueryFactory;
import org.alfresco.query.CannedQueryResults;
+import org.alfresco.query.EmptyPagingResults;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.blog.cannedqueries.DraftsAndPublishedBlogPostsCannedQuery;
@@ -37,6 +38,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.repo.site.SiteServiceImpl;
import org.alfresco.service.cmr.blog.BlogPostInfo;
import org.alfresco.service.cmr.blog.BlogService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -50,8 +52,11 @@ 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.site.SiteService;
+import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
+import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ISO9075;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
@@ -70,6 +75,8 @@ public class BlogServiceImpl implements BlogService
*/
private static final int MAX_QUERY_ENTRY_COUNT = 10000;
+ public static final String BLOG_COMPONENT = "blog";
+
// Injected services
private NamedObjectRegistry> cannedQueryRegistry;
private GetBlogPostsCannedQueryFactory draftPostsCannedQueryFactory;
@@ -82,7 +89,10 @@ public class BlogServiceImpl implements BlogService
private DictionaryService dictionaryService;
private NamespaceService namespaceService;
private NodeService nodeService;
+ private SiteService siteService;
+ private TransactionService transactionService;
private PermissionService permissionService;
+ private TaggingService taggingService;
private SearchService searchService;
public void setCannedQueryRegistry(NamedObjectRegistry> cannedQueryRegistry)
@@ -130,16 +140,41 @@ public class BlogServiceImpl implements BlogService
this.nodeService = nodeService;
}
+ public void setSiteService(SiteService siteService)
+ {
+ this.siteService = siteService;
+ }
+
+ public void setTransactionService(TransactionService transactionService)
+ {
+ this.transactionService = transactionService;
+ }
+
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
+ public void setTaggingService(TaggingService taggingService)
+ {
+ this.taggingService = taggingService;
+ }
+
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
+ /**
+ * Fetches the Blogs Container on a site, creating as required if requested.
+ */
+ protected NodeRef getSiteBlogContainer(final String siteShortName, boolean create)
+ {
+ return SiteServiceImpl.getSiteContainer(
+ siteShortName, BLOG_COMPONENT, create,
+ siteService, transactionService, taggingService);
+ }
+
@Override
public boolean isDraftBlogPost(NodeRef blogPostNode)
{
@@ -151,11 +186,14 @@ public class BlogServiceImpl implements BlogService
public BlogPostInfo createBlogPost(String siteShortName, String blogTitle,
String blogContent, boolean isDraft)
{
- // TODO Implement
- return null;
+ // Grab the location to stor ein
+ NodeRef container = getSiteBlogContainer(siteShortName, true);
+
+ // Add by Parent NodeRef
+ return createBlogPost(container, blogTitle, blogContent, isDraft);
}
- @Override
+ @Override
public BlogPostInfo createBlogPost(NodeRef blogContainerNode, String blogTitle,
String blogContent, boolean isDraft)
{
@@ -197,7 +235,7 @@ public class BlogServiceImpl implements BlogService
throw new IllegalArgumentException("Can't update a post that was never persisted, call create instead");
}
- // TODO Implement
+ // TODO Implement, once BlogPostInfo is finished
return null;
}
@@ -216,8 +254,15 @@ public class BlogServiceImpl implements BlogService
public PagingResults getDrafts(String siteShortName,
String username, PagingRequest pagingReq)
{
- // TODO Implement
- return null;
+ NodeRef container = getSiteBlogContainer(siteShortName, false);
+ if (container == null)
+ {
+ // No blog posts yet
+ return new EmptyPagingResults();
+ }
+
+ // We can now fetch by parent nodeRef
+ return getDrafts(container, username, pagingReq);
}
@Override
@@ -239,8 +284,15 @@ public class BlogServiceImpl implements BlogService
public PagingResults getPublishedExternally(
String siteShortName, PagingRequest pagingReq)
{
- // TODO Implement
- return null;
+ NodeRef container = getSiteBlogContainer(siteShortName, false);
+ if (container == null)
+ {
+ // No blog posts yet
+ return new EmptyPagingResults();
+ }
+
+ // We can now fetch by parent nodeRef
+ return getPublishedExternally(container, pagingReq);
}
@Override
@@ -262,8 +314,15 @@ public class BlogServiceImpl implements BlogService
public PagingResults getPublished(String siteShortName,
Date fromDate, Date toDate, String byUser, PagingRequest pagingReq)
{
- // TODO Implement
- return null;
+ NodeRef container = getSiteBlogContainer(siteShortName, false);
+ if (container == null)
+ {
+ // No blog posts yet
+ return new EmptyPagingResults();
+ }
+
+ // We can now fetch by parent nodeRef
+ return getPublished(container, fromDate, toDate, byUser, pagingReq);
}
@Override
@@ -341,8 +400,15 @@ public class BlogServiceImpl implements BlogService
public PagingResults findBlogPosts(String siteShortName,
RangedDateProperty dateRange, String tag, PagingRequest pagingReq)
{
- // TODO Implement
- return null;
+ NodeRef container = getSiteBlogContainer(siteShortName, false);
+ if (container == null)
+ {
+ // No blog posts yet
+ return new EmptyPagingResults();
+ }
+
+ // We can now fetch by parent nodeRef
+ return findBlogPosts(container, dateRange, tag, pagingReq);
}
@Override
diff --git a/source/java/org/alfresco/repo/blog/BlogServiceImplTest.java b/source/java/org/alfresco/repo/blog/BlogServiceImplTest.java
index da453d54b0..702cafd228 100644
--- a/source/java/org/alfresco/repo/blog/BlogServiceImplTest.java
+++ b/source/java/org/alfresco/repo/blog/BlogServiceImplTest.java
@@ -54,7 +54,6 @@ import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.tagging.TaggingService;
-import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.Pair;
@@ -101,6 +100,7 @@ public class BlogServiceImplTest
*/
private static List CLASS_TEST_NODES_TO_TIDY = new ArrayList();
+ private static SiteInfo BLOG_SITE;
private static NodeRef BLOG_CONTAINER_NODE;
@BeforeClass public static void initTestsContext() throws Exception
@@ -125,24 +125,35 @@ public class BlogServiceImplTest
private static void createTestSiteWithBlogContainer() throws Exception
{
- BLOG_CONTAINER_NODE = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback()
+ BLOG_SITE = TRANSACTION_HELPER.doInTransaction(
+ new RetryingTransactionHelper.RetryingTransactionCallback()
{
@Override
- public NodeRef execute() throws Throwable
+ public SiteInfo execute() throws Throwable
{
SiteInfo site = SITE_SERVICE.createSite("BlogSitePreset", BlogServiceImplTest.class.getSimpleName() + "_testSite" + System.currentTimeMillis(),
"test site title", "test site description", SiteVisibility.PUBLIC);
CLASS_TEST_NODES_TO_TIDY.add(site.getNodeRef());
+ return site;
+ }
+ });
- NodeRef result = SITE_SERVICE.getContainer(site.getShortName(), "blog");
-
+ BLOG_CONTAINER_NODE = TRANSACTION_HELPER.doInTransaction(
+ new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ @Override
+ public NodeRef execute() throws Throwable
+ {
+ SiteInfo site = BLOG_SITE;
+ NodeRef result = SITE_SERVICE.getContainer(site.getShortName(), BlogServiceImpl.BLOG_COMPONENT);
+
if (result == null)
{
- result = NODE_SERVICE.createNode(site.getNodeRef(), ContentModel.ASSOC_CONTAINS,
- QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "blog"), ContentModel.TYPE_FOLDER, null).getChildRef();
- CLASS_TEST_NODES_TO_TIDY.add(result);
+ result = SITE_SERVICE.createContainer(site.getShortName(), BlogServiceImpl.BLOG_COMPONENT,
+ ContentModel.TYPE_FOLDER, null);
+ CLASS_TEST_NODES_TO_TIDY.add(result);
}
-
+
return result;
}
});
@@ -215,7 +226,17 @@ public class BlogServiceImplTest
for (int i = 0; i < arbitraryNumberGreaterThanPageSize; i++)
{
- BlogPostInfo newBlogPost = BLOG_SERVICE.createBlogPost(BLOG_CONTAINER_NODE, "title_" + i, "Hello world", true);
+ BlogPostInfo newBlogPost;
+ if(i % 2 == 0)
+ {
+ // By container ref
+ newBlogPost = BLOG_SERVICE.createBlogPost(BLOG_CONTAINER_NODE, "title_" + i, "Hello world", true);
+ }
+ else
+ {
+ // By site name
+ newBlogPost = BLOG_SERVICE.createBlogPost(BLOG_SITE.getShortName(), "title_" + i, "Hello world", true);
+ }
results.add(newBlogPost.getNodeRef());
testNodesToTidy.add(newBlogPost.getNodeRef());