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;
}
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");
}
}
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());
}
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();
}
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);
}
}
Aggregations