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