use of org.alfresco.service.cmr.blog.BlogPostInfo in project alfresco-repository by Alfresco.
the class BlogServiceImplTest method createTaggedDraftBlogPost.
@Category(RedundantTests.class)
@Test
public void createTaggedDraftBlogPost() throws Exception {
// Our tags, which are a mixture of English, Accented European and Chinese
final List<String> tags = Arrays.asList(new String[] { "alpha", "beta", "gamma", "fran\u00e7ais", "chinese_\u535a\u5ba2" });
// Create a list of Blog Posts, all drafts, each with one of the tags above.
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<List<NodeRef>>() {
@Override
public List<NodeRef> execute() throws Throwable {
List<NodeRef> results = new ArrayList<NodeRef>();
for (String tag : tags) {
final String blogTitle = "draftWithTag" + tag;
BlogPostInfo newBlogPost = BLOG_SERVICE.createBlogPost(BLOG_CONTAINER_NODE, blogTitle, "Hello world", true);
TAGGING_SERVICE.addTags(newBlogPost.getNodeRef(), Arrays.asList(new String[] { tag }));
testNodesToTidy.add(newBlogPost.getNodeRef());
results.add(newBlogPost.getNodeRef());
}
return results;
}
});
// Check we get the correct tags back
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Now we'll recover these blogposts & we should expect to find the same tags.
Set<String> expectedTags = new HashSet<String>();
expectedTags.addAll(tags);
PagingRequest pagingReq = new PagingRequest(0, 10, null);
PagingResults<BlogPostInfo> pagedResults = BLOG_SERVICE.getDrafts(BLOG_CONTAINER_NODE, ADMIN_USER, pagingReq);
assertEquals("Wrong number of blog posts", tags.size(), pagedResults.getPage().size());
for (BlogPostInfo bpi : pagedResults.getPage()) {
NodeRef blogNode = bpi.getNodeRef();
List<String> recoveredTags = TAGGING_SERVICE.getTags(blogNode);
assertEquals("Wrong number of tags", 1, recoveredTags.size());
String tag = recoveredTags.get(0);
assertTrue("Tag found on node but not expected: " + tag, expectedTags.remove(tag));
}
assertTrue("Not all tags were recovered from a blogpost", expectedTags.isEmpty());
return null;
}
});
// Check we can find the posts by their tags
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
PagingRequest pagingReq = new PagingRequest(0, 10, null);
RangedDateProperty dates = new RangedDateProperty(null, null, ContentModel.PROP_CREATED);
for (String tag : tags) {
PagingResults<BlogPostInfo> pagedResults = BLOG_SERVICE.findBlogPosts(BLOG_CONTAINER_NODE, dates, tag, pagingReq);
// Check we found our post
assertEquals("Wrong number of blog posts for " + tag, 1, pagedResults.getPage().size());
}
return null;
}
});
}
use of org.alfresco.service.cmr.blog.BlogPostInfo in project alfresco-repository by Alfresco.
the class BlogServiceImplTest method ensureBlogPostsAreCorrectlySorted.
@Test
public void ensureBlogPostsAreCorrectlySorted() throws Exception {
final int testBlogCount = 3;
// Set up some test data to check sorting. We don't need to retain references to these posts.
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// Create some blog posts. They'll all be published 'now' but the slight delay between each should ensure they
// are given distinct creation dates
final long slightDelay = 50;
for (int i = 0; i < testBlogCount; i++) {
BlogPostInfo newDraft = BLOG_SERVICE.createBlogPost(BLOG_CONTAINER_NODE, "draftPost_ensureBlogPostsAreCorrectlySorted" + i, "x", true);
Thread.sleep(slightDelay);
// And the same for some published posts...
BlogPostInfo newPublished = BLOG_SERVICE.createBlogPost(BLOG_CONTAINER_NODE, "publishedPost_ensureBlogPostsAreCorrectlySorted" + i, "x", false);
Thread.sleep(slightDelay);
testNodesToTidy.add(newDraft.getNodeRef());
testNodesToTidy.add(newPublished.getNodeRef());
}
return null;
}
});
final PagingRequest pagingReq = new PagingRequest(100);
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@SuppressWarnings("deprecation")
@Override
public Void execute() throws Throwable {
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
// get DRAFTS
PagingResults<BlogPostInfo> resultsPage = BLOG_SERVICE.getDrafts(BLOG_CONTAINER_NODE, currentUser, pagingReq);
List<BlogPostInfo> blogPosts = resultsPage.getPage();
assertTrue("Expected more draft blog posts than " + blogPosts.size(), blogPosts.size() >= testBlogCount);
assertSortingIsCorrect(blogPosts);
// And the published ones
// Date filtering tested elsewhere.
resultsPage = BLOG_SERVICE.getPublished(BLOG_CONTAINER_NODE, null, null, currentUser, pagingReq);
blogPosts = resultsPage.getPage();
assertTrue("Expected more published blog posts than " + blogPosts.size(), blogPosts.size() >= testBlogCount);
assertSortingIsCorrect(blogPosts);
// And the combination. This should be ordered:
// published posts, most recent cm:published first - followed by
// draft posts, most recent cm:created first
System.out.println(" getMyDraftsAndAllPublished");
resultsPage = BLOG_SERVICE.getMyDraftsAndAllPublished(BLOG_CONTAINER_NODE, null, null, pagingReq);
blogPosts = resultsPage.getPage();
assertSortingIsCorrect(blogPosts);
return null;
}
});
}
use of org.alfresco.service.cmr.blog.BlogPostInfo in project alfresco-repository by Alfresco.
the class BlogServiceImplTest method testGetBlogPostsByTagPaging.
/**
* Test that correct paging info is returned when searching for tagged blog posts.
*/
@Test
@Category(RedundantTests.class)
public void testGetBlogPostsByTagPaging() throws Exception {
final String tagToSearchBy = "testtag";
final int numberOfBlogPostsTagged = 2;
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<List<NodeRef>>() {
@Override
public List<NodeRef> execute() throws Throwable {
List<NodeRef> results = new ArrayList<NodeRef>();
do {
final String blogTitle = "blogTitle" + GUID.generate();
BlogPostInfo newBlogPost = BLOG_SERVICE.createBlogPost(BLOG_CONTAINER_NODE, blogTitle, "Hello world", false);
TAGGING_SERVICE.addTags(newBlogPost.getNodeRef(), Arrays.asList(new String[] { tagToSearchBy }));
testNodesToTidy.add(newBlogPost.getNodeRef());
results.add(newBlogPost.getNodeRef());
} while (results.size() < numberOfBlogPostsTagged);
return results;
}
});
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
PagingRequest pagingReq = new PagingRequest(0, 1, null);
RangedDateProperty dates = new RangedDateProperty(null, null, ContentModel.PROP_CREATED);
PagingResults<BlogPostInfo> pagedResults = BLOG_SERVICE.findBlogPosts(BLOG_CONTAINER_NODE, dates, tagToSearchBy, pagingReq);
assertEquals("Wrong number of blog posts on page 1 for " + tagToSearchBy, 1, pagedResults.getPage().size());
assertEquals("Wrong total number of blog posts for " + tagToSearchBy, new Pair<Integer, Integer>(2, 2), pagedResults.getTotalResultCount());
assertEquals("There should still be blog posts available to be retrieved for " + tagToSearchBy, true, pagedResults.hasMoreItems());
pagingReq = new PagingRequest(1, 1, null);
pagedResults = BLOG_SERVICE.findBlogPosts(BLOG_CONTAINER_NODE, dates, tagToSearchBy, pagingReq);
assertEquals("Wrong number of blog posts on page 2 for " + tagToSearchBy, 1, pagedResults.getPage().size());
assertEquals("Wrong total number of blog posts for " + tagToSearchBy, new Pair<Integer, Integer>(2, 2), pagedResults.getTotalResultCount());
assertEquals("All blog posts should have been retrieved by now for " + tagToSearchBy, false, pagedResults.hasMoreItems());
return null;
}
});
}
use of org.alfresco.service.cmr.blog.BlogPostInfo in project alfresco-repository by Alfresco.
the class BlogServiceImpl method wrap.
private PagingResults<BlogPostInfo> wrap(final CannedQueryResults<BlogEntity> results, final NodeRef containerNodeRef) {
// Wrap
return new PagingResults<BlogPostInfo>() {
@Override
public String getQueryExecutionId() {
return results.getQueryExecutionId();
}
@Override
public Pair<Integer, Integer> getTotalResultCount() {
return results.getTotalResultCount();
}
@Override
public boolean hasMoreItems() {
return results.hasMoreItems();
}
@Override
public List<BlogPostInfo> getPage() {
List<BlogEntity> entities = results.getPage();
List<BlogPostInfo> posts = new ArrayList<BlogPostInfo>(entities.size());
for (BlogEntity entity : entities) {
posts.add(new BlogPostInfoImpl(entity.getNodeRef(), containerNodeRef, entity.getName()));
}
return posts;
}
};
}
use of org.alfresco.service.cmr.blog.BlogPostInfo in project alfresco-remote-api by Alfresco.
the class AbstractGetBlogWebScript method createFtlModel.
protected void createFtlModel(WebScriptRequest req, Map<String, Object> model, NodeRef node, PagingRequest pagingReq, PagingResults<BlogPostInfo> blogPostList) {
Map<String, Object> blogPostsData = new HashMap<String, Object>();
final Pair<Integer, Integer> totalResultCount = blogPostList.getTotalResultCount();
int total = blogPostList.getPage().size();
if (totalResultCount != null && totalResultCount.getFirst() != null) {
total = totalResultCount.getFirst();
}
// FIXME What to do? null
blogPostsData.put("total", total);
blogPostsData.put("pageSize", pagingReq.getMaxItems());
blogPostsData.put("startIndex", pagingReq.getSkipCount());
blogPostsData.put("itemCount", blogPostList.getPage().size());
if (total == pagingReq.getRequestTotalCountMax()) {
blogPostsData.put("totalRecordsUpper", true);
} else {
blogPostsData.put("totalRecordsUpper", false);
}
List<Map<String, Object>> blogPostDataSets = new ArrayList<Map<String, Object>>(blogPostList.getPage().size());
for (BlogPostInfo postInfo : blogPostList.getPage()) {
Map<String, Object> data = BlogPostLibJs.getBlogPostData(postInfo.getNodeRef(), services);
blogPostDataSets.add(data);
}
blogPostsData.put("items", blogPostDataSets);
model.put("data", blogPostsData);
// fetch the contentLength param
String contentLengthStr = req.getParameter("contentLength");
int contentLength = contentLengthStr == null ? -1 : Integer.parseInt(contentLengthStr);
model.put("contentLength", contentLength);
// assign the blog node
model.put("blog", node);
model.put("externalBlogConfig", BlogPostLibJs.hasExternalBlogConfiguration(node, services));
}
Aggregations