View Javadoc
1   /*
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.social.webui.space;
18  
19  import java.util.*;
20  
21  import org.apache.commons.lang.ArrayUtils;
22  import org.apache.commons.lang.StringEscapeUtils;
23  import org.apache.commons.lang.StringUtils;
24  
25  import org.exoplatform.commons.utils.LazyPageList;
26  import org.exoplatform.container.ExoContainerContext;
27  import org.exoplatform.container.PortalContainer;
28  import org.exoplatform.portal.application.PortalRequestContext;
29  import org.exoplatform.portal.webui.util.Util;
30  import org.exoplatform.services.log.ExoLogger;
31  import org.exoplatform.services.log.Log;
32  import org.exoplatform.services.organization.MembershipTypeHandler;
33  import org.exoplatform.social.core.identity.model.Identity;
34  import org.exoplatform.social.core.identity.model.Profile;
35  import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
36  import org.exoplatform.social.core.manager.IdentityManager;
37  import org.exoplatform.social.core.space.SpaceUtils;
38  import org.exoplatform.social.core.space.model.Space;
39  import org.exoplatform.social.core.space.spi.SpaceService;
40  import org.exoplatform.social.webui.StringListAccess;
41  import org.exoplatform.social.webui.UIUserInvitation;
42  import org.exoplatform.social.webui.Utils;
43  import org.exoplatform.web.application.ApplicationMessage;
44  import org.exoplatform.web.application.RequestContext;
45  import org.exoplatform.webui.application.WebuiRequestContext;
46  import org.exoplatform.webui.config.annotation.ComponentConfig;
47  import org.exoplatform.webui.config.annotation.ComponentConfigs;
48  import org.exoplatform.webui.config.annotation.EventConfig;
49  import org.exoplatform.webui.core.UIApplication;
50  import org.exoplatform.webui.core.UIContainer;
51  import org.exoplatform.webui.core.UIPageIterator;
52  import org.exoplatform.webui.core.UIPopupWindow;
53  import org.exoplatform.webui.event.Event;
54  import org.exoplatform.webui.event.EventListener;
55  import org.exoplatform.webui.organization.account.UIUserSelector;
56  
57  
58  @ComponentConfigs ({
59    @ComponentConfig(
60       template =  "war:/groovy/social/webui/space/UISpaceMember.gtmpl",
61       events = {
62         @EventConfig(listeners = UISpaceMember.RevokeInvitedUserActionListener.class),
63         @EventConfig(listeners = UISpaceMember.DeclineUserActionListener.class),
64         @EventConfig(listeners = UISpaceMember.ValidateUserActionListener.class),
65         @EventConfig(listeners = UISpaceMember.RemoveUserActionListener.class),
66         @EventConfig(listeners = UISpaceMember.ToggleLeadershipActionListener.class)
67         }
68   )
69  })
70  
71  public class UISpaceMember extends UIContainer {
72  
73    private static final Log LOG = ExoLogger.getLogger(UISpaceMember.class);
74  
75  
76    private static final String MSG_ERROR_NOT_LEADER = "UISpaceMember.msg.error_not_leader";
77    private static final String MSG_ERROR_SELF_REMOVE_LEADER = "UISpaceMember.msg.error_self_remove_leader";
78    private static final String MSG_ERROR_SELF_REMOVE_LEADER_YOU = "UISpaceMember.msg.error_self_remove_leader_you";
79    private static final String MSG_ERROR_SELF_REMOVE_LEADER_ARE = "UISpaceMember.msg.error_self_remove_leader_are";
80    private static final String MSG_ERROR_SELF_REMOVE_LEADER_IS = "UISpaceMember.msg.error_self_remove_leader_is";
81    private static final String MSG_ERROR_SELF_REMOVE_LEADER_LEAVING_IT = "UISpaceMember.msg.error_self_remove_leader_leaving_it";
82    private static final String MSG_ERROR_SELF_REMOVE_LEADER_REMOVING_THE_RIGHTS = "UISpaceMember.msg.error_self_remove_leader_removing_the_rights";
83    private static final String MSG_ERROR_MEMBERS_LOADING = "UISpaceMember.label.MembersLoadingError";
84    private static final String MSG_ERROR_PENDING_USERS_LOADING = "UISpaceMember.label.PendingUsersLoadingError";
85    private static final String MSG_ERROR_INVITED_USERS_LOADING = "UISpaceMember.label.InvitedUsersLoadingError";
86    /**
87     * The first page.
88     */
89    private static final int FIRST_PAGE = 1;
90  
91    private String spaceId;
92    private SpaceService spaceService = null;
93    private UIPageIterator iteratorPendingUsers;
94    private UIPageIterator iteratorInvitedUsers;
95    private UIPageIterator iteratorExistingUsers;
96    private final String iteratorPendingID = "UIIteratorPendding";
97    private final String iteratorInvitedID = "UIIteratorInvited";
98    private final String iteratorExistingID = "UIIteratorExisting";
99    private final Integer PENDING_PER_PAGE = 10;
100   private final Integer INVITATION_PER_PAGE = 10;
101   private final Integer MEMBERS_PER_PAGE = 20;
102   private static final String USER_TO_INVITE = "user_to_invite";
103   String typeOfRelation = null;
104   String spaceURL = null;
105   private boolean hasErr = false;
106   private IdentityManager identityManager;
107 
108   /**
109    * The flag notifies a new search when clicks search icon or presses enter.
110    */
111   private boolean isNewSearch;
112 
113 
114   /**
115    * Constructor.
116    *
117    * @throws Exception
118    */
119   public UISpaceMember() throws Exception {
120     addChild(UIUserInvitation.class, null, null);
121     identityManager = ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(IdentityManager.class);
122     iteratorPendingUsers = createUIComponent(UIPageIterator.class, null, iteratorPendingID);
123     iteratorInvitedUsers = createUIComponent(UIPageIterator.class, null, iteratorInvitedID);
124     iteratorExistingUsers = createUIComponent(UIPageIterator.class, null, iteratorExistingID);
125     addChild(iteratorPendingUsers);
126     addChild(iteratorInvitedUsers);
127     addChild(iteratorExistingUsers);
128     setTypeOfRelation(USER_TO_INVITE);
129   }
130 
131   /**
132    * Gets uiPageIteratorPendingUsers
133    *
134    * @return uiPageIterator
135    */
136   public UIPageIterator getUIPageIteratorPendingUsers() {
137     return iteratorPendingUsers;
138   }
139 
140   /**
141    * Gets uiPageIteratorInvitedUsers to display; revoke
142    *
143    * @return uiPageIteraatorInvitedUsers
144    */
145   public UIPageIterator getUIPageIteratorInvitedUsers() {
146     return iteratorInvitedUsers;
147   }
148 
149   /**
150    * Gets uiPageIteratorExistingUsers to display; remove or set/remove leader.
151    *
152    * @return uiPageiteratorExistingUsers
153    */
154   public UIPageIterator getUIPageIteratorExistingUsers() {
155     return iteratorExistingUsers;
156   }
157 
158   /**
159    * Sets spaceId to this for getting current space
160    *
161    * @param spaceId
162    * @throws Exception
163    */
164   public void setValue(String spaceId) throws Exception {
165     this.spaceId = spaceId;
166   }
167 
168 
169   /**
170    * Gets type of relation with current user.
171    */
172   public String getTypeOfRelation() {
173     return typeOfRelation;
174   }
175 
176   /**
177    * Sets type of relation with current user to variable.
178    *
179    * @param typeOfRelation <code>char</code>
180    */
181   public void setTypeOfRelation(String typeOfRelation) {
182     this.typeOfRelation = typeOfRelation;
183   }
184 
185   /**
186    * Gets space url.
187    */
188   public String getSpaceURL() {
189     return spaceURL;
190   }
191 
192   /**
193    * Sets space url.
194    *
195    * @param spaceURL <code>char</code>
196    */
197   public void setSpaceURL(String spaceURL) {
198     this.spaceURL = spaceURL;
199   }
200 
201   /**
202    * @return the hasErr
203    */
204   public boolean isHasErr() {
205     return hasErr;
206   }
207 
208   /**
209    * @param hasErr the hasErr to set
210    */
211   public void setHasErr(boolean hasErr) {
212     this.hasErr = hasErr;
213   }
214 
215   /**
216    * Gets current user name.
217    *
218    * @return
219    */
220   public String getCurrentUserName() {
221     RequestContext context = RequestContext.getCurrentInstance();
222     return context.getRemoteUser();
223   }
224 
225   /**
226    * Gets current rest context name.
227    *
228    * @return
229    */
230   protected String getRestContextName() {
231     return PortalContainer.getCurrentRestContextName();
232   }
233 
234   /**
235    * Gets portal name.
236    *
237    * @return
238    */
239   protected String getPortalName() {
240     return PortalContainer.getCurrentPortalContainerName();
241   }
242 
243   /**
244    * Gets list of pending users in a space
245    *
246    * @return list of pending users
247    */
248   @SuppressWarnings("unchecked")
249   public List<String> getPendingUsers() throws Exception {
250     SpaceService spaceService = getSpaceService();
251     Space space = spaceService.getSpaceById(spaceId);
252     try {
253       if (space == null) {
254         throw new Exception("Could not get the space with ID "+ spaceId);
255       }
256 
257       String[] pendingUsers = space.getPendingUsers();
258       if (pendingUsers == null || pendingUsers.length == 0) {
259         return new ArrayList<String>();
260       }
261       pendingUsers = sortUsers(pendingUsers);
262 
263       int currentPage = iteratorPendingUsers.getCurrentPage();
264       LazyPageList<String> pageList = new LazyPageList<String>(
265           new StringListAccess(Arrays.asList(pendingUsers)),
266           PENDING_PER_PAGE);
267       iteratorPendingUsers.setPageList(pageList);
268       int pageCount = iteratorPendingUsers.getAvailablePage();
269       if (pageCount >= currentPage) {
270         iteratorPendingUsers.setCurrentPage(currentPage);
271       } else if (pageCount < currentPage) {
272         iteratorPendingUsers.setCurrentPage(currentPage - 1);
273       }
274       return iteratorPendingUsers.getCurrentPageData();
275     } catch(Exception e) {
276       LOG.error("An error occurred while retrieving space pending users",e);
277       WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
278       UIApplication uiApplication = context.getUIApplication();
279       uiApplication.addMessage(new ApplicationMessage(MSG_ERROR_PENDING_USERS_LOADING,
280                                                       null,
281                                                       ApplicationMessage.ERROR));
282     }
283     return new ArrayList<>();
284   }
285 
286   /**
287    * Gets list of invited users in a space
288    *
289    * @return lists of invited users
290    */
291   @SuppressWarnings("unchecked")
292   public List<String> getInvitedUsers() {
293     SpaceService spaceService = getSpaceService();
294     Space space = spaceService.getSpaceById(spaceId);
295     try {
296       if (space == null) {
297         throw new Exception("Could not get the space with ID "+ spaceId);
298       }
299 
300       String[] invitedUsers = space.getInvitedUsers();
301       if (invitedUsers == null || invitedUsers.length == 0) {
302         return new ArrayList<String>();
303       }
304       invitedUsers = sortUsers(invitedUsers);
305 
306       int currentPage = iteratorInvitedUsers.getCurrentPage();
307       LazyPageList<String> pageList = new LazyPageList<String>(
308           new StringListAccess(Arrays.asList(invitedUsers)),
309           INVITATION_PER_PAGE);
310       iteratorInvitedUsers.setPageList(pageList);
311       int pageCount = iteratorInvitedUsers.getAvailablePage();
312       if (pageCount >= currentPage) {
313         iteratorInvitedUsers.setCurrentPage(currentPage);
314       } else if (pageCount < currentPage) {
315         iteratorInvitedUsers.setCurrentPage(currentPage - 1);
316       }
317 
318       return iteratorInvitedUsers.getCurrentPageData();
319     } catch(Exception e) {
320       LOG.error("An error occurred while retrieving space invited users",e);
321       WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
322       UIApplication uiApplication = context.getUIApplication();
323       uiApplication.addMessage(new ApplicationMessage(MSG_ERROR_INVITED_USERS_LOADING,
324                                                       null,
325                                                       ApplicationMessage.ERROR));
326     }
327     return new ArrayList<>();
328   }
329 
330   private String[] sortUsers(String[] users) {
331     List<String> sortedIdentities = identityManager.sortIdentities(Arrays.asList(users), Profile.FULL_NAME);
332     users = sortedIdentities.toArray(new String[0]);
333     return users;
334   }
335 
336   /**
337    * Gets list of existing users in a space
338    *
339    * @return list of existing users
340    */
341   @SuppressWarnings("unchecked")
342   public List<String> getExistingUsers() {
343     SpaceService spaceService = getSpaceService();
344     Space space = spaceService.getSpaceById(spaceId);
345 
346     try {
347       if (space == null) {
348         throw new Exception("Could not get the space with ID "+ spaceId);
349       }
350 
351       String[] memberUsers = space.getMembers();
352       if (memberUsers == null || memberUsers.length == 0) {
353         return new ArrayList<String>();
354       }
355       memberUsers = sortUsers(memberUsers);
356 
357       int currentPage = iteratorExistingUsers.getCurrentPage();
358       Set<String> users = new LinkedHashSet<String>(Arrays.asList(memberUsers));
359 
360       LazyPageList<String> pageList = new LazyPageList<>(new StringListAccess(new ArrayList<>(users)), MEMBERS_PER_PAGE);
361       iteratorExistingUsers.setPageList(pageList);
362       if (this.isNewSearch()) {
363         iteratorExistingUsers.setCurrentPage(FIRST_PAGE);
364       } else {
365         iteratorExistingUsers.setCurrentPage(currentPage);
366       }
367       this.setNewSearch(false);
368       return iteratorExistingUsers.getCurrentPageData();
369     }catch (Exception e) {
370       LOG.error("An error occurred while retrieving space members",e);
371       WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
372       UIApplication uiApplication = context.getUIApplication();
373       uiApplication.addMessage(new ApplicationMessage(MSG_ERROR_MEMBERS_LOADING,
374                                                       null,
375                                                       ApplicationMessage.ERROR));
376     }
377     return new ArrayList<>();
378   }
379   
380   /**
381    * Sets users name to the input string
382    *
383    * @param userName string of users name
384    */
385   public void setUsersName(String userName) {
386 //    getUIStringInput(USER).setValue(userName);
387   }
388 
389   /**
390    * Gets string of user names input: a, b, c
391    *
392    * @return string of user names input
393    */
394   public String getUsersName() {
395 //    String value = getUIStringInput(USER).getValue();
396 //    return value != null ? value : "";
397     return null;
398   }
399 
400   /**
401    * Checks whether the remote user is a spaces super manager
402    *
403    * @return true or false
404    * @throws Exception
405    */
406   public boolean isSuperManager() throws Exception {
407     return spaceService.isSuperManager(getRemoteUser());
408   }
409 
410   /**
411    * Gets spaceUrl
412    *
413    * @return string homespace url
414    * @throws Exception
415    */
416   public String getHomeSpaceUrl() throws Exception {
417     Space space = getSpaceService().getSpaceById(spaceId);
418     return Utils.getSpaceHomeURL(space);
419   }
420 
421   /**
422    * Gets Manage Spaces Url (UIManageMySpaces)
423    *
424    * @return manage spaces url
425    * @throws Exception
426    */
427   public String getManageSpacesUrl() throws Exception {
428     //TODO hoatle: Hard-coded
429     return Utils.getURI("spaces");
430   }
431 
432   /**
433    * Checks if a user is a leader of a space.
434    *
435    * @param userName logged-in user
436    * @return true or false
437    * @throws Exception
438    */
439   public boolean isLeader(String userName) throws Exception {
440     SpaceService spaceService = getSpaceService();
441     Space space = spaceService.getSpaceById(spaceId);
442     return spaceService.isManager(space, userName);
443   }
444 
445   /**
446    * Checks if user has wild card membership.
447    * 
448    * @param userId target user to check.
449    * @return true if user has wild card membership in space.
450    */
451   protected boolean hasWildCardMembership(String userId) {
452     SpaceService spaceService = getSpaceService();
453     Space space = spaceService.getSpaceById(spaceId);
454     return SpaceUtils.isUserHasMembershipTypesInGroup(userId, space.getGroupId(), MembershipTypeHandler.ANY_MEMBERSHIP_TYPE);
455   }
456   
457   public boolean isCurrentUser(String userName) throws Exception {
458     return (getRemoteUser().equals(userName));
459   }
460 
461   /**
462    * Triggers this action when user clicks on "revoke invited" button.
463    *
464    * @author hoatle
465    */
466   static public class RevokeInvitedUserActionListener extends EventListener<UISpaceMember> {
467     public void execute(Event<UISpaceMember> event) throws Exception {
468       UISpaceMember uiSpaceMember = event.getSource();
469       WebuiRequestContext requestContext = event.getRequestContext();
470       String userName = event.getRequestContext().getRequestParameter(OBJECTID);
471 
472       SpaceService spaceService = uiSpaceMember.getSpaceService();
473       spaceService.removeInvitedUser(spaceService.getSpaceById(uiSpaceMember.spaceId), userName);
474       requestContext.addUIComponentToUpdateByAjax(uiSpaceMember);
475     }
476   }
477 
478   /**
479    * Triggers this action when user clicks on "decline user's request" button.
480    *
481    * @author hoatle
482    */
483   static public class DeclineUserActionListener extends EventListener<UISpaceMember> {
484     public void execute(Event<UISpaceMember> event) throws Exception {
485       UISpaceMember uiSpaceMember = event.getSource();
486       WebuiRequestContext requestContext = event.getRequestContext();
487       String userName = event.getRequestContext().getRequestParameter(OBJECTID);
488 
489       SpaceService spaceService = uiSpaceMember.getSpaceService();
490       spaceService.removePendingUser(spaceService.getSpaceById(uiSpaceMember.spaceId), userName);
491       requestContext.addUIComponentToUpdateByAjax(uiSpaceMember);
492     }
493   }
494 
495   /**
496    * Triggers this action when user clicks on "remove user" button.
497    *
498    * @author hoatle
499    */
500   static public class RemoveUserActionListener extends EventListener<UISpaceMember> {
501 
502     public void execute(Event<UISpaceMember> event) throws Exception {
503       UISpaceMember uiSpaceMember = event.getSource();
504       WebuiRequestContext requestContext = event.getRequestContext();
505       PortalRequestContext prContext = Util.getPortalRequestContext();
506       boolean useAjax = prContext.useAjax();
507       UIApplication uiApp = requestContext.getUIApplication();
508       SpaceService spaceService = uiSpaceMember.getSpaceService();
509       Space space = spaceService.getSpaceById(uiSpaceMember.spaceId);
510       String currentUser = requestContext.getRemoteUser();
511       String userName = event.getRequestContext().getRequestParameter(OBJECTID);
512       if (!useAjax) {
513         userName = currentUser;
514       }
515 
516       if (spaceService.isOnlyManager(space, userName)) {
517         uiApp.addMessage(new ApplicationMessage(MSG_ERROR_SELF_REMOVE_LEADER,
518                                                 uiSpaceMember.makeParamSelfRemoveLeaderErrorMessage(userName, currentUser),
519                                                 ApplicationMessage.WARNING));
520         return;
521       }
522 
523       spaceService.removeMember(space, userName);
524       spaceService.setManager(spaceService.getSpaceById(space.getId()), userName, false);
525 
526       if (!useAjax) { // self remove.
527         prContext = Util.getPortalRequestContext();
528         prContext.setResponseComplete(true);
529         StringBuffer url = new StringBuffer();
530         if (uiSpaceMember.isSuperManager()) {
531           url.append(Utils.getSpaceHomeURL(space)).append("/SpaceSettingPortlet");
532         } else {
533           url.append(Utils.getURI("spaces"));
534         }
535         prContext.getResponse().sendRedirect(url.toString());
536         return;
537       } else { // remove other and use ajax to update.
538         requestContext.addUIComponentToUpdateByAjax(uiSpaceMember);
539       }
540     }
541   }
542 
543   /**
544    * Triggers this action when user click on "validate user's request" button
545    *
546    * @author hoatle
547    */
548   static public class ValidateUserActionListener extends EventListener<UISpaceMember> {
549     public void execute(Event<UISpaceMember> event) throws Exception {
550       UISpaceMember uiSpaceMember = event.getSource();
551       WebuiRequestContext requestContext = event.getRequestContext();
552       String userName = event.getRequestContext().getRequestParameter(OBJECTID);
553 
554       SpaceService spaceService = uiSpaceMember.getSpaceService();
555       spaceService.addMember(spaceService.getSpaceById(uiSpaceMember.spaceId), userName);
556       requestContext.addUIComponentToUpdateByAjax(uiSpaceMember);
557     }
558   }
559 
560   static public class ToggleLeadershipActionListener extends EventListener<UISpaceMember> {
561     @Override
562     public void execute(Event<UISpaceMember> event) throws Exception {
563       UISpaceMember uiSpaceMember = event.getSource();
564       SpaceService spaceService = uiSpaceMember.getSpaceService();
565       WebuiRequestContext rcontext = event.getRequestContext();
566       String authenticatedUser = rcontext.getRemoteUser();
567       Space space = spaceService.getSpaceById(uiSpaceMember.spaceId);
568 
569       // only space administrators and managers can promote/revoke manager
570       if(!spaceService.isSuperManager(authenticatedUser) && !spaceService.isManager(space, authenticatedUser)) {
571         UIApplication uiApp = rcontext.getUIApplication();
572         uiApp.addMessage(new ApplicationMessage(MSG_ERROR_NOT_LEADER, new String[]{}, ApplicationMessage.WARNING));
573         return;
574       }
575 
576       String targetUser = rcontext.getRequestParameter(OBJECTID);
577       space.setEditor(Utils.getViewerRemoteId());
578       
579       boolean success = false;
580       if (spaceService.isManager(space, targetUser)) {
581         if (spaceService.isOnlyManager(space, targetUser)) {
582           UIApplication uiApp = rcontext.getUIApplication();
583           uiApp.addMessage(new ApplicationMessage(MSG_ERROR_SELF_REMOVE_LEADER,
584                   uiSpaceMember.makeParamSelfRemoveLeaderErrorMessage(targetUser, authenticatedUser),
585                   ApplicationMessage.WARNING));
586           return;
587         }
588         spaceService.setManager(space, targetUser, false);
589         success = true;
590       } else if (spaceService.isMember(space, targetUser)) {
591         spaceService.setManager(space, targetUser, true);
592         success = true;
593       }
594 
595       if (success) {
596         ((WebuiRequestContext) rcontext.getParentAppRequestContext()).setResponseComplete(true);
597       }
598     }
599   }
600   
601   /**
602    * Triggers this action when user clicks on popup's close button.
603    *
604    * @author hoatle
605    */
606   static public class CloseActionListener extends EventListener<UIUserSelector> {
607     public void execute(Event<UIUserSelector> event) throws Exception {
608       UIUserSelector uiForm = event.getSource();
609       UISpaceMember uiSpaceMember = uiForm.getAncestorOfType(UISpaceMember.class);
610       UIPopupWindow uiPopup = uiSpaceMember.getChild(UIPopupWindow.class);
611       uiPopup.setUIComponent(null);
612       uiPopup.setShow(false);
613       event.getRequestContext().addUIComponentToUpdateByAjax(uiSpaceMember);
614     }
615   }
616 
617   protected boolean isMember(String userId) {
618     SpaceService spaceService = getSpaceService();
619     Space space = spaceService.getSpaceById(spaceId);
620     try {
621       if (ArrayUtils.contains(space.getMembers(), userId)) {
622         return true;
623       }
624     } catch (Exception e) {
625       return false;
626     }
627     return false;
628   }
629 
630   /**
631    * Gets spaceService
632    *
633    * @return spaceService
634    * @see SpaceService
635    */
636   private SpaceService getSpaceService() {
637     if (spaceService == null) {
638       spaceService = getApplicationComponent(SpaceService.class);
639     }
640     return spaceService;
641   }
642 
643   /**
644    * Gets remoteUser ~ currently logged-in user
645    *
646    * @return remoteUser
647    * @throws Exception
648    */
649   private String getRemoteUser() throws Exception {
650     return Util.getPortalRequestContext().getRemoteUser();
651   }
652   
653   /**
654    * Get full name from userId.
655    * 
656    * @param userId
657    * @return Full name
658    */
659   public String getFullName(String userId) {
660     Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId, true);
661     
662     if (identity == null) return StringUtils.EMPTY;
663     
664     return StringEscapeUtils.escapeHtml(identity.getProfile().getFullName());
665   }
666 
667   public boolean isNewSearch() {
668     return isNewSearch;
669   }
670 
671   public void setNewSearch(boolean isNewSearch) {
672     this.isNewSearch = isNewSearch;
673   }
674   
675   private String[] makeParamSelfRemoveLeaderErrorMessage(String userName, String currentUser) {
676     if (userName == null || currentUser == null) {
677       return null;
678     }
679     if (currentUser.equals(userName)) {
680       return new String[] {MSG_ERROR_SELF_REMOVE_LEADER_YOU, MSG_ERROR_SELF_REMOVE_LEADER_ARE, MSG_ERROR_SELF_REMOVE_LEADER_LEAVING_IT};
681     }
682     return new String[] {getFullName(userName), MSG_ERROR_SELF_REMOVE_LEADER_IS, MSG_ERROR_SELF_REMOVE_LEADER_REMOVING_THE_RIGHTS};
683   }
684 }