Search in sources :

Example 81 with Before

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

the class VoteProcessor method voteUpArticle.

/**
 * Votes up an article.
 * <p>
 * The request json object:
 * <pre>
 * {
 *   "dataId": ""
 * }
 * </pre>
 * </p>
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/vote/up/article", method = HTTPRequestMethod.POST)
@Before(adviceClass = { LoginCheck.class, PermissionCheck.class })
public void voteUpArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    context.renderJSON();
    final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
    final String dataId = requestJSONObject.optString(Common.DATA_ID);
    final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
    final String userId = currentUser.optString(Keys.OBJECT_ID);
    if (!Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE)) && voteQueryService.isOwn(userId, dataId, Vote.DATA_TYPE_C_ARTICLE)) {
        context.renderFalseResult().renderMsg(langPropsService.get("cantVoteSelfLabel"));
        return;
    }
    final int vote = voteQueryService.isVoted(userId, dataId);
    if (Vote.TYPE_C_UP == vote) {
        voteMgmtService.voteCancel(userId, dataId, Vote.DATA_TYPE_C_ARTICLE);
    } else {
        voteMgmtService.voteUp(userId, dataId, Vote.DATA_TYPE_C_ARTICLE);
        final JSONObject article = articleQueryService.getArticle(dataId);
        final String articleAuthorId = article.optString(Article.ARTICLE_AUTHOR_ID);
        if (!VOTES.contains(userId + dataId) && !userId.equals(articleAuthorId)) {
            final JSONObject notification = new JSONObject();
            notification.put(Notification.NOTIFICATION_USER_ID, articleAuthorId);
            notification.put(Notification.NOTIFICATION_DATA_ID, dataId + "-" + userId);
            notificationMgmtService.addArticleVoteUpNotification(notification);
        }
        VOTES.add(userId + dataId);
    }
    context.renderTrueResult().renderJSONValue(Vote.TYPE, vote);
}
Also used : JSONObject(org.json.JSONObject) Before(org.b3log.latke.servlet.annotation.Before) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 82 with Before

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

the class ActivityProcessor method showEatingSnake.

/**
 * Shows eating snake.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/activity/eating-snake", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void showEatingSnake(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("/activity/eating-snake.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    dataModelService.fillRandomArticles(avatarViewMode, dataModel);
    dataModelService.fillSideHotArticles(avatarViewMode, dataModel);
    dataModelService.fillSideTags(dataModel);
    dataModelService.fillLatestCmts(dataModel);
    final List<JSONObject> maxUsers = activityQueryService.getTopEatingSnakeUsersMax(avatarViewMode, 10);
    dataModel.put("maxUsers", (Object) maxUsers);
    final List<JSONObject> sumUsers = activityQueryService.getTopEatingSnakeUsersSum(avatarViewMode, 10);
    dataModel.put("sumUsers", (Object) sumUsers);
    final JSONObject user = (JSONObject) request.getAttribute(User.USER);
    final String userId = user.optString(Keys.OBJECT_ID);
    final int startPoint = activityQueryService.getEatingSnakeAvgPoint(userId);
    String pointActivityEatingSnake = langPropsService.get("activityStartEatingSnakeTipLabel");
    pointActivityEatingSnake = pointActivityEatingSnake.replace("{point}", String.valueOf(startPoint));
    dataModel.put("activityStartEatingSnakeTipLabel", pointActivityEatingSnake);
}
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 83 with Before

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

the class ActivityProcessor method showGobang.

/**
 * Shows gobang.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/activity/gobang", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void showGobang(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("/activity/gobang.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
    final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
    dataModelService.fillRandomArticles(avatarViewMode, dataModel);
    dataModelService.fillSideHotArticles(avatarViewMode, dataModel);
    dataModelService.fillSideTags(dataModel);
    String pointActivityGobang = langPropsService.get("activityStartGobangTipLabel");
    pointActivityGobang = pointActivityGobang.replace("{point}", String.valueOf(Pointtransfer.TRANSFER_SUM_C_ACTIVITY_GOBANG_START));
    dataModel.put("activityStartGobangTipLabel", pointActivityGobang);
}
Also used : 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 84 with Before

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

the class ActivityProcessor method startEatingSnake.

/**
 * Starts eating snake.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/activity/eating-snake/start", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class, CSRFCheck.class })
@After(adviceClass = StopwatchEndAdvice.class)
public void startEatingSnake(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
    final String fromId = currentUser.optString(Keys.OBJECT_ID);
    final JSONObject ret = activityMgmtService.startEatingSnake(fromId);
    context.renderJSON(ret);
}
Also used : JSONObject(org.json.JSONObject) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 85 with Before

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

the class ActivityProcessor method submitCharacter.

/**
 * Submits character.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 */
@RequestProcessing(value = "/activity/character/submit", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { StopwatchEndAdvice.class })
public void submitCharacter(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) {
    context.renderJSON().renderFalseResult();
    JSONObject requestJSONObject;
    try {
        requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
        request.setAttribute(Keys.REQUEST, requestJSONObject);
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, "Submits character failed", e);
        context.renderJSON(false).renderMsg(langPropsService.get("activityCharacterRecognizeFailedLabel"));
        return;
    }
    final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
    final String userId = currentUser.optString(Keys.OBJECT_ID);
    final String dataURL = requestJSONObject.optString("dataURL");
    final String dataPart = StringUtils.substringAfter(dataURL, ",");
    final String character = requestJSONObject.optString("character");
    final JSONObject result = activityMgmtService.submitCharacter(userId, dataPart, character);
    context.renderJSON(result);
}
Also used : JSONObject(org.json.JSONObject) 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