View Javadoc
1   package org.exoplatform.cs.event;
2   
3   import org.apache.commons.lang.StringEscapeUtils;
4   import org.exoplatform.calendar.service.*;
5   import org.exoplatform.calendar.service.impl.NewUserListener;
6   import org.exoplatform.commons.utils.DateUtils;
7   import org.exoplatform.container.PortalContainer;
8   import org.exoplatform.portal.application.PortalRequestContext;
9   import org.exoplatform.portal.webui.util.Util;
10  import org.exoplatform.services.log.ExoLogger;
11  import org.exoplatform.services.log.Log;
12  import org.exoplatform.services.organization.OrganizationService;
13  import org.exoplatform.services.security.ConversationState;
14  import org.exoplatform.services.security.Identity;
15  import org.exoplatform.services.security.MembershipEntry;
16  import org.exoplatform.web.application.ApplicationMessage;
17  import org.exoplatform.webui.application.WebuiRequestContext;
18  import org.exoplatform.webui.config.annotation.ComponentConfig;
19  import org.exoplatform.webui.config.annotation.EventConfig;
20  import org.exoplatform.webui.core.UIComponent;
21  import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
22  import org.exoplatform.webui.core.model.SelectItem;
23  import org.exoplatform.webui.core.model.SelectItemOption;
24  import org.exoplatform.webui.core.model.SelectOption;
25  import org.exoplatform.webui.core.model.SelectOptionGroup;
26  import org.exoplatform.webui.event.Event;
27  import org.exoplatform.webui.event.EventListener;
28  import org.exoplatform.webui.form.*;
29  
30  import java.text.DateFormat;
31  import java.text.SimpleDateFormat;
32  import java.util.*;
33  import java.util.Calendar;
34  
35  /**
36   * Created with IntelliJ IDEA.
37   * User: Racha
38   * Date: 01/11/12
39   * Time: 11:08
40   * To change this template use File | Settings | File Templates.
41   */
42  @ComponentConfig(
43                   lifecycle = UIFormLifecycle.class,
44                   template = "classpath:groovy/webui/create/UICreateEvent.gtmpl",
45                   events = {
46  
47                           @EventConfig(
48                                   listeners = UICreateEvent.NextActionListener.class,
49                                   phase = Event.Phase.DECODE
50                         )   ,
51                           @EventConfig(
52                                   listeners = UICreateEvent.CancelActionListener.class,
53                                   phase = Event.Phase.DECODE
54                           )
55                   }
56      )
57  
58  public class UICreateEvent extends UIForm {
59  
60    public static final String PRIVATE_CALENDARS = "privateCalendar";
61    public static final String SHARED_CALENDARS = "sharedCalendar";
62    public static final String PUBLIC_CALENDARS = "publicCalendar";
63    public static final String PRIVATE_TYPE = "0";
64    public static final String SHARED_TYPE = "1";
65    public static final String PUBLIC_TYPE = "2";
66    public static final String COLON = ":";
67    public static final String COMMA = ",";
68    public static final String ANY = "*.*";
69    public static final String ANY_OF = "*.";
70    public static final String DOT = ".";
71    public static final String SLASH_COLON = "/:";
72    public static final String OPEN_PARENTHESIS = "(";
73    public static final String CLOSE_PARENTHESIS = ")";
74    private static Log log = ExoLogger.getLogger(UICreateEvent.class);
75  
76    static String TITLE = "Title";
77    static String POPUP_TITLE = "Popup_title";
78  
79    public static String END_EVENT = "EndEvent";
80    public static String CALENDAR = "Calendar";
81    public static String START_EVENT = "StartEvent";
82    public static String START_TIME = "start_time";
83    public static String END_TIME = "end_time";
84    public static String ALL_DAY = "all-day";
85    private String calType_ = "0";
86    public static final String TIMEFORMAT = "HH:mm";
87    public static final String DISPLAY_TIMEFORMAT = "hh:mm a";
88    public static final long DEFAULT_TIME_INTERVAL = 30;
89  
90    public UICreateEvent() throws Exception {
91      addUIFormInput(new UIFormStringInput(TITLE, TITLE, null));
92      addUIFormInput(new UIFormDateTimeInput(START_EVENT, START_EVENT, getInstanceOfCurrentCalendar().getTime(), false));
93      addUIFormInput(new UIFormDateTimeInput(END_EVENT, END_EVENT, getInstanceOfCurrentCalendar().getTime(), false));
94      addUIFormInput(new UIFormSelectBoxWithGroups(CALENDAR, CALENDAR, getCalendarOption()));
95      addUIFormInput(new UIFormSelectBox(START_TIME, START_TIME, getTimesSelectBoxOptions(DISPLAY_TIMEFORMAT)));
96      addUIFormInput(new UIFormSelectBox(END_TIME, END_TIME, getTimesSelectBoxOptions(DISPLAY_TIMEFORMAT)));
97    }
98  
99  
100   protected String getDateTimeFormat(){
101     UIFormDateTimeInput fromField = getChildById(START_EVENT);
102     return fromField.getDatePattern_();
103   }
104 
105 
106   static public class NextActionListener extends EventListener<UICreateEvent> {
107     public void execute(Event<UICreateEvent> event)
108         throws Exception {
109       UICreateEvent uiForm = event.getSource();
110       String summary = uiForm.getEventSummary();
111       if (summary == null || summary.trim().length() <= 0) {
112         event.getRequestContext().getUIApplication().addMessage(new ApplicationMessage(uiForm.getId()
113                                                                                        + ".msg.summary-field-required", null, ApplicationMessage.WARNING));
114         ((PortalRequestContext) event.getRequestContext().getParentAppRequestContext()).ignoreAJAXUpdateOnPortlets(true);
115         return;
116       }
117       summary = summary.trim();
118       UIFormDateTimeInput fromField = uiForm.getChildById(START_EVENT);
119       UIFormDateTimeInput toField = uiForm.getChildById(END_EVENT);
120       Date from = uiForm.getDateTime(fromField, UICreateEvent.START_TIME);
121       Date to = uiForm.getDateTime(toField, UICreateEvent.END_TIME);
122       if (from == null) {
123         event.getRequestContext().getUIApplication().addMessage(new ApplicationMessage(uiForm.getId() + ".msg.fromDate-format", null, ApplicationMessage.WARNING));
124         ((PortalRequestContext) event.getRequestContext().getParentAppRequestContext()).ignoreAJAXUpdateOnPortlets(true);
125         return;
126       }
127       if (to == null) {
128         event.getRequestContext().getUIApplication().addMessage(new ApplicationMessage(uiForm.getId() + ".msg.toDate-format", null, ApplicationMessage.WARNING));
129         ((PortalRequestContext) event.getRequestContext().getParentAppRequestContext()).ignoreAJAXUpdateOnPortlets(true);
130         return;
131       }
132       if (from.after(to) || from.equals(to)) {
133         event.getRequestContext().getUIApplication().addMessage(new ApplicationMessage(uiForm.getId() + ".msg.logic-required", null, ApplicationMessage.WARNING));
134         ((PortalRequestContext) event.getRequestContext().getParentAppRequestContext()).ignoreAJAXUpdateOnPortlets(true);
135         return;
136       }
137 
138       CalendarService calService = getCalendarService();
139       if (calService.isRemoteCalendar(getCurrentUser(), uiForm.getEventCalendar())) {
140         event.getRequestContext().getUIApplication().addMessage(new ApplicationMessage(uiForm.getId() +".msg.cant-add-event-on-remote-calendar", null, ApplicationMessage.WARNING));
141         ((PortalRequestContext) event.getRequestContext().getParentAppRequestContext()).ignoreAJAXUpdateOnPortlets(true);
142         return;
143       }
144 
145       try {
146         CalendarEvent calEvent = new CalendarEvent();
147         calEvent.setSummary(summary);
148         calEvent.setCalendarId(uiForm.getEventCalendar());
149         String username = getCurrentUser();
150         calEvent.setEventType(CalendarEvent.TYPE_EVENT);
151         calEvent.setEventState(CalendarEvent.ST_BUSY);
152 
153         calEvent.setRepeatType(CalendarEvent.RP_NOREPEAT);
154         calEvent.setFromDateTime(from);
155         calEvent.setToDateTime(to);
156         calEvent.setCalType(uiForm.calType_);
157         String calName="";
158         if(calService.getUserCalendar(username,uiForm.getEventCalendar())!=null) {
159             calName = calService.getUserCalendar(username,uiForm.getEventCalendar()).getName();
160 
161         } else {
162           if(calService.getGroupCalendar(uiForm.getEventCalendar())!=null){
163             calName= getGroupCalendarName(calService.getGroupCalendar(uiForm.getEventCalendar()).getGroups()[0].substring(calService.getGroupCalendar(uiForm.getEventCalendar()).getGroups()[0].lastIndexOf("/") + 1),
164                                           calService.getGroupCalendar(uiForm.getEventCalendar()).getName()) ;
165 
166           } else {
167             if( calService.getSharedCalendars(username,true).getCalendarById(uiForm.getEventCalendar())!=null){
168               String defaultCalendarName = getCalendarService().getDefaultCalendarName();
169               if (calService.getUserCalendar(username,uiForm.getEventCalendar()).getId().equals(Utils.getDefaultCalendarId(calService.getUserCalendar(username,uiForm.getEventCalendar()).getCalendarOwner())) && calService.getUserCalendar(username,uiForm.getEventCalendar()).getName().equals(defaultCalendarName)) {
170                 String defaultCalendarId = getCalendarService().getDefaultCalendarId();
171                 calName = getResourceBundle("UICreateEvent.label." + defaultCalendarId, defaultCalendarId);
172 
173               }
174               String owner = "";
175               if (calService.getUserCalendar(username,uiForm.getEventCalendar()).getCalendarOwner() != null) owner = calService.getUserCalendar(username,uiForm.getEventCalendar()).getCalendarOwner() + " - ";
176               calName= new StringBuilder(owner).append(calName).toString();
177             }
178           }
179         }
180         if (uiForm.calType_.equals(PRIVATE_TYPE)) {
181           calService.saveUserEvent(username, calEvent.getCalendarId(), calEvent, true);
182         } else if (uiForm.calType_.equals(SHARED_TYPE)) {
183           calService.saveEventToSharedCalendar(username, calEvent.getCalendarId(), calEvent, true);
184         } else if (uiForm.calType_.equals(PUBLIC_TYPE)) {
185           calService.savePublicEvent(calEvent.getCalendarId(), calEvent, true);
186         }
187         String defaultMsg = "The event has been added to the {1}.";
188         String message =  UICreateEvent.getResourceBundle(uiForm.getId()+".msg.add-successfully."+ calEvent.getEventType(),defaultMsg);
189         message = message.replace("{1}", calName);
190         Event<UIComponent> cancelEvent = uiForm.<UIComponent>getParent().createEvent("Cancel", Event.Phase.PROCESS, event.getRequestContext());
191         if (cancelEvent != null) {
192           cancelEvent.broadcast();
193         }
194         event.getRequestContext().getJavascriptManager().require("SHARED/navigation-toolbar", "toolbarnav")
195              .addScripts("toolbarnav.UIPortalNavigation.cancelNextClick('UICreateList','UICreatePlatformToolBarPortlet','" + StringEscapeUtils.escapeJavaScript(message) + "');");
196       } catch (Exception e) {
197         if (log.isDebugEnabled()) {
198           log.debug("Fail to quick add event to the calendar", e);
199         }
200         event.getRequestContext().getUIApplication().addMessage(new ApplicationMessage(uiForm.getId() + ".msg.add-unsuccessfully", null));
201       }
202 
203 
204     }
205   }
206 
207   public Date getDateTime(UIFormDateTimeInput input, String selectId) throws Exception {
208     String timeField = getUIFormSelectBox(selectId).getValue();
209     boolean isAllDate = ALL_DAY.equals(timeField);
210     if (END_TIME.equals(selectId)) {
211       return getEndDate(isAllDate, input.getDatePattern_(), input.getValue(), TIMEFORMAT, timeField);
212     } else return getBeginDate(isAllDate, input.getDatePattern_(), input.getValue(), TIMEFORMAT, timeField);
213   }
214 
215   public static Date getBeginDate(boolean isAllDate, String dateFormat, String fromField, String timeFormat, String timeField) throws Exception {
216     try {
217     WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
218     Locale locale = context.getParentAppRequestContext().getLocale();
219     if (isAllDate) {
220       DateFormat df = new SimpleDateFormat(dateFormat, locale);
221       df.setCalendar(getInstanceOfCurrentCalendar());
222       return getBeginDay(df.parse(fromField)).getTime();
223     }
224     DateFormat df = new SimpleDateFormat(dateFormat + Utils.SPACE + timeFormat, locale);
225     df.setCalendar(getInstanceOfCurrentCalendar());
226     return df.parse(fromField + Utils.SPACE + timeField);
227     } catch (Exception e) {
228       return null;
229     }
230   }
231 
232   public static Date getEndDate(boolean isAllDate, String dateFormat, String fromField, String timeFormat, String timeField) throws Exception {
233     try {
234       WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
235       Locale locale = context.getParentAppRequestContext().getLocale();
236       if (isAllDate) {
237         DateFormat df = new SimpleDateFormat(dateFormat, locale);
238         df.setCalendar(getInstanceOfCurrentCalendar());
239         Calendar temp = getEndDay(df.parse(fromField)) ;
240         temp.setTimeInMillis(temp.getTimeInMillis()-1);
241         return temp.getTime();
242       }
243       DateFormat df = new SimpleDateFormat(dateFormat + Utils.SPACE + timeFormat, locale);
244       df.setCalendar(getInstanceOfCurrentCalendar());
245       return df.parse(fromField + Utils.SPACE + timeField);
246     } catch (Exception e) {
247       return null;
248     }
249   }
250 
251   public static CalendarSetting getCurrentUserCalendarSetting() {
252     try {
253       String user = getCurrentUser();
254       CalendarSetting setting = getCalendarService().getCalendarSetting(user);
255       return setting;
256     } catch (Exception e) {
257       log.warn("could not get calendar setting of user", e);
258       return null;
259     }
260 
261   }
262 
263   public static Calendar getInstanceOfCurrentCalendar() {
264     try {
265       CalendarSetting setting = getCurrentUserCalendarSetting();
266       return getCalendarInstanceBySetting(setting);
267     } catch (Exception e) {
268       if (log.isWarnEnabled()) log.warn("Could not get calendar setting!", e);
269       Calendar calendar = GregorianCalendar.getInstance();
270       calendar.setLenient(false);
271       return calendar;
272     }
273   }
274 
275   public static Calendar getCalendarInstanceBySetting(final CalendarSetting calendarSetting) {
276     Calendar calendar = GregorianCalendar.getInstance();
277     calendar.setLenient(false);
278     calendar.setTimeZone(DateUtils.getTimeZone(calendarSetting.getTimeZone()));
279     calendar.setFirstDayOfWeek(Integer.parseInt(calendarSetting.getWeekStartOn()));
280     // fix CS-4725
281     calendar.setMinimalDaysInFirstWeek(4);
282     return calendar;
283   }
284 
285   public static Calendar getBeginDay(Calendar cal) {
286     Calendar newCal = (Calendar) cal.clone();
287 
288     newCal.set(Calendar.HOUR_OF_DAY, 0);
289     newCal.set(Calendar.MINUTE, 0);
290     newCal.set(Calendar.SECOND, 0);
291     newCal.set(Calendar.MILLISECOND, 0);
292     return newCal;
293   }
294 
295   public static Calendar getEndDay(Calendar cal) {
296     Calendar newCal = (Calendar) cal.clone();
297     newCal.set(Calendar.HOUR_OF_DAY, 0);
298     newCal.set(Calendar.MINUTE, 0);
299     newCal.set(Calendar.SECOND, 0);
300     newCal.set(Calendar.MILLISECOND, 0);
301     newCal.add(Calendar.HOUR_OF_DAY, 24);
302     return newCal;
303   }
304 
305   public static Calendar getBeginDay(Date date) {
306     Calendar cal = getInstanceOfCurrentCalendar();
307     cal.setTime(date);
308     return getBeginDay(cal);
309   }
310 
311   public static Calendar getEndDay(Date date) {
312     Calendar cal = getInstanceOfCurrentCalendar();
313     cal.setTime(date);
314     return getEndDay(cal);
315   }
316 
317   static public class CancelActionListener extends EventListener<UICreateEvent> {
318 
319 
320     public void execute(Event<UICreateEvent> event)
321         throws Exception {
322       UICreateEvent uisource = event.getSource();
323       WebuiRequestContext ctx = event.getRequestContext();
324       Event<UIComponent> cancelEvent = uisource.<UIComponent>getParent().createEvent("Cancel", Event.Phase.DECODE, ctx);
325       if (cancelEvent != null) {
326         cancelEvent.broadcast();
327       }
328 
329 
330     }
331   }
332 
333   public static List<SelectItemOption<String>> getTimesSelectBoxOptions(String timeFormat) {
334     WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
335     Locale locale = context.getParentAppRequestContext().getLocale();
336     return getTimesSelectBoxOptions(timeFormat, TIMEFORMAT, DEFAULT_TIME_INTERVAL, locale);
337   }
338 
339   public static List<SelectItemOption<String>> getTimesSelectBoxOptions(String labelFormat, String valueFormat, long timeInteval) {
340 
341     WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
342     Locale locale = context.getParentAppRequestContext().getLocale();
343     return getTimesSelectBoxOptions(labelFormat, valueFormat, timeInteval, locale);
344   }
345 
346   public static List<SelectItemOption<String>> getTimesSelectBoxOptions(String labelFormat, String valueFormat, long timeInteval, Locale locale) {
347     List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>();
348     options.add(new SelectItemOption<String>(getResourceBundle("UICreateEvent.label."+ALL_DAY,"All Day"), ALL_DAY));
349     Calendar cal = Calendar.getInstance(DateUtils.getTimeZone("")); // get a GMT calendar
350     cal.set(Calendar.HOUR_OF_DAY, 0);
351     cal.set(Calendar.MINUTE, 0);
352     cal.set(Calendar.MILLISECOND, 0);
353 
354     DateFormat dfLabel = new SimpleDateFormat(labelFormat, locale);
355     dfLabel.setCalendar(cal);
356     DateFormat dfValue = new SimpleDateFormat(valueFormat, locale);
357     dfValue.setCalendar(cal);
358 
359     int day = cal.get(Calendar.DAY_OF_MONTH);
360     while (day == cal.get(Calendar.DAY_OF_MONTH)) {
361       options.add(new SelectItemOption<String>(dfLabel.format(cal.getTime()), dfValue.format(cal.getTime())));
362       cal.add(java.util.Calendar.MINUTE, (int) timeInteval);
363     }
364     cal.set(Calendar.DAY_OF_MONTH, day);
365     cal.set(Calendar.HOUR_OF_DAY, 23);
366     cal.set(Calendar.MINUTE, 59);
367     cal.set(Calendar.MILLISECOND, 59);
368     options.add(new SelectItemOption<String>(dfLabel.format(cal.getTime()), dfValue.format(cal.getTime())));
369     return options;
370   }
371 
372   public static List<SelectItem> getCalendarOption() throws Exception {
373     List<SelectItem> options = new ArrayList<SelectItem>();
374     CalendarService calendarService = getCalendarService();
375     String username = getCurrentUser();
376     Map<String, String> hash = new HashMap<String, String>();
377     // private calendars group
378     SelectOptionGroup privGrp = new SelectOptionGroup(PRIVATE_CALENDARS);
379     List<org.exoplatform.calendar.service.Calendar> calendars = calendarService.getUserCalendars(username, true);
380     String defaultCalendarId = getCalendarService().getDefaultCalendarId();
381     for (org.exoplatform.calendar.service.Calendar c : calendars) {
382       if (c.getId().equals(Utils.getDefaultCalendarId(username)) && c.getName().equals(getCalendarService().getDefaultCalendarName())) {
383         String newName = getResourceBundle("UICreateEvent.label." + defaultCalendarId, defaultCalendarId);
384         c.setName(newName);
385       }
386       if (!hash.containsKey(c.getId())) {
387         hash.put(c.getId(), "");
388         privGrp.addOption(new SelectOption(c.getName(), PRIVATE_TYPE + COLON + c.getId()));
389       }
390     }
391     if (privGrp.getOptions().size() > 0) options.add(privGrp);
392     // shared calendars group
393     GroupCalendarData gcd = calendarService.getSharedCalendars(username, true);
394     if (gcd != null) {
395       SelectOptionGroup sharedGrp = new SelectOptionGroup(SHARED_CALENDARS);
396       for (org.exoplatform.calendar.service.Calendar c : gcd.getCalendars()) {
397         if (canEdit(null, Utils.getEditPerUsers(c), username)) {
398           if (c.getId().equals(Utils.getDefaultCalendarId(c.getCalendarOwner())) && c.getName().equals(getCalendarService().getDefaultCalendarName())) {
399             String newName = getResourceBundle("UICreateEvent.label." + defaultCalendarId, defaultCalendarId);
400             c.setName(newName);
401           }
402           String owner = "";
403           if (c.getCalendarOwner() != null) owner = c.getCalendarOwner() + " - ";
404           if (!hash.containsKey(c.getId())) {
405             hash.put(c.getId(), "");
406             sharedGrp.addOption(new SelectOption(owner + c.getName(), SHARED_TYPE + COLON + c.getId()));
407           }
408         }
409       }
410       if (sharedGrp.getOptions().size() > 0) options.add(sharedGrp);
411     }
412     // public calendars group
413     List<GroupCalendarData> lgcd = calendarService.getGroupCalendars(getUserGroups(username), true, username);
414 
415     if (lgcd != null) {
416       SelectOptionGroup pubGrp = new SelectOptionGroup(PUBLIC_CALENDARS);
417       String[] checkPerms = getCheckPermissionString().split(COMMA);
418       for (GroupCalendarData g : lgcd) {
419         String groupName = g.getName();
420         for (org.exoplatform.calendar.service.Calendar c : g.getCalendars()) {
421           if (hasEditPermission(c.getEditPermission(), checkPerms)) {
422             if (!hash.containsKey(c.getId())) {
423               hash.put(c.getId(), "");
424               pubGrp.addOption(new SelectOption(getGroupCalendarName(groupName.substring(groupName.lastIndexOf("/") + 1),
425                                                                      c.getName()), PUBLIC_TYPE + COLON + c.getId()));
426             }
427           }
428         }
429       }
430       if (pubGrp.getOptions().size() > 0) options.add(pubGrp);
431     }
432     return options;
433   }
434 
435   static public CalendarService getCalendarService() throws Exception {
436     return (CalendarService) PortalContainer.getInstance().getComponentInstance(CalendarService.class);
437   }
438 
439   @SuppressWarnings("unchecked")
440   public static String getCheckPermissionString() throws Exception {
441     Identity identity = ConversationState.getCurrent().getIdentity();
442     StringBuffer sb = new StringBuffer(identity.getUserId());
443     Set<String> groupsId = identity.getGroups();
444     for (String groupId : groupsId) {
445       sb.append(COMMA).append(groupId).append(SLASH_COLON).append(ANY);
446       sb.append(COMMA).append(groupId).append(SLASH_COLON).append(identity.getUserId());
447     }
448     Collection<MembershipEntry> memberships = identity.getMemberships();
449     for (MembershipEntry membership : memberships) {
450       sb.append(COMMA).append(membership.getGroup()).append(SLASH_COLON).append(ANY_OF + membership.getMembershipType());
451     }
452     return sb.toString();
453   }
454 
455   public static boolean hasEditPermission(String[] savePerms, String[] checkPerms) {
456     if (savePerms != null)
457       for (String sp : savePerms) {
458         for (String cp : checkPerms) {
459           if (sp.equals(cp)) {
460             return true;
461           }
462         }
463       }
464     return false;
465   }
466 
467   public static String getResourceBundle(String key, String defaultValue) {
468     WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
469     ResourceBundle res = context.getApplicationResourceBundle();
470     try {
471       return res.getString(key);
472     } catch (MissingResourceException e) {
473       log.warn("Can not find the resource for key: " + key);
474       return defaultValue;
475     }
476   }
477 
478   static public String getCurrentUser() throws Exception {
479     return Util.getPortalRequestContext().getRemoteUser();
480   }
481 
482   public static boolean canEdit(OrganizationService oService, String[] savePerms, String username) throws Exception {
483     String checkPerms = getCheckPermissionString();
484     return hasEditPermission(savePerms, checkPerms.toString().split(COMMA));
485   }
486 
487   public static final String[] getUserGroups(String username) throws Exception {
488     ConversationState conversationState = ConversationState.getCurrent();
489     Identity identity = conversationState.getIdentity();
490     Set<String> objs = identity.getGroups();
491     String[] groups = new String[objs.size()];
492     int i = 0;
493     for (String obj : objs) {
494       groups[i++] = obj;
495     }
496     return groups;
497   }
498 
499   public static String getGroupCalendarName(String groupName, String calendarName) {
500     return calendarName + Utils.SPACE + OPEN_PARENTHESIS + groupName + CLOSE_PARENTHESIS;
501   }
502 
503   private String getEventSummary() {
504     return getUIStringInput(TITLE).getValue();
505   }
506 
507   private String getEventCalendar() {
508     String values = getUIFormSelectBoxGroup(CALENDAR).getValue();
509     if (values != null && values.trim().length() > 0 && values.split(COLON).length > 0) {
510       calType_ = values.split(COLON)[0];
511       return values.split(COLON)[1];
512     }
513     return null;
514 
515   }
516 
517   public UIFormSelectBoxWithGroups getUIFormSelectBoxGroup(String id) {
518     return findComponentById(id);
519   }
520 }