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: GroupDO.java,v $
031: * Revision 1.9 2005/10/11 18:53:07 colinmacleod
032: * Fixed some checkstyle and javadoc issues.
033: *
034: * Revision 1.8 2005/10/03 10:21:13 colinmacleod
035: * Fixed some style and javadoc issues.
036: *
037: * Revision 1.7 2005/10/02 14:08:55 colinmacleod
038: * Added/improved log4j logging.
039: *
040: * Revision 1.6 2005/09/29 13:22:44 colinmacleod
041: * Added read-only functionality to data object classes (with a check on each
042: * setter).
043: *
044: * Revision 1.5 2005/09/14 14:52:01 colinmacleod
045: * Added serialVersionUID.
046: *
047: * Revision 1.4 2005/04/28 18:47:10 colinmacleod
048: * Fixed XHMTL, styles and resin compatibility.
049: * Added support for URL rewriting.
050: *
051: * Revision 1.3 2005/04/10 20:09:36 colinmacleod
052: * Added new themes.
053: * Changed id type to String.
054: * Changed i tag to em and b tag to strong.
055: * Improved PicoContainerFactory with NanoContainer scripts.
056: *
057: * Revision 1.2 2005/04/09 17:19:07 colinmacleod
058: * Changed copyright text to GPL v2 explicitly.
059: *
060: * Revision 1.1.1.1 2005/03/10 17:50:31 colinmacleod
061: * Restructured ivata op around Hibernate/PicoContainer.
062: * Renamed ivata groupware.
063: *
064: * Revision 1.6 2004/12/31 18:22:13 colinmacleod
065: * Added override for displayValue.
066: *
067: * Revision 1.5 2004/11/12 15:57:05 colinmacleod
068: * Removed dependencies on SSLEXT.
069: * Moved Persistence classes to ivata masks.
070: *
071: * Revision 1.4 2004/07/13 19:41:13 colinmacleod
072: * Moved project to POJOs from EJBs.
073: * Applied PicoContainer to services layer (replacing session EJBs).
074: * Applied Hibernate to persistence layer (replacing entity EJBs).
075: *
076: * Revision 1.3 2004/03/21 21:16:06 colinmacleod
077: * Shortened name to ivata op.
078: *
079: * Revision 1.2 2004/02/01 22:00:32 colinmacleod
080: * Added full names to author tags
081: *
082: * Revision 1.1.1.1 2004/01/27 20:57:51 colinmacleod
083: * Moved ivata openportal to SourceForge..
084: *
085: * Revision 1.3 2003/10/17 12:36:12 jano
086: * fixing problems with building
087: * converting intranet -> portal
088: * Eclipse building
089: *
090: * Revision 1.2 2003/10/15 13:18:02 colin
091: * fixing for XDoclet
092: *
093: * Revision 1.3 2003/07/29 15:45:55 jano
094: * we have new field in groupDO
095: *
096: * Revision 1.2 2003/06/02 22:04:53 colin
097: * added comparison method
098: *
099: * Revision 1.1 2003/02/24 19:09:21 colin
100: * moved to business
101: *
102: * Revision 1.7 2003/02/04 17:43:45 colin
103: * copyright notice
104: *
105: * Revision 1.6 2003/01/10 10:29:23 jano
106: * we need information about user who created group
107: *
108: * Revision 1.5 2003/01/09 10:01:52 jano
109: * we are not storing group's rights in geoupDO now
110: * we are using methods in addressBookRightsBean
111: *
112: * Revision 1.4 2002/12/12 15:05:55 jano
113: * rights for groups
114: *
115: * Revision 1.3 2002/06/21 12:48:58 colin
116: * restructured com.ivata.groupware.web
117: *
118: * Revision 1.2 2002/06/17 07:28:54 colin
119: * improved and extended javadoc documentation
120: *
121: * Revision 1.1 2002/06/13 11:21:24 colin
122: * first version with rose model integration.
123: * -----------------------------------------------------------------------------
124: */
125: package com.ivata.groupware.business.addressbook.person.group;
126:
127: import java.util.HashSet;
128: import java.util.Set;
129:
130: import org.apache.log4j.Logger;
131:
132: import com.ivata.groupware.business.addressbook.person.PersonDO;
133: import com.ivata.groupware.container.persistence.AuthorTimestampNamedDO;
134: import com.ivata.groupware.web.tree.TreeNode;
135:
136: /**
137: * <p>Represents a group of people. This can be a company, a department or
138: * a team within the addressbook. On the basis of these groupings, access
139: * rights are assigned throughout the system.</p>
140: *
141: * @since 2002-05-15
142: * @author Colin MacLeod
143: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
144: * @version $Revision: 1.9 $
145: *
146: * @hibernate.class
147: * table="person_group"
148: * @hibernate.cache
149: * usage="read-write"
150: */
151: public class GroupDO extends AuthorTimestampNamedDO implements TreeNode {
152: /**
153: * Logger for this class.
154: */
155: private static final Logger logger = Logger
156: .getLogger(GroupDO.class);
157: /**
158: * Serialization version (for <code>Serializable</code> interface).
159: */
160: private static final long serialVersionUID = 1L;
161: /**
162: * <p>Store a clear-text description of the function and purpose of this
163: * group.</p>
164: */
165: private String description;
166:
167: /**
168: * <p>Store the the person who is head of this group. In the case
169: * where the group represents a company department, this should be the
170: * manager of that department.</p>
171: */
172: private PersonDO head;
173:
174: /**
175: * <p>Store the name of the group. This name should uniquely identify the
176: * group in clear text.</p>
177: */
178: private String name;
179: /**
180: * <p>Parent group - group which contains this group.</p>
181: */
182: private GroupDO parent;
183:
184: /**
185: * <p>All the people in this group.</p>
186: */
187: private Set people = new HashSet();
188:
189: /**
190: * <p>
191: * Address book group - used to reference the address book this group is in.
192: * </p>
193: *
194: * @return Address book group - used to reference the address book this
195: * group is in.
196: */
197: public final GroupDO getAddressBook() {
198: if (logger.isDebugEnabled()) {
199: logger.debug("getAddressBook() - start");
200: }
201:
202: // check this is not an address book itself
203: assert (parent != null);
204: if (GroupConstants.equals(getId(), GroupConstants.ADDRESS_BOOK)
205: || GroupConstants.equals(GroupConstants.ADDRESS_BOOK,
206: parent.getId())) {
207: if (logger.isDebugEnabled()) {
208: logger.debug("getAddressBook() - end - return value = "
209: + this );
210: }
211: return this ;
212: }
213: GroupDO addressBook = this ;
214: assert (addressBook.parent.parent != null);
215:
216: // go thro' all parents till we find the address book.
217: while (!GroupConstants.equals(
218: addressBook.parent.parent.getId(),
219: GroupConstants.ADDRESS_BOOK)) {
220: addressBook = addressBook.parent;
221: // if you get this, it is because the group tree has become unstable
222: // : this group has no parent which is an address book anywhere up
223: // the tree.
224: if (addressBook.parent.parent == null) {
225: throw new NullPointerException("ERROR in UserGroupDO: "
226: + "the group hierarchy is invalid: group '"
227: + name + "' (" + getId()
228: + ") has no address book as a parent.");
229: }
230: }
231:
232: if (logger.isDebugEnabled()) {
233: logger.debug("getAddressBook() - end - return value = "
234: + addressBook);
235: }
236: return addressBook;
237: }
238:
239: /**
240: * <p>Get a clear-text description of the function and purpose of this
241: * group.</p>
242: *
243: * @return a clear-text description of the function and purpose of this
244: * group.
245: * @hibernate.property
246: */
247: public final String getDescription() {
248: if (logger.isDebugEnabled()) {
249: logger.debug("getDescription() - start");
250: }
251:
252: if (logger.isDebugEnabled()) {
253: logger.debug("getDescription() - end - return value = "
254: + description);
255: }
256: return description;
257: }
258:
259: /**
260: * <p>
261: * This method returns the value to show on display, for example in a
262: * choice box field.
263: * For a group, the value displayed in a choice box is just the name.
264: * </p>
265: *
266: * @see #getName()
267: */
268: public final String getDisplayValue() {
269: if (logger.isDebugEnabled()) {
270: logger.debug("getDisplayValue() - start");
271: }
272:
273: if (logger.isDebugEnabled()) {
274: logger.debug("getDisplayValue() - end - return value = "
275: + name);
276: }
277: return name;
278: }
279:
280: /**
281: * <p>Get the the person who is head of this group. In the case where
282: * the group represents a company department, this should be the manager of
283: * that department.</p>
284: *
285: * @return the the person who is head of this group.
286: * @hibernate.many-to-one
287: */
288: public PersonDO getHead() {
289: if (logger.isDebugEnabled()) {
290: logger.debug("getHead() - start");
291: }
292:
293: if (logger.isDebugEnabled()) {
294: logger.debug("getHead() - end - return value = " + head);
295: }
296: return head;
297: }
298:
299: /**
300: * <p>Get the name of the group. This name should uniquely identify the
301: * group within its place in the heirarchy in clear text.</p>
302: *
303: * @return the name of this group, a clear-text string which identifies the
304: * group uniquely within its place in the group heirarchy.
305: * @hibernate.property
306: * column="name"
307: */
308: public final String getName() {
309: if (logger.isDebugEnabled()) {
310: logger.debug("getName() - start");
311: }
312:
313: if (logger.isDebugEnabled()) {
314: logger.debug("getName() - end - return value = " + name);
315: }
316: return name;
317: }
318:
319: /**
320: * <p>
321: * Get the parent group of this group - the group which contains this one.
322: * </p>
323: *
324: * @return the parent group of this group.
325: * @hibernate.many-to-one
326: * column="parent"
327: */
328: public final GroupDO getParent() {
329: if (logger.isDebugEnabled()) {
330: logger.debug("getParent() - start");
331: }
332:
333: if (logger.isDebugEnabled()) {
334: logger
335: .debug("getParent() - end - return value = "
336: + parent);
337: }
338: return parent;
339: }
340:
341: /**
342: * <p>All the people in this group.</p>
343: *
344: * @return the people in this group.
345: *
346: * @hibernate.set
347: * @hibernate.collection-key
348: * column="person_group"
349: * @hibernate.collection-one-to-many
350: * cascade="all"
351: * class="com.ivata.groupware.business.addressbook.person.PersonDO"
352: */
353: public final Set getPeople() {
354: if (logger.isDebugEnabled()) {
355: logger.debug("getPeople() - start");
356: }
357:
358: if (logger.isDebugEnabled()) {
359: logger
360: .debug("getPeople() - end - return value = "
361: + people);
362: }
363: return people;
364: }
365:
366: /**
367: * <p>Set a clear-text description of the function and purpose of this
368: * group.</p>
369: *
370: * @param descriptionParam a clear-text description of the function and
371: * purpose of this group.
372: */
373: public final void setDescription(final String descriptionParam) {
374: if (logger.isDebugEnabled()) {
375: logger.debug("setDescription(String description = "
376: + descriptionParam + ") - start");
377: }
378:
379: checkSetter();
380: this .description = descriptionParam;
381:
382: if (logger.isDebugEnabled()) {
383: logger.debug("setDescription(String) - end");
384: }
385: }
386:
387: /**
388: * <p>Set the person who is head of this group. In the case where
389: * the group represents a company department, this should be the manager of
390: * that department.</p>
391: *
392: * @param headParam the person who is head of this group.
393: */
394: public void setHead(final PersonDO headParam) {
395: if (logger.isDebugEnabled()) {
396: logger.debug("setHead before: '" + head + "', after: '"
397: + headParam + "'");
398: }
399: checkSetter();
400:
401: head = headParam;
402:
403: if (logger.isDebugEnabled()) {
404: logger.debug("setHead(PersonDO) - end");
405: }
406: }
407:
408: /**
409: * <p>Set the name of the group. This name should uniquely identify the
410: * group in clear text.</p>
411: *
412: * @param nameParam the new name to set for this group.
413: */
414: public void setName(final String nameParam) {
415: if (logger.isDebugEnabled()) {
416: logger.debug("setName before: '" + name + "', after: '"
417: + nameParam + "'");
418: }
419: checkSetter();
420:
421: name = nameParam;
422:
423: if (logger.isDebugEnabled()) {
424: logger.debug("setName(String) - end");
425: }
426: }
427:
428: /**
429: * <p>Set the parent of this group.</p>
430: *
431: * @param parentParam the parent of this group.
432: */
433: public void setParent(final GroupDO parentParam) {
434: if (logger.isDebugEnabled()) {
435: logger.debug("setParent before: '" + parent + "', after: '"
436: + parentParam + "'");
437: }
438: checkSetter();
439:
440: parent = parentParam;
441:
442: if (logger.isDebugEnabled()) {
443: logger.debug("setParent(GroupDO) - end");
444: }
445: }
446:
447: /**
448: * <p>All the people in this group.</p>
449: *
450: * @param peopleParam the people in this group.
451: */
452: public void setPeople(final Set peopleParam) {
453: if (logger.isDebugEnabled()) {
454: logger.debug("setPeople before: '" + people + "', after: '"
455: + peopleParam + "'");
456: }
457: checkSetter();
458:
459: people = peopleParam;
460:
461: if (logger.isDebugEnabled()) {
462: logger.debug("setPeople(Set) - end");
463: }
464: }
465: }
|