KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > addressbook > person > group > right > GroupRights


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: GroupRights.java,v $
31  * Revision 1.4.2.1 2005/10/08 16:14:31 colinmacleod
32  * Added new rule that parent groups cannot be deleted.
33  *
34  * Revision 1.4 2005/04/28 18:47:10 colinmacleod
35  * Fixed XHMTL, styles and resin compatibility.
36  * Added support for URL rewriting.
37  *
38  * Revision 1.3 2005/04/10 18:47:35 colinmacleod
39  * Changed i tag to em and b tag to strong.
40  *
41  * Revision 1.2 2005/04/09 17:19:07 colinmacleod
42  * Changed copyright text to GPL v2 explicitly.
43  *
44  * Revision 1.1.1.1 2005/03/10 17:50:35 colinmacleod
45  * Restructured ivata op around Hibernate/PicoContainer.
46  * Renamed ivata groupware.
47  *
48  * -----------------------------------------------------------------------------
49  */

50 package com.ivata.groupware.business.addressbook.person.group.right;
51
52 import java.io.Serializable JavaDoc;
53 import java.util.List JavaDoc;
54
55 import com.ivata.groupware.business.addressbook.AddressBook;
56 import com.ivata.groupware.business.addressbook.person.group.GroupConstants;
57 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
58 import com.ivata.mask.persistence.right.PersistenceRights;
59 import com.ivata.mask.valueobject.ValueObject;
60
61 import com.ivata.groupware.admin.security.server.SecurityServer;
62 import com.ivata.groupware.admin.security.server.SecuritySession;
63 import com.ivata.mask.util.SystemException;
64
65 /**
66  * This class will implement ivata groupware rights, by checking against the
67  * group right table/entities.
68  * To keep things simple for this release, however, it returns <code>true</code>
69  * for <em>almost</em> everything - it doesn't let you delete major things like
70  * the system-wide address book, but that is about it.
71  *
72  * @since ivata groupware 0.10 (2005-01-14)
73  * @author Colin MacLeod
74  * <a HREF="mailto:colin.macleod@ivata.com">colin.macleod@ivata.com</a>
75  * @version $Revision: 1.4.2.1 $
76  */

77
78 public class GroupRights implements PersistenceRights, Serializable JavaDoc {
79     private AddressBook addressBook;
80     private SecurityServer securityServer;
81     public GroupRights (AddressBook addressBook, SecurityServer securityServer) {
82         this.addressBook = addressBook;
83         this.securityServer = securityServer;
84     }
85     /**
86      * Refer to {@link PersistenceRights#canAdd}.
87      * @param valueObjectClassParam Refer to {@link PersistenceRights#canAdd}.
88      *
89      * @return Refer to {@link PersistenceRights#canAdd}.
90      */

91     public boolean canAdd(String JavaDoc userName,
92             Class JavaDoc valueObjectClassParam) {
93         return true;
94     }
95
96     /**
97      * Refer to
98      * {@link PersistenceRights#canAmend(String, ValueObject)}.
99      * @param valueObjectParam Refer to
100      * {@link PersistenceRights#canAmend(String, ValueObject)}.
101      *
102      * @return Refer to
103      * {@link PersistenceRights#canAmend(String, ValueObject)}.
104      */

105     public boolean canAmend(String JavaDoc userNameParam,
106             ValueObject valueObjectParam) {
107         return true;
108     }
109
110     /**
111      * Refer to {@link PersistenceRights#canAmend(String,
112      * ValueObject, String)}.
113      * @param valueObjectParam Refer to
114      * {@link PersistenceRights#canAmend(String,
115      * ValueObject, String)}.
116      * @param fieldNameParam Refer to
117      * {@link PersistenceRights#canAmend(String,
118      * ValueObject, String)}.
119      * @return Refer to
120      * {@link PersistenceRights#canAmend(String,
121      * ValueObject, String)}.
122      * @see PersistenceRights#canAmend(String, com.ivata.mask.valueobject.ValueObject, java.lang.String)
123      */

124     public boolean canAmend(String JavaDoc userNameParam,
125             ValueObject valueObjectParam, String JavaDoc fieldNameParam) {
126         // you can only change the name of an address book if it is not
127
// private
128
if (valueObjectParam instanceof GroupDO) {
129             GroupDO group = (GroupDO)valueObjectParam;
130             GroupDO parent = group.getParent();
131             // you can't rename a private address book
132
if ((parent != null)
133                     && "name".equals(fieldNameParam)
134                     && (GroupConstants.equals(
135                             parent.getId(),
136                             GroupConstants.ADDRESS_BOOK_PRIVATE))) {
137                 return false;
138             }
139         }
140
141         // everything else goes...
142
return true;
143     }
144
145     /**
146      * Refer to {@link PersistenceRights#canRemove}.
147      * @param valueObjectParam Refer to {@link
148      * PersistenceRights#canRemove}.
149      *
150      * @return Refer to {@link PersistenceRights#canRemove}.
151      */

152     public boolean canRemove(String JavaDoc userNameParam,
153             ValueObject valueObjectParam) {
154         // only return false if this is a major component
155
if (valueObjectParam instanceof GroupDO) {
156             GroupDO group = (GroupDO)valueObjectParam;
157             // you can't delete the default, system-wide address book
158
if (GroupConstants.equals(
159                     group.getId(),
160                     GroupConstants.ADDRESS_BOOK_DEFAULT)) {
161                 return false;
162             }
163             GroupDO parent = group.getParent();
164             // you can't delete a private address book
165
if ((parent == null)
166                     || (GroupConstants.equals(
167                             parent.getId(),
168                             GroupConstants.ADDRESS_BOOK_PRIVATE))) {
169                 return false;
170             }
171             // you can't delete a group which has users, people
172
if ((group.getPeople().size() > 0)
173                     || (group.getUsers().size() > 0)) {
174                 return false;
175             }
176             // you can't delete a group which has children groups
177
try {
178                 SecuritySession guestSession = securityServer.loginGuest();
179                 List JavaDoc children = addressBook.findGroupsByParent(guestSession,
180                     group.getId());
181                 if ((children != null)
182                         && (children.size() > 0)) {
183                     return false;
184                 }
185             } catch (SystemException e) {
186                 throw new RuntimeException JavaDoc(e);
187             }
188         }
189         // everything else goes...
190
return true;
191     }
192 }
193
Popular Tags