use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.
the class ArticleProcessor method getArticleContent.
/**
* Gets article content with the specified context.
*
* @param context the specified context
* @param request the specified request
*/
@RequestProcessing(value = "/get-article-content", method = HTTPRequestMethod.GET)
public void getArticleContent(final HTTPRequestContext context, final HttpServletRequest request) {
final String articleId = request.getParameter("id");
if (Strings.isEmptyOrNull(articleId)) {
return;
}
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
String content;
try {
content = articleQueryService.getArticleContent(request, articleId);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, "Can not get article content", e);
return;
}
if (null == content) {
return;
}
renderer.setContent(content);
}
use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.
the class RepairProcessor method removeUnusedArticleProperties.
/**
* Removes unused properties of each article.
*
* @param context the specified context
*/
@RequestProcessing(value = "/fix/normalization/articles/properties", method = HTTPRequestMethod.POST)
public void removeUnusedArticleProperties(final HTTPRequestContext context) {
LOGGER.log(Level.INFO, "Processes remove unused article properties");
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
Transaction transaction = null;
try {
final JSONArray articles = articleRepository.get(new Query()).getJSONArray(Keys.RESULTS);
if (articles.length() <= 0) {
renderer.setContent("No unused article properties");
return;
}
transaction = articleRepository.beginTransaction();
final Set<String> keyNames = Repositories.getKeyNames(Article.ARTICLE);
for (int i = 0; i < articles.length(); i++) {
final JSONObject article = articles.getJSONObject(i);
final JSONArray names = article.names();
final Set<String> nameSet = CollectionUtils.<String>jsonArrayToSet(names);
if (nameSet.removeAll(keyNames)) {
for (final String unusedName : nameSet) {
article.remove(unusedName);
}
articleRepository.update(article.getString(Keys.OBJECT_ID), article);
LOGGER.log(Level.INFO, "Found an article[id={0}] exists unused properties[{1}]", new Object[] { article.getString(Keys.OBJECT_ID), nameSet });
}
}
transaction.commit();
} catch (final Exception e) {
if (null != transaction && transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.ERROR, e.getMessage(), e);
renderer.setContent("Removes unused article properties failed, error msg[" + e.getMessage() + "]");
}
}
use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.
the class RepairProcessor method removeAllDataPOST.
/**
* Removes all data.
*
* @param context the specified context
*/
@RequestProcessing(value = "/rm-all-data.do", method = HTTPRequestMethod.POST)
public void removeAllDataPOST(final HTTPRequestContext context) {
LOGGER.info("Removing all data....");
boolean succeed = false;
try {
remove(beanManager.getReference(ArchiveDateArticleRepositoryImpl.class));
remove(beanManager.getReference(ArchiveDateRepositoryImpl.class));
remove(beanManager.getReference(ArticleRepositoryImpl.class));
remove(beanManager.getReference(CommentRepositoryImpl.class));
remove(beanManager.getReference(LinkRepositoryImpl.class));
remove(beanManager.getReference(OptionRepositoryImpl.class));
remove(beanManager.getReference(PageRepositoryImpl.class));
remove(beanManager.getReference(PluginRepositoryImpl.class));
remove(beanManager.getReference(StatisticRepositoryImpl.class));
remove(beanManager.getReference(TagArticleRepositoryImpl.class));
remove(beanManager.getReference(TagRepositoryImpl.class));
remove(beanManager.getReference(UserRepositoryImpl.class));
succeed = true;
} catch (final Exception e) {
LOGGER.log(Level.WARN, "Removed partial data only", e);
}
final StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.append("<html><head><title>Result</title></head><body>");
try {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
if (succeed) {
htmlBuilder.append("Removed all data!");
} else {
htmlBuilder.append("Refresh this page and run this remover again.");
}
htmlBuilder.append("</body></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);
}
}
LOGGER.info("Removed all data....");
}
use of org.b3log.latke.servlet.renderer.TextHTMLRenderer in project solo by b3log.
the class RepairProcessor method repairTagArticleCounter.
/**
* Repairs tag article counter.
*
* @param context the specified context
*/
@RequestProcessing(value = "/fix/tag-article-counter-repair.do", method = HTTPRequestMethod.GET)
@Transactional
public void repairTagArticleCounter(final HTTPRequestContext context) {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
try {
final JSONObject result = tagRepository.get(new Query());
final JSONArray tagArray = result.getJSONArray(Keys.RESULTS);
final List<JSONObject> tags = CollectionUtils.jsonArrayToList(tagArray);
for (final JSONObject tag : tags) {
final String tagId = tag.getString(Keys.OBJECT_ID);
final JSONObject tagArticleResult = tagArticleRepository.getByTagId(tagId, 1, Integer.MAX_VALUE);
final JSONArray tagArticles = tagArticleResult.getJSONArray(Keys.RESULTS);
final int tagRefCnt = tagArticles.length();
int publishedTagRefCnt = 0;
for (int i = 0; i < tagRefCnt; i++) {
final JSONObject tagArticle = tagArticles.getJSONObject(i);
final String articleId = tagArticle.getString(Article.ARTICLE + "_" + Keys.OBJECT_ID);
final JSONObject article = articleRepository.get(articleId);
if (null == article) {
tagArticleRepository.remove(tagArticle.optString(Keys.OBJECT_ID));
continue;
}
if (article.getBoolean(Article.ARTICLE_IS_PUBLISHED)) {
publishedTagRefCnt++;
}
}
tag.put(Tag.TAG_REFERENCE_COUNT, tagRefCnt);
tag.put(Tag.TAG_PUBLISHED_REFERENCE_COUNT, publishedTagRefCnt);
tagRepository.update(tagId, tag);
LOGGER.log(Level.INFO, "Repaired tag[title={0}, refCnt={1}, publishedTagRefCnt={2}]", new Object[] { tag.getString(Tag.TAG_TITLE), tagRefCnt, publishedTagRefCnt });
}
renderer.setContent("Repair sucessfully!");
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
renderer.setContent("Repairs failed, error msg[" + e.getMessage() + "]");
}
}
use of org.b3log.latke.servlet.renderer.TextHTMLRenderer 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() + "]");
}
}
Aggregations