001
014
015 package com.liferay.portlet.social.service.impl;
016
017 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
018 import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
019 import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
020 import com.liferay.portal.kernel.dao.orm.ProjectionList;
021 import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
022 import com.liferay.portal.kernel.exception.SystemException;
023 import com.liferay.portal.kernel.util.OrderByComparator;
024 import com.liferay.portlet.social.model.SocialEquityUser;
025 import com.liferay.portlet.social.model.SocialEquityValue;
026 import com.liferay.portlet.social.service.base.SocialEquityUserLocalServiceBaseImpl;
027
028 import java.util.List;
029
030
033 public class SocialEquityUserLocalServiceImpl
034 extends SocialEquityUserLocalServiceBaseImpl {
035
036 public SocialEquityValue getContributionEquity(long userId)
037 throws SystemException {
038
039 ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
040
041 projectionList.add(ProjectionFactoryUtil.sum("contributionK"));
042 projectionList.add(ProjectionFactoryUtil.sum("contributionB"));
043
044 return getSocialEquityValue(userId, projectionList);
045 }
046
047 public SocialEquityValue getParticipationEquity(long userId)
048 throws SystemException {
049
050 ProjectionList projectionList = ProjectionFactoryUtil.projectionList();
051
052 projectionList.add(ProjectionFactoryUtil.sum("participationK"));
053 projectionList.add(ProjectionFactoryUtil.sum("participationB"));
054
055 return getSocialEquityValue(userId, projectionList);
056 }
057
058 public List<SocialEquityUser> getRankedSocialEquityUsers(
059 long groupId, int start, int end,
060 OrderByComparator orderByComparator)
061 throws SystemException {
062
063 return socialEquityUserPersistence.findByGroupRanked(
064 groupId, start, end, orderByComparator);
065 }
066
067 public int getRankedSocialEquityUsersCount(long groupId)
068 throws SystemException {
069
070 return socialEquityUserPersistence.countByGroupRanked(groupId);
071 }
072
073 protected SocialEquityValue getSocialEquityValue(
074 long userId, ProjectionList projectionList)
075 throws SystemException {
076
077 DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
078 SocialEquityUser.class);
079
080 dynamicQuery.setProjection(projectionList);
081
082 dynamicQuery.add(RestrictionsFactoryUtil.eq("userId", userId));
083
084 List<?> results = dynamicQuery(dynamicQuery);
085
086 Object[] values = (Object[])results.get(0);
087
088 SocialEquityValue socialEquityValue = null;
089
090 if (values[0] != null) {
091 socialEquityValue = new SocialEquityValue(
092 (Double)values[0], (Double)values[1]);
093 }
094 else {
095 socialEquityValue = new SocialEquityValue(0, 0);
096 }
097
098 return socialEquityValue;
099 }
100
101 }