Search in sources :

Example 6 with BlogPostInfo

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;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) PagingResults(org.alfresco.query.PagingResults) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RangedDateProperty(org.alfresco.service.cmr.blog.BlogService.RangedDateProperty) BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo) PagingRequest(org.alfresco.query.PagingRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) List(java.util.List) Category(org.junit.experimental.categories.Category) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 7 with BlogPostInfo

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;
        }
    });
}
Also used : PagingResults(org.alfresco.query.PagingResults) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ArrayList(java.util.ArrayList) List(java.util.List) BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo) PagingRequest(org.alfresco.query.PagingRequest) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 8 with BlogPostInfo

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;
        }
    });
}
Also used : PagingResults(org.alfresco.query.PagingResults) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RangedDateProperty(org.alfresco.service.cmr.blog.BlogService.RangedDateProperty) BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo) PagingRequest(org.alfresco.query.PagingRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.alfresco.util.Pair) Category(org.junit.experimental.categories.Category) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 9 with BlogPostInfo

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;
        }
    };
}
Also used : BlogEntity(org.alfresco.repo.blog.cannedqueries.BlogEntity) EmptyPagingResults(org.alfresco.query.EmptyPagingResults) PagingResults(org.alfresco.query.PagingResults) ArrayList(java.util.ArrayList) BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo)

Example 10 with BlogPostInfo

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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo)

Aggregations

BlogPostInfo (org.alfresco.service.cmr.blog.BlogPostInfo)16 ArrayList (java.util.ArrayList)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 PagingRequest (org.alfresco.query.PagingRequest)8 PagingResults (org.alfresco.query.PagingResults)8 List (java.util.List)7 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)7 BaseSpringTest (org.alfresco.util.BaseSpringTest)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)5 Date (java.util.Date)4 JSONObject (org.json.simple.JSONObject)4 RangedDateProperty (org.alfresco.service.cmr.blog.BlogService.RangedDateProperty)3 Pair (org.alfresco.util.Pair)3 Category (org.junit.experimental.categories.Category)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 IOException (java.io.IOException)1