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