Search in sources :

Example 1 with Article

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

the class BlogPlugin method getNeighbourArticle.

/**
 * Get the previous or next article in the blog. Does not take into account subscribed blogs or
 * archived articles.
 *
 * @param article
 * @param next
 *          true gets the next, false the previous article
 * @return
 */
public Article getNeighbourArticle(Article article, boolean next, XWikiContext context) {
    String aSpace = article.getDocName().substring(0, article.getDocName().indexOf('.'));
    List<Article> articles = null;
    try {
        articles = getBlogArticles(aSpace, "", context.getLanguage(), false, false, false, false, true, true, true, false, true, true, context);
    } catch (ArticleLoadException exc) {
        LOGGER.error("could not get articles for blog", exc);
    }
    Article nArticle = null;
    if (articles != null) {
        for (int i = 0; i < articles.size(); i++) {
            Article tmpArt = articles.get(i);
            if (article.getDocName().equals(tmpArt.getDocName())) {
                if (next) {
                    if ((i + 1) == articles.size()) {
                        nArticle = articles.get(0);
                    } else {
                        nArticle = articles.get(i + 1);
                    }
                } else {
                    if (i == 0) {
                        nArticle = articles.get(articles.size() - 1);
                    } else {
                        nArticle = articles.get(i - 1);
                    }
                }
            }
        }
    }
    return nArticle;
}
Also used : Article(com.celements.blog.article.Article) ArticleLoadException(com.celements.blog.article.ArticleLoadException)

Example 2 with Article

use of com.celements.blog.article.Article 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 3 with Article

use of com.celements.blog.article.Article 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 4 with Article

use of com.celements.blog.article.Article 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)

Aggregations

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