Search in sources :

Example 11 with Transactional

use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.

the class LivenessMgmtService method incLiveness.

/**
 * Increments a field of the specified liveness.
 *
 * @param userId the specified user id
 * @param field  the specified field
 */
@Transactional
public void incLiveness(final String userId, final String field) {
    Stopwatchs.start("Inc liveness");
    final String date = DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd");
    try {
        JSONObject liveness = livenessRepository.getByUserAndDate(userId, date);
        if (null == liveness) {
            liveness = new JSONObject();
            liveness.put(Liveness.LIVENESS_USER_ID, userId);
            liveness.put(Liveness.LIVENESS_DATE, date);
            liveness.put(Liveness.LIVENESS_POINT, 0);
            liveness.put(Liveness.LIVENESS_ACTIVITY, 0);
            liveness.put(Liveness.LIVENESS_ARTICLE, 0);
            liveness.put(Liveness.LIVENESS_COMMENT, 0);
            liveness.put(Liveness.LIVENESS_PV, 0);
            liveness.put(Liveness.LIVENESS_REWARD, 0);
            liveness.put(Liveness.LIVENESS_THANK, 0);
            liveness.put(Liveness.LIVENESS_VOTE, 0);
            liveness.put(Liveness.LIVENESS_VOTE, 0);
            livenessRepository.add(liveness);
        }
        liveness.put(field, liveness.optInt(field) + 1);
        livenessRepository.update(liveness.optString(Keys.OBJECT_ID), liveness);
    } catch (final RepositoryException e) {
        LOGGER.log(Level.ERROR, "Updates a liveness [" + date + "] field [" + field + "] failed", e);
    } finally {
        Stopwatchs.end();
    }
}
Also used : JSONObject(org.json.JSONObject) RepositoryException(org.b3log.latke.repository.RepositoryException) Transactional(org.b3log.latke.repository.annotation.Transactional)

Example 12 with Transactional

use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.

the class NotificationMgmtService method addNewFollowerNotification.

/**
 * Adds a 'new follower' type notification with the specified request json object.
 *
 * @param requestJSONObject the specified request json object, for example,
 *                          "userId": "",
 *                          "dataId": "" // new follower id
 * @throws ServiceException service exception
 */
@Transactional
public void addNewFollowerNotification(final JSONObject requestJSONObject) throws ServiceException {
    try {
        requestJSONObject.put(Notification.NOTIFICATION_DATA_TYPE, Notification.DATA_TYPE_C_NEW_FOLLOWER);
        addNotification(requestJSONObject);
    } catch (final RepositoryException e) {
        final String msg = "Adds notification [type=new_follower] failed";
        LOGGER.log(Level.ERROR, msg, e);
        throw new ServiceException(msg);
    }
}
Also used : ServiceException(org.b3log.latke.service.ServiceException) Transactional(org.b3log.latke.repository.annotation.Transactional)

Example 13 with Transactional

use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.

the class NotificationMgmtService method addSysAnnounceArticleNotification.

/**
 * Adds a 'sys announce - article' type notification with the specified request json object.
 *
 * @param requestJSONObject the specified request json object, for example,
 *                          "userId"; "",
 *                          "dataId": "" // article id
 * @throws ServiceException service exception
 */
@Transactional
public void addSysAnnounceArticleNotification(final JSONObject requestJSONObject) throws ServiceException {
    try {
        requestJSONObject.put(Notification.NOTIFICATION_DATA_TYPE, Notification.DATA_TYPE_C_SYS_ANNOUNCE_ARTICLE);
        addNotification(requestJSONObject);
    } catch (final RepositoryException e) {
        final String msg = "Adds notification [type=sys_announce_article] failed";
        LOGGER.log(Level.ERROR, msg, e);
        throw new ServiceException(msg);
    }
}
Also used : ServiceException(org.b3log.latke.service.ServiceException) Transactional(org.b3log.latke.repository.annotation.Transactional)

Example 14 with Transactional

use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.

the class NotificationMgmtService method addCommentVoteDownNotification.

/**
 * Adds a 'comment vote down' type notification with the specified request json object.
 *
 * @param requestJSONObject the specified request json object, for example,
 *                          "userId": "",
 *                          "dataId": "" // comment id-vote user id
 * @throws ServiceException service exception
 */
@Transactional
public void addCommentVoteDownNotification(final JSONObject requestJSONObject) throws ServiceException {
    try {
        requestJSONObject.put(Notification.NOTIFICATION_DATA_TYPE, Notification.DATA_TYPE_C_COMMENT_VOTE_DOWN);
        addNotification(requestJSONObject);
    } catch (final RepositoryException e) {
        final String msg = "Adds notification [type=comment_vote_down] failed";
        LOGGER.log(Level.ERROR, msg, e);
        throw new ServiceException(msg);
    }
}
Also used : ServiceException(org.b3log.latke.service.ServiceException) Transactional(org.b3log.latke.repository.annotation.Transactional)

Example 15 with Transactional

use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.

the class NotificationMgmtService method addAbusePointDeductNotification.

/**
 * Adds a 'abuse point deduct' type notification with the specified request json object.
 *
 * @param requestJSONObject the specified request json object, for example,
 *                          "userId"; "",
 *                          "dataId": "" // transfer record id
 * @throws ServiceException service exception
 */
@Transactional
public void addAbusePointDeductNotification(final JSONObject requestJSONObject) throws ServiceException {
    try {
        requestJSONObject.put(Notification.NOTIFICATION_DATA_TYPE, Notification.DATA_TYPE_C_ABUSE_POINT_DEDUCT);
        addNotification(requestJSONObject);
    } catch (final RepositoryException e) {
        final String msg = "Adds notification [type=abuse_point_deduct] failed";
        LOGGER.log(Level.ERROR, msg, e);
        throw new ServiceException(msg);
    }
}
Also used : ServiceException(org.b3log.latke.service.ServiceException) Transactional(org.b3log.latke.repository.annotation.Transactional)

Aggregations

Transactional (org.b3log.latke.repository.annotation.Transactional)52 ServiceException (org.b3log.latke.service.ServiceException)42 JSONObject (org.json.JSONObject)20 JSONArray (org.json.JSONArray)11 RepositoryException (org.b3log.latke.repository.RepositoryException)6 Query (org.b3log.latke.repository.Query)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 ExecutionException (java.util.concurrent.ExecutionException)1 PropertyFilter (org.b3log.latke.repository.PropertyFilter)1 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)1 TextHTMLRenderer (org.b3log.latke.servlet.renderer.TextHTMLRenderer)1