001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.tools.accounts; 029 030import org.opencms.file.CmsGroup; 031import org.opencms.file.CmsUser; 032import org.opencms.file.CmsUserSearchParameters; 033import org.opencms.file.CmsUserSearchParameters.SortKey; 034import org.opencms.jsp.CmsJspActionElement; 035import org.opencms.main.CmsException; 036import org.opencms.main.CmsRuntimeException; 037import org.opencms.main.OpenCms; 038import org.opencms.security.CmsOrganizationalUnit; 039import org.opencms.security.CmsRole; 040import org.opencms.workplace.list.CmsListItem; 041import org.opencms.workplace.list.CmsListMetadata; 042import org.opencms.workplace.list.CmsListOrderEnum; 043import org.opencms.workplace.list.CmsListState; 044 045import java.util.List; 046import java.util.Set; 047 048import javax.servlet.http.HttpServletRequest; 049import javax.servlet.http.HttpServletResponse; 050import javax.servlet.jsp.PageContext; 051 052import com.google.common.collect.Lists; 053 054/** 055 * Role users list view.<p> 056 * 057 * @since 6.5.6 058 */ 059public class CmsShowRoleUsersList extends A_CmsRoleUsersList { 060 061 /** list id constant. */ 062 public static final String LIST_ID = "lsru"; 063 064 /** 065 * Public constructor.<p> 066 * 067 * @param jsp an initialized JSP action element 068 */ 069 public CmsShowRoleUsersList(CmsJspActionElement jsp) { 070 071 this(jsp, LIST_ID); 072 } 073 074 /** 075 * Public constructor with JSP variables.<p> 076 * 077 * @param context the JSP page context 078 * @param req the JSP request 079 * @param res the JSP response 080 */ 081 public CmsShowRoleUsersList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 082 083 this(new CmsJspActionElement(context, req, res)); 084 } 085 086 /** 087 * Protected constructor.<p> 088 * @param jsp an initialized JSP action element 089 * @param listId the id of the specialized list 090 */ 091 protected CmsShowRoleUsersList(CmsJspActionElement jsp, String listId) { 092 093 super(jsp, listId, Messages.get().container(Messages.GUI_ROLEUSERS_LIST_NAME_0), true); 094 } 095 096 /** 097 * Public constructor.<p> 098 * 099 * @param jsp an initialized JSP action element 100 * @param lazy the lazy flag 101 */ 102 public CmsShowRoleUsersList(CmsJspActionElement jsp, boolean lazy) { 103 104 this(jsp, LIST_ID, lazy); 105 } 106 107 /** 108 * Public constructor with JSP variables.<p> 109 * 110 * @param context the JSP page context 111 * @param req the JSP request 112 * @param res the JSP response 113 * @param lazy the lazy flag 114 */ 115 public CmsShowRoleUsersList(PageContext context, HttpServletRequest req, HttpServletResponse res, boolean lazy) { 116 117 this(new CmsJspActionElement(context, req, res), lazy); 118 } 119 120 /** 121 * Protected constructor.<p> 122 * @param jsp an initialized JSP action element 123 * @param listId the id of the specialized list 124 * @param lazy the lazy flag 125 */ 126 protected CmsShowRoleUsersList(CmsJspActionElement jsp, String listId, boolean lazy) { 127 128 super(jsp, listId, Messages.get().container(Messages.GUI_ROLEUSERS_LIST_NAME_0), true, lazy); 129 } 130 131 /** 132 * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlStart() 133 */ 134 @Override 135 public String defaultActionHtmlStart() { 136 137 return getList().listJs() + dialogContentStart(getParamTitle()); 138 } 139 140 /** 141 * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions() 142 */ 143 @Override 144 public void executeListMultiActions() throws CmsRuntimeException { 145 146 throwListUnsupportedActionException(); 147 } 148 149 /** 150 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions() 151 */ 152 @Override 153 public void executeListSingleActions() { 154 155 throwListUnsupportedActionException(); 156 } 157 158 /** 159 * @see org.opencms.workplace.tools.accounts.A_CmsRoleUsersList#setColumns(org.opencms.workplace.list.CmsListMetadata) 160 */ 161 @Override 162 public void setColumns(CmsListMetadata meta) { 163 164 if (m_lazy) { 165 meta.setSelfManaged(true); 166 } 167 super.setColumns(meta); 168 } 169 170 /** 171 * @see org.opencms.workplace.tools.accounts.A_CmsRoleUsersList#getUsers(boolean) 172 */ 173 @Override 174 protected List<CmsUser> getUsers(boolean withOtherOus) throws CmsException { 175 176 return OpenCms.getRoleManager().getUsersOfRole( 177 getCms(), 178 CmsRole.valueOf(getCms().readGroup(getParamRole())), 179 withOtherOus, 180 false); 181 } 182 183 /** 184 * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata) 185 */ 186 @Override 187 protected void setMultiActions(CmsListMetadata metadata) { 188 189 // noop 190 } 191 192 /** 193 * @see org.opencms.workplace.tools.accounts.A_CmsRoleUsersList#getListItems() 194 */ 195 @Override 196 protected List<CmsListItem> getListItems() throws CmsException { 197 198 if (!m_lazy) { 199 return super.getListItems(); 200 } else { 201 CmsUserSearchParameters params = getSearchParams(); 202 List<CmsUser> users = OpenCms.getOrgUnitManager().searchUsers(getCms(), params); 203 int count = (int)OpenCms.getOrgUnitManager().countUsers(getCms(), params); 204 getList().setSize(count); 205 List<CmsListItem> result = Lists.newArrayList(); 206 for (CmsUser user : users) { 207 CmsListItem item = makeUserItem(user); 208 result.add(item); 209 } 210 return result; 211 } 212 } 213 214 /** 215 * Gets the search parameters.<p> 216 * 217 * @return the search parameters 218 * 219 * @throws CmsException if something goes wrong 220 */ 221 protected CmsUserSearchParameters getSearchParams() throws CmsException { 222 223 CmsListState state = getListState(); 224 CmsUserSearchParameters params = new CmsUserSearchParameters(); 225 String searchFilter = state.getFilter(); 226 params.setSearchFilter(searchFilter); 227 if (!otherOrgUnitsVisible()) { 228 CmsOrganizationalUnit ou = OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), getParamOufqn()); 229 params.setOrganizationalUnit(ou); 230 } 231 params.setPaging(getList().getMaxItemsPerPage(), state.getPage()); 232 CmsRole role = CmsRole.valueOf(getCms().readGroup(getParamRole())); 233 Set<CmsGroup> roleGroups = OpenCms.getRoleManager().getRoleGroups(getCms(), role, false); 234 params.setAnyGroups(roleGroups); 235 params.setSorting(getSortKey(state.getColumn()), state.getOrder().equals(CmsListOrderEnum.ORDER_ASCENDING)); 236 params.setFilterByGroupOu(false); 237 return params; 238 } 239 240 /** 241 * Gets the sort key for a column.<p> 242 * 243 * @param column a column 244 * @return the sort key 245 */ 246 protected SortKey getSortKey(String column) { 247 248 if (column == null) { 249 return null; 250 } 251 if (column.equals(LIST_COLUMN_FULLNAME)) { 252 return SortKey.fullName; 253 } else if (column.equals(LIST_COLUMN_NAME)) { 254 return SortKey.loginName; 255 } else if (column.equals(LIST_COLUMN_ORGUNIT)) { 256 return SortKey.orgUnit; 257 } 258 return null; 259 } 260 261}