KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > bean > GroupsBean


1 /*
2  * Copyright (C) 2006 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.bean;
18
19 import java.text.MessageFormat JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import javax.faces.application.FacesMessage;
28 import javax.faces.component.UIComponent;
29 import javax.faces.context.FacesContext;
30 import javax.faces.event.ActionEvent;
31 import javax.faces.model.DataModel;
32 import javax.faces.model.ListDataModel;
33 import javax.faces.model.SelectItem;
34 import javax.faces.validator.ValidatorException;
35 import javax.transaction.UserTransaction JavaDoc;
36
37 import org.alfresco.model.ContentModel;
38 import org.alfresco.service.ServiceRegistry;
39 import org.alfresco.service.cmr.repository.NodeRef;
40 import org.alfresco.service.cmr.repository.NodeService;
41 import org.alfresco.service.cmr.security.AuthorityService;
42 import org.alfresco.service.cmr.security.AuthorityType;
43 import org.alfresco.service.cmr.security.PersonService;
44 import org.alfresco.service.namespace.NamespaceService;
45 import org.alfresco.web.app.Application;
46 import org.alfresco.web.app.context.IContextListener;
47 import org.alfresco.web.app.context.UIContextService;
48 import org.alfresco.web.bean.repository.Repository;
49 import org.alfresco.web.ui.common.SortableSelectItem;
50 import org.alfresco.web.ui.common.Utils;
51 import org.alfresco.web.ui.common.component.IBreadcrumbHandler;
52 import org.alfresco.web.ui.common.component.UIActionLink;
53 import org.alfresco.web.ui.common.component.UIBreadcrumb;
54 import org.alfresco.web.ui.common.component.UIGenericPicker;
55 import org.alfresco.web.ui.common.component.UIModeList;
56 import org.alfresco.web.ui.common.component.data.UIRichList;
57 import org.apache.log4j.Logger;
58
59 /**
60  * Backing Bean for the Groups Management pages.
61  *
62  * @author Kevin Roast
63  */

64 public class GroupsBean implements IContextListener
65 {
66    private static final String JavaDoc FILTER_CHILDREN = "children";
67    private static final String JavaDoc FILTER_ALL = "all";
68
69    private static final String JavaDoc DEFAULT_OUTCOME = "finish";
70
71    private static final String JavaDoc MSG_GROUPS = "root_groups";
72
73    private static Logger logger = Logger.getLogger(GroupsBean.class);
74    
75    /** The NodeService to be used by the bean */
76    private NodeService nodeService;
77    
78    /** The AuthorityService to be used by the bean */
79    private AuthorityService authService;
80    
81    /** personService bean reference */
82    private PersonService personService;
83    
84    /** Component references */
85    private UIRichList groupsRichList;
86    private UIRichList usersRichList;
87    
88    /** datamodel for table of users added to group */
89    private DataModel usersDataModel = null;
90    
91    /** Currently visible Group Authority */
92    private String JavaDoc group = null;
93    private String JavaDoc groupName = null;
94    
95    /** Action group authority */
96    private String JavaDoc actionGroup = null;
97    private String JavaDoc actionGroupName = null;
98    private int actionGroupItems = 0;
99    
100    /** selected users to be added to a group */
101    private List JavaDoc<UserAuthorityDetails> usersForGroup = null;
102    
103    /** Dialog properties */
104    private String JavaDoc name = null;
105    
106    /** RichList view mode */
107    private String JavaDoc viewMode = "icons";
108    
109    /** List filter mode */
110    private String JavaDoc filterMode = FILTER_CHILDREN;
111    
112    /** Groups path breadcrumb location */
113    private List JavaDoc<IBreadcrumbHandler> location = null;
114    
115    
116    // ------------------------------------------------------------------------------
117
// Construction
118

119    /**
120     * Default Constructor
121     */

122    public GroupsBean()
123    {
124       UIContextService.getInstance(FacesContext.getCurrentInstance()).registerBean(this);
125    }
126    
127    
128    // ------------------------------------------------------------------------------
129
// Bean property getters and setters
130

131    /**
132     * @param nodeService The NodeService to set.
133     */

134    public void setNodeService(NodeService nodeService)
135    {
136       this.nodeService = nodeService;
137    }
138
139    /**
140     * @param authService The AuthorityService to set.
141     */

142    public void setAuthorityService(AuthorityService authService)
143    {
144       this.authService = authService;
145    }
146    
147    /**
148     * @param permissionService The PermissionService to set.
149     */

150    public void setPersonService(PersonService personService)
151    {
152       this.personService = personService;
153    }
154
155    /**
156     * @return Returns the groups RichList to set.
157     */

158    public UIRichList getGroupsRichList()
159    {
160       return this.groupsRichList;
161    }
162    
163    /**
164     * @param list The RichList to set.
165     */

166    public void setGroupsRichList(UIRichList list)
167    {
168       this.groupsRichList = list;
169    }
170    
171    /**
172     * @return Returns the users RichList.
173     */

174    public UIRichList getUsersRichList()
175    {
176       return this.usersRichList;
177    }
178
179    /**
180     * @param usersRichList The RichList to set.
181     */

182    public void setUsersRichList(UIRichList usersRichList)
183    {
184       this.usersRichList = usersRichList;
185    }
186    
187    /**
188     * @return Returns the usersDataModel.
189     */

190    public DataModel getUsersDataModel()
191    {
192       if (this.usersDataModel == null)
193       {
194          this.usersDataModel = new ListDataModel();
195       }
196       
197       this.usersDataModel.setWrappedData(this.usersForGroup);
198       
199       return this.usersDataModel;
200    }
201
202    /**
203     * @param usersDataModel The usersDataModel to set.
204     */

205    public void setUsersDataModel(DataModel usersDataModel)
206    {
207       this.usersDataModel = usersDataModel;
208    }
209
210    /**
211     * @return Returns the name.
212     */

213    public String JavaDoc getName()
214    {
215       return this.name;
216    }
217
218    /**
219     * @param name The name to set.
220     */

221    public void setName(String JavaDoc name)
222    {
223       this.name = name;
224    }
225    
226    /**
227     * @return Returns the viewMode.
228     */

229    public String JavaDoc getViewMode()
230    {
231       return this.viewMode;
232    }
233
234    /**
235     * @param viewMode The viewMode to set.
236     */

237    public void setViewMode(String JavaDoc viewMode)
238    {
239       this.viewMode = viewMode;
240    }
241    
242    /**
243     * @return Returns the filterMode.
244     */

245    public String JavaDoc getFilterMode()
246    {
247       return this.filterMode;
248    }
249
250    /**
251     * @param filterMode The filterMode to set.
252     */

253    public void setFilterMode(String JavaDoc filterMode)
254    {
255       this.filterMode = filterMode;
256       
257       // clear datalist cache ready to change results based on filter setting
258
contextUpdated();
259    }
260    
261    /**
262     * @return Returns the Group being used for the current action screen.
263     */

264    public String JavaDoc getActionGroup()
265    {
266       return this.actionGroup;
267    }
268    
269    /**
270     * @param actionSpace Set the Group to be used for the current action screen.
271     */

272    public void setActionGroup(String JavaDoc group)
273    {
274       this.actionGroup = group;
275       
276       if (group != null)
277       {
278          // calculate action group metadata
279
setActionGroupName(this.authService.getShortName(group));
280          int count = this.authService.getContainedAuthorities(AuthorityType.GROUP, group, false).size();
281          count += this.authService.getContainedAuthorities(AuthorityType.USER, group, false).size();
282          setActionGroupItems(count);
283       }
284       else
285       {
286          setActionGroupName(null);
287          setActionGroupItems(0);
288       }
289       
290       // clear value used by Create Group form
291
this.name = null;
292       
293       // clear list for Add Users to Group screen
294
this.usersForGroup = new ArrayList JavaDoc<UserAuthorityDetails>();
295    }
296    
297    /**
298     * @return Returns the actionGroupName.
299     */

300    public String JavaDoc getActionGroupName()
301    {
302       return this.actionGroupName;
303    }
304
305    /**
306     * @param actionGroupName The actionGroupName to set.
307     */

308    public void setActionGroupName(String JavaDoc actionGroupName)
309    {
310       this.actionGroupName = actionGroupName;
311    }
312    
313    /**
314     * @return Returns the action Group Items count.
315     */

316    public int getActionGroupItems()
317    {
318       return this.actionGroupItems;
319    }
320
321    /**
322     * @param actionGroupItems The action Group Items count to set.
323     */

324    public void setActionGroupItems(int actionGroupItems)
325    {
326       this.actionGroupItems = actionGroupItems;
327    }
328    
329    /**
330     * @return The currently displayed group or null if at the root.
331     */

332    public String JavaDoc getCurrentGroup()
333    {
334       return this.group;
335    }
336    
337    /**
338     * Set the current Group Authority.
339     * <p>
340     * Setting this value causes the UI to update and display the specified node as current.
341     *
342     * @param group The current group authority.
343     */

344    public void setCurrentGroup(String JavaDoc group, String JavaDoc groupName)
345    {
346       if (logger.isDebugEnabled())
347          logger.debug("Setting current group: " + group);
348       
349       // set the current Group Authority for our UI context operations
350
this.group = group;
351       this.groupName = groupName;
352       
353       // inform that the UI needs updating after this change
354
contextUpdated();
355    }
356    
357    /**
358     * @return Returns the groupName.
359     */

360    public String JavaDoc getGroupName()
361    {
362       return this.groupName;
363    }
364
365    /**
366     * @param groupName The groupName to set.
367     */

368    public void setGroupName(String JavaDoc groupName)
369    {
370       this.groupName = groupName;
371    }
372    
373    /**
374     * @return Breadcrumb location list
375     */

376    public List JavaDoc<IBreadcrumbHandler> getLocation()
377    {
378       if (this.location == null)
379       {
380          List JavaDoc<IBreadcrumbHandler> loc = new ArrayList JavaDoc<IBreadcrumbHandler>(8);
381          loc.add(new GroupBreadcrumbHandler(null,
382                Application.getMessage(FacesContext.getCurrentInstance(), MSG_GROUPS)));
383          
384          this.location = loc;
385       }
386       return this.location;
387    }
388    
389    /**
390     * @param location Breadcrumb location list
391     */

392    public void setLocation(List JavaDoc<IBreadcrumbHandler> location)
393    {
394       this.location = location;
395    }
396    
397    /**
398     * @return The list of group objects to display. Returns the list of root groups or the
399     * list of sub-groups for the current group if set.
400     */

401    public List JavaDoc<Map JavaDoc> getGroups()
402    {
403       List JavaDoc<Map JavaDoc> groups;
404       
405       UserTransaction JavaDoc tx = null;
406       try
407       {
408          FacesContext context = FacesContext.getCurrentInstance();
409          tx = Repository.getUserTransaction(context);
410          tx.begin();
411          
412          Set JavaDoc<String JavaDoc> authorities;
413          boolean immediate = (this.filterMode.equals(FILTER_CHILDREN));
414          if (this.group == null)
415          {
416             // root groups
417
if (immediate == true)
418             {
419                authorities = this.authService.getAllRootAuthorities(AuthorityType.GROUP);
420             }
421             else
422             {
423                authorities = this.authService.getAllAuthorities(AuthorityType.GROUP);
424             }
425          }
426          else
427          {
428             // sub-group of an existing group
429
authorities = this.authService.getContainedAuthorities(AuthorityType.GROUP, group, immediate);
430          }
431          groups = new ArrayList JavaDoc<Map JavaDoc>(authorities.size());
432          for (String JavaDoc authority : authorities)
433          {
434             Map JavaDoc authMap = new HashMap JavaDoc(3, 1.0f);
435             
436             String JavaDoc name = this.authService.getShortName(authority);
437             authMap.put("name", name);
438             authMap.put("id", authority);
439             
440             groups.add(authMap);
441          }
442          
443          // commit the transaction
444
tx.commit();
445       }
446       catch (Throwable JavaDoc err)
447       {
448          Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
449                FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
450          groups = Collections.<Map JavaDoc>emptyList();
451          try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc tex) {}
452       }
453       
454       return groups;
455    }
456    
457    /**
458     * @return The list of user objects to display. Returns the list of user for the current group.
459     */

460    public List JavaDoc<Map JavaDoc> getUsers()
461    {
462       List JavaDoc<Map JavaDoc> users;
463       
464       UserTransaction JavaDoc tx = null;
465       try
466       {
467          FacesContext context = FacesContext.getCurrentInstance();
468          tx = Repository.getUserTransaction(context);
469          tx.begin();
470          
471          Set JavaDoc<String JavaDoc> authorities;
472          if (this.group == null)
473          {
474             authorities = Collections.<String JavaDoc>emptySet();
475          }
476          else
477          {
478             // users of an existing group
479
boolean immediate = (this.filterMode.equals(FILTER_CHILDREN));
480             authorities = this.authService.getContainedAuthorities(AuthorityType.USER, group, immediate);
481          }
482          users = new ArrayList JavaDoc<Map JavaDoc>(authorities.size());
483          for (String JavaDoc authority : authorities)
484          {
485             Map JavaDoc authMap = new HashMap JavaDoc(3, 1.0f);
486             
487             String JavaDoc userName = this.authService.getShortName(authority);
488             authMap.put("userName", userName);
489             authMap.put("id", authority);
490             
491             // get Person details for this Authority
492
NodeRef ref = this.personService.getPerson(authority);
493             String JavaDoc firstName = (String JavaDoc)this.nodeService.getProperty(ref, ContentModel.PROP_FIRSTNAME);
494             String JavaDoc lastName = (String JavaDoc)this.nodeService.getProperty(ref, ContentModel.PROP_LASTNAME);
495             
496             // build a sensible label for display
497
StringBuilder JavaDoc label = new StringBuilder JavaDoc(48);
498             label.append(firstName)
499                  .append(' ')
500                  .append(lastName);
501             authMap.put("name", label.toString());
502             
503             users.add(authMap);
504          }
505          
506          // commit the transaction
507
tx.commit();
508       }
509       catch (Throwable JavaDoc err)
510       {
511          Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
512                FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
513          users = Collections.<Map JavaDoc>emptyList();
514          try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc tex) {}
515       }
516       
517       return users;
518    }
519    
520    /**
521     * Validate password field data is acceptable
522     */

523    public void validateGroupName(FacesContext context, UIComponent component, Object JavaDoc value)
524          throws ValidatorException
525    {
526       String JavaDoc name = (String JavaDoc)value;
527       if (name.indexOf('\'') != -1 || name.indexOf('"') != -1 || name.indexOf('\\') != -1)
528       {
529          String JavaDoc err = MessageFormat.format(Application.getMessage(context, "groups_err_group_name"),
530                new Object JavaDoc[]{"', \", \\"});
531          throw new ValidatorException(new FacesMessage(err));
532       }
533    }
534    
535    /**
536     * Query callback method executed by the Generic Picker component.
537     * This method is part of the contract to the Generic Picker, it is up to the backing bean
538     * to execute whatever query is appropriate and return the results.
539     *
540     * @param filterIndex Index of the filter drop-down selection
541     * @param contains Text from the contains textbox
542     *
543     * @return An array of SelectItem objects containing the results to display in the picker.
544     */

545    public SelectItem[] pickerCallback(int filterIndex, String JavaDoc contains)
546    {
547       FacesContext context = FacesContext.getCurrentInstance();
548       
549       SelectItem[] items;
550       
551       UserTransaction JavaDoc tx = null;
552       try
553       {
554          tx = Repository.getUserTransaction(context);
555          tx.begin();
556          
557          // build xpath to match available User/Person objects
558
ServiceRegistry services = Repository.getServiceRegistry(context);
559          NodeRef peopleRef = personService.getPeopleContainer();
560          String JavaDoc xpath = "*[like(@" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + "firstName, '%" + contains + "%', false)" +
561                  " or " + "like(@" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + "lastName, '%" + contains + "%', false)]";
562          
563          List JavaDoc<NodeRef> nodes = services.getSearchService().selectNodes(
564                peopleRef,
565                xpath,
566                null,
567                services.getNamespaceService(),
568                false);
569          
570          items = new SelectItem[nodes.size()];
571          for (int index=0; index<nodes.size(); index++)
572          {
573             NodeRef personRef = nodes.get(index);
574             String JavaDoc firstName = (String JavaDoc)this.nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
575             String JavaDoc lastName = (String JavaDoc)this.nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
576             String JavaDoc username = (String JavaDoc)this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
577             SelectItem item = new SortableSelectItem(username, firstName + " " + lastName, lastName);
578             items[index] = item;
579          }
580          
581          // commit the transaction
582
tx.commit();
583       }
584       catch (Exception JavaDoc err)
585       {
586          Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
587                FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err );
588          try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc tex) {}
589          
590          items = new SelectItem[0];
591       }
592       
593       return items;
594    }
595    
596    /**
597     * Set the Group to be used for next action dialog
598     */

599    public void setupGroupAction(ActionEvent event)
600    {
601       UIActionLink link = (UIActionLink)event.getComponent();
602       Map JavaDoc<String JavaDoc, String JavaDoc> params = link.getParameterMap();
603       String JavaDoc group = params.get("id");
604       if (group != null && group.length() != 0)
605       {
606          if (logger.isDebugEnabled())
607             logger.debug("Setup for action, setting current Group to: " + group);
608          
609          // prepare a node for the action context
610
setActionGroup(group);
611          
612          // clear datalist cache ready from return from action dialog
613
contextUpdated();
614       }
615    }
616    
617    /**
618     * Clear the Group action context - e.g. ready for a Create Root Group operation
619     */

620    public void clearGroupAction(ActionEvent event)
621    {
622       setActionGroup(null);
623       
624       // clear datalist cache ready from return from action dialog
625
contextUpdated();
626    }
627    
628    /**
629     * Action called when a Group folder is clicked.
630     * Navigate into the Group and show child Groups and child Users.
631     */

632    public void clickGroup(ActionEvent event)
633    {
634       UIActionLink link = (UIActionLink)event.getComponent();
635       Map JavaDoc<String JavaDoc, String JavaDoc> params = link.getParameterMap();
636       String JavaDoc group = params.get("id");
637       if (group != null && group.length() != 0)
638       {
639          // refresh UI based on node selection
640
updateUILocation(group);
641       }
642    }
643    
644    /**
645     * Action handler called on Create Group finish button click.
646     */

647    public String JavaDoc finishCreate()
648    {
649       String JavaDoc outcome = DEFAULT_OUTCOME;
650       
651       UserTransaction JavaDoc tx = null;
652       try
653       {
654          FacesContext context = FacesContext.getCurrentInstance();
655          tx = Repository.getUserTransaction(context);
656          tx.begin();
657          
658          // create new Group using Authentication Service
659
this.authService.createAuthority(AuthorityType.GROUP, getActionGroup(), this.name);
660          
661          // commit the transaction
662
tx.commit();
663       }
664       catch (Throwable JavaDoc err)
665       {
666          // rollback the transaction
667
try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc tex) {}
668          Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
669                FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
670          outcome = null;
671       }
672       
673       return outcome;
674    }
675    
676    /**
677     * Action handler called on Delete Group finish button click.
678     */

679    public String JavaDoc finishDelete()
680    {
681       String JavaDoc outcome = DEFAULT_OUTCOME;
682       
683       UserTransaction JavaDoc tx = null;
684       try
685       {
686          FacesContext context = FacesContext.getCurrentInstance();
687          tx = Repository.getUserTransaction(context);
688          tx.begin();
689          
690          // delete group using the Authentication Service
691
this.authService.deleteAuthority(getActionGroup());
692          
693          // commit the transaction
694
tx.commit();
695          
696          // remove this node from the breadcrumb if required
697
List JavaDoc<IBreadcrumbHandler> location = getLocation();
698          GroupBreadcrumbHandler handler = (GroupBreadcrumbHandler)location.get(location.size() - 1);
699          
700          // see if the current breadcrumb location is our Group
701
if ( getActionGroup().equals(handler.Group) )
702          {
703             location.remove(location.size() - 1);
704             
705             // now work out which Group to set the list to refresh against
706
if (location.size() != 0)
707             {
708                handler = (GroupBreadcrumbHandler)location.get(location.size() - 1);
709                this.setCurrentGroup(handler.Group, handler.Label);
710             }
711          }
712          
713          // clear action context
714
setActionGroup(null);
715       }
716       catch (Throwable JavaDoc err)
717       {
718          // rollback the transaction
719
try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc tex) {}
720          Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
721                FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
722          outcome = null;
723       }
724       
725       return outcome;
726    }
727    
728    /**
729     * Remove specified user from the current group
730     */

731    public void removeUser(ActionEvent event)
732    {
733       UIActionLink link = (UIActionLink)event.getComponent();
734       Map JavaDoc<String JavaDoc, String JavaDoc> params = link.getParameterMap();
735       String JavaDoc authority = params.get("id");
736       if (authority != null && authority.length() != 0)
737       {
738          try
739          {
740             this.authService.removeAuthority(this.group, authority);
741             
742             // refresh UI after change
743
contextUpdated();
744          }
745          catch (Throwable JavaDoc err)
746          {
747             Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
748                FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
749          }
750       }
751    }
752    
753    /**
754     * Action handler called when Finish button clicked on Add User to Group page
755     */

756    public String JavaDoc finishAddUser()
757    {
758       String JavaDoc outcome = DEFAULT_OUTCOME;
759       
760       UserTransaction JavaDoc tx = null;
761       try
762       {
763          FacesContext context = FacesContext.getCurrentInstance();
764          tx = Repository.getUserTransaction(context);
765          tx.begin();
766          
767          // add each selected user to the current group in turn
768
for (UserAuthorityDetails wrapper : this.usersForGroup)
769          {
770             this.authService.addAuthority(getActionGroup(), wrapper.authority);
771          }
772          
773          // commit the transaction
774
tx.commit();
775       }
776       catch (Throwable JavaDoc err)
777       {
778          // rollback the transaction
779
try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc tex) {}
780          Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
781                FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
782          outcome = null;
783       }
784       
785       return outcome;
786    }
787    
788    /**
789     * Add the selected User to the list for adding to a Group
790     */

791    public void addSelectedUsers(ActionEvent event)
792    {
793       UIGenericPicker picker = (UIGenericPicker)event.getComponent().findComponent("picker");
794       String JavaDoc[] results = picker.getSelectedResults();
795       if (results != null)
796       {
797          for (int i=0; i<results.length; i++)
798          {
799             String JavaDoc authority = results[i];
800             
801             // check for same authority so not added twice
802
boolean foundExisting = false;
803             for (int n=0; n<this.usersForGroup.size(); n++)
804             {
805                UserAuthorityDetails wrapper = this.usersForGroup.get(n);
806                if (authority.equals(wrapper.getAuthority()))
807                {
808                   foundExisting = true;
809                   break;
810                }
811             }
812             
813             if (foundExisting == false)
814             {
815                StringBuilder JavaDoc label = new StringBuilder JavaDoc(48);
816                
817                // build a display label showing the user person name
818
if (this.personService.personExists(authority) == true)
819                {
820                   // found a Person with a User authority
821
NodeRef ref = this.personService.getPerson(authority);
822                   String JavaDoc firstName = (String JavaDoc)this.nodeService.getProperty(ref, ContentModel.PROP_FIRSTNAME);
823                   String JavaDoc lastName = (String JavaDoc)this.nodeService.getProperty(ref, ContentModel.PROP_LASTNAME);
824                   
825                   // build a sensible label for display
826
label.append(firstName)
827                        .append(' ')
828                        .append(lastName);
829                   
830                   // add a wrapper object with the details to the results list for display
831
UserAuthorityDetails userDetails = new UserAuthorityDetails(label.toString(), authority);
832                   this.usersForGroup.add(userDetails);
833                }
834             }
835          }
836       }
837    }
838    
839    /**
840     * Action handler called when the Remove button is pressed to remove a user from the results list
841     */

842    public void removeUserSelection(ActionEvent event)
843    {
844       UserAuthorityDetails wrapper = (UserAuthorityDetails)this.usersDataModel.getRowData();
845       if (wrapper != null)
846       {
847          this.usersForGroup.remove(wrapper);
848       }
849    }
850    
851    /**
852     * Change the current view mode based on user selection
853     */

854    public void viewModeChanged(ActionEvent event)
855    {
856       UIModeList viewList = (UIModeList)event.getComponent();
857       
858       // update view mode from user selection
859
setViewMode(viewList.getValue().toString());
860    }
861    
862    /**
863     * Change the current list filter mode based on user selection
864     */

865    public void filterModeChanged(ActionEvent event)
866    {
867       UIModeList viewList = (UIModeList)event.getComponent();
868       
869       // update list filter mode from user selection
870
setFilterMode(viewList.getValue().toString());
871    }
872    
873    /**
874     * Update the breadcrumb with the clicked Group location
875     */

876    private void updateUILocation(String JavaDoc group)
877    {
878       String JavaDoc groupName = this.authService.getShortName(group);
879       this.location.add(new GroupBreadcrumbHandler(group, groupName));
880       this.setCurrentGroup(group, groupName);
881    }
882    
883    
884    // ------------------------------------------------------------------------------
885
// IContextListener implementation
886

887    /**
888     * @see org.alfresco.web.app.context.IContextListener#contextUpdated()
889     */

890    public void contextUpdated()
891    {
892       if (logger.isDebugEnabled())
893          logger.debug("Invalidating Group Management Components...");
894       
895       // force a requery of the richlist dataset
896
this.groupsRichList.setValue(null);
897       this.usersRichList.setValue(null);
898    }
899    
900    
901    // ------------------------------------------------------------------------------
902
// Inner classes
903

904    /**
905     * Class to handle breadcrumb interaction for Group pages
906     */

907    private class GroupBreadcrumbHandler implements IBreadcrumbHandler
908    {
909       private static final long serialVersionUID = 1871876653151036630L;
910       
911       /**
912        * Constructor
913        *
914        * @param group The group for this navigation element if any
915        * @param label Element label
916        */

917       public GroupBreadcrumbHandler(String JavaDoc group, String JavaDoc label)
918       {
919          this.Group = group;
920          this.Label = label;
921       }
922       
923       /**
924        * @see java.lang.Object#toString()
925        */

926       public String JavaDoc toString()
927       {
928          return this.Label;
929       }
930
931       /**
932        * @see org.alfresco.web.ui.common.component.IBreadcrumbHandler#navigationOutcome(org.alfresco.web.ui.common.component.UIBreadcrumb)
933        */

934       public String JavaDoc navigationOutcome(UIBreadcrumb breadcrumb)
935       {
936          // All group breadcrumb elements relate to a Group
937
// when selected we set the current Group Id and return
938
setCurrentGroup(this.Group, this.Label);
939          setLocation( (List JavaDoc)breadcrumb.getValue() );
940          
941          return null;
942       }
943       
944       public String JavaDoc Group;
945       public String JavaDoc Label;
946    }
947    
948    /**
949     * Simple wrapper bean exposing user authority and person details for JSF results list
950     */

951    public static class UserAuthorityDetails
952    {
953       public UserAuthorityDetails(String JavaDoc name, String JavaDoc authority)
954       {
955          this.name = name;
956          this.authority = authority;
957       }
958       
959       public String JavaDoc getName()
960       {
961          return this.name;
962       }
963       
964       public String JavaDoc getAuthority()
965       {
966          return this.authority;
967       }
968       
969       private String JavaDoc name;
970       private String JavaDoc authority;
971    }
972 }
973
Popular Tags