use of org.b3log.solo.repository.ArticleRepository in project solo by b3log.
the class ArticleRepositoryImplTestCase method getRandomly.
/**
* Get Randomly.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = { "add", "previousAndNext", "getMostCommentArticles", "getMostViewCountArticles" })
public void getRandomly() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
List<JSONObject> articles = articleRepository.getRandomly(3);
Assert.assertNotNull(articles);
}
use of org.b3log.solo.repository.ArticleRepository in project solo by b3log.
the class ArticleRepositoryImplTestCase method add.
/**
* Adds successfully.
*
* @throws Exception exception
*/
@Test
public void add() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
final JSONObject article = new JSONObject();
article.put(Article.ARTICLE_TITLE, "article title1");
article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2");
article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com");
article.put(Article.ARTICLE_COMMENT_COUNT, 0);
article.put(Article.ARTICLE_VIEW_COUNT, 0);
article.put(Article.ARTICLE_CONTENT, "article content");
article.put(Article.ARTICLE_PERMALINK, "article permalink1");
article.put(Article.ARTICLE_HAD_BEEN_PUBLISHED, true);
article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_CREATE_DATE, new Date());
article.put(Article.ARTICLE_UPDATE_DATE, new Date());
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.ARTICLE_SIGN_ID, "1");
article.put(Article.ARTICLE_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_EDITOR_TYPE, "");
final Transaction transaction = articleRepository.beginTransaction();
articleRepository.add(article);
transaction.commit();
final JSONArray results = articleRepository.getByAuthorEmail("test@gmail.com", 1, Integer.MAX_VALUE).getJSONArray(Keys.RESULTS);
Assert.assertEquals(results.length(), 1);
}
use of org.b3log.solo.repository.ArticleRepository in project solo by b3log.
the class ArticleRepositoryImplTestCase method getMostViewCountArticles.
/**
* Get Most View Count Articles
*
* @throws Exception exception
*/
@Test(dependsOnMethods = { "add", "previousAndNext", "getMostCommentArticles" })
public void getMostViewCountArticles() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
final JSONObject article = new JSONObject();
article.put(Article.ARTICLE_TITLE, "article title4");
article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2");
article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com");
article.put(Article.ARTICLE_COMMENT_COUNT, 3);
article.put(Article.ARTICLE_VIEW_COUNT, 3);
article.put(Article.ARTICLE_CONTENT, "article content");
article.put(Article.ARTICLE_PERMALINK, "article permalink4");
article.put(Article.ARTICLE_HAD_BEEN_PUBLISHED, false);
// Unpublished
article.put(Article.ARTICLE_IS_PUBLISHED, false);
article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_CREATE_DATE, new Date());
article.put(Article.ARTICLE_UPDATE_DATE, new Date());
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.ARTICLE_SIGN_ID, "1");
article.put(Article.ARTICLE_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_EDITOR_TYPE, "");
final Transaction transaction = articleRepository.beginTransaction();
articleRepository.add(article);
transaction.commit();
List<JSONObject> mostViewCountArticles = articleRepository.getMostViewCountArticles(2);
Assert.assertNotNull(mostViewCountArticles);
Assert.assertEquals(mostViewCountArticles.size(), 2);
Assert.assertEquals(mostViewCountArticles.get(0).getInt(Article.ARTICLE_VIEW_COUNT), 2);
Assert.assertEquals(mostViewCountArticles.get(1).getInt(Article.ARTICLE_VIEW_COUNT), 1);
mostViewCountArticles = articleRepository.getMostViewCountArticles(1);
Assert.assertNotNull(mostViewCountArticles);
Assert.assertEquals(mostViewCountArticles.size(), 1);
Assert.assertEquals(mostViewCountArticles.get(0).getInt(Article.ARTICLE_VIEW_COUNT), 2);
}
use of org.b3log.solo.repository.ArticleRepository in project solo by b3log.
the class PermalinkFilter method doFilter.
/**
* Tries to dispatch request to article processor.
*
* @param request the specified request
* @param response the specified response
* @param chain filter chain
* @throws IOException io exception
* @throws ServletException servlet exception
*/
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
final String requestURI = httpServletRequest.getRequestURI();
LOGGER.log(Level.DEBUG, "Request URI[{0}]", requestURI);
final String contextPath = Latkes.getContextPath();
final String permalink = StringUtils.substringAfter(requestURI, contextPath);
if (PermalinkQueryService.invalidPermalinkFormat(permalink)) {
LOGGER.log(Level.DEBUG, "Skip filter request[URI={0}]", permalink);
chain.doFilter(request, response);
return;
}
JSONObject article;
JSONObject page = null;
final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
try {
final ArticleRepository articleRepository = beanManager.getReference(ArticleRepositoryImpl.class);
article = articleRepository.getByPermalink(permalink);
if (null == article) {
final PageRepository pageRepository = beanManager.getReference(PageRepositoryImpl.class);
page = pageRepository.getByPermalink(permalink);
}
if (null == page && null == article) {
LOGGER.log(Level.DEBUG, "Not found article/page with permalink[{0}]", permalink);
chain.doFilter(request, response);
return;
}
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Processes article permalink filter failed", e);
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// If requests an article and the article need view passowrd, sends redirect to the password form
final ArticleQueryService articleQueryService = beanManager.getReference(ArticleQueryService.class);
if (null != article && articleQueryService.needViewPwd(httpServletRequest, article)) {
try {
httpServletResponse.sendRedirect(Latkes.getServePath() + "/console/article-pwd?articleId=" + article.optString(Keys.OBJECT_ID));
return;
} catch (final Exception e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
dispatchToArticleOrPageProcessor(request, response, article, page);
}
Aggregations