001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata groupware may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: UserGroupDO.java,v $
031: * Revision 1.5 2005/10/14 14:33:30 colinmacleod
032: * Added isMember method to test for users which are members of this
033: * group.
034: *
035: * Revision 1.4 2005/10/12 18:36:50 colinmacleod
036: * Standardized format of Logger declaration - to make it easier to find
037: * instances which are not both static and final.
038: *
039: * Revision 1.3 2005/10/03 10:21:15 colinmacleod
040: * Fixed some style and javadoc issues.
041: *
042: * Revision 1.2 2005/10/02 14:08:58 colinmacleod
043: * Added/improved log4j logging.
044: *
045: * Revision 1.1 2005/09/29 14:17:04 colinmacleod
046: * Split UserGroupDO off from GroupDO.
047: * Moved UserGroupDO, Right classes to security subproject (from
048: * addressbook).
049: * Centralized user right handling into Rights and RightsImpl.
050: *
051: * Revision 1.5 2005/09/14 14:52:01 colinmacleod
052: * Added serialVersionUID.
053: *
054: * Revision 1.4 2005/04/28 18:47:10 colinmacleod
055: * Fixed XHMTL, styles and resin compatibility.
056: * Added support for URL rewriting.
057: *
058: * Revision 1.3 2005/04/10 20:09:36 colinmacleod
059: * Added new themes.
060: * Changed id type to String.
061: * Changed i tag to em and b tag to strong.
062: * Improved PicoContainerFactory with NanoContainer scripts.
063: *
064: * Revision 1.2 2005/04/09 17:19:07 colinmacleod
065: * Changed copyright text to GPL v2 explicitly.
066: *
067: * Revision 1.1.1.1 2005/03/10 17:50:31 colinmacleod
068: * Restructured ivata op around Hibernate/PicoContainer.
069: * Renamed ivata groupware.
070: *
071: * Revision 1.6 2004/12/31 18:22:13 colinmacleod
072: * Added override for displayValue.
073: *
074: * Revision 1.5 2004/11/12 15:57:05 colinmacleod
075: * Removed dependencies on SSLEXT.
076: * Moved Persistence classes to ivata masks.
077: *
078: * Revision 1.4 2004/07/13 19:41:13 colinmacleod
079: * Moved project to POJOs from EJBs.
080: * Applied PicoContainer to services layer (replacing session EJBs).
081: * Applied Hibernate to persistence layer (replacing entity EJBs).
082: *
083: * Revision 1.3 2004/03/21 21:16:06 colinmacleod
084: * Shortened name to ivata op.
085: *
086: * Revision 1.2 2004/02/01 22:00:32 colinmacleod
087: * Added full names to author tags
088: *
089: * Revision 1.1.1.1 2004/01/27 20:57:51 colinmacleod
090: * Moved ivata openportal to SourceForge..
091: *
092: * Revision 1.3 2003/10/17 12:36:12 jano
093: * fixing problems with building
094: * converting intranet -> portal
095: * Eclipse building
096: *
097: * Revision 1.2 2003/10/15 13:18:02 colin
098: * fixing for XDoclet
099: *
100: * Revision 1.3 2003/07/29 15:45:55 jano
101: * we have new field in groupDO
102: *
103: * Revision 1.2 2003/06/02 22:04:53 colin
104: * added comparison method
105: *
106: * Revision 1.1 2003/02/24 19:09:21 colin
107: * moved to business
108: *
109: * Revision 1.7 2003/02/04 17:43:45 colin
110: * copyright notice
111: *
112: * Revision 1.6 2003/01/10 10:29:23 jano
113: * we need information about user who created group
114: *
115: * Revision 1.5 2003/01/09 10:01:52 jano
116: * we are not storing group's rights in geoupDO now
117: * we are using methods in addressBookRightsBean
118: *
119: * Revision 1.4 2002/12/12 15:05:55 jano
120: * rights for groups
121: *
122: * Revision 1.3 2002/06/21 12:48:58 colin
123: * restructured com.ivata.groupware.web
124: *
125: * Revision 1.2 2002/06/17 07:28:54 colin
126: * improved and extended javadoc documentation
127: *
128: * Revision 1.1 2002/06/13 11:21:24 colin
129: * first version with rose model integration.
130: * -----------------------------------------------------------------------------
131: */
132: package com.ivata.groupware.admin.security.user.group;
133:
134: import java.util.HashSet;
135: import java.util.Iterator;
136: import java.util.Set;
137:
138: import org.apache.log4j.Logger;
139:
140: import com.ivata.groupware.admin.security.user.UserDO;
141: import com.ivata.groupware.container.persistence.AuthorTimestampNamedDO;
142:
143: /**
144: * <p>Represents a group of users. On the basis of these groupings, access
145: * rights are assigned throughout the system.</p>
146: *
147: * @since ivata groupware 1.0 (2002-05-15 - addressbook)
148: * @author Colin MacLeod
149: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
150: * @version $Revision: 1.5 $
151: *
152: * @hibernate.class
153: * table="user_group"
154: * @hibernate.cache
155: * usage="read-write"
156: */
157: public class UserGroupDO extends AuthorTimestampNamedDO {
158: /**
159: * Logger for this class.
160: */
161: private static final Logger logger = Logger
162: .getLogger(UserGroupDO.class);
163: /**
164: * Serialization version (for <code>Serializable</code> interface).
165: */
166: private static final long serialVersionUID = 1L;
167: /**
168: * <p>Store a clear-text description of the function and purpose of this
169: * group.</p>
170: */
171: private String description;
172:
173: /**
174: * <p>Store the name of the group. This name should uniquely identify the
175: * group in clear text.</p>
176: */
177: private String name;
178:
179: /**
180: * <p>All the users in this group.</p>
181: */
182: private Set users = new HashSet();
183:
184: /**
185: * <p>Get a clear-text description of the function and purpose of this
186: * group.</p>
187: *
188: * @return a clear-text description of the function and purpose of this
189: * group.
190: * @hibernate.property
191: */
192: public final String getDescription() {
193: if (logger.isDebugEnabled()) {
194: logger.debug("getDescription() - start");
195: }
196:
197: if (logger.isDebugEnabled()) {
198: logger.debug("getDescription() - end - return value = "
199: + description);
200: }
201: return description;
202: }
203:
204: /**
205: * <p>
206: * For a group, the value displayed in a choice box is just the name.
207: * </p>
208: *
209: * @see com.ivata.mask.valueobject.ValueObject#getDisplayValue()
210: */
211: public final String getDisplayValue() {
212: if (logger.isDebugEnabled()) {
213: logger.debug("getDisplayValue() - start");
214: }
215:
216: if (logger.isDebugEnabled()) {
217: logger.debug("getDisplayValue() - end - return value = "
218: + name);
219: }
220: return name;
221: }
222:
223: /**
224: * <p>Get the name of the group. This name should uniquely identify the
225: * group within its place in the heirarchy in clear text.</p>
226: *
227: * @return the name of this group, a clear-text string which identifies the
228: * group uniquely within its place in the group heirarchy.
229: * @hibernate.property
230: * column="name"
231: */
232: public final String getName() {
233: if (logger.isDebugEnabled()) {
234: logger.debug("getName() - start");
235: }
236:
237: if (logger.isDebugEnabled()) {
238: logger.debug("getName() - end - return value = " + name);
239: }
240: return name;
241: }
242:
243: /**
244: * <p>All the users in this group.</p>
245: *
246: * @return the users in this group.
247: *
248: * @hibernate.set
249: * role="person_user"
250: * table="user_group_member"
251: * @hibernate.collection-key
252: * column="user_group"
253: * @hibernate.collection-many-to-many
254: * class="com.ivata.groupware.admin.security.user.UserDO"
255: * column="person_user"
256: */
257: public final Set getUsers() {
258: if (logger.isDebugEnabled()) {
259: logger.debug("getUsers() - start");
260: }
261:
262: if (logger.isDebugEnabled()) {
263: logger.debug("getUsers() - end - return value = " + users);
264: }
265: return users;
266: }
267:
268: /**
269: * Check if the given user is in this group. This assumes the integrity of
270: * the users collection!
271: *
272: * @param userId The unique identifier of the user to check for
273: * membership.
274: * @return <code>true</code> if the given user is a member of this group.
275: */
276: public boolean isMember(final Integer userId) {
277: if (logger.isDebugEnabled()) {
278: logger.debug("isMember(Integer userId = " + userId
279: + ") - start");
280: }
281: assert (userId != null);
282:
283: Iterator iterator = users.iterator();
284: while (iterator.hasNext()) {
285: UserDO user = (UserDO) iterator.next();
286: if (userId.equals(user.getId())) {
287: if (logger.isDebugEnabled()) {
288: logger
289: .debug("isMember - end - return value = " + true);
290: }
291: return true;
292: }
293: }
294: // if it gets down here, no luck!
295: if (logger.isDebugEnabled()) {
296: logger
297: .debug("isMember(Integer) - end - return value = " + false);
298: }
299: return false;
300: }
301:
302: /**
303: * <p>Set a clear-text description of the function and purpose of this
304: * group.</p>
305: *
306: * @param descriptionParam a clear-text description of the function and
307: * purpose of this group.
308: */
309: public final void setDescription(final String descriptionParam) {
310: if (logger.isDebugEnabled()) {
311: logger.debug("setDescription(String description = "
312: + descriptionParam + ") - start");
313: }
314:
315: checkSetter();
316: this .description = descriptionParam;
317:
318: if (logger.isDebugEnabled()) {
319: logger.debug("setDescription(String) - end");
320: }
321: }
322:
323: /**
324: * <p>Set the name of the group. This name should uniquely identify the
325: * group in clear text.</p>
326: *
327: * @param nameParam the new name to set for this group.
328: */
329: public void setName(final String nameParam) {
330: if (logger.isDebugEnabled()) {
331: logger.debug("setName before: '" + name + "', after: '"
332: + nameParam + "'");
333: }
334: checkSetter();
335:
336: name = nameParam;
337:
338: if (logger.isDebugEnabled()) {
339: logger.debug("setName(String) - end");
340: }
341: }
342:
343: /**
344: * <p>All the users in this group.</p>
345: *
346: * @param usersParam the users in this group.
347: */
348: public void setUsers(final Set usersParam) {
349: if (logger.isDebugEnabled()) {
350: logger.debug("setUsers before: '" + users + "', after: '"
351: + usersParam + "'");
352: }
353: checkSetter();
354:
355: users = usersParam;
356:
357: if (logger.isDebugEnabled()) {
358: logger.debug("setUsers(Set) - end");
359: }
360: }
361: }
|