use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.
the class NotificationMgmtService method addCommentThankNotification.
/**
* Adds a 'comment thank' type notification with the specified request json object.
*
* @param requestJSONObject the specified request json object, for example,
* "userId"; "",
* "dataId": "" // reward id
* @throws ServiceException service exception
*/
@Transactional
public void addCommentThankNotification(final JSONObject requestJSONObject) throws ServiceException {
try {
requestJSONObject.put(Notification.NOTIFICATION_DATA_TYPE, Notification.DATA_TYPE_C_POINT_COMMENT_THANK);
addNotification(requestJSONObject);
} catch (final RepositoryException e) {
final String msg = "Adds notification [type=comment_thank] failed";
LOGGER.log(Level.ERROR, msg, e);
throw new ServiceException(msg);
}
}
use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.
the class ReferralMgmtService method updateReferral.
/**
* Adds or updates a referral.
*
* @param referral the specified referral
*/
@Transactional
public void updateReferral(final JSONObject referral) {
final String dataId = referral.optString(Referral.REFERRAL_DATA_ID);
final String ip = referral.optString(Referral.REFERRAL_IP);
try {
JSONObject record = referralRepository.getByDataIdAndIP(dataId, ip);
if (null == record) {
record = new JSONObject();
record.put(Referral.REFERRAL_AUTHOR_HAS_POINT, false);
record.put(Referral.REFERRAL_CLICK, 1);
record.put(Referral.REFERRAL_DATA_ID, dataId);
record.put(Referral.REFERRAL_IP, ip);
record.put(Referral.REFERRAL_TYPE, referral.optInt(Referral.REFERRAL_TYPE));
record.put(Referral.REFERRAL_USER, referral.optString(Referral.REFERRAL_USER));
record.put(Referral.REFERRAL_USER_HAS_POINT, false);
referralRepository.add(record);
} else {
final String currentReferralUser = referral.optString(Referral.REFERRAL_USER);
final String firstReferralUser = record.optString(Referral.REFERRAL_USER);
if (!currentReferralUser.equals(firstReferralUser)) {
return;
}
record.put(Referral.REFERRAL_CLICK, record.optInt(Referral.REFERRAL_CLICK) + 1);
referralRepository.update(record.optString(Keys.OBJECT_ID), record);
}
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Updates a referral failed", e);
}
}
use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.
the class RoleMgmtService method updateRolePermissions.
/**
* Updates role permissions.
*
* @param roleId the specified role id
*/
@Transactional
public void updateRolePermissions(final String roleId, final Set<String> permissionIds) {
try {
rolePermissionRepository.removeByRoleId(roleId);
for (final String permissionId : permissionIds) {
final JSONObject rel = new JSONObject();
rel.put(Role.ROLE_ID, roleId);
rel.put(Permission.PERMISSION_ID, permissionId);
rolePermissionRepository.add(rel);
}
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Updates role permissions failed", e);
}
}
use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.
the class ArticleMgmtService method adminStick.
/**
* Admin sticks an article specified by the given article id.
*
* @param articleId the given article id
* @throws ServiceException service exception
*/
@Transactional
public synchronized void adminStick(final String articleId) throws ServiceException {
try {
final JSONObject article = articleRepository.get(articleId);
if (null == article) {
return;
}
article.put(Article.ARTICLE_STICK, Long.MAX_VALUE);
articleRepository.update(articleId, article);
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Admin sticks an article[id=" + articleId + "] failed", e);
throw new ServiceException(langPropsService.get("stickFailedLabel"));
}
}
use of org.b3log.latke.repository.annotation.Transactional in project symphony by b3log.
the class DomainMgmtService method removeDomainTag.
/**
* Removes a domain-tag relation.
*
* @param domainId the specified domain id
* @param tagId the specified tag id
* @throws ServiceException service exception
*/
@Transactional
public void removeDomainTag(final String domainId, final String tagId) throws ServiceException {
try {
final JSONObject domain = domainRepository.get(domainId);
domain.put(Domain.DOMAIN_TAG_COUNT, domain.optInt(Domain.DOMAIN_TAG_COUNT) - 1);
domainRepository.update(domainId, domain);
final Query query = new Query().setFilter(CompositeFilterOperator.and(new PropertyFilter(Domain.DOMAIN + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, domainId), new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId)));
final JSONArray relations = domainTagRepository.get(query).optJSONArray(Keys.RESULTS);
if (relations.length() < 1) {
return;
}
final JSONObject relation = relations.optJSONObject(0);
domainTagRepository.remove(relation.optString(Keys.OBJECT_ID));
// Refresh cache
domainCache.loadDomains();
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Adds a domain-tag relation failed", e);
throw new ServiceException(e);
}
}
Aggregations