use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class ErrorProcessor method handleErrorPage.
/**
* Handles the error.
*
* @param context the specified context
* @param request the specified HTTP servlet request
* @param response the specified HTTP servlet response
* @param statusCode the specified status code
* @throws Exception exception
*/
@RequestProcessing(value = "/error/{statusCode}", method = { HTTPRequestMethod.GET, HTTPRequestMethod.POST })
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void handleErrorPage(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String statusCode) throws Exception {
if (StringUtils.equals("GET", request.getMethod())) {
final String requestURI = request.getRequestURI();
final String templateName = statusCode + ".ftl";
LOGGER.log(Level.TRACE, "Shows error page[requestURI={0}, templateName={1}]", requestURI, templateName);
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
renderer.setTemplateName("error/" + templateName);
context.setRenderer(renderer);
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.putAll(langPropsService.getAll(Locales.getLocale()));
dataModelService.fillHeaderAndFooter(request, response, dataModel);
if (HttpServletResponse.SC_FORBIDDEN == Integer.valueOf(statusCode)) {
dataModelService.fillSideHotArticles(UserExt.USER_AVATAR_VIEW_MODE_C_ORIGINAL, dataModel);
dataModelService.fillRandomArticles(UserExt.USER_AVATAR_VIEW_MODE_C_ORIGINAL, dataModel);
dataModelService.fillSideTags(dataModel);
}
} else {
context.renderJSON().renderMsg(statusCode);
}
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class FollowProcessor method followUser.
/**
* Follows a user.
* <p>
* The request json object:
* <pre>
* {
* "followingId": ""
* }
* </pre>
* </p>
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/follow/user", method = HTTPRequestMethod.POST)
@Before(adviceClass = LoginCheck.class)
public void followUser(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
context.renderJSON();
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
final String followingUserId = requestJSONObject.optString(Follow.FOLLOWING_ID);
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final String followerUserId = currentUser.optString(Keys.OBJECT_ID);
followMgmtService.followUser(followerUserId, followingUserId);
if (!FOLLOWS.contains(followingUserId + followerUserId)) {
final JSONObject notification = new JSONObject();
notification.put(Notification.NOTIFICATION_USER_ID, followingUserId);
notification.put(Notification.NOTIFICATION_DATA_ID, followerUserId);
notificationMgmtService.addNewFollowerNotification(notification);
}
FOLLOWS.add(followingUserId + followerUserId);
context.renderTrueResult();
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class FollowProcessor method unfollowArticle.
/**
* Unfollows an article.
* <p>
* The request json object:
* <pre>
* {
* "followingId": ""
* }
* </pre>
* </p>
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/follow/article", method = HTTPRequestMethod.DELETE)
@Before(adviceClass = LoginCheck.class)
public void unfollowArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
context.renderJSON();
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
final String followingArticleId = requestJSONObject.optString(Follow.FOLLOWING_ID);
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final String followerUserId = currentUser.optString(Keys.OBJECT_ID);
followMgmtService.unfollowArticle(followerUserId, followingArticleId);
context.renderTrueResult();
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class FollowProcessor method unwatchArticle.
/**
* Unwatches an article.
* <p>
* The request json object:
* <pre>
* {
* "followingId": ""
* }
* </pre>
* </p>
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/follow/article-watch", method = HTTPRequestMethod.DELETE)
@Before(adviceClass = LoginCheck.class)
public void unwatchArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
context.renderJSON();
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
final String followingArticleId = requestJSONObject.optString(Follow.FOLLOWING_ID);
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final String followerUserId = currentUser.optString(Keys.OBJECT_ID);
followMgmtService.unwatchArticle(followerUserId, followingArticleId);
context.renderTrueResult();
}
use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.
the class StatisticProcessor method loadStatData.
/**
* Loads statistic data.
*
* @param request the specified HTTP servlet request
* @param response the specified HTTP servlet response
* @param context the specified HTTP request context
* @throws Exception exception
*/
@RequestProcessing(value = "/cron/stat", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = StopwatchEndAdvice.class)
public void loadStatData(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
final Date end = new Date();
final Date dayStart = DateUtils.addDays(end, -30);
monthDays.clear();
userCnts.clear();
articleCnts.clear();
commentCnts.clear();
months.clear();
historyArticleCnts.clear();
historyCommentCnts.clear();
historyUserCnts.clear();
for (int i = 0; i < 31; i++) {
final Date day = DateUtils.addDays(dayStart, i);
monthDays.add(DateFormatUtils.format(day, "yyyy-MM-dd"));
final int userCnt = userQueryService.getUserCntInDay(day);
userCnts.add(userCnt);
final int articleCnt = articleQueryService.getArticleCntInDay(day);
articleCnts.add(articleCnt);
final int commentCnt = commentQueryService.getCommentCntInDay(day);
commentCnts.add(commentCnt);
}
final JSONObject firstAdmin = userQueryService.getAdmins().get(0);
final long monthStartTime = Times.getMonthStartTime(firstAdmin.optLong(Keys.OBJECT_ID));
final Date monthStart = new Date(monthStartTime);
int i = 1;
while (true) {
final Date month = DateUtils.addMonths(monthStart, i);
if (month.after(end)) {
break;
}
i++;
months.add(DateFormatUtils.format(month, "yyyy-MM"));
final int userCnt = userQueryService.getUserCntInMonth(month);
historyUserCnts.add(userCnt);
final int articleCnt = articleQueryService.getArticleCntInMonth(month);
historyArticleCnts.add(articleCnt);
final int commentCnt = commentQueryService.getCommentCntInMonth(month);
historyCommentCnts.add(commentCnt);
}
}
Aggregations