use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class PageConsole method changeOrder.
/**
* Changes a page order by the specified page 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/page/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);
pageMgmtService.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 PageConsole method updatePage.
/**
* Updates a page 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>
* {
* "page": {
* "oId": "",
* "pageTitle": "",
* "pageContent": "",
* "pageOrder": int,
* "pageCommentCount": int,
* "pagePermalink": "",
* "pageCommentable": boolean,
* "pageType": "",
* "pageOpenTarget": ""
* }
* }, see {@link org.b3log.solo.model.Page} for more details
* </pre>
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = "/console/page/", method = HTTPRequestMethod.PUT)
public void updatePage(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);
pageMgmtService.updatePage(requestJSONObject);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
renderer.setJSONObject(ret);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, e.getMessage());
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class PageConsole method getPages.
/**
* Gets pages by the specified request.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "pagination": {
* "paginationPageCount": 100,
* "paginationPageNums": [1, 2, 3, 4, 5]
* },
* "pages": [{
* "oId": "",
* "pageTitle": "",
* "pageCommentCount": int,
* "pageOrder": int,
* "pagePermalink": ""
* }, ....]
* "sc": "GET_PAGES_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
* @see Requests#PAGINATION_PATH_PATTERN
*/
@RequestProcessing(value = "/console/pages/*/*/*", /* Requests.PAGINATION_PATH_PATTERN */
method = HTTPRequestMethod.GET)
public void getPages(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/pages/").length());
final JSONObject requestJSONObject = Requests.buildPaginationRequest(path);
final JSONObject result = pageQueryService.getPages(requestJSONObject);
final JSONArray pages = result.optJSONArray(Page.PAGES);
// Site-internal URLs process
for (int i = 0; i < pages.length(); i++) {
final JSONObject page = pages.getJSONObject(i);
if ("page".equals(page.optString(Page.PAGE_TYPE))) {
final String permalink = page.optString(Page.PAGE_PERMALINK);
page.put(Page.PAGE_PERMALINK, Latkes.getServePath() + permalink);
}
}
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 PluginConsole method toSetting.
/**
* get the info of the specified pluginoId,just fot the plugin-setting.
* @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @param renderer the specified {@link ConsoleRenderer}
* @throws Exception exception
*/
@RequestProcessing(value = "/console/plugin/toSetting", method = HTTPRequestMethod.POST)
public void toSetting(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context, final ConsoleRenderer renderer) throws Exception {
context.setRenderer(renderer);
try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String pluginId = requestJSONObject.getString(Keys.OBJECT_ID);
final String setting = pluginQueryService.getPluginSetting(pluginId);
renderer.setTemplateName("admin-plugin-setting.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
Keys.fillRuntime(dataModel);
dataModel.put(Plugin.PLUGIN_SETTING, setting);
dataModel.put(Keys.OBJECT_ID, pluginId);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
final JSONRenderer jsonRenderer = new JSONRenderer();
jsonRenderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class PluginConsole method getPlugins.
/**
* Gets plugins by the specified request.
*
* <p>
* The request URI contains the pagination arguments. For example, the
* request URI is /console/plugins/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]
* },
* "plugins": [{
* "name": "",
* "version": "",
* "author": "",
* "status": "", // Enumeration name of {@link org.b3log.latke.plugin.PluginStatus}
* }, ....]
* }
* </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
* @see Requests#PAGINATION_PATH_PATTERN
*/
@RequestProcessing(value = "/console/plugins/*/*/*", /* Requests.PAGINATION_PATH_PATTERN */
method = HTTPRequestMethod.GET)
public void getPlugins(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
try {
final String requestURI = request.getRequestURI();
final String path = requestURI.substring((Latkes.getContextPath() + "/console/plugins/").length());
final JSONObject requestJSONObject = Requests.buildPaginationRequest(path);
final JSONObject result = pluginQueryService.getPlugins(requestJSONObject);
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