Search in sources :

Example 21 with RepositoryException

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);
}
Also used : JSONObject(org.json.JSONObject) RepositoryException(org.b3log.latke.repository.RepositoryException)

Example 22 with RepositoryException

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);
}
Also used : Transaction(org.b3log.latke.repository.Transaction) JSONObject(org.json.JSONObject) RepositoryException(org.b3log.latke.repository.RepositoryException)

Example 23 with RepositoryException

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);
}
Also used : JSONObject(org.json.JSONObject) RepositoryException(org.b3log.latke.repository.RepositoryException)

Example 24 with RepositoryException

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);
    }
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) JSONArray(org.json.JSONArray) RepositoryException(org.b3log.latke.repository.RepositoryException)

Example 25 with RepositoryException

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);
    }
}
Also used : Transaction(org.b3log.latke.repository.Transaction) ServiceException(org.b3log.latke.service.ServiceException) RepositoryException(org.b3log.latke.repository.RepositoryException)

Aggregations

RepositoryException (org.b3log.latke.repository.RepositoryException)35 JSONObject (org.json.JSONObject)32 ServiceException (org.b3log.latke.service.ServiceException)14 JSONArray (org.json.JSONArray)10 Query (org.b3log.latke.repository.Query)8 Transaction (org.b3log.latke.repository.Transaction)8 Date (java.util.Date)5 ParseException (java.text.ParseException)4 PropertyFilter (org.b3log.latke.repository.PropertyFilter)4 JSONException (org.json.JSONException)4 EventException (org.b3log.latke.event.EventException)2 ArchiveDate (org.b3log.solo.model.ArchiveDate)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 LatkeBeanManager (org.b3log.latke.ioc.LatkeBeanManager)1 GeneralUser (org.b3log.latke.user.GeneralUser)1 ArticleRepository (org.b3log.solo.repository.ArticleRepository)1 PageRepository (org.b3log.solo.repository.PageRepository)1