use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class PluginConsole method setPluginStatus.
/**
* Sets a plugin's status with the specified plugin id, status.
*
* <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/plugin/status/", method = HTTPRequestMethod.PUT)
public void setPluginStatus(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String pluginId = requestJSONObject.getString(Keys.OBJECT_ID);
final String status = requestJSONObject.getString(Plugin.PLUGIN_STATUS);
final JSONObject result = pluginMgmtService.setPluginStatus(pluginId, status);
renderer.setJSONObject(result);
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class PreferenceConsole method updateQiniu.
/**
* Updates the Qiniu preference by the specified request.
*
* @param request the specified http servlet request, for example, <pre>
* {
* "qiniuAccessKey": "",
* "qiniuSecretKey": "",
* "qiniuDomain": "",
* "qiniuBucket": ""
* }, see {@link org.b3log.solo.model.Option} for more details
* </pre>
*
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = PREFERENCE_URI_PREFIX + "qiniu", method = HTTPRequestMethod.PUT)
public void updateQiniu(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);
try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String accessKey = requestJSONObject.optString(Option.ID_C_QINIU_ACCESS_KEY).trim();
final String secretKey = requestJSONObject.optString(Option.ID_C_QINIU_SECRET_KEY).trim();
String domain = requestJSONObject.optString(Option.ID_C_QINIU_DOMAIN).trim();
final String bucket = requestJSONObject.optString(Option.ID_C_QINIU_BUCKET).trim();
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
if (StringUtils.isNotBlank(domain) && !StringUtils.endsWith(domain, "/")) {
domain += "/";
}
final JSONObject accessKeyOpt = new JSONObject();
accessKeyOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_ACCESS_KEY);
accessKeyOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
accessKeyOpt.put(Option.OPTION_VALUE, accessKey);
final JSONObject secretKeyOpt = new JSONObject();
secretKeyOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_SECRET_KEY);
secretKeyOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
secretKeyOpt.put(Option.OPTION_VALUE, secretKey);
final JSONObject domainOpt = new JSONObject();
domainOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_DOMAIN);
domainOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
domainOpt.put(Option.OPTION_VALUE, domain);
final JSONObject bucketOpt = new JSONObject();
bucketOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_BUCKET);
bucketOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
bucketOpt.put(Option.OPTION_VALUE, bucket);
optionMgmtService.addOrUpdateOption(accessKeyOpt);
optionMgmtService.addOrUpdateOption(secretKeyOpt);
optionMgmtService.addOrUpdateOption(domainOpt);
optionMgmtService.addOrUpdateOption(bucketOpt);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
} 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 PreferenceConsole method getPreference.
/**
* Gets preference.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "preference": {
* "mostViewArticleDisplayCount": int,
* "recentCommentDisplayCount": int,
* "mostUsedTagDisplayCount": int,
* "articleListDisplayCount": int,
* "articleListPaginationWindowSize": int,
* "mostCommentArticleDisplayCount": int,
* "externalRelevantArticlesDisplayCount": int,
* "relevantArticlesDisplayCount": int,
* "randomArticlesDisplayCount": int,
* "blogTitle": "",
* "blogSubtitle": "",
* "localeString": "",
* "timeZoneId": "",
* "skinName": "",
* "skinDirName": "",
* "skins": "[{
* "skinName": "",
* "skinDirName": ""
* }, ....]",
* "noticeBoard": "",
* "footerContent": "",
* "htmlHead": "",
* "adminEmail": "",
* "metaKeywords": "",
* "metaDescription": "",
* "enableArticleUpdateHint": boolean,
* "signs": "[{
* "oId": "",
* "signHTML": ""
* }, ...]",
* "allowVisitDraftViaPermalink": boolean,
* "allowRegister": boolean,
* "version": "",
* "articleListStyle": "", // Optional values: "titleOnly"/"titleAndContent"/"titleAndAbstract"
* "commentable": boolean,
* "feedOutputMode: "" // Optional values: "abstract"/"full"
* "feedOutputCnt": int
* }
* }
* </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 = PREFERENCE_URI_PREFIX, method = HTTPRequestMethod.GET)
public void getPreference(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);
try {
final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) {
renderer.setJSONObject(QueryResults.defaultResult());
return;
}
String footerContent = "";
final JSONObject opt = optionQueryService.getOptionById(Option.ID_C_FOOTER_CONTENT);
if (null != opt) {
footerContent = opt.optString(Option.OPTION_VALUE);
}
preference.put(Option.ID_C_FOOTER_CONTENT, footerContent);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
ret.put(Option.CATEGORY_C_PREFERENCE, preference);
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 PreferenceConsole method updatePreference.
/**
* Updates the preference by the specified request.
*
* @param request the specified http servlet request, for example, <pre>
* {
* "preference": {
* "mostViewArticleDisplayCount": int,
* "recentCommentDisplayCount": int,
* "mostUsedTagDisplayCount": int,
* "articleListDisplayCount": int,
* "articleListPaginationWindowSize": int,
* "mostCommentArticleDisplayCount": int,
* "externalRelevantArticlesDisplayCount": int,
* "relevantArticlesDisplayCount": int,
* "randomArticlesDisplayCount": int,
* "blogTitle": "",
* "blogSubtitle": "",
* "skinDirName": "",
* "localeString": "",
* "timeZoneId": "",
* "noticeBoard": "",
* "footerContent": "",
* "htmlHead": "",
* "metaKeywords": "",
* "metaDescription": "",
* "enableArticleUpdateHint": boolean,
* "signs": [{
* "oId": "",
* "signHTML": ""
* }, ...],
* "allowVisitDraftViaPermalink": boolean,
* "allowRegister": boolean,
* "articleListStyle": "",
* "commentable": boolean,
* "feedOutputMode: "",
* "feedOutputCnt": int
* }
* }, see {@link org.b3log.solo.model.Preference} for more details
* </pre>
*
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = PREFERENCE_URI_PREFIX, method = HTTPRequestMethod.PUT)
public void updatePreference(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);
try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final JSONObject preference = requestJSONObject.getJSONObject(Option.CATEGORY_C_PREFERENCE);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
if (isInvalid(preference, ret)) {
return;
}
preferenceMgmtService.updatePreference(preference);
final Cookie cookie = new Cookie(Skin.SKIN, preference.getString(Skin.SKIN_DIR_NAME));
cookie.setPath("/");
response.addCookie(cookie);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
} 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 PreferenceConsole method getSigns.
/**
* Gets signs.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "signs": [{
* "oId": "",
* "signHTML": ""
* }, ...]
* }
* </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/signs/", method = HTTPRequestMethod.GET)
public void getSigns(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 JSONObject preference = preferenceQueryService.getPreference();
final JSONArray signs = new JSONArray();
final JSONArray allSigns = // includes the empty sign(id=0)
new JSONArray(preference.getString(Option.ID_C_SIGNS));
for (int i = 1; i < allSigns.length(); i++) {
// excludes the empty sign
signs.put(allSigns.getJSONObject(i));
}
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
ret.put(Sign.SIGNS, signs);
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"));
}
}
Aggregations