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.CmsUser; 031import org.opencms.i18n.CmsMessageContainer; 032import org.opencms.jsp.CmsJspActionElement; 033import org.opencms.main.CmsException; 034import org.opencms.main.OpenCms; 035import org.opencms.security.CmsOrganizationalUnit; 036import org.opencms.security.CmsRole; 037import org.opencms.workplace.list.A_CmsListDialog; 038import org.opencms.workplace.list.CmsListColumnAlignEnum; 039import org.opencms.workplace.list.CmsListColumnDefinition; 040import org.opencms.workplace.list.CmsListItem; 041import org.opencms.workplace.list.CmsListMetadata; 042import org.opencms.workplace.list.CmsListOrderEnum; 043 044import java.util.ArrayList; 045import java.util.Iterator; 046import java.util.List; 047 048/** 049 * Generalized organizational unit users view.<p> 050 * 051 * @since 6.5.6 052 */ 053public abstract class A_CmsOrgUnitUsersList extends A_CmsListDialog { 054 055 /** list action id constant. */ 056 public static final String LIST_ACTION_ICON = "ai"; 057 058 /** list action id constant. */ 059 public static final String LIST_ACTION_STATE = "as"; 060 061 /** list column id constant. */ 062 public static final String LIST_COLUMN_FULLNAME = "cf"; 063 064 /** list column id constant. */ 065 public static final String LIST_COLUMN_ICON = "ci"; 066 067 /** list column id constant. */ 068 public static final String LIST_COLUMN_LOGIN = "cl"; 069 070 /** list column id constant. */ 071 public static final String LIST_COLUMN_NAME = "cn"; 072 073 /** list column id constant. */ 074 public static final String LIST_COLUMN_ORGUNIT = "co"; 075 076 /** list column id constant. */ 077 public static final String LIST_COLUMN_STATE = "cs"; 078 079 /** Constant for session attribute. */ 080 public static final String NOT_ORGUNIT_USERS = "not_orgunit_users"; 081 082 /** Constant for session attribute. */ 083 public static final String ORGUNIT_USERS = "orgunit_users"; 084 085 /** Stores the users not in the current ou.*/ 086 private List<CmsUser> m_notOuUsers; 087 088 /** Stores the users of the the current ou.*/ 089 private List<CmsUser> m_ouUsers; 090 091 /** Stores the value of the request parameter for the organizational unit fqn. */ 092 private String m_paramOufqn; 093 094 /** 095 * Public constructor.<p> 096 * 097 * @param jsp an initialized JSP action element 098 * @param listId the id of the list 099 * @param listName the name of the list 100 * @param searchable searchable flag 101 */ 102 protected A_CmsOrgUnitUsersList( 103 CmsJspActionElement jsp, 104 String listId, 105 CmsMessageContainer listName, 106 boolean searchable) { 107 108 super( 109 jsp, 110 listId, 111 listName, 112 LIST_COLUMN_LOGIN, 113 CmsListOrderEnum.ORDER_ASCENDING, 114 searchable ? LIST_COLUMN_NAME : null); 115 } 116 117 /** 118 * Returns the notOuUsers.<p> 119 * 120 * @return the notOuUsers 121 */ 122 public List<CmsUser> getNotOuUsers() { 123 124 return m_notOuUsers; 125 } 126 127 /** 128 * Returns the ouUsers.<p> 129 * 130 * @return the ouUsers 131 */ 132 public List<CmsUser> getOuUsers() { 133 134 return m_ouUsers; 135 } 136 137 /** 138 * Returns the right icon path for the given list item.<p> 139 * 140 * @param item the list item to get the icon path for 141 * 142 * @return the icon path for the given role 143 */ 144 public String getIconPath(CmsListItem item) { 145 146 try { 147 CmsUser user = getCms().readUser((String)item.get(LIST_COLUMN_LOGIN)); 148 if (user.getOuFqn().equals(getParamOufqn())) { 149 return A_CmsUsersList.PATH_BUTTONS + "user.png"; 150 } else { 151 return A_CmsUsersList.PATH_BUTTONS + "user_other_ou.png"; 152 } 153 } catch (CmsException e) { 154 return A_CmsUsersList.PATH_BUTTONS + "user.png"; 155 } 156 } 157 158 /** 159 * Returns the organizational unit fqn parameter value.<p> 160 * 161 * @return the organizational unit fqn parameter value 162 */ 163 public String getParamOufqn() { 164 165 return m_paramOufqn; 166 } 167 168 /** 169 * Sets the notOuUsers.<p> 170 * 171 * @param notOuUsers the notOuUsers to set 172 */ 173 public void setNotOuUsers(List<CmsUser> notOuUsers) { 174 175 m_notOuUsers = notOuUsers; 176 getJsp().getRequest().getSession().setAttribute(A_CmsOrgUnitUsersList.NOT_ORGUNIT_USERS, m_notOuUsers); 177 } 178 179 /** 180 * Sets the ouUsers.<p> 181 * 182 * @param ouUsers the ouUsers to set 183 */ 184 public void setOuUsers(List<CmsUser> ouUsers) { 185 186 m_ouUsers = ouUsers; 187 getJsp().getRequest().getSession().setAttribute(A_CmsOrgUnitUsersList.ORGUNIT_USERS, m_ouUsers); 188 } 189 190 /** 191 * Sets the organizational unit fqn parameter value.<p> 192 * 193 * @param ouFqn the organizational unit fqn parameter value 194 */ 195 public void setParamOufqn(String ouFqn) { 196 197 if (ouFqn == null) { 198 ouFqn = ""; 199 } 200 m_paramOufqn = ouFqn; 201 } 202 203 /** 204 * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String) 205 */ 206 @Override 207 protected void fillDetails(String detailId) { 208 209 // noop 210 } 211 212 /** 213 * @see org.opencms.workplace.list.A_CmsListDialog#getListItems() 214 */ 215 @Override 216 protected List<CmsListItem> getListItems() throws CmsException { 217 218 List<CmsListItem> ret = new ArrayList<CmsListItem>(); 219 220 // get content 221 List<CmsUser> users = getUsers(); 222 Iterator<CmsUser> itUsers = users.iterator(); 223 while (itUsers.hasNext()) { 224 CmsUser user = itUsers.next(); 225 CmsListItem item = getList().newItem(user.getId().toString()); 226 item.set(LIST_COLUMN_LOGIN, user.getName()); 227 item.set(LIST_COLUMN_NAME, user.getSimpleName()); 228 item.set(LIST_COLUMN_ORGUNIT, CmsOrganizationalUnit.SEPARATOR + user.getOuFqn()); 229 item.set(LIST_COLUMN_FULLNAME, user.getFullName()); 230 ret.add(item); 231 } 232 233 return ret; 234 } 235 236 /** 237 * Returns a list of users to display.<p> 238 * 239 * @return a list of <code><{@link CmsUser}</code>s 240 * 241 * @throws CmsException if something goes wrong 242 */ 243 protected abstract List<CmsUser> getUsers() throws CmsException; 244 245 /** 246 * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata) 247 */ 248 @Override 249 protected void setColumns(CmsListMetadata metadata) { 250 251 // create column for icon display 252 CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON); 253 iconCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_ICON_0)); 254 iconCol.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_COLS_ICON_HELP_0)); 255 iconCol.setWidth("20"); 256 iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 257 iconCol.setSorteable(false); 258 // set icon action 259 setIconAction(iconCol); 260 // add it to the list definition 261 metadata.addColumn(iconCol); 262 263 setStateActionCol(metadata); 264 265 // create column for login 266 CmsListColumnDefinition loginCol = new CmsListColumnDefinition(LIST_COLUMN_LOGIN); 267 loginCol.setVisible(false); 268 // add it to the list definition 269 metadata.addColumn(loginCol); 270 271 // create column for name 272 CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME); 273 nameCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_LOGIN_0)); 274 nameCol.setWidth("20%"); 275 setDefaultAction(nameCol); 276 // add it to the list definition 277 metadata.addColumn(nameCol); 278 279 // create column for organizational unit 280 CmsListColumnDefinition orgUnitCol = new CmsListColumnDefinition(LIST_COLUMN_ORGUNIT); 281 orgUnitCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_ORGUNIT_0)); 282 orgUnitCol.setWidth("40%"); 283 // add it to the list definition 284 metadata.addColumn(orgUnitCol); 285 286 // create column for fullname 287 CmsListColumnDefinition fullnameCol = new CmsListColumnDefinition(LIST_COLUMN_FULLNAME); 288 fullnameCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_FULLNAME_0)); 289 fullnameCol.setWidth("40%"); 290 fullnameCol.setTextWrapping(true); 291 // add it to the list definition 292 metadata.addColumn(fullnameCol); 293 } 294 295 /** 296 * Sets the optional login default action.<p> 297 * 298 * @param loginCol the login column 299 */ 300 protected abstract void setDefaultAction(CmsListColumnDefinition loginCol); 301 302 /** 303 * Sets the needed icon action(s).<p> 304 * 305 * @param iconCol the list column for edition. 306 */ 307 protected abstract void setIconAction(CmsListColumnDefinition iconCol); 308 309 /** 310 * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata) 311 */ 312 @Override 313 protected void setIndependentActions(CmsListMetadata metadata) { 314 315 // noop 316 } 317 318 /** 319 * Sets the optional state change action column.<p> 320 * 321 * @param metadata the list metadata object 322 */ 323 protected abstract void setStateActionCol(CmsListMetadata metadata); 324 325 /** 326 * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters() 327 */ 328 @Override 329 protected void validateParamaters() throws Exception { 330 331 // test the needed parameters 332 OpenCms.getRoleManager().checkRole(getCms(), CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn())); 333 OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), m_paramOufqn).getName(); 334 } 335}