001
014
015 package com.liferay.portlet.social.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.model.User;
020 import com.liferay.portlet.social.model.SocialAchievement;
021 import com.liferay.portlet.social.model.SocialActivityAchievement;
022 import com.liferay.portlet.social.service.base.SocialActivityAchievementLocalServiceBaseImpl;
023
024 import java.util.List;
025
026
030 public class SocialActivityAchievementLocalServiceImpl
031 extends SocialActivityAchievementLocalServiceBaseImpl {
032
033 public void addActivityAchievement(
034 long userId, long groupId, SocialAchievement achievement)
035 throws PortalException, SystemException {
036
037 SocialActivityAchievement activityAchievement =
038 socialActivityAchievementPersistence.fetchByG_U_N(
039 groupId, userId, achievement.getName());
040
041 if (activityAchievement != null) {
042 return;
043 }
044
045 User user = userPersistence.findByPrimaryKey(userId);
046
047 long activityAchievementId = counterLocalService.increment();
048
049 activityAchievement = socialActivityAchievementPersistence.create(
050 activityAchievementId);
051
052 activityAchievement.setGroupId(groupId);
053 activityAchievement.setCompanyId(user.getCompanyId());
054 activityAchievement.setUserId(userId);
055 activityAchievement.setCreateDate(System.currentTimeMillis());
056
057 int count = socialActivityAchievementPersistence.countByG_N(
058 groupId, achievement.getName());
059
060 if (count == 0) {
061 activityAchievement.setFirstInGroup(true);
062 }
063
064 activityAchievement.setName(achievement.getName());
065
066 socialActivityAchievementPersistence.update(activityAchievement);
067
068 socialActivityCounterLocalService.incrementUserAchievementCounter(
069 userId, groupId);
070 }
071
072 public SocialActivityAchievement fetchUserAchievement(
073 long userId, long groupId, String name)
074 throws SystemException {
075
076 return socialActivityAchievementPersistence.fetchByG_U_N(
077 groupId, userId, name);
078 }
079
080 public List<SocialActivityAchievement> getGroupAchievements(long groupId)
081 throws SystemException {
082
083 return socialActivityAchievementPersistence.findByGroupId(groupId);
084 }
085
086 public List<SocialActivityAchievement> getGroupAchievements(
087 long groupId, String name)
088 throws SystemException {
089
090 return socialActivityAchievementPersistence.findByG_N(groupId, name);
091 }
092
093 public int getGroupAchievementsCount(long groupId) throws SystemException {
094 return socialActivityAchievementPersistence.countByGroupId(groupId);
095 }
096
097 public int getGroupAchievementsCount(long groupId, String name)
098 throws SystemException {
099
100 return socialActivityAchievementPersistence.countByG_N(groupId, name);
101 }
102
103 public List<SocialActivityAchievement> getGroupFirstAchievements(
104 long groupId)
105 throws SystemException {
106
107 return socialActivityAchievementPersistence.findByG_F(groupId, true);
108 }
109
110 public int getGroupFirstAchievementsCount(long groupId)
111 throws SystemException {
112
113 return socialActivityAchievementPersistence.countByG_F(groupId, true);
114 }
115
116 public int getUserAchievementCount(long userId, long groupId, String name)
117 throws SystemException {
118
119 return socialActivityAchievementPersistence.countByG_U_N(
120 groupId, userId, name);
121 }
122
123 public List<SocialActivityAchievement> getUserAchievements(
124 long userId, long groupId, String name)
125 throws SystemException {
126
127 return socialActivityAchievementPersistence.findByG_U(groupId, userId);
128 }
129
130 }