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