001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsRoleUsersList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.accounts;
033:
034: import org.opencms.file.CmsUser;
035: import org.opencms.i18n.CmsMessageContainer;
036: import org.opencms.jsp.CmsJspActionElement;
037: import org.opencms.main.CmsException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.security.CmsOrganizationalUnit;
040: import org.opencms.security.CmsRole;
041: import org.opencms.workplace.CmsWorkplace;
042: import org.opencms.workplace.list.A_CmsListDialog;
043: import org.opencms.workplace.list.CmsListColumnAlignEnum;
044: import org.opencms.workplace.list.CmsListColumnDefinition;
045: import org.opencms.workplace.list.CmsListDirectAction;
046: import org.opencms.workplace.list.CmsListIndependentAction;
047: import org.opencms.workplace.list.CmsListItem;
048: import org.opencms.workplace.list.CmsListItemDetails;
049: import org.opencms.workplace.list.CmsListItemDetailsFormatter;
050: import org.opencms.workplace.list.CmsListMetadata;
051: import org.opencms.workplace.list.CmsListOrderEnum;
052: import org.opencms.workplace.tools.A_CmsHtmlIconButton;
053:
054: import java.util.ArrayList;
055: import java.util.Iterator;
056: import java.util.List;
057:
058: /**
059: * Generalized role users view.<p>
060: *
061: * @author Raphael Schnuck
062: *
063: * @version $Revision: 1.4 $
064: *
065: * @since 6.5.6
066: */
067: public abstract class A_CmsRoleUsersList extends A_CmsListDialog {
068:
069: /** list action id constant. */
070: public static final String LIST_ACTION_ICON = "ai";
071:
072: /** list column id constant. */
073: public static final String LIST_COLUMN_FULLNAME = "cf";
074:
075: /** list column id constant. */
076: public static final String LIST_COLUMN_ICON = "ci";
077:
078: /** list column id constant. */
079: public static final String LIST_COLUMN_LOGIN = "cl";
080:
081: /** list column id constant. */
082: public static final String LIST_COLUMN_NAME = "cn";
083:
084: /** list column id constant. */
085: public static final String LIST_COLUMN_ORGUNIT = "co";
086:
087: /** list column id constant. */
088: public static final String LIST_COLUMN_STATE = "cs";
089:
090: /** list item detail id constant. */
091: public static final String LIST_DETAIL_ORGUNIT = "dou";
092:
093: /** Path to the list buttons. */
094: public static final String PATH_BUTTONS = "tools/accounts/buttons/";
095:
096: /** Cached value. */
097: private Boolean m_hasUsersInOtherOus;
098:
099: /** Stores the value of the request parameter for the organizational unit fqn. */
100: private String m_paramOufqn;
101:
102: /** Stores the value of the request parameter for the role name. */
103: private String m_paramRole;
104:
105: /**
106: * Public constructor.<p>
107: *
108: * @param jsp an initialized JSP action element
109: * @param listId the id of the list
110: * @param listName the name of the list
111: * @param searchable searchable flag
112: */
113: protected A_CmsRoleUsersList(CmsJspActionElement jsp,
114: String listId, CmsMessageContainer listName,
115: boolean searchable) {
116:
117: super (jsp, listId, listName, LIST_COLUMN_LOGIN,
118: CmsListOrderEnum.ORDER_ASCENDING,
119: searchable ? LIST_COLUMN_NAME : null);
120: }
121:
122: /**
123: * Returns the organizational unit fqn parameter value.<p>
124: *
125: * @return the organizational unit fqn parameter value
126: */
127: public String getParamOufqn() {
128:
129: return m_paramOufqn;
130: }
131:
132: /**
133: * Returns the role name parameter value.<p>
134: *
135: * @return the role name parameter value
136: */
137: public String getParamRole() {
138:
139: return m_paramRole;
140: }
141:
142: /**
143: * Returns if the list of users has users of other organizational units.<p>
144: *
145: * @return if the list of users has users of other organizational units
146: */
147: public boolean hasUsersInOtherOus() {
148:
149: if (m_hasUsersInOtherOus == null) {
150: // lazzy initialization
151: m_hasUsersInOtherOus = Boolean.FALSE;
152: try {
153: Iterator itUsers = getUsers(true).iterator();
154: while (itUsers.hasNext()) {
155: CmsUser user = (CmsUser) itUsers.next();
156: if (!user.getOuFqn().equals(getParamOufqn())) {
157: m_hasUsersInOtherOus = Boolean.TRUE;
158: break;
159: }
160: }
161: } catch (Exception e) {
162: // ignore
163: }
164: }
165: return m_hasUsersInOtherOus.booleanValue();
166: }
167:
168: /**
169: * Sets the organizational unit fqn parameter value.<p>
170: *
171: * @param ouFqn the organizational unit fqn parameter value
172: */
173: public void setParamOufqn(String ouFqn) {
174:
175: if (ouFqn == null) {
176: ouFqn = "";
177: }
178: m_paramOufqn = ouFqn;
179: }
180:
181: /**
182: * Sets the role name parameter value.<p>
183: *
184: * @param roleName the role name parameter value
185: */
186: public void setParamRole(String roleName) {
187:
188: m_paramRole = roleName;
189: }
190:
191: /**
192: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
193: */
194: protected void fillDetails(String detailId) {
195:
196: // noop
197: }
198:
199: /**
200: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
201: */
202: protected List getListItems() throws CmsException {
203:
204: List ret = new ArrayList();
205:
206: boolean withOtherOus = hasUsersInOtherOus()
207: && getList().getMetadata().getItemDetailDefinition(
208: LIST_DETAIL_ORGUNIT).isVisible();
209:
210: // get content
211: List users = getUsers(withOtherOus);
212: Iterator itUsers = users.iterator();
213: while (itUsers.hasNext()) {
214: CmsUser user = (CmsUser) itUsers.next();
215: CmsListItem item = getList().newItem(
216: user.getId().toString());
217: item.set(LIST_COLUMN_LOGIN, user.getName());
218: item.set(LIST_COLUMN_NAME, user.getSimpleName());
219: item.set(LIST_COLUMN_ORGUNIT,
220: CmsOrganizationalUnit.SEPARATOR + user.getOuFqn());
221: item.set(LIST_COLUMN_FULLNAME, user.getFullName());
222: ret.add(item);
223: }
224:
225: return ret;
226: }
227:
228: /**
229: * Returns a list of users to display.<p>
230: *
231: * @param withOtherOus if not set only users of the current ou should be returned
232: *
233: * @return a list of <code><{@link CmsUser}</code>s
234: *
235: * @throws CmsException if something goes wrong
236: */
237: protected abstract List getUsers(boolean withOtherOus)
238: throws CmsException;
239:
240: /**
241: * @see org.opencms.workplace.list.A_CmsListDialog#initializeDetail(java.lang.String)
242: */
243: protected void initializeDetail(String detailId) {
244:
245: super .initializeDetail(detailId);
246: if (detailId.equals(LIST_DETAIL_ORGUNIT)) {
247: boolean visible = hasUsersInOtherOus()
248: && getList().getMetadata().getItemDetailDefinition(
249: LIST_DETAIL_ORGUNIT).isVisible();
250: getList().getMetadata().getColumnDefinition(
251: LIST_COLUMN_ORGUNIT).setVisible(visible);
252: getList().getMetadata().getColumnDefinition(
253: LIST_COLUMN_ORGUNIT).setPrintable(visible);
254: }
255: }
256:
257: /**
258: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
259: */
260: protected void setColumns(CmsListMetadata metadata) {
261:
262: // create column for icon display
263: CmsListColumnDefinition iconCol = new CmsListColumnDefinition(
264: LIST_COLUMN_ICON);
265: iconCol.setName(Messages.get().container(
266: Messages.GUI_USERS_LIST_COLS_ICON_0));
267: iconCol.setHelpText(Messages.get().container(
268: Messages.GUI_USERS_LIST_COLS_ICON_HELP_0));
269: iconCol.setWidth("20");
270: iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
271: iconCol.setSorteable(false);
272:
273: CmsListDirectAction iconAction = new CmsListDirectAction(
274: LIST_ACTION_ICON) {
275:
276: /**
277: * @see org.opencms.workplace.list.CmsListDirectAction#buttonHtml(org.opencms.workplace.CmsWorkplace)
278: */
279: public String buttonHtml(CmsWorkplace wp) {
280:
281: if (!isVisible()) {
282: return "";
283: }
284: return A_CmsHtmlIconButton.defaultButtonHtml(
285: resolveButtonStyle(), getId()
286: + getItem().getId(), getId()
287: + getItem().getId(), resolveName(wp
288: .getLocale()), resolveHelpText(wp
289: .getLocale()), isEnabled(),
290: getIconPath(), null, resolveOnClic(wp
291: .getLocale()), false, null);
292: }
293:
294: /**
295: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getHelpText()
296: */
297: public CmsMessageContainer getHelpText() {
298:
299: try {
300: CmsUser user = getCms().readUser(
301: (String) getItem().get(LIST_COLUMN_LOGIN));
302: if (user.getOuFqn().equals(
303: ((A_CmsRoleUsersList) getWp())
304: .getParamOufqn())) {
305: List userRoles = OpenCms.getRoleManager()
306: .getRolesOfUser(
307: ((A_CmsRoleUsersList) getWp())
308: .getCms(),
309: user.getName(),
310: ((A_CmsRoleUsersList) getWp())
311: .getParamOufqn(),
312: false, true, true);
313: Iterator itUserRoles = userRoles.iterator();
314: while (itUserRoles.hasNext()) {
315: CmsRole role = (CmsRole) itUserRoles.next();
316: if (role.getGroupName().equals(
317: ((A_CmsRoleUsersList) getWp())
318: .getParamRole())) {
319: return Messages
320: .get()
321: .container(
322: Messages.GUI_USERS_LIST_INROLE_HELP_0);
323: }
324: }
325: return Messages
326: .get()
327: .container(
328: Messages.GUI_USERS_LIST_INROLE_INDIRECT_HELP_0);
329:
330: } else {
331: return Messages
332: .get()
333: .container(
334: Messages.GUI_USERS_LIST_INROLE_OTHEROU_HELP_0);
335: }
336: } catch (CmsException e) {
337: return Messages.get().container(
338: Messages.GUI_USERS_LIST_INROLE_HELP_0);
339: }
340: }
341:
342: /**
343: * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getIconPath()
344: */
345: public String getIconPath() {
346:
347: try {
348: CmsUser user = getCms().readUser(
349: (String) getItem().get(LIST_COLUMN_LOGIN));
350: if (user.getOuFqn().equals(
351: ((A_CmsRoleUsersList) getWp())
352: .getParamOufqn())) {
353: List userRoles = OpenCms.getRoleManager()
354: .getRolesOfUser(
355: ((A_CmsRoleUsersList) getWp())
356: .getCms(),
357: user.getName(),
358: ((A_CmsRoleUsersList) getWp())
359: .getParamOufqn(),
360: false, true, true);
361: Iterator itUserRoles = userRoles.iterator();
362: while (itUserRoles.hasNext()) {
363: CmsRole role = (CmsRole) itUserRoles.next();
364: if (role.getGroupName().equals(
365: ((A_CmsRoleUsersList) getWp())
366: .getParamRole())) {
367: return A_CmsUsersList.PATH_BUTTONS
368: + "user.png";
369: }
370: }
371: return A_CmsUsersList.PATH_BUTTONS
372: + "user_indirect.png";
373:
374: } else {
375: return A_CmsUsersList.PATH_BUTTONS
376: + "user_other_ou.png";
377: }
378: } catch (CmsException e) {
379: return A_CmsUsersList.PATH_BUTTONS + "user.png";
380: }
381: }
382:
383: /**
384: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getName()
385: */
386: public CmsMessageContainer getName() {
387:
388: try {
389: CmsUser user = getCms().readUser(
390: (String) getItem().get(LIST_COLUMN_LOGIN));
391: if (user.getOuFqn().equals(
392: ((A_CmsRoleUsersList) getWp())
393: .getParamOufqn())) {
394: List userRoles = OpenCms.getRoleManager()
395: .getRolesOfUser(
396: ((A_CmsRoleUsersList) getWp())
397: .getCms(),
398: user.getName(),
399: ((A_CmsRoleUsersList) getWp())
400: .getParamOufqn(),
401: false, true, true);
402: Iterator itUserRoles = userRoles.iterator();
403: while (itUserRoles.hasNext()) {
404: CmsRole role = (CmsRole) itUserRoles.next();
405: if (role.getGroupName().equals(
406: ((A_CmsRoleUsersList) getWp())
407: .getParamRole())) {
408: return Messages
409: .get()
410: .container(
411: Messages.GUI_USERS_LIST_INROLE_NAME_0);
412: }
413: }
414: return Messages
415: .get()
416: .container(
417: Messages.GUI_USERS_LIST_INROLE_INDIRECT_NAME_0);
418:
419: } else {
420: return Messages
421: .get()
422: .container(
423: Messages.GUI_USERS_LIST_INROLE_OTHEROU_NAME_0);
424: }
425: } catch (CmsException e) {
426: return Messages.get().container(
427: Messages.GUI_USERS_LIST_INROLE_NAME_0);
428: }
429: }
430: };
431: iconAction.setName(Messages.get().container(
432: Messages.GUI_USERS_LIST_INROLE_NAME_0));
433: iconAction.setHelpText(Messages.get().container(
434: Messages.GUI_USERS_LIST_INROLE_HELP_0));
435: iconAction.setIconPath(PATH_BUTTONS + "user.png");
436: iconAction.setEnabled(false);
437: iconCol.addDirectAction(iconAction);
438: // add it to the list definition
439: metadata.addColumn(iconCol);
440:
441: // create column for login
442: CmsListColumnDefinition loginCol = new CmsListColumnDefinition(
443: LIST_COLUMN_LOGIN);
444: loginCol.setVisible(false);
445: // add it to the list definition
446: metadata.addColumn(loginCol);
447:
448: // create column for name
449: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
450: LIST_COLUMN_NAME);
451: nameCol.setName(Messages.get().container(
452: Messages.GUI_USERS_LIST_COLS_LOGIN_0));
453: nameCol.setWidth("35%");
454: // add it to the list definition
455: metadata.addColumn(nameCol);
456:
457: // create column for orgunit
458: CmsListColumnDefinition orgunitCol = new CmsListColumnDefinition(
459: LIST_COLUMN_ORGUNIT);
460: orgunitCol.setName(Messages.get().container(
461: Messages.GUI_USERS_LIST_COLS_ORGUNIT_0));
462: orgunitCol.setVisible(false);
463: // add it to the list definition
464: metadata.addColumn(orgunitCol);
465:
466: // create column for fullname
467: CmsListColumnDefinition fullnameCol = new CmsListColumnDefinition(
468: LIST_COLUMN_FULLNAME);
469: fullnameCol.setName(Messages.get().container(
470: Messages.GUI_USERS_LIST_COLS_FULLNAME_0));
471: fullnameCol.setWidth("65%");
472: fullnameCol.setTextWrapping(true);
473: // add it to the list definition
474: metadata.addColumn(fullnameCol);
475: }
476:
477: /**
478: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
479: */
480: protected void setIndependentActions(CmsListMetadata metadata) {
481:
482: // add other ou button
483: CmsListItemDetails otherOuDetails = new CmsListItemDetails(
484: LIST_DETAIL_ORGUNIT);
485: otherOuDetails.setAtColumn(LIST_COLUMN_NAME);
486: otherOuDetails.setVisible(false);
487: otherOuDetails.setHideAction(new CmsListIndependentAction(
488: LIST_DETAIL_ORGUNIT) {
489:
490: /**
491: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
492: */
493: public String getIconPath() {
494:
495: return A_CmsListDialog.ICON_DETAILS_HIDE;
496: }
497:
498: /**
499: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
500: */
501: public boolean isVisible() {
502:
503: return ((A_CmsRoleUsersList) getWp())
504: .hasUsersInOtherOus();
505: }
506: });
507: otherOuDetails.setShowAction(new CmsListIndependentAction(
508: LIST_DETAIL_ORGUNIT) {
509:
510: /**
511: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
512: */
513: public String getIconPath() {
514:
515: return A_CmsListDialog.ICON_DETAILS_SHOW;
516: }
517:
518: /**
519: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
520: */
521: public boolean isVisible() {
522:
523: return ((A_CmsRoleUsersList) getWp())
524: .hasUsersInOtherOus();
525: }
526: });
527: otherOuDetails.setShowActionName(Messages.get().container(
528: Messages.GUI_USERS_DETAIL_SHOW_OTHEROU_NAME_0));
529: otherOuDetails.setShowActionHelpText(Messages.get().container(
530: Messages.GUI_USERS_DETAIL_SHOW_OTHEROU_HELP_0));
531: otherOuDetails.setHideActionName(Messages.get().container(
532: Messages.GUI_USERS_DETAIL_HIDE_OTHEROU_NAME_0));
533: otherOuDetails.setHideActionHelpText(Messages.get().container(
534: Messages.GUI_USERS_DETAIL_HIDE_OTHEROU_HELP_0));
535: otherOuDetails.setName(Messages.get().container(
536: Messages.GUI_USERS_DETAIL_OTHEROU_NAME_0));
537: otherOuDetails.setFormatter(new CmsListItemDetailsFormatter(
538: Messages.get().container(
539: Messages.GUI_USERS_DETAIL_OTHEROU_NAME_0)));
540: otherOuDetails.setVisible(true);
541: metadata.addItemDetails(otherOuDetails);
542: }
543:
544: /**
545: * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
546: */
547: protected void validateParamaters() throws Exception {
548:
549: // test the needed parameters
550: OpenCms.getRoleManager().checkRole(getCms(),
551: CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn()));
552: CmsRole.valueOf(getCms().readGroup(getParamRole()))
553: .getRoleName();
554: }
555:
556: }
|