use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class StatisticMgmtService method setPublishedBlogCommentCount.
/**
* Sets blog comment(published article) count with the specified count.
*
* @param count the specified count
* @throws JSONException json exception
* @throws RepositoryException repository exception
*/
public void setPublishedBlogCommentCount(final int count) throws JSONException, RepositoryException {
final JSONObject statistic = statisticRepository.get(Statistic.STATISTIC);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Statistic.STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT, count);
statisticRepository.update(Statistic.STATISTIC, statistic);
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class StatisticMgmtService method incBlogViewCount.
/**
* Blog statistic view count +1.
*
* <p>
* If it is a search engine bot made the specified request, will NOT increment blog statistic view count.
* </p>
*
* <p>
* There is a cron job (/console/stat/viewcnt) to flush the blog view count from cache to datastore.
* </p>
*
* @param request the specified request
* @param response the specified response
* @throws ServiceException service exception
* @see Requests#searchEngineBotRequest(javax.servlet.http.HttpServletRequest)
*/
public void incBlogViewCount(final HttpServletRequest request, final HttpServletResponse response) throws ServiceException {
if (Requests.searchEngineBotRequest(request)) {
return;
}
if (Requests.hasBeenServed(request, response)) {
return;
}
final Transaction transaction = statisticRepository.beginTransaction();
JSONObject statistic = null;
try {
statistic = statisticRepository.get(Statistic.STATISTIC);
if (null == statistic) {
return;
}
LOGGER.log(Level.TRACE, "Before inc blog view count[statistic={0}]", statistic);
int blogViewCnt = statistic.optInt(Statistic.STATISTIC_BLOG_VIEW_COUNT);
++blogViewCnt;
statistic.put(Statistic.STATISTIC_BLOG_VIEW_COUNT, blogViewCnt);
statisticRepository.update(Statistic.STATISTIC, statistic);
transaction.commit();
} catch (final RepositoryException e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.ERROR, "Updates blog view count failed", e);
return;
}
LOGGER.log(Level.TRACE, "Inced blog view count[statistic={0}]", statistic);
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class StatisticMgmtService method decPublishedBlogArticleCount.
/**
* Blog statistic published article count -1.
*
* @throws JSONException json exception
* @throws RepositoryException repository exception
*/
public void decPublishedBlogArticleCount() throws JSONException, RepositoryException {
final JSONObject statistic = statisticRepository.get(Statistic.STATISTIC);
if (null == statistic) {
throw new RepositoryException("Not found statistic");
}
statistic.put(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT, statistic.getInt(Statistic.STATISTIC_PUBLISHED_ARTICLE_COUNT) - 1);
statisticRepository.update(Statistic.STATISTIC, statistic);
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class TagQueryService method getBottomTags.
/**
* Gets bottom (reference count ascending) tags.
*
* @param fetchSize the specified fetch size
* @return for example, <pre>
* [
* {"tagTitle": "", "tagReferenceCount": int, ....},
* ....
* ]
* </pre>, returns an empty list if not found
*
* @throws ServiceException service exception
*/
public List<JSONObject> getBottomTags(final int fetchSize) throws ServiceException {
try {
final Query query = new Query().setPageCount(1).setPageSize(fetchSize).addSort(Tag.TAG_PUBLISHED_REFERENCE_COUNT, SortDirection.ASCENDING);
final JSONObject result = tagRepository.get(query);
final JSONArray tagArray = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(tagArray);
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Gets bottom tags failed", e);
throw new ServiceException(e);
}
}
use of org.b3log.latke.repository.RepositoryException in project solo by b3log.
the class UserMgmtService method removeUser.
/**
* Removes a user specified by the given user id.
*
* @param userId the given user id
* @throws ServiceException service exception
*/
public void removeUser(final String userId) throws ServiceException {
final Transaction transaction = userRepository.beginTransaction();
try {
userRepository.remove(userId);
transaction.commit();
} catch (final RepositoryException e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.ERROR, "Removes a user[id=" + userId + "] failed", e);
throw new ServiceException(e);
}
}
Aggregations