use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class TagConsole method removeUnusedTags.
/**
* Removes all unused tags.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "msg": ""
* }
* </pre>
* </p>
*
* @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @throws IOException io exception
*/
@RequestProcessing(value = "/console/tag/unused", method = HTTPRequestMethod.DELETE)
public void removeUnusedTags(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws IOException {
if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
try {
tagMgmtService.removeUnusedTags();
jsonObject.put(Keys.MSG, langPropsService.get("removeSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Removes unused tags failed", e);
jsonObject.put(Keys.MSG, langPropsService.get("removeFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class UserConsole method getUsers.
/**
* Gets users by the specified request json object.
* <p>
* The request URI contains the pagination arguments. For example, the request URI is /console/users/1/10/20, means
* the current page is 1, the page size is 10, and the window size is 20.
* </p>
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "pagination": {
* "paginationPageCount": 100,
* "paginationPageNums": [1, 2, 3, 4, 5]
* },
* "users": [{
* "oId": "",
* "userName": "",
* "userEmail": "",
* "userPassword": "",
* "roleName": ""
* }, ....]
* "sc": "GET_USERS_SUCC"
* }
* </pre>
* </p>
*
* @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 = "/console/users/*/*/*", /* Requests.PAGINATION_PATH_PATTERN */
method = HTTPRequestMethod.GET)
public void getUsers(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
try {
final String requestURI = request.getRequestURI();
final String path = requestURI.substring((Latkes.getContextPath() + "/console/users/").length());
final JSONObject requestJSONObject = Requests.buildPaginationRequest(path);
final JSONObject result = userQueryService.getUsers(requestJSONObject);
result.put(Keys.STATUS_CODE, true);
renderer.setJSONObject(result);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class UserConsole method changeUserRole.
/**
* Change a user role.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "msg": ""
* }
* </pre>
* </p>
*
* @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 = "/console/changeRole/*", method = HTTPRequestMethod.GET)
public void changeUserRole(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
try {
final String userId = request.getRequestURI().substring((Latkes.getContextPath() + "/console/changeRole/").length());
userMgmtService.changeRole(userId);
jsonObject.put(Keys.STATUS_CODE, true);
jsonObject.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
jsonObject.put(Keys.STATUS_CODE, false);
jsonObject.put(Keys.MSG, langPropsService.get("removeFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class ArticleConsole method cancelPublishArticle.
/**
* Cancels publish an article by the specified request.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "msg": ""
* }
* </pre>
* </p>
*
* @param context the specified http request context
* @param request the specified http servlet request
* @param response the specified http servlet response
* @throws Exception exception
*/
@RequestProcessing(value = "/console/article/unpublish/*", method = HTTPRequestMethod.PUT)
public void cancelPublishArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
try {
final String articleId = request.getRequestURI().substring((Latkes.getContextPath() + "/console/article/unpublish/").length());
if (!articleQueryService.canAccessArticle(articleId, request)) {
ret.put(Keys.STATUS_CODE, false);
ret.put(Keys.MSG, langPropsService.get("forbiddenLabel"));
return;
}
articleMgmtService.cancelPublishArticle(articleId);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("unPulbishSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.STATUS_CODE, false);
jsonObject.put(Keys.MSG, langPropsService.get("unPulbishFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class ArticleConsole method getArticle.
/**
* Gets an article by the specified request json object.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "oId": "",
* "articleTitle": "",
* "articleAbstract": "",
* "articleContent": "",
* "articlePermalink": "",
* "articleHadBeenPublished": boolean,
* "articleTags": [{
* "oId": "",
* "tagTitle": ""
* }, ....],
* "articleSignId": "",
* "signs": [{
* "oId": "",
* "signHTML": ""
* }, ....]
* "sc": "GET_ARTICLE_SUCC"
* }
* </pre>
* </p>
*
* @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 = "/console/article/*", method = HTTPRequestMethod.GET)
public void getArticle(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
try {
final String articleId = request.getRequestURI().substring((Latkes.getContextPath() + "/console/article/").length());
final JSONObject result = articleQueryService.getArticle(articleId);
result.put(Keys.STATUS_CODE, true);
renderer.setJSONObject(result);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
Aggregations