Exemplo n.º 1
1
  public static List<org.exoplatform.calendar.service.Calendar> getAllOfCalendars(String username)
      throws Exception {
    List<org.exoplatform.calendar.service.Calendar> calendars =
        new ArrayList<org.exoplatform.calendar.service.Calendar>();
    CalendarService calendarService = getCalendarService();
    /*---- get private calendars ----*/
    List<GroupCalendarData> groupCalendars;
    for (org.exoplatform.calendar.service.Calendar calendar :
        calendarService.getUserCalendars(username, true)) {
      calendars.add(calendar);
    }

    /*---- get public calendars ----*/
    String[] groups = CalendarUtils.getUserGroups(username);
    groupCalendars =
        calendarService.getGroupCalendars(groups, true, CalendarUtils.getCurrentUser());
    Map<String, org.exoplatform.calendar.service.Calendar> mapCal =
        new HashMap<String, org.exoplatform.calendar.service.Calendar>();
    for (GroupCalendarData group : groupCalendars) {
      for (org.exoplatform.calendar.service.Calendar cal : group.getCalendars()) {
        mapCal.put(cal.getId(), cal);
      }
    }
    calendars.addAll(mapCal.values());

    /*---- get shared calendars ----*/
    GroupCalendarData groupCalendar = calendarService.getSharedCalendars(username, true);
    if (groupCalendar != null) {
      for (org.exoplatform.calendar.service.Calendar calendar : groupCalendar.getCalendars()) {
        calendars.add(calendar);
      }
    }
    return calendars;
  }
Exemplo n.º 2
1
 public static List<org.exoplatform.calendar.service.Calendar> getAllOfCurrentUserCalendars()
     throws Exception {
   List<org.exoplatform.calendar.service.Calendar> list =
       new ArrayList<org.exoplatform.calendar.service.Calendar>();
   CalendarService calendarService = getCalendarService();
   String username = getCurrentUser();
   List<org.exoplatform.calendar.service.Calendar> calendars =
       calendarService.getUserCalendars(username, true);
   for (org.exoplatform.calendar.service.Calendar c : calendars) {
     list.add(c);
   }
   GroupCalendarData gcd = calendarService.getSharedCalendars(username, true);
   if (gcd != null) {
     for (org.exoplatform.calendar.service.Calendar c : gcd.getCalendars()) {
       if (Utils.hasPermission(Utils.getEditPerUsers(c))) {
         list.add(c);
       }
     }
   }
   List<GroupCalendarData> lgcd =
       calendarService.getGroupCalendars(CalendarUtils.getUserGroups(username), true, username);
   if (lgcd != null) {
     for (GroupCalendarData g : lgcd) {
       for (org.exoplatform.calendar.service.Calendar c : g.getCalendars()) {
         if (Utils.hasPermission(c.getEditPermission())) {
           list.add(c);
         }
       }
     }
   }
   return list;
 }
Exemplo n.º 3
0
  @Override
  public List<org.exoplatform.calendar.model.Calendar> findCalendars(CalendarQuery query) {
    List<org.exoplatform.calendar.model.Calendar> calendars =
        new LinkedList<org.exoplatform.calendar.model.Calendar>();
    List<String> excludes = Collections.emptyList();
    String[] excludesId = query.getExclusions();
    if (excludesId != null) {
      excludes = Arrays.asList(excludesId);
    }

    try {
      Identity identity = query.getIdentity();
      List<Calendar> cals = dataStorage.getUserCalendars(identity.getUserId(), true);
      if (cals != null && cals.size() > 0) {
        for (Calendar c : cals) {
          if (!excludes.contains(c.getId())) {
            calendars.add(c);
          }
        }
      }

      GroupCalendarData data = dataStorage.getSharedCalendars(identity.getUserId(), true);
      if (data != null && data.getCalendars().size() > 0) {
        for (Calendar c : data.getCalendars()) {
          if (!excludes.contains(c.getId())) {
            calendars.add(c);
          }
        }
      }

      List<GroupCalendarData> datas =
          dataStorage.getGroupCalendars(
              identity.getGroups().toArray(new String[0]), true, identity.getUserId());
      if (datas != null && datas.size() > 0) {
        for (GroupCalendarData d : datas) {
          for (Calendar c : d.getCalendars()) {
            if (!excludes.contains(c.getId())) {
              calendars.add(c);
            }
          }
        }
      }

      for (org.exoplatform.calendar.model.Calendar cal : calendars) {
        cal.setDS(JCRStorage.JCR_STORAGE);
      }

      return calendars;
    } catch (Exception ex) {
      LOG.error(ex);
    }
    return null;
  }
Exemplo n.º 4
0
 public static org.exoplatform.calendar.service.Calendar getCalendar(
     String calType, String calendarId) throws Exception {
   CalendarService calService = CalendarUtils.getCalendarService();
   String currentUser = CalendarUtils.getCurrentUser();
   org.exoplatform.calendar.service.Calendar calendar = null;
   if (CalendarUtils.PRIVATE_TYPE.equals(calType)) {
     calendar = calService.getUserCalendar(currentUser, calendarId);
   } else if (CalendarUtils.SHARED_TYPE.equals(calType)) {
     GroupCalendarData gCalendarData = calService.getSharedCalendars(currentUser, true);
     if (gCalendarData != null) calendar = gCalendarData.getCalendarById(calendarId);
   } else if (CalendarUtils.PUBLIC_TYPE.equals(calType)) {
     calendar = calService.getGroupCalendar(calendarId);
   }
   return calendar;
 }
Exemplo n.º 5
0
  /**
   * 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;
  }