use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class RepairProcessor method restoreSigns.
/**
* Restores the signs of preference to default.
*
* @param context the specified context
*/
@RequestProcessing(value = "/fix/restore-signs.do", method = HTTPRequestMethod.GET)
public void restoreSigns(final HTTPRequestContext context) {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
try {
final JSONObject preference = preferenceQueryService.getPreference();
final String originalSigns = preference.getString(Option.ID_C_SIGNS);
preference.put(Option.ID_C_SIGNS, Option.DefaultPreference.DEFAULT_SIGNS);
preferenceMgmtService.updatePreference(preference);
// Sends the sample signs to developer
final Message msg = new MailService.Message();
msg.setFrom(preference.getString(Option.ID_C_ADMIN_EMAIL));
msg.addRecipient("DL88250@gmail.com");
msg.setSubject("Restore signs");
msg.setHtmlBody(originalSigns + "<p>Admin email: " + preference.getString(Option.ID_C_ADMIN_EMAIL) + "</p>");
MAIL_SVC.send(msg);
renderer.setContent("Restores signs succeeded.");
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
renderer.setContent("Restores signs failed, error msg[" + e.getMessage() + "]");
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class RepairProcessor method removeAllDataGET.
/**
* Shows remove all data page.
*
* @param context the specified context
* @param request the specified HTTP servlet request
*/
@RequestProcessing(value = "/rm-all-data.do", method = HTTPRequestMethod.GET)
public void removeAllDataGET(final HTTPRequestContext context, final HttpServletRequest request) {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
try {
final StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.append("<html><head><title>WARNING!</title>");
htmlBuilder.append("<script type='text/javascript'");
htmlBuilder.append("src='").append(Latkes.getStaticServer()).append("/js/lib/jquery/jquery.min.js'");
htmlBuilder.append("></script></head><body>");
htmlBuilder.append("<button id='ok' onclick='removeData()'>");
htmlBuilder.append("Continue to delete ALL DATA</button></body>");
htmlBuilder.append("<script type='text/javascript'>");
htmlBuilder.append("function removeData() {");
htmlBuilder.append("$.ajax({type: 'POST',url:'").append(Latkes.getContextPath()).append("/rm-all-data.do',");
htmlBuilder.append("dataType: 'text/html',success: function(result){");
htmlBuilder.append("$('html').html(result);}});}</script></html>");
renderer.setContent(htmlBuilder.toString());
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
try {
context.getResponse().sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
} catch (final IOException ex) {
throw new RuntimeException(ex);
}
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class RepairProcessor method restoreStat.
/**
* Restores the statistics.
*
* <p>
* <ul>
* <li>Uses the value of {@link Statistic#STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT} for
* {@link Statistic#STATISTIC_BLOG_COMMENT_COUNT}</li>
* <li>Uses the value of {@link Statistic#STATISTIC_PUBLISHED_ARTICLE_COUNT} for
* {@link Statistic#STATISTIC_BLOG_ARTICLE_COUNT}</li>
* </ul>
* </p>
*
* @param context the specified context
*/
@RequestProcessing(value = "/fix/restore-stat.do", method = HTTPRequestMethod.GET)
public void restoreStat(final HTTPRequestContext context) {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
try {
final JSONObject statistic = statisticQueryService.getStatistic();
if (statistic.has(Statistic.STATISTIC_BLOG_COMMENT_COUNT) && statistic.has(Statistic.STATISTIC_BLOG_ARTICLE_COUNT)) {
LOGGER.info("No need for repairing statistic");
renderer.setContent("No need for repairing statistic.");
return;
}
if (!statistic.has(Statistic.STATISTIC_BLOG_COMMENT_COUNT)) {
statistic.put(Statistic.STATISTIC_BLOG_COMMENT_COUNT, statistic.getInt(Statistic.STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT));
}
if (!statistic.has(Statistic.STATISTIC_BLOG_ARTICLE_COUNT)) {
statistic.put(Statistic.STATISTIC_BLOG_ARTICLE_COUNT, statistic.getInt(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT));
}
statisticMgmtService.updateStatistic(statistic);
renderer.setContent("Restores statistic succeeded.");
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
renderer.setContent("Restores statistics failed, error msg[" + e.getMessage() + "]");
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class TagConsole method getUnusedTags.
/**
* Gets all unused tags.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "unusedTags": [
* {"tagTitle": "", tagReferenceCount": 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 IOException io exception
*/
@RequestProcessing(value = "/console/tag/unused", method = HTTPRequestMethod.GET)
public void getUnusedTags(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws IOException {
if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
final List<JSONObject> unusedTags = new ArrayList<JSONObject>();
try {
jsonObject.put(Common.UNUSED_TAGS, unusedTags);
final List<JSONObject> tags = tagQueryService.getTags();
for (int i = 0; i < tags.size(); i++) {
final JSONObject tag = tags.get(i);
final int tagRefCnt = tag.getInt(Tag.TAG_REFERENCE_COUNT);
if (0 == tagRefCnt) {
unusedTags.add(tag);
}
}
jsonObject.put(Keys.STATUS_CODE, true);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets unused tags failed", e);
jsonObject.put(Keys.STATUS_CODE, false);
}
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class TagConsole method getTags.
/**
* Gets all tags.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "tags": [
* {"tagTitle": "", tagReferenceCount": 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 IOException io exception
*/
@RequestProcessing(value = "/console/tags", method = HTTPRequestMethod.GET)
public void getTags(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws IOException {
if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
try {
jsonObject.put(Tag.TAGS, tagQueryService.getTags());
jsonObject.put(Keys.STATUS_CODE, true);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets tags failed", e);
jsonObject.put(Keys.STATUS_CODE, false);
}
}
Aggregations