Search in sources :

Example 1 with PageRepository

use of org.b3log.solo.repository.PageRepository in project solo by b3log.

the class PageRepositoryImplTestCase method getByOrder.

/**
     * Get By Order.
     * 
     * @throws Exception exception
     */
@Test(dependsOnMethods = { "add", "getMaxOrder" })
public void getByOrder() throws Exception {
    final PageRepository pageRepository = getPageRepository();
    final JSONObject page1 = pageRepository.getByOrder(0);
    Assert.assertNotNull(page1);
    Assert.assertEquals(page1.getString(Page.PAGE_TITLE), "page1 title");
    Assert.assertNull(pageRepository.getByOrder(Integer.MIN_VALUE));
}
Also used : JSONObject(org.json.JSONObject) PageRepository(org.b3log.solo.repository.PageRepository) Test(org.testng.annotations.Test)

Example 2 with PageRepository

use of org.b3log.solo.repository.PageRepository in project solo by b3log.

the class PageRepositoryImplTestCase method add.

/**
     * Adds successfully.
     * 
     * @throws Exception exception
     */
@Test
public void add() throws Exception {
    final PageRepository pageRepository = getPageRepository();
    Assert.assertEquals(pageRepository.getMaxOrder(), -1);
    final JSONObject page = new JSONObject();
    page.put(Page.PAGE_COMMENT_COUNT, 0);
    page.put(Page.PAGE_CONTENT, "page1 content");
    page.put(Page.PAGE_ORDER, 0);
    page.put(Page.PAGE_PERMALINK, "page1 permalink");
    page.put(Page.PAGE_TITLE, "page1 title");
    page.put(Page.PAGE_COMMENTABLE, true);
    page.put(Page.PAGE_TYPE, "page");
    page.put(Page.PAGE_OPEN_TARGET, "_self");
    page.put(Page.PAGE_EDITOR_TYPE, "");
    final Transaction transaction = pageRepository.beginTransaction();
    pageRepository.add(page);
    transaction.commit();
    final List<JSONObject> pages = pageRepository.getPages();
    Assert.assertNotNull(pages);
    Assert.assertEquals(pages.size(), 1);
}
Also used : JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) PageRepository(org.b3log.solo.repository.PageRepository) Test(org.testng.annotations.Test)

Example 3 with PageRepository

use of org.b3log.solo.repository.PageRepository 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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONObject(org.json.JSONObject) PageRepository(org.b3log.solo.repository.PageRepository) ArticleQueryService(org.b3log.solo.service.ArticleQueryService) HttpServletResponse(javax.servlet.http.HttpServletResponse) ArticleRepository(org.b3log.solo.repository.ArticleRepository) RepositoryException(org.b3log.latke.repository.RepositoryException) ServletException(javax.servlet.ServletException) RepositoryException(org.b3log.latke.repository.RepositoryException) IOException(java.io.IOException) LatkeBeanManager(org.b3log.latke.ioc.LatkeBeanManager)

Example 4 with PageRepository

use of org.b3log.solo.repository.PageRepository in project solo by b3log.

the class PageProcessorTestCase method addPage.

private JSONObject addPage() throws Exception {
    final PageMgmtService pageMgmtService = getPageMgmtService();
    final JSONObject requestJSONObject = new JSONObject();
    final JSONObject page = new JSONObject();
    requestJSONObject.put(Page.PAGE, page);
    page.put(Page.PAGE_CONTENT, "page1 content");
    page.put(Page.PAGE_PERMALINK, "pagepermalink");
    page.put(Page.PAGE_TITLE, "page1 title");
    page.put(Page.PAGE_COMMENTABLE, true);
    page.put(Page.PAGE_TYPE, "page");
    page.put(Page.PAGE_OPEN_TARGET, "_self");
    final String pageId = pageMgmtService.addPage(requestJSONObject);
    final PageRepository pageRepository = getPageRepository();
    return pageRepository.get(pageId);
}
Also used : PageMgmtService(org.b3log.solo.service.PageMgmtService) JSONObject(org.json.JSONObject) PageRepository(org.b3log.solo.repository.PageRepository)

Example 5 with PageRepository

use of org.b3log.solo.repository.PageRepository in project solo by b3log.

the class PageRepositoryImplTestCase method getMaxOrder.

/**
     * Get Max Order.
     * 
     * @throws Exception exception
     */
@Test(dependsOnMethods = "add")
public void getMaxOrder() throws Exception {
    final PageRepository pageRepository = getPageRepository();
    final JSONObject page = new JSONObject();
    page.put(Page.PAGE_COMMENT_COUNT, 0);
    page.put(Page.PAGE_CONTENT, "page2 content");
    page.put(Page.PAGE_ORDER, 1);
    page.put(Page.PAGE_PERMALINK, "page2 permalink");
    page.put(Page.PAGE_TITLE, "page2 title");
    page.put(Page.PAGE_COMMENTABLE, true);
    page.put(Page.PAGE_TYPE, "page");
    page.put(Page.PAGE_OPEN_TARGET, "_self");
    page.put(Page.PAGE_EDITOR_TYPE, "");
    final Transaction transaction = pageRepository.beginTransaction();
    pageRepository.add(page);
    transaction.commit();
    final int maxOrder = pageRepository.getMaxOrder();
    Assert.assertEquals(maxOrder, 1);
}
Also used : JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) PageRepository(org.b3log.solo.repository.PageRepository) Test(org.testng.annotations.Test)

Aggregations

PageRepository (org.b3log.solo.repository.PageRepository)7 JSONObject (org.json.JSONObject)7 Test (org.testng.annotations.Test)5 Transaction (org.b3log.latke.repository.Transaction)3 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 LatkeBeanManager (org.b3log.latke.ioc.LatkeBeanManager)1 RepositoryException (org.b3log.latke.repository.RepositoryException)1 ArticleRepository (org.b3log.solo.repository.ArticleRepository)1 ArticleQueryService (org.b3log.solo.service.ArticleQueryService)1 PageMgmtService (org.b3log.solo.service.PageMgmtService)1