Search in sources :

Example 96 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method showInvitecode.

/**
 * Shows an invitecode.
 *
 * @param context      the specified context
 * @param request      the specified request
 * @param response     the specified response
 * @param invitecodeId the specified invitecode id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/invitecode/{invitecodeId}", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showInvitecode(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String invitecodeId) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/invitecode.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final JSONObject invitecode = invitecodeQueryService.getInvitecodeById(invitecodeId);
    dataModel.put(Invitecode.INVITECODE, invitecode);
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 97 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method updateMisc.

/**
 * Updates admin miscellaneous.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/misc", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateMisc(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/misc.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    List<JSONObject> misc = new ArrayList<>();
    final Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        final String name = parameterNames.nextElement();
        final String value = request.getParameter(name);
        final JSONObject option = new JSONObject();
        option.put(Keys.OBJECT_ID, name);
        option.put(Option.OPTION_VALUE, value);
        option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_MISC);
        misc.add(option);
    }
    for (final JSONObject option : misc) {
        optionMgmtService.updateOption(option.getString(Keys.OBJECT_ID), option);
    }
    misc = optionQueryService.getMisc();
    dataModel.put(Option.OPTIONS, misc);
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 98 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method showComments.

/**
 * Shows admin comments.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/comments", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showComments(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/comments.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    final int pageNum = Integer.valueOf(pageNumStr);
    final int pageSize = PAGE_SIZE;
    final int windowSize = WINDOW_SIZE;
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, pageSize);
    requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, windowSize);
    final Map<String, Class<?>> commentFields = new HashMap<>();
    commentFields.put(Keys.OBJECT_ID, String.class);
    commentFields.put(Comment.COMMENT_CREATE_TIME, String.class);
    commentFields.put(Comment.COMMENT_AUTHOR_ID, String.class);
    commentFields.put(Comment.COMMENT_ON_ARTICLE_ID, String.class);
    commentFields.put(Comment.COMMENT_SHARP_URL, String.class);
    commentFields.put(Comment.COMMENT_STATUS, Integer.class);
    commentFields.put(Comment.COMMENT_CONTENT, String.class);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    final JSONObject result = commentQueryService.getComments(avatarViewMode, requestJSONObject, commentFields);
    dataModel.put(Comment.COMMENTS, CollectionUtils.jsonArrayToList(result.optJSONArray(Comment.COMMENTS)));
    final JSONObject pagination = result.optJSONObject(Pagination.PAGINATION);
    final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT);
    final JSONArray pageNums = pagination.optJSONArray(Pagination.PAGINATION_PAGE_NUMS);
    dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.opt(0));
    dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.opt(pageNums.length() - 1));
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, CollectionUtils.jsonArrayToList(pageNums));
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 99 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method updateComment.

/**
 * Updates a comment.
 *
 * @param context   the specified context
 * @param request   the specified request
 * @param response  the specified response
 * @param commentId the specified comment id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/comment/{commentId}", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateComment(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String commentId) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/comment.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    JSONObject comment = commentQueryService.getComment(commentId);
    final Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        final String name = parameterNames.nextElement();
        final String value = request.getParameter(name);
        if (name.equals(Comment.COMMENT_STATUS) || name.equals(Comment.COMMENT_GOOD_CNT) || name.equals(Comment.COMMENT_BAD_CNT)) {
            comment.put(name, Integer.valueOf(value));
        } else {
            comment.put(name, value);
        }
    }
    commentMgmtService.updateComment(commentId, comment);
    comment = commentQueryService.getComment(commentId);
    dataModel.put(Comment.COMMENT, comment);
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 100 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method showTags.

/**
 * Shows admin tags.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/tags", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showTags(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/tags.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    String pageNumStr = request.getParameter("p");
    if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
        pageNumStr = "1";
    }
    final int pageNum = Integer.valueOf(pageNumStr);
    final int pageSize = PAGE_SIZE;
    final int windowSize = WINDOW_SIZE;
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, pageSize);
    requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, windowSize);
    final String tagTitle = request.getParameter(Common.TITLE);
    if (!Strings.isEmptyOrNull(tagTitle)) {
        requestJSONObject.put(Tag.TAG_TITLE, tagTitle);
    }
    final Map<String, Class<?>> tagFields = new HashMap<>();
    tagFields.put(Keys.OBJECT_ID, String.class);
    tagFields.put(Tag.TAG_TITLE, String.class);
    tagFields.put(Tag.TAG_DESCRIPTION, String.class);
    tagFields.put(Tag.TAG_ICON_PATH, String.class);
    tagFields.put(Tag.TAG_COMMENT_CNT, Integer.class);
    tagFields.put(Tag.TAG_REFERENCE_CNT, Integer.class);
    tagFields.put(Tag.TAG_FOLLOWER_CNT, Integer.class);
    tagFields.put(Tag.TAG_STATUS, Integer.class);
    tagFields.put(Tag.TAG_GOOD_CNT, Integer.class);
    tagFields.put(Tag.TAG_BAD_CNT, Integer.class);
    tagFields.put(Tag.TAG_URI, String.class);
    tagFields.put(Tag.TAG_CSS, String.class);
    final JSONObject result = tagQueryService.getTags(requestJSONObject, tagFields);
    dataModel.put(Tag.TAGS, CollectionUtils.jsonArrayToList(result.optJSONArray(Tag.TAGS)));
    final JSONObject pagination = result.optJSONObject(Pagination.PAGINATION);
    final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT);
    final JSONArray pageNums = pagination.optJSONArray(Pagination.PAGINATION_PAGE_NUMS);
    dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.opt(0));
    dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.opt(pageNums.length() - 1));
    dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
    dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
    dataModel.put(Pagination.PAGINATION_PAGE_NUMS, CollectionUtils.jsonArrayToList(pageNums));
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Aggregations

Before (org.b3log.latke.servlet.annotation.Before)169 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)169 JSONObject (org.json.JSONObject)166 After (org.b3log.latke.servlet.annotation.After)135 AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)105 ServiceException (org.b3log.latke.service.ServiceException)37 Date (java.util.Date)13 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 JSONArray (org.json.JSONArray)8 Auth (com.qiniu.util.Auth)7 ParseException (java.text.ParseException)6 List (java.util.List)6 ServletException (javax.servlet.ServletException)3 Configuration (com.qiniu.storage.Configuration)1 UploadManager (com.qiniu.storage.UploadManager)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1