KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > addressbook > struts > GroupRightAction


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: GroupRightAction.java,v $
31  * Revision 1.5 2005/04/29 02:48:14 colinmacleod
32  * Data bugfixes.
33  * Changed primary key back to Integer.
34  *
35  * Revision 1.4 2005/04/28 18:47:09 colinmacleod
36  * Fixed XHMTL, styles and resin compatibility.
37  * Added support for URL rewriting.
38  *
39  * Revision 1.3 2005/04/10 20:32:02 colinmacleod
40  * Added new themes.
41  * Changed id type to String.
42  * Changed i tag to em and b tag to strong.
43  * Improved PicoContainerFactory with NanoContainer scripts.
44  *
45  * Revision 1.2 2005/04/09 17:19:08 colinmacleod
46  * Changed copyright text to GPL v2 explicitly.
47  *
48  * Revision 1.1.1.1 2005/03/10 17:50:25 colinmacleod
49  * Restructured ivata op around Hibernate/PicoContainer.
50  * Renamed ivata groupware.
51  *
52  * Revision 1.9 2004/12/31 18:27:42 colinmacleod
53  * Added MaskFactory to constructor of MaskAction.
54  *
55  * Revision 1.8 2004/12/23 21:01:25 colinmacleod
56  * Updated Struts to v1.2.4.
57  * Changed base classes to use ivata masks.
58  *
59  * Revision 1.7 2004/11/12 18:19:13 colinmacleod
60  * Change action and form classes to extend MaskAction, MaskForm respectively.
61  *
62  * Revision 1.6 2004/11/12 15:57:06 colinmacleod
63  * Removed dependencies on SSLEXT.
64  * Moved Persistence classes to ivata masks.
65  *
66  * Revision 1.5 2004/11/03 15:31:50 colinmacleod
67  * Change method interfaces to remove log.
68  *
69  * Revision 1.4 2004/07/13 19:41:14 colinmacleod
70  * Moved project to POJOs from EJBs.
71  * Applied PicoContainer to services layer (replacing session EJBs).
72  * Applied Hibernate to persistence layer (replacing entity EJBs).
73  *
74  * Revision 1.3 2004/03/21 21:16:08 colinmacleod
75  * Shortened name to ivata op.
76  *
77  * Revision 1.2 2004/02/01 22:00:33 colinmacleod
78  * Added full names to author tags
79  *
80  * Revision 1.1.1.1 2004/01/27 20:57:53 colinmacleod
81  * Moved ivata openportal to SourceForge..
82  *
83  * Revision 1.3 2003/10/17 12:36:12 jano
84  * fixing problems with building
85  * converting intranet -> portal
86  * Eclipse building
87  *
88  * Revision 1.2 2003/10/15 13:18:02 colin
89  * fixing for XDoclet
90  *
91  * Revision 1.6 2003/08/19 14:53:31 jano
92  * *** empty log message ***
93  *
94  * Revision 1.5 2003/08/14 08:20:11 jano
95  * fixing bug
96  *
97  * Revision 1.4 2003/08/13 13:32:43 jano
98  * addressBook exttension: next level
99  *
100  * Revision 1.3 2003/08/05 14:57:35 jano
101  * addressBook extension
102  *
103  * Revision 1.2 2003/06/10 10:42:15 peter
104  * changed keys when flushing tree jsp caches
105  *
106  * Revision 1.1 2003/06/02 22:17:48 colin
107  * changes for new user rights interface
108  * -----------------------------------------------------------------------------
109  */

110 package com.ivata.groupware.business.addressbook.struts;
111
112 import java.rmi.RemoteException JavaDoc;
113 import java.util.Arrays JavaDoc;
114 import java.util.Collection JavaDoc;
115 import java.util.Iterator JavaDoc;
116 import java.util.Set JavaDoc;
117 import java.util.TreeSet JavaDoc;
118 import java.util.Vector JavaDoc;
119
120 import javax.servlet.http.HttpServletRequest JavaDoc;
121 import javax.servlet.http.HttpServletResponse JavaDoc;
122 import javax.servlet.http.HttpSession JavaDoc;
123
124 import org.apache.struts.action.ActionErrors;
125 import org.apache.struts.action.ActionForm;
126 import org.apache.struts.action.ActionMapping;
127 import org.apache.struts.action.ActionMessage;
128 import org.apache.struts.action.ActionMessages;
129 import org.picocontainer.PicoContainer;
130
131 import com.ivata.groupware.admin.security.server.SecuritySession;
132 import com.ivata.groupware.admin.security.user.UserDO;
133 import com.ivata.groupware.business.addressbook.AddressBook;
134 import com.ivata.groupware.business.addressbook.person.group.GroupConstants;
135 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
136 import com.ivata.groupware.business.addressbook.person.group.right.RightConstants;
137 import com.ivata.groupware.business.addressbook.right.AddressBookRights;
138 import com.ivata.mask.MaskFactory;
139 import com.ivata.mask.util.StringHandling;
140 import com.ivata.mask.util.SystemException;
141 import com.ivata.mask.web.struts.MaskAction;
142 import com.ivata.mask.web.struts.MaskAuthenticator;
143
144
145 /**
146  * <p>This action is invoked whenever
147  * <code>/addressBook/groupRight.jsp</code> is submitted.</p>
148  *
149  * @since 2003-05-09
150  * @author Colin MacLeod
151  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
152  * @version $Revision: 1.5 $
153  */

154 public class GroupRightAction extends MaskAction {
155     AddressBook addressBook;
156     AddressBookRights addressBookRights;
157
158     /**
159      * <p>
160      * Constructor. Called by <strong>PicoContainer.</strong>.
161      * </p>
162      *
163      * @param addressBook valid address book implementation.
164      * @param addressBookRights valid address book rights implementation
165      * @param maskFactory This factory is needed to access the masks and groups
166      * of masks.
167      * @param authenticator used to confirm whether or not the
168      * user should be allowed to continue, in the <code>execute</code> method.
169      */

170     public GroupRightAction(AddressBook addressBook, AddressBookRights
171             addressBookRights, MaskFactory maskFactory,
172             MaskAuthenticator authenticator) {
173         super(maskFactory, authenticator);
174         this.addressBook = addressBook;
175         this.addressBookRights = addressBookRights;
176     }
177     /**
178      * <p>Called when the clear button is pressed, or after an ok or
179      * delete button, where the session should be restored to its default
180      * state.</p>
181      *
182      * @param mapping current action mapping from <em>Struts</em> config.
183      * @param log valid logging object to write messages to.
184      * @param errors valid errors object to append errors to. If there are
185      * any errors, the action will return to the input.
186      * @param form optional ActionForm bean for this request (if any)
187      * @param request non-HTTP request we are processing
188      * @param response The non-HTTP response we are creating
189      * @param session returned from the <code>request</code> parameter.
190      * @param userName valid, non-null user name from session.
191      * @param settings valid, non-null settings from session.
192      * @exception SystemException if there is any problem which
193      * prevents processing. It will result in the webapp being forwarded
194      * to
195      * the standard error page.
196      */

197     public void clear(final ActionMapping mapping,
198             final ActionErrors errors,
199             final ActionForm form,
200             final HttpServletRequest JavaDoc request,
201             final HttpServletResponse JavaDoc response,
202             final HttpSession JavaDoc session)
203         throws SystemException {
204         GroupRightForm groupRightForm = (GroupRightForm) form;
205         groupRightForm.setGroup(new GroupDO());
206
207         groupRightForm.setGroupRightTab_activeTab(new Integer JavaDoc(0));
208         groupRightForm.setSelected(new String JavaDoc[0]);
209
210         groupRightForm.setIncludePage("/addressBook/groupRightGeneral.jsp");
211
212         groupRightForm.setGroupRightsAdd(new String JavaDoc[0]);
213         groupRightForm.setGroupRightsAmend(new String JavaDoc[0]);
214         groupRightForm.setGroupRightsRemove(new String JavaDoc[0]);
215         groupRightForm.setGroupRightsView(new String JavaDoc[0]);
216
217         groupRightForm.setGroupIds(new Vector JavaDoc());
218         groupRightForm.setRowNames(new Vector JavaDoc());
219         groupRightForm.setRows(new Vector JavaDoc());
220
221         session.removeAttribute("groupRightTab_activeTab");
222     }
223
224     /**
225      * <p>Helper method to convert a <code>Collection</code> of
226      * <code>GroupDO</code> instances to a string array.</p>
227      *
228      * @param collection the <code>Collection</code> to convert.
229      * @return a string array of the integers in the source collection.
230      */

231     private String JavaDoc[] convertGroupCollectionToStringArray(final Collection JavaDoc collection) {
232         String JavaDoc[] stringArray = new String JavaDoc[collection.size()];
233         int index = 0;
234
235         for (Iterator JavaDoc i = collection.iterator(); i.hasNext(); ++index) {
236             stringArray[index] = ((Integer JavaDoc) i.next()).toString();
237         }
238
239         return stringArray;
240     }
241
242     /**
243      * <p>Overridden from the default intranet implementation to
244      * process tab changes.</p>
245      *
246      * @param mapping current action mapping from <em>Struts</em> config.
247      * @param log valid logging object to write messages to.
248      * @param errors valid errors object to append errors to. If there
249      * are any errors, the action will return to the input.
250      * @param form optional ActionForm bean for this request (if any)
251      * @param request non-HTTP request we are processing
252      * @param response The non-HTTP response we are creating
253      * @param session returned from the <code>request</code> parameter.
254      * @param userName current user name from session. .
255      * @param settings valid, non-null settings from session.
256      * @exception SystemException if there is any problem which
257      * prevents processing. It will result in the webapp being forwarded
258      * to
259      * the standard error page.
260      * @return this method returns the string used to identify the correct
261      * <em>Struts</em> <code>ActionForward</code> which should follow this
262      * page, or <code>null</code> if it should return to the input.
263      */

264     public String JavaDoc execute(final ActionMapping mapping,
265             final ActionErrors errors,
266             final ActionForm form,
267             final HttpServletRequest JavaDoc request,
268             final HttpServletResponse JavaDoc response,
269             final HttpSession JavaDoc session)
270         throws SystemException {
271         GroupRightForm groupRightForm = (GroupRightForm) form;
272         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
273
274         if ((request.getParameter("reset") != null) &&
275                 request.getParameter("reset").equals("true")) {
276             groupRightForm.setGroup(new GroupDO());
277             groupRightForm.setAddGroup(null);
278             groupRightForm.setType(request.getParameter("type"));
279             groupRightForm.setIncludePage("/addressBook/groupRightGeneral.jsp");
280             groupRightForm.setHelpKey("addressbook.groupRightUser");
281             groupRightForm.setReadOnly(false);
282             groupRightForm.setCanRemove(false);
283             session.removeAttribute("groupRightTab_activeTab");
284         }
285
286         if (groupRightForm == null) {
287             PicoContainer container = securitySession.getContainer();
288             groupRightForm = (GroupRightForm) container.getComponentInstance(GroupRightForm.class);
289             session.setAttribute("addressBookGroupRightForm", groupRightForm);
290         }
291
292         // if there is a request parameter for the group id, set it from that
293
Integer JavaDoc requestGroupId = StringHandling.integerValue(request.getParameter(
294                     "requestGroupId"));
295
296         if (requestGroupId != null) {
297             GroupDO requestGroup = addressBook.findGroupByPrimaryKey(
298                     securitySession,
299                     requestGroupId);
300             groupRightForm.setGroup(requestGroup);
301
302             // now get and set all of the address book rights
303
Set JavaDoc allGroups = new TreeSet JavaDoc();
304
305             Collection JavaDoc addressBookView = addressBookRights.findRightsForGroup(securitySession,
306                     requestGroup, RightConstants.ACCESS_VIEW);
307             allGroups.addAll(addressBookView);
308             groupRightForm.setGroupRightsView(convertGroupCollectionToStringArray(
309                     addressBookView));
310
311             Collection JavaDoc addressBookAdd = addressBookRights.findRightsForGroup(securitySession,
312                     requestGroup, RightConstants.ACCESS_ADD);
313             allGroups.addAll(addressBookAdd);
314             groupRightForm.setGroupRightsAdd(convertGroupCollectionToStringArray(
315                     addressBookAdd));
316
317             Collection JavaDoc addressBookAmend = addressBookRights.findRightsForGroup(securitySession,
318                     requestGroup, RightConstants.ACCESS_AMEND);
319             allGroups.addAll(addressBookAmend);
320             groupRightForm.setGroupRightsAmend(convertGroupCollectionToStringArray(
321                     addressBookAmend));
322
323             Collection JavaDoc addressBookRemove = addressBookRights.findRightsForGroup(securitySession,
324                     requestGroup, RightConstants.ACCESS_REMOVE);
325             allGroups.addAll(addressBookRemove);
326             groupRightForm.setGroupRightsRemove(convertGroupCollectionToStringArray(
327                     addressBookRemove));
328
329             Vector JavaDoc groupIds = new Vector JavaDoc();
330             Vector JavaDoc groupNames = new Vector JavaDoc();
331
332             for (Iterator JavaDoc i = allGroups.iterator(); i.hasNext();) {
333                 Integer JavaDoc userGroupId = (Integer JavaDoc) i.next();
334                 groupIds.add(userGroupId);
335                 groupNames.add(addressBook.findGroupByPrimaryKey(
336                         securitySession, userGroupId).getName());
337             }
338
339             groupRightForm.setGroupIds(groupIds);
340             groupRightForm.setGroupNames(groupNames);
341
342             // set Up READ ONLY flag
343
groupRightForm.setReadOnly(!addressBookRights.canAmendInGroup(
344                     securitySession, requestGroup));
345
346             // set Up CAN REMOVE flag
347
groupRightForm.setCanRemove(addressBookRights.canRemoveFromGroup(
348                     securitySession, requestGroup));
349
350             session.removeAttribute("groupRightTab_activeTab");
351             groupRightForm.setGroupRightTab_activeTab(null);
352         }
353
354         // default put everyone group to list
355
if (!groupRightForm.getGroupIds().contains(GroupConstants.USER_GROUP)) {
356             groupRightForm.getGroupIds().add(GroupConstants.USER_GROUP);
357             groupRightForm.getGroupNames().add("everyone");
358         }
359
360         // in case when you click on TAB, you will be here (other actions
361
// are taken care of by the individual methods
362
int activeTab = (groupRightForm.getGroupRightTab_activeTab() == null)
363             ? 0 : groupRightForm.getGroupRightTab_activeTab().intValue();
364
365         if (groupRightForm.getType() == null) {
366             groupRightForm.setType(request.getParameter("type"));
367         }
368
369         // this flag is used later in this method to see whether the selected
370
// items refers to groups or topics
371
if (activeTab == 1) {
372             groupRightForm.setIncludePage("/addressBook/groupRightDetail.jsp");
373             groupRightForm.setHelpKey("addressbook.groupRightAddressBook");
374             groupRightForm.setRows(groupRightForm.getGroupIds());
375             groupRightForm.setRowNames(groupRightForm.getGroupNames());
376
377             if (groupRightForm.getType().equals("addressBook")) {
378                 groupRightForm.setEmptyListMessage(
379                     "groupRight.addressBook.label.list.empty");
380             } else {
381                 groupRightForm.setEmptyListMessage(
382                     "groupRight.userGroup.label.list.empty");
383             }
384         } else {
385             groupRightForm.setIncludePage("/addressBook/groupRightGeneral.jsp");
386
387             if (groupRightForm.getType().equals("addressBook")) {
388                 groupRightForm.setHelpKey("addressbook.groupRightUser");
389             }
390         }
391
392         // if we should add a group to the list, get the value
393
Integer JavaDoc addGroup = groupRightForm.getAddGroup();
394
395         if ((addGroup != null) && !addGroup.equals(new Integer JavaDoc(0))) {
396             GroupDO group = addressBook.findGroupByPrimaryKey(securitySession,
397                     addGroup);
398
399             // only add if the id is not already there
400
if (!groupRightForm.getGroupIds().contains(group.getId())) {
401                 groupRightForm.getGroupIds().add(group.getId());
402                 groupRightForm.getGroupNames().add(group.getName());
403             }
404         }
405
406         // see if the remove button was pressed
407
if (!StringHandling.isNullOrEmpty(groupRightForm.getRemove())) {
408             String JavaDoc[] selected = groupRightForm.getSelected();
409
410             for (int i = 0; i < selected.length; i++) {
411                 Integer JavaDoc selectedId = StringHandling.integerValue(selected[i]);
412
413                 for (int index = 0; index < groupRightForm.getRows().size();
414                         ++index) {
415                     // is this the id to remove?
416
if (groupRightForm.getRows().get(index).equals(selectedId)) {
417                         groupRightForm.getRows().remove(index);
418                         groupRightForm.getRowNames().remove(index);
419
420                         break;
421                     }
422                 }
423             }
424         }
425
426         return "addressBookGroupRight";
427     }
428
429     /**
430      * <p>This method is called if the ok or apply buttons are pressed.</p>
431      *
432      * @param mapping current action mapping from <em>Struts</em> config.
433      * @param log valid logging object to write messages to.
434      * @param errors valid errors object to append errors to. If there are
435      * any errors, the action will return to the input.
436      * @param form optional ActionForm bean for this request (if any)
437      * @param request non-HTTP request we are processing
438      * @param response The non-HTTP response we are creating
439      * @param session returned from the <code>request</code> parameter.
440      * @param userName valid, non-null user name from session.
441      * @param settings valid, non-null settings from session.
442      * @param ok <code>true</code> if the ok button was pressed, otherwise
443      * <code>false</code> if the apply button was pressed.
444      * @exception SystemException if there is any problem which
445      * prevents processing. It will result in the webapp being forwarded
446      * to
447      * the standard error page.
448      * @return this method returns the string used to identify the correct
449      * <em>Struts</em> <code>ActionForward</code> which should follow this
450      * page, or <code>null</code> if it should return to the input.
451      */

452     public String JavaDoc onConfirm(final ActionMapping mapping,
453             final ActionErrors errors,
454             final ActionForm form,
455             final HttpServletRequest JavaDoc request,
456             final HttpServletResponse JavaDoc response,
457             final HttpSession JavaDoc session,
458             final String JavaDoc defaultForward)
459         throws SystemException {
460         GroupRightForm groupRightForm = (GroupRightForm) form;
461         GroupDO group = groupRightForm.getGroup();
462         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
463         UserDO user = securitySession.getUser();
464
465         // if I have not ID , so it's new group
466
if (group.getId() == null) {
467             group.setCreatedBy(user);
468
469             // see what are we going add: addressBook or userGroup
470
if (groupRightForm.getType().equals("addressBook")) {
471                 group = addressBook.addAddressBook(securitySession, group);
472             } else {
473                 group = addressBook.addUserGroup(securitySession, group);
474             }
475
476             groupRightForm.setGroup(group);
477             groupRightForm.setReadOnly(false);
478             groupRightForm.setCanRemove(true);
479         } else {
480             try {
481                 // see what are we going amend: addressBook or userGroup
482
if (groupRightForm.getType().equals("addressBook")) {
483                     group = addressBook.amendGroup(securitySession, group);
484                 } else {
485                     group = addressBook.amendGroup(securitySession, group);
486                 }
487
488                 groupRightForm.setGroup(group);
489             } catch (SystemException e) {
490                 errors.add(ActionMessages.GLOBAL_MESSAGE,
491                     new ActionMessage("errors.addressBook.group.amend",
492                         group.getName()));
493             }
494         }
495
496         // do thi only if user schoose rights
497
if ((groupRightForm.getGroupRightsAdd() != null) &&
498                 (groupRightForm.getGroupRightsAmend() != null) &&
499                 (groupRightForm.getGroupRightsRemove() != null) &&
500                 (groupRightForm.getGroupRightsView() != null)) {
501             // now go thro' all the groups and amend the rights
502
updateGroupRights(securitySession, groupRightForm, groupRightForm.getGroup());
503
504             // refresh list of rigts
505
// now get and set all of the address book rights
506
Set JavaDoc allGroups = new TreeSet JavaDoc();
507             Collection JavaDoc addressBookView = addressBookRights.findRightsForGroup(securitySession,
508                     group, RightConstants.ACCESS_VIEW);
509             allGroups.addAll(addressBookView);
510             groupRightForm.setGroupRightsView(convertGroupCollectionToStringArray(
511                     addressBookView));
512
513             Collection JavaDoc addressBookAdd = addressBookRights.findRightsForGroup(securitySession,
514                     group, RightConstants.ACCESS_ADD);
515             allGroups.addAll(addressBookAdd);
516             groupRightForm.setGroupRightsAdd(convertGroupCollectionToStringArray(
517                     addressBookAdd));
518
519             Collection JavaDoc addressBookAmend = addressBookRights.findRightsForGroup(securitySession,
520                     group, RightConstants.ACCESS_AMEND);
521             allGroups.addAll(addressBookAmend);
522             groupRightForm.setGroupRightsAmend(convertGroupCollectionToStringArray(
523                     addressBookAmend));
524
525             Collection JavaDoc addressBookRemove = addressBookRights.findRightsForGroup(securitySession,
526                     group, RightConstants.ACCESS_REMOVE);
527             allGroups.addAll(addressBookRemove);
528             groupRightForm.setGroupRightsRemove(convertGroupCollectionToStringArray(
529                     addressBookRemove));
530
531             Vector JavaDoc groupIds = new Vector JavaDoc();
532             Vector JavaDoc groupNames = new Vector JavaDoc();
533
534             for (Iterator JavaDoc i = allGroups.iterator(); i.hasNext();) {
535                 Integer JavaDoc userGroupId = (Integer JavaDoc) i.next();
536                 groupIds.add(userGroupId);
537                 groupNames.add(addressBook.findGroupByPrimaryKey(
538                         securitySession, userGroupId).getName());
539             }
540
541             groupRightForm.setGroupIds(groupIds);
542             groupRightForm.setGroupNames(groupNames);
543
544             groupRightForm.setRows(groupRightForm.getGroupIds());
545             groupRightForm.setRowNames(groupRightForm.getGroupNames());
546
547             // set Up READ ONLY flag
548
groupRightForm.setReadOnly(!addressBookRights.canAmendInGroup(
549                     securitySession, group));
550
551             // set Up CAN REMOVE flag
552
groupRightForm.setCanRemove(addressBookRights.canRemoveFromGroup(
553                     securitySession, group));
554         }
555
556         // default put everyone group to list
557
if (!groupRightForm.getGroupIds().contains(GroupConstants.USER_GROUP)) {
558             groupRightForm.getGroupIds().add(GroupConstants.USER_GROUP);
559             groupRightForm.getGroupNames().add("everyone");
560         }
561
562         // flush the cached contact trees
563
// flushCache("ContactTree",javax.servlet.jsp.PageContext.APPLICATION_SCOPE, request);
564
// close the pop-up if this is ok
565
if (groupRightForm.getOk() != null) {
566             // the form is finished now
567
session.removeAttribute("addressBookGroupRightForm");
568
569             return "utilClosePopUp";
570         }
571
572         return defaultForward;
573     }
574
575     /**
576      * <p>This method is called if the delete (confirm, not warn) button
577      * is pressed.</p>
578      * @param mapping The ActionMapping used to select this instance.
579      * @param errors valid errors object to append errors to. If there are
580      * any errors, the action will return to the input.
581      * @param form optional ActionForm bean for this request (if any)
582      * @param request non-HTTP request we are processing
583      * @param response The non-HTTP response we are creating
584      * @param session returned from the <code>request</code> parameter.
585      * @param log valid logging object to write messages to.
586      * @param userName valid, non-null user name from session.
587      * @param settings valid, non-null settings from session.
588      *
589      * @exception SystemException if there is any problem which
590      * prevents processing. It will result in the webapp being forwarded
591      * to
592      * the standard error page.
593      * @return this method returns the string used to identify the correct
594      * <em>Struts</em> <code>ActionForward</code> which should follow this
595      * page, or <code>null</code> if it should return to the input.
596      */

597     public String JavaDoc onDelete(final ActionMapping mapping,
598             final ActionErrors errors,
599             final ActionForm form,
600             final HttpServletRequest JavaDoc request,
601             final HttpServletResponse JavaDoc response,
602             final HttpSession JavaDoc session, final String JavaDoc defaultForward)
603             throws SystemException {
604         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
605         GroupRightForm groupRightForm = (GroupRightForm) form;
606         GroupDO group = groupRightForm.getGroup();
607
608         try {
609             // see what are we going remove: addressBook or userGroup
610
if (groupRightForm.getType().equals("addressBook")) {
611                 addressBook.removeGroup(securitySession, group.getId());
612             } else {
613                 addressBook.removeGroup(securitySession, group.getId());
614             }
615         } catch (SystemException e) {
616             errors.add(ActionMessages.GLOBAL_MESSAGE,
617                 new ActionMessage("errors.addressBook.group.remove",
618                     group.getName()));
619         }
620
621         return null;
622     }
623
624     /**
625      * <p>Update all the rights concerning groups. This is called by <code>onConfirm</code>.</p>
626      *
627      *
628      * @param groupRightForm the form which has just been submitted.
629      * @param addressBookRights remote address book rights object.
630      * @param userName the name of the user who is submitting the form - used to
631      * check user rights of the user to change rights.
632      * @param groupId the unique identifier of the group for whom the rights are
633      * being set.
634      * @throws RemoteException
635      */

636     private void updateGroupRights(final SecuritySession securitySession,
637             final GroupRightForm groupRightForm,
638             final GroupDO group)
639             throws SystemException {
640         // the arrays of rights and access must match up!
641
String JavaDoc[][] rightsArray = {
642             groupRightForm.getGroupRightsAdd(),
643             groupRightForm.getGroupRightsAmend(),
644             groupRightForm.getGroupRightsRemove(),
645             groupRightForm.getGroupRightsView()
646         };
647         Integer JavaDoc[] accessArray = {
648             RightConstants.ACCESS_ADD, RightConstants.ACCESS_AMEND,
649             RightConstants.ACCESS_REMOVE, RightConstants.ACCESS_VIEW
650         };
651
652         for (Iterator JavaDoc i = groupRightForm.getGroupIds().iterator(); i.hasNext();) {
653             Integer JavaDoc id = (Integer JavaDoc) i.next();
654
655             Vector JavaDoc rightsForGroup = new Vector JavaDoc();
656             boolean hasRightNow;
657
658             for (int index = 0; index < accessArray.length; index++) {
659                 Integer JavaDoc access = accessArray[index];
660                 String JavaDoc[] rights = rightsArray[index];
661
662                 // if we are maintaining user group so group "everyone" has always "view" access to each userGroup
663
if (access.equals(RightConstants.ACCESS_VIEW) &&
664                         groupRightForm.getType().equals("userGroup") &&
665                         GroupConstants.equals(id, GroupConstants.USER_GROUP)) {
666                     hasRightNow = true;
667                 } else {
668                     Arrays.sort(rights);
669                     hasRightNow = Arrays.binarySearch(rights, id.toString()) >= 0;
670                 }
671
672                 rightsForGroup.addAll(addressBookRights.findRightsForGroup(
673                         securitySession, group, access));
674
675                 // if it wasn't there before, and is now, then add it
676
if (!rightsForGroup.contains(id) && hasRightNow) {
677                     rightsForGroup.add(id);
678                     addressBookRights.amendRightsForGroup(securitySession,
679                         group, rightsForGroup, access);
680
681                     // otherwise find if it was there before and isn't now
682
} else if (rightsForGroup.contains(id) && !hasRightNow) {
683                     rightsForGroup.remove(id);
684                     addressBookRights.amendRightsForGroup(securitySession,
685                         group, rightsForGroup, access);
686                 }
687
688                 rightsForGroup.clear();
689             }
690         }
691     }
692 }
693
Popular Tags