001
014
015 package com.liferay.portlet.usersadmin.action;
016
017 import com.liferay.portal.kernel.util.ParamUtil;
018 import com.liferay.portal.kernel.util.StringUtil;
019 import com.liferay.portal.model.Organization;
020 import com.liferay.portal.model.UserGroup;
021 import com.liferay.portal.service.UserLocalServiceUtil;
022 import com.liferay.portal.struts.AJAXAction;
023 import com.liferay.portal.util.PortalUtil;
024
025 import java.util.LinkedHashMap;
026
027 import javax.servlet.http.HttpServletRequest;
028 import javax.servlet.http.HttpServletResponse;
029
030 import org.apache.struts.action.ActionForm;
031 import org.apache.struts.action.ActionMapping;
032
033
036 public class GetUsersCountAction extends AJAXAction {
037
038 @Override
039 public String getText(
040 ActionMapping actionMapping, ActionForm actionForm,
041 HttpServletRequest request, HttpServletResponse response)
042 throws Exception {
043
044 long companyId = PortalUtil.getCompanyId(request);
045
046 String className = ParamUtil.getString(request, "className");
047 long[] ids = StringUtil.split(ParamUtil.getString(request, "ids"), 0L);
048 int status = ParamUtil.getInteger(request, "status");
049
050 int count = 0;
051
052 if (className.equals(Organization.class.getName())) {
053 count = getOrganizationUsersCount(companyId, ids, status);
054 }
055 else if (className.equals(UserGroup.class.getName())) {
056 count = getUserGroupUsersCount(companyId, ids, status);
057 }
058
059 return String.valueOf(count);
060 }
061
062 protected int getOrganizationUsersCount(
063 long companyId, long[] organizationIds, int status)
064 throws Exception {
065
066 int count = 0;
067
068 for (long organizationId : organizationIds) {
069 LinkedHashMap<String, Object> params =
070 new LinkedHashMap<String, Object>();
071
072 params.put("usersOrgs", organizationId);
073
074 count+= UserLocalServiceUtil.searchCount(
075 companyId, null, status, params);
076 }
077
078 return count;
079 }
080
081 protected int getUserGroupUsersCount(
082 long companyId, long[] userGroupIds, int status)
083 throws Exception {
084
085 int count = 0;
086
087 for (long userGroupId : userGroupIds) {
088 LinkedHashMap<String, Object> params =
089 new LinkedHashMap<String, Object>();
090
091 params.put("usersUserGroups", userGroupId);
092
093 count+= UserLocalServiceUtil.searchCount(
094 companyId, null, status, params);
095 }
096
097 return count;
098 }
099
100 }