/** * get all users calendars (private, public, shared) * * @return * @throws Exception */ public static List<SelectItem> getCalendarOption() throws Exception { List<SelectItem> options = new ArrayList<SelectItem>(); CalendarService calendarService = getCalendarService(); String username = getCurrentUser(); /* * hash map to check existence of a calendar in the list. */ Map<String, String> hash = new HashMap<String, String>(); /* * Modified by Philippe ([email protected]) * Uses SelectItemOptionGroup to differienciate private, shared and public groups */ // private calendars group SelectOptionGroup privGrp = new SelectOptionGroup(CalendarUtils.PRIVATE_CALENDARS); List<org.exoplatform.calendar.service.Calendar> calendars = calendarService.getUserCalendars(username, true); for (org.exoplatform.calendar.service.Calendar c : calendars) { if (!hash.containsKey(c.getId())) { hash.put(c.getId(), ""); privGrp.addOption( new SelectOption( c.getName(), CalendarUtils.PRIVATE_TYPE + CalendarUtils.COLON + c.getId())); } } if (privGrp.getOptions().size() > 0) options.add(privGrp); // shared calendars group GroupCalendarData gcd = calendarService.getSharedCalendars(username, true); if (gcd != null) { SelectOptionGroup sharedGrp = new SelectOptionGroup(CalendarUtils.SHARED_CALENDARS); for (org.exoplatform.calendar.service.Calendar c : gcd.getCalendars()) { if (Utils.hasPermission(Utils.getEditPerUsers(c))) { if (!hash.containsKey(c.getId())) { hash.put(c.getId(), ""); sharedGrp.addOption( new SelectOption( c.getName(), CalendarUtils.SHARED_TYPE + CalendarUtils.COLON + c.getId())); } } } if (sharedGrp.getOptions().size() > 0) options.add(sharedGrp); } // public calendars group List<GroupCalendarData> lgcd = calendarService.getGroupCalendars(CalendarUtils.getUserGroups(username), true, username); if (lgcd != null) { SelectOptionGroup pubGrp = new SelectOptionGroup(CalendarUtils.PUBLIC_CALENDARS); for (GroupCalendarData g : lgcd) { for (org.exoplatform.calendar.service.Calendar c : g.getCalendars()) { if (Utils.hasPermission(c.getEditPermission())) { if (!hash.containsKey(c.getId())) { hash.put(c.getId(), ""); pubGrp.addOption( new SelectOption( c.getName(), CalendarUtils.PUBLIC_TYPE + CalendarUtils.COLON + c.getId())); } } } } if (pubGrp.getOptions().size() > 0) options.add(pubGrp); } return options; }