001
014
015 package com.liferay.portlet.enterpriseadmin.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 public String getText(
039 ActionMapping mapping, ActionForm form, HttpServletRequest request,
040 HttpServletResponse response)
041 throws Exception {
042
043 long companyId = PortalUtil.getCompanyId(request);
044
045 String className = ParamUtil.getString(request, "className");
046 long[] ids = StringUtil.split(ParamUtil.getString(request, "ids"), 0L);
047 boolean active = ParamUtil.getBoolean(request, "active");
048
049 int count = 0;
050
051 if (className.equals(Organization.class.getName())) {
052 count = getOrganizationUsersCount(companyId, ids, active);
053 }
054 else if (className.equals(UserGroup.class.getName())) {
055 count = getUserGroupUsersCount(companyId, ids, active);
056 }
057
058 return String.valueOf(count);
059 }
060
061 protected int getOrganizationUsersCount(
062 long companyId, long[] organizationIds, boolean active)
063 throws Exception {
064
065 int count = 0;
066
067 for (long organizationId : organizationIds) {
068 LinkedHashMap<String, Object> params =
069 new LinkedHashMap<String, Object>();
070
071 params.put("usersOrgs", organizationId);
072
073 count+= UserLocalServiceUtil.searchCount(
074 companyId, null, active, params);
075 }
076
077 return count;
078 }
079
080 protected int getUserGroupUsersCount(
081 long companyId, long[] userGroupIds, boolean active)
082 throws Exception {
083
084 int count = 0;
085
086 for (long userGroupId : userGroupIds) {
087 LinkedHashMap<String, Object> params =
088 new LinkedHashMap<String, Object>();
089
090 params.put("usersUserGroups", userGroupId);
091
092 count+= UserLocalServiceUtil.searchCount(
093 companyId, null, active, params);
094 }
095
096 return count;
097 }
098
099 }