use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class CommentConsole method getArticleComments.
/**
* Gets comments of an article specified by the article id for administrator.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "comments": [{
* "oId": "",
* "commentName": "",
* "commentEmail": "",
* "thumbnailUrl": "",
* "commentURL": "",
* "commentContent": "",
* "commentTime": long,
* "commentSharpURL": "",
* "isReply": boolean
* }, ....]
* }
* </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/comments/article/*", method = HTTPRequestMethod.GET)
public void getArticleComments(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);
try {
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
final String requestURI = request.getRequestURI();
final String articleId = requestURI.substring((Latkes.getContextPath() + "/console/comments/article/").length());
final List<JSONObject> comments = commentQueryService.getComments(articleId);
ret.put(Comment.COMMENTS, comments);
ret.put(Keys.STATUS_CODE, true);
} catch (final Exception 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.annotation.RequestProcessing in project solo by b3log.
the class LinkConsole method getLinks.
/**
* Gets links by the specified request.
*
* <p>
* The request URI contains the pagination arguments. For example, the
* request URI is /console/links/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>
* {
* "sc": boolean,
* "pagination": {
* "paginationPageCount": 100,
* "paginationPageNums": [1, 2, 3, 4, 5]
* },
* "links": [{
* "oId": "",
* "linkTitle": "",
* "linkAddress": "",
* "linkDescription": ""
* }, ....]
* }
* </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/links/*/*/*", /* Requests.PAGINATION_PATH_PATTERN */
method = HTTPRequestMethod.GET)
public void getLinks(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 requestURI = request.getRequestURI();
final String path = requestURI.substring((Latkes.getContextPath() + "/console/links/").length());
final JSONObject requestJSONObject = Requests.buildPaginationRequest(path);
final JSONObject result = linkQueryService.getLinks(requestJSONObject);
result.put(Keys.STATUS_CODE, true);
renderer.setJSONObject(result);
} catch (final Exception 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.annotation.RequestProcessing in project solo by b3log.
the class LinkConsole method changeOrder.
/**
* Changes a link order by the specified link id and direction.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "msg": ""
* }
* </pre>
* </p>
*
* @param request the specified http servlet request, for example,
* <pre>
* {
* "oId": "",
* "direction": "" // "up"/"down"
* }
* </pre>
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = "/console/link/order/", method = HTTPRequestMethod.PUT)
public void changeOrder(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 ret = new JSONObject();
try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String linkId = requestJSONObject.getString(Keys.OBJECT_ID);
final String direction = requestJSONObject.getString(Common.DIRECTION);
linkMgmtService.changeOrder(linkId, direction);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
renderer.setJSONObject(ret);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("updateFailLabel"));
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class LinkConsole method updateLink.
/**
* Updates a link by the specified request.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "msg": ""
* }
* </pre>
* </p>
*
* @param request the specified http servlet request, for example,
* <pre>
* {
* "link": {
* "oId": "",
* "linkTitle": "",
* "linkAddress": "",
* "linkDescription": ""
* }
* }, see {@link org.b3log.solo.model.Link} for more details
* </pre>
* @param context the specified http request context
* @param response the specified http servlet response
* @throws Exception exception
*/
@RequestProcessing(value = "/console/link/", method = HTTPRequestMethod.PUT)
public void updateLink(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 ret = new JSONObject();
try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
linkMgmtService.updateLink(requestJSONObject);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
renderer.setJSONObject(ret);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("updateFailLabel"));
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class LinkConsole method getLink.
/**
* Gets the file with the specified request.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "link": {
* "oId": "",
* "linkTitle": "",
* "linkAddress": "",
* "linkDescription": ""
* }
* }
* </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/link/*", method = HTTPRequestMethod.GET)
public void getLink(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 requestURI = request.getRequestURI();
final String linkId = requestURI.substring((Latkes.getContextPath() + "/console/link/").length());
final JSONObject result = linkQueryService.getLink(linkId);
if (null == result) {
renderer.setJSONObject(QueryResults.defaultResult());
return;
}
renderer.setJSONObject(result);
result.put(Keys.STATUS_CODE, true);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
Aggregations