Search in sources :

Example 6 with ArticleLoadParameter

use of com.celements.blog.article.ArticleLoadParameter in project celements-blog by celements.

the class BlogServiceTest method testGetArticles_nullparam.

@Test
public void testGetArticles_nullparam() throws Exception {
    DocumentReference docRef = new DocumentReference(wikiRef.getName(), "space", "blog");
    Capture<ArticleLoadParameter> paramCapture = new Capture<>();
    expect(xwiki.getDocument(eq(docRef), same(context))).andReturn(new XWikiDocument(docRef)).once();
    expect(xwiki.getXWikiPreference(eq("blog_article_engine"), eq("blog.article.engine"), isNull(String.class), same(getContext()))).andReturn(testEngineHint).once();
    expect(articleEngineMock.getArticles(capture(paramCapture))).andReturn(Collections.<Article>emptyList()).once();
    replayDefault();
    List<Article> ret = blogService.getArticles(docRef, null);
    verifyDefault();
    assertEquals(0, ret.size());
    ArticleLoadParameter param = paramCapture.getValue();
    assertEquals(docRef, param.getBlogDocRef());
}
Also used : ArticleLoadParameter(com.celements.blog.article.ArticleLoadParameter) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Article(com.celements.blog.article.Article) DocumentReference(org.xwiki.model.reference.DocumentReference) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 7 with ArticleLoadParameter

use of com.celements.blog.article.ArticleLoadParameter in project celements-blog by celements.

the class BlogServiceTest method testGetArticles.

@Test
public void testGetArticles() throws Exception {
    DocumentReference docRef = new DocumentReference(wikiRef.getName(), "space", "blog");
    ArticleLoadParameter param = new ArticleLoadParameter();
    param.setExecutionDate(new Date(0));
    param.setSubscribedToBlogs(Arrays.asList(docRef));
    expect(xwiki.getDocument(eq(docRef), same(context))).andReturn(new XWikiDocument(docRef)).once();
    expect(xwiki.getXWikiPreference(eq("blog_article_engine"), eq("blog.article.engine"), isNull(String.class), same(getContext()))).andReturn(testEngineHint).once();
    expect(articleEngineMock.getArticles(same(param))).andReturn(Collections.<Article>emptyList()).once();
    replayDefault();
    List<Article> ret = blogService.getArticles(docRef, param);
    verifyDefault();
    assertEquals(0, ret.size());
    assertTrue(new Date(0).before(param.getExecutionDate()));
    Date dateNow = new Date();
    assertTrue(param.getExecutionDate().before(dateNow) || dateNow.equals(param.getExecutionDate()));
    assertEquals(docRef, param.getBlogDocRef());
    assertEquals(0, param.getSubscribedToBlogs().size());
}
Also used : ArticleLoadParameter(com.celements.blog.article.ArticleLoadParameter) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Article(com.celements.blog.article.Article) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date) Test(org.junit.Test)

Example 8 with ArticleLoadParameter

use of com.celements.blog.article.ArticleLoadParameter in project celements-blog by celements.

the class BlogServiceTest method testGetArticles_ALE.

@Test
public void testGetArticles_ALE() throws Exception {
    DocumentReference docRef = new DocumentReference(wikiRef.getName(), "space", "blog");
    ArticleLoadParameter param = new ArticleLoadParameter();
    expect(xwiki.getDocument(eq(docRef), same(context))).andReturn(new XWikiDocument(docRef)).once();
    expect(xwiki.getXWikiPreference(eq("blog_article_engine"), eq("blog.article.engine"), isNull(String.class), same(getContext()))).andReturn(testEngineHint).once();
    ArticleLoadException cause = new ArticleLoadException("");
    expect(articleEngineMock.getArticles(same(param))).andThrow(cause).once();
    replayDefault();
    try {
        blogService.getArticles(docRef, param);
        fail("expecting ALE");
    } catch (ArticleLoadException ale) {
        assertSame(cause, ale);
    }
    verifyDefault();
    assertEquals(docRef, param.getBlogDocRef());
}
Also used : ArticleLoadParameter(com.celements.blog.article.ArticleLoadParameter) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArticleLoadException(com.celements.blog.article.ArticleLoadException) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 9 with ArticleLoadParameter

use of com.celements.blog.article.ArticleLoadParameter in project celements-blog by celements.

the class BlogService method getArticles.

@Override
public List<Article> getArticles(DocumentReference blogConfDocRef, ArticleLoadParameter param) throws ArticleLoadException {
    try {
        if (param == null) {
            param = new ArticleLoadParameter();
        }
        param.setExecutionDate(new Date());
        param.setBlogDocRef(blogConfDocRef);
        param.setSubscribedToBlogs(getSubribedToBlogs(blogConfDocRef));
        List<Article> articles = getArticleEngine().getArticles(param);
        LOGGER.info("getArticles: for " + param + " got " + articles.size() + " articles");
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("getArticles: for " + param + " got: " + articles);
        }
        return Collections.unmodifiableList(articles);
    } catch (XWikiException xwe) {
        throw new ArticleLoadException("Error for '" + blogConfDocRef + "'", xwe);
    } catch (QueryException qexc) {
        throw new ArticleLoadException("Error for '" + blogConfDocRef + "'", qexc);
    }
}
Also used : ArticleLoadParameter(com.celements.blog.article.ArticleLoadParameter) QueryException(org.xwiki.query.QueryException) Article(com.celements.blog.article.Article) ArticleLoadException(com.celements.blog.article.ArticleLoadException) Date(java.util.Date) XWikiException(com.xpn.xwiki.XWikiException)

Example 10 with ArticleLoadParameter

use of com.celements.blog.article.ArticleLoadParameter in project celements-blog by celements.

the class BlogPlugin method getBlogArticles.

/**
 * @deprecated since 1.32 instead use
 *             {@link BlogService#getArticles(DocumentReference, ArticleLoadParameter)}
 * @param blogArticleSpace
 *          Space where the blog's articles are saved.
 * @param subscribedBlogsStr
 *          Comma separated String with all the blog article spaces the blog has subscribed to.
 * @param language
 *          default language
 * @param archiveOnly
 *          Only get articles from the archive (archivedate < now)
 * @param futurOnly
 *          Only get articles that are not yet published (publishdate > now)
 * @param subscribableOnly
 *          Only get articles from subscribed blogs, but not the ones from the blog the user is
 *          on.
 * @param withArchive
 *          Include archived articles in the answer. Has no effect if archiveOnly = true.
 * @param withFutur
 *          Include not yet published articles. Only possible if the page has been saved with
 *          programmingrights or the user has edit right on the article. Has no effect if
 *          futurOnly = true.
 * @param withSubscribable
 *          Include articles from subscribed blogs.
 * @param withSubscribed
 *          Include articles the blog has subscribed to.
 * @param withUnsubscribed
 *          Include articles the blog has unsubscribed from. Only works with edit rights or
 *          programmingrights.
 * @param withUndecided
 *          Include articles the blog has not yet desided about a subscription. Only works with
 *          edit rights or programmingrights.
 * @param checkAccessRights
 *          Do pay attention to the rights. Default = true if no programmingrights.
 * @param context
 * @return
 * @throws XWikiException
 */
@Deprecated
public List<Article> getBlogArticles(String blogArticleSpace, String subscribedBlogsStr, String language, boolean archiveOnly, boolean futurOnly, boolean subscribableOnly, boolean withArchive, boolean withFutur, boolean withSubscribable, boolean withSubscribed, boolean withUnsubscribed, boolean withUndecided, boolean checkAccessRights, XWikiContext context) throws ArticleLoadException {
    try {
        SpaceReference spaceRef = new SpaceReference(blogArticleSpace, new WikiReference(context.getDatabase()));
        DocumentReference blogConfDocRef = getBlogService().getBlogConfigDocRef(spaceRef);
        ArticleLoadParameter param = new ArticleLoadParameter();
        param.setBlogDocRef(blogConfDocRef);
        param.setWithBlogArticles(!subscribableOnly);
        param.setLanguage(language);
        if (withSubscribable) {
            param.setSubscriptionModes(getSubsModes(withSubscribed, withUnsubscribed, withUndecided));
        }
        param.setDateModes(getDateModes(archiveOnly, futurOnly, withArchive, withFutur));
        LOGGER.debug("Got " + param + "' for: blogArticleSpace=" + blogArticleSpace + ", subscribedBlogs=" + subscribedBlogsStr + ", language=" + language + ", archiveOnly=" + archiveOnly + ", futurOnly=" + futurOnly + ", withArchive=" + withArchive + ", withFutur=" + withFutur + ", subscribableOnly=" + subscribableOnly + ", withSubscribable=" + withSubscribable + ", withSubscribed=" + withSubscribed + ", withUnsubscribed=" + withUnsubscribed + ", withUndecided=" + withUndecided + ", checkAccessRights=" + checkAccessRights);
        return getBlogService().getArticles(blogConfDocRef, param);
    } catch (XWikiException xwe) {
        throw new ArticleLoadException(xwe);
    } catch (QueryException qexc) {
        throw new ArticleLoadException(qexc);
    }
}
Also used : ArticleLoadParameter(com.celements.blog.article.ArticleLoadParameter) QueryException(org.xwiki.query.QueryException) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) ArticleLoadException(com.celements.blog.article.ArticleLoadException) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

ArticleLoadParameter (com.celements.blog.article.ArticleLoadParameter)10 DocumentReference (org.xwiki.model.reference.DocumentReference)4 Article (com.celements.blog.article.Article)3 ArticleLoadException (com.celements.blog.article.ArticleLoadException)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 Test (org.junit.Test)3 XWikiException (com.xpn.xwiki.XWikiException)2 Date (java.util.Date)2 QueryException (org.xwiki.query.QueryException)2 Capture (org.easymock.Capture)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1