Search in sources :

Example 6 with TextHTMLRenderer

use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.

the class RepairProcessor method removeAllDataGET.

/**
     * Shows remove all data page.
     *
     * @param context the specified context
     * @param request the specified HTTP servlet request
     */
@RequestProcessing(value = "/rm-all-data.do", method = HTTPRequestMethod.GET)
public void removeAllDataGET(final HTTPRequestContext context, final HttpServletRequest request) {
    final TextHTMLRenderer renderer = new TextHTMLRenderer();
    context.setRenderer(renderer);
    try {
        final StringBuilder htmlBuilder = new StringBuilder();
        htmlBuilder.append("<html><head><title>WARNING!</title>");
        htmlBuilder.append("<script type='text/javascript'");
        htmlBuilder.append("src='").append(Latkes.getStaticServer()).append("/js/lib/jquery/jquery.min.js'");
        htmlBuilder.append("></script></head><body>");
        htmlBuilder.append("<button id='ok' onclick='removeData()'>");
        htmlBuilder.append("Continue to delete ALL DATA</button></body>");
        htmlBuilder.append("<script type='text/javascript'>");
        htmlBuilder.append("function removeData() {");
        htmlBuilder.append("$.ajax({type: 'POST',url:'").append(Latkes.getContextPath()).append("/rm-all-data.do',");
        htmlBuilder.append("dataType: 'text/html',success: function(result){");
        htmlBuilder.append("$('html').html(result);}});}</script></html>");
        renderer.setContent(htmlBuilder.toString());
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, e.getMessage(), e);
        try {
            context.getResponse().sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
Also used : IOException(java.io.IOException) TextHTMLRenderer(org.b3log.latke.servlet.renderer.TextHTMLRenderer) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 7 with TextHTMLRenderer

use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.

the class RepairProcessor method restoreStat.

/**
     * Restores the statistics.
     *
     * <p>
     * <ul>
     * <li>Uses the value of {@link Statistic#STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT} for
     * {@link Statistic#STATISTIC_BLOG_COMMENT_COUNT}</li>
     * <li>Uses the value of {@link Statistic#STATISTIC_PUBLISHED_ARTICLE_COUNT} for
     * {@link Statistic#STATISTIC_BLOG_ARTICLE_COUNT}</li>
     * </ul>
     * </p>
     *
     * @param context the specified context
     */
@RequestProcessing(value = "/fix/restore-stat.do", method = HTTPRequestMethod.GET)
public void restoreStat(final HTTPRequestContext context) {
    final TextHTMLRenderer renderer = new TextHTMLRenderer();
    context.setRenderer(renderer);
    try {
        final JSONObject statistic = statisticQueryService.getStatistic();
        if (statistic.has(Statistic.STATISTIC_BLOG_COMMENT_COUNT) && statistic.has(Statistic.STATISTIC_BLOG_ARTICLE_COUNT)) {
            LOGGER.info("No need for repairing statistic");
            renderer.setContent("No need for repairing statistic.");
            return;
        }
        if (!statistic.has(Statistic.STATISTIC_BLOG_COMMENT_COUNT)) {
            statistic.put(Statistic.STATISTIC_BLOG_COMMENT_COUNT, statistic.getInt(Statistic.STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT));
        }
        if (!statistic.has(Statistic.STATISTIC_BLOG_ARTICLE_COUNT)) {
            statistic.put(Statistic.STATISTIC_BLOG_ARTICLE_COUNT, statistic.getInt(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT));
        }
        statisticMgmtService.updateStatistic(statistic);
        renderer.setContent("Restores statistic succeeded.");
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, e.getMessage(), e);
        renderer.setContent("Restores statistics failed, error msg[" + e.getMessage() + "]");
    }
}
Also used : JSONObject(org.json.JSONObject) TextHTMLRenderer(org.b3log.latke.servlet.renderer.TextHTMLRenderer) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Aggregations

RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)7 TextHTMLRenderer (org.b3log.latke.servlet.renderer.TextHTMLRenderer)7 IOException (java.io.IOException)6 ExecutionException (java.util.concurrent.ExecutionException)6 JSONObject (org.json.JSONObject)4 JSONArray (org.json.JSONArray)2 Message (org.b3log.latke.mail.MailService.Message)1 Transactional (org.b3log.latke.repository.annotation.Transactional)1 ServiceException (org.b3log.latke.service.ServiceException)1 ArchiveDateArticleRepositoryImpl (org.b3log.solo.repository.impl.ArchiveDateArticleRepositoryImpl)1 ArchiveDateRepositoryImpl (org.b3log.solo.repository.impl.ArchiveDateRepositoryImpl)1 ArticleRepositoryImpl (org.b3log.solo.repository.impl.ArticleRepositoryImpl)1 CommentRepositoryImpl (org.b3log.solo.repository.impl.CommentRepositoryImpl)1 LinkRepositoryImpl (org.b3log.solo.repository.impl.LinkRepositoryImpl)1 OptionRepositoryImpl (org.b3log.solo.repository.impl.OptionRepositoryImpl)1 PageRepositoryImpl (org.b3log.solo.repository.impl.PageRepositoryImpl)1 PluginRepositoryImpl (org.b3log.solo.repository.impl.PluginRepositoryImpl)1 StatisticRepositoryImpl (org.b3log.solo.repository.impl.StatisticRepositoryImpl)1 TagArticleRepositoryImpl (org.b3log.solo.repository.impl.TagArticleRepositoryImpl)1 TagRepositoryImpl (org.b3log.solo.repository.impl.TagRepositoryImpl)1