use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class ActivityProcessor method bet1A0001.
/**
* Bets 1A0001.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/activity/1A0001/bet", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class, CSRFCheck.class, Activity1A0001Validation.class })
@After(adviceClass = StopwatchEndAdvice.class)
public void bet1A0001(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
context.renderJSON().renderFalseResult();
final JSONObject requestJSONObject = (JSONObject) request.getAttribute(Keys.REQUEST);
final int amount = requestJSONObject.optInt(Common.AMOUNT);
final int smallOrLarge = requestJSONObject.optInt(Common.SMALL_OR_LARGE);
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final String fromId = currentUser.optString(Keys.OBJECT_ID);
final JSONObject ret = activityMgmtService.bet1A0001(fromId, amount, smallOrLarge);
if (ret.optBoolean(Keys.STATUS_CODE)) {
String msg = langPropsService.get("activity1A0001BetedLabel");
final String small = langPropsService.get("activity1A0001BetSmallLabel");
final String large = langPropsService.get("activity1A0001BetLargeLabel");
msg = msg.replace("{smallOrLarge}", smallOrLarge == 0 ? small : large);
msg = msg.replace("{point}", String.valueOf(amount));
context.renderTrueResult().renderMsg(msg);
}
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class AdminProcessor method addTag.
/**
* Adds a tag.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/add-tag", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void addTag(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
String title = StringUtils.trim(request.getParameter(Tag.TAG_TITLE));
try {
if (Strings.isEmptyOrNull(title)) {
throw new Exception(langPropsService.get("tagsErrorLabel"));
}
title = Tag.formatTags(title);
if (!Tag.containsWhiteListTags(title)) {
if (!Tag.TAG_TITLE_PATTERN.matcher(title).matches()) {
throw new Exception(langPropsService.get("tagsErrorLabel"));
}
if (title.length() > Tag.MAX_TAG_TITLE_LENGTH) {
throw new Exception(langPropsService.get("tagsErrorLabel"));
}
}
} catch (final Exception e) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, e.getMessage());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
final JSONObject admin = (JSONObject) request.getAttribute(User.USER);
final String userId = admin.optString(Keys.OBJECT_ID);
String tagId;
try {
tagId = tagMgmtService.addTag(userId, title);
} catch (final ServiceException e) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, e.getMessage());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
response.sendRedirect(Latkes.getServePath() + "/admin/tag/" + tagId);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class AdminProcessor method updateArticle.
/**
* Updates an article.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param articleId the specified article id
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/article/{articleId}", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String articleId) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/article.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
JSONObject article = articleQueryService.getArticle(articleId);
final Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
final String name = parameterNames.nextElement();
final String value = request.getParameter(name);
if (name.equals(Article.ARTICLE_REWARD_POINT) || name.equals(Article.ARTICLE_STATUS) || name.equals(Article.ARTICLE_TYPE) || name.equals(Article.ARTICLE_GOOD_CNT) || name.equals(Article.ARTICLE_BAD_CNT) || name.equals(Article.ARTICLE_PERFECT) || name.equals(Article.ARTICLE_ANONYMOUS_VIEW)) {
article.put(name, Integer.valueOf(value));
} else {
article.put(name, value);
}
}
final String articleTags = Tag.formatTags(article.optString(Article.ARTICLE_TAGS));
article.put(Article.ARTICLE_TAGS, articleTags);
articleMgmtService.updateArticleByAdmin(articleId, article);
article = articleQueryService.getArticle(articleId);
dataModel.put(Article.ARTICLE, article);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class AdminProcessor method showReservedWords.
/**
* Shows reserved words.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/reserved-words", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showReservedWords(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/reserved-words.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Common.WORDS, optionQueryService.getReservedWords());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class AdminProcessor method showDomains.
/**
* Shows admin domains.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/domains", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showDomains(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/domains.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 domainTitle = request.getParameter(Common.TITLE);
if (!Strings.isEmptyOrNull(domainTitle)) {
requestJSONObject.put(Domain.DOMAIN_TITLE, domainTitle);
}
final Map<String, Class<?>> domainFields = new HashMap<>();
domainFields.put(Keys.OBJECT_ID, String.class);
domainFields.put(Domain.DOMAIN_TITLE, String.class);
domainFields.put(Domain.DOMAIN_DESCRIPTION, String.class);
domainFields.put(Domain.DOMAIN_ICON_PATH, String.class);
domainFields.put(Domain.DOMAIN_STATUS, String.class);
domainFields.put(Domain.DOMAIN_URI, String.class);
final JSONObject result = domainQueryService.getDomains(requestJSONObject, domainFields);
dataModel.put(Common.ALL_DOMAINS, CollectionUtils.jsonArrayToList(result.optJSONArray(Domain.DOMAINS)));
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