Search in sources :

Example 1 with ArticleLoadException

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

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

the class BlogService method getArticleEngine.

private IArticleEngineRole getArticleEngine() throws ArticleLoadException {
    IArticleEngineRole engine = null;
    String engineHint = getContext().getWiki().getXWikiPreference("blog_article_engine", "blog.article.engine", null, getContext());
    try {
        Map<String, IArticleEngineRole> engineMap = componentManager.lookupMap(IArticleEngineRole.class);
        engine = engineMap.get(engineHint);
        if (engine == null) {
            engine = engineMap.get("default");
        }
    } catch (ComponentLookupException exc) {
        LOGGER.error("Error looking up engine components", exc);
    }
    if (engine != null) {
        LOGGER.info("getArticleEngine: got engine '" + engine + "' for hint '" + engineHint + "'");
        return engine;
    } else {
        throw new ArticleLoadException("Unable to load engine for hint");
    }
}
Also used : IArticleEngineRole(com.celements.blog.article.IArticleEngineRole) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ArticleLoadException(com.celements.blog.article.ArticleLoadException)

Example 3 with ArticleLoadException

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

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

the class BlogServiceTest method testGetArticles_ALEfromXWE.

@Test
public void testGetArticles_ALEfromXWE() throws Exception {
    DocumentReference docRef = new DocumentReference(wikiRef.getName(), "space", "blog");
    XWikiException cause = new XWikiException();
    expect(xwiki.getDocument(eq(docRef), same(context))).andThrow(cause).once();
    replayDefault();
    try {
        blogService.getArticles(docRef, null);
        fail("expecting ALE");
    } catch (ArticleLoadException ale) {
        assertSame(cause, ale.getCause());
    }
    verifyDefault();
}
Also used : ArticleLoadException(com.celements.blog.article.ArticleLoadException) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) Test(org.junit.Test)

Example 5 with ArticleLoadException

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

ArticleLoadException (com.celements.blog.article.ArticleLoadException)6 ArticleLoadParameter (com.celements.blog.article.ArticleLoadParameter)3 XWikiException (com.xpn.xwiki.XWikiException)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 Article (com.celements.blog.article.Article)2 Test (org.junit.Test)2 QueryException (org.xwiki.query.QueryException)2 IArticleEngineRole (com.celements.blog.article.IArticleEngineRole)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 Date (java.util.Date)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1