use of org.b3log.latke.service.ServiceException in project solo by b3log.
the class UserConsole method removeUser.
/**
* Removes a user 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
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = "/console/user/*", method = HTTPRequestMethod.DELETE)
public void removeUser(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/user/").length());
userMgmtService.removeUser(userId);
jsonObject.put(Keys.STATUS_CODE, true);
jsonObject.put(Keys.MSG, langPropsService.get("removeSuccLabel"));
} 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.service.ServiceException in project solo by b3log.
the class UserConsole method updateUser.
/**
* Updates a user 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>
* {
* "oId": "",
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userRole": "", // optional
* "userURL": "", // optional
* "userAvatar": "" // optional
* }
* </pre>
*
* @param context the specified http request context
* @param response the specified http servlet response
* @throws Exception exception
*/
@RequestProcessing(value = "/console/user/", method = HTTPRequestMethod.PUT)
public void updateUser(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);
userMgmtService.updateUser(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.service.ServiceException in project solo by b3log.
the class FillTagArticles method exec.
@Override
public Object exec(final List arguments) throws TemplateModelException {
if (arguments.size() != ARG_SIZE) {
LOGGER.debug("FillTagArticles with wrong arguments!");
throw new TemplateModelException("Wrong arguments!");
}
final String tagTitle = (String) arguments.get(0);
final int currentPageNum = Integer.parseInt((String) arguments.get(1));
final int pageSize = Integer.parseInt((String) arguments.get(2));
try {
final JSONObject result = tagQueryService.getTagByTitle(tagTitle);
if (null == result) {
return new ArrayList<JSONObject>();
}
final JSONObject tag = result.getJSONObject(Tag.TAG);
final String tagId = tag.getString(Keys.OBJECT_ID);
final List<JSONObject> list = articleQueryService.getArticlesByTag(tagId, currentPageNum, pageSize);
return list;
} catch (final ServiceException e) {
e.printStackTrace();
} catch (final JSONException e) {
e.printStackTrace();
}
return null;
}
use of org.b3log.latke.service.ServiceException in project solo by b3log.
the class Filler method fillPageNavigations.
/**
* Fills page navigations.
*
* @param dataModel data model
* @throws ServiceException service exception
*/
private void fillPageNavigations(final Map<String, Object> dataModel) throws ServiceException {
Stopwatchs.start("Fill Navigations");
try {
LOGGER.debug("Filling page navigations....");
final List<JSONObject> pages = pageRepository.getPages();
for (final JSONObject page : pages) {
if ("page".equals(page.optString(Page.PAGE_TYPE))) {
final String permalink = page.optString(Page.PAGE_PERMALINK);
page.put(Page.PAGE_PERMALINK, Latkes.getServePath() + permalink);
}
}
dataModel.put(Common.PAGE_NAVIGATIONS, pages);
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Fills page navigations failed", e);
throw new ServiceException(e);
} finally {
Stopwatchs.end();
}
}
use of org.b3log.latke.service.ServiceException in project solo by b3log.
the class Filler method fillMostViewCountArticles.
/**
* Fills most view count articles.
*
* @param dataModel data model
* @param preference the specified preference
* @throws ServiceException service exception
*/
public void fillMostViewCountArticles(final Map<String, Object> dataModel, final JSONObject preference) throws ServiceException {
Stopwatchs.start("Fill Most View Articles");
try {
LOGGER.debug("Filling the most view count articles....");
final int mostCommentArticleDisplayCnt = preference.getInt(Option.ID_C_MOST_VIEW_ARTICLE_DISPLAY_CNT);
final List<JSONObject> mostViewCountArticles = articleRepository.getMostViewCountArticles(mostCommentArticleDisplayCnt);
dataModel.put(Common.MOST_VIEW_COUNT_ARTICLES, mostViewCountArticles);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Fills most view count articles failed", e);
throw new ServiceException(e);
} finally {
Stopwatchs.end();
}
}
Aggregations