コード例 #1
0
  @RequestMapping(value = "/listEvents", method = RequestMethod.GET)
  public String listEvents(
      HttpServletRequest request,
      Model uiModel,
      @RequestParam(required = true) String date,
      @RequestParam(required = true) String beginDate,
      @RequestParam(required = true) String endDate) {
    User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    Calendar selectedDate = Calendar.getInstance();
    Calendar beginCalendar = Calendar.getInstance();
    Calendar endCalendar = Calendar.getInstance();
    try {
      if (date != null) {
        selectedDate.setTime(sdf.parse(date));
      }
      if (beginDate != null) {
        beginCalendar.setTime(sdf.parse(beginDate));
      }
      if (endDate != null) {
        endCalendar.setTime(sdf.parse(endDate));
      }
    } catch (ParseException e) {
      return list(request, uiModel, date);
    }
    try {
      Filter filter = (Filter) request.getSession().getAttribute("calendar.event.filterId");
      ListViewEvents listViewEvents =
          calendarEventOAuthService.retrieveViewEventsList(
              user.getUserId(),
              selectedDate.getTime(),
              beginCalendar.getTime(),
              endCalendar.getTime(),
              filter != null ? filter.getFilterId() : null);

      Calendar currentEndDate = (Calendar) endCalendar.clone();
      Calendar previousDate = (Calendar) beginCalendar.clone();
      previousDate.add(Calendar.DATE, -listViewEvents.getAppData().getListViewFutureDaysLimit());
      endCalendar.add(Calendar.DATE, listViewEvents.getAppData().getListViewFutureDaysLimit());

      SimpleDateFormat my = new SimpleDateFormat("yyyyMM");
      uiModel.addAttribute("selectedDate", sdf.format(selectedDate.getTime()));
      uiModel.addAttribute("monthSelectedDate", my.format(selectedDate.getTime()));
      uiModel.addAttribute("beginDate", sdf.format(beginCalendar.getTime()));
      uiModel.addAttribute("endDate", sdf.format(endCalendar.getTime()));
      uiModel.addAttribute("currentEndDate", sdf.format(currentEndDate.getTime()));
      uiModel.addAttribute("previousDate", sdf.format(previousDate.getTime()));
      uiModel.addAttribute("days", listViewEvents.getAppData().getListViewFutureDaysLimit());
      uiModel.addAttribute("viewData", listViewEvents.getViewData());
      uiModel.addAttribute("appData", listViewEvents.getAppData());
      uiModel.addAttribute("events", listViewEvents.getEvents());
      uiModel.addAttribute("filter", filter);
    } catch (PageLevelException pageLevelException) {
      uiModel.addAttribute("message", pageLevelException.getMessage());
      return "calendar/message";
    }
    return "calendar/list";
  }
コード例 #2
0
 @RequestMapping(value = "/selectFilter", method = RequestMethod.POST)
 public String selectFilter(
     HttpServletRequest request, Model uiModel, @ModelAttribute("filter") Filter filter) {
   User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
   try {
     if (filter.getFilterId() != null && !"".equals(filter.getFilterId().trim())) {
       Filter filterFound =
           calendarEventOAuthService.retrieveFilter(user.getUserId(), filter.getFilterId());
       request.getSession().setAttribute("calendar.event.filterId", filterFound);
     }
   } catch (PageLevelException pageLevelException) {
     uiModel.addAttribute("message", pageLevelException.getMessage());
     return "calendar/message";
   }
   return "redirect:/calendar/options";
 }
コード例 #3
0
  @RequestMapping(value = "/month", method = RequestMethod.GET)
  public String month(
      HttpServletRequest request, Model uiModel, @RequestParam(required = false) String date) {
    User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    SimpleDateFormat my = new SimpleDateFormat("yyyyMM");
    Calendar selectedDate = Calendar.getInstance();
    try {
      if (date != null) {
        selectedDate.setTime(my.parse(date));
      }
    } catch (ParseException e) {

    }
    try {
      Filter filter = (Filter) request.getSession().getAttribute("calendar.event.filterId");
      MonthViewEvents monthEvents =
          calendarEventOAuthService.retrieveMonthEvents(
              user.getUserId(),
              selectedDate.getTime(),
              filter != null ? filter.getFilterId() : null);
      uiModel.addAttribute("viewData", monthEvents.getViewData());
      uiModel.addAttribute("appData", monthEvents.getAppData());

      int days = selectedDate.getActualMaximum(Calendar.DATE);

      Calendar startDate = (Calendar) selectedDate.clone();
      startDate.set(Calendar.DATE, selectedDate.getActualMinimum(Calendar.DATE));
      days += startDate.get(Calendar.DAY_OF_WEEK) - 1;

      Calendar endDate = (Calendar) selectedDate.clone();
      endDate.set(Calendar.DATE, selectedDate.getActualMaximum(Calendar.DATE));
      days += 7 - endDate.get(Calendar.DAY_OF_WEEK);

      startDate.set(Calendar.DAY_OF_WEEK, 1);
      Map<String, MobileDayOfMonth> daysInMonth = new LinkedHashMap<String, MobileDayOfMonth>();

      uiModel.addAttribute("selectedDate", sdf.format(selectedDate.getTime()));
      for (int i = 0; i < days; i++) {
        MobileDayOfMonth mobileDayOfMonth = new MobileDayOfMonth(startDate.get(Calendar.DATE));
        mobileDayOfMonth.setCurrentMonth(
            startDate.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH));
        if (!mobileDayOfMonth.isCurrentMonth()) {
          mobileDayOfMonth.setBeforeCurrentMonth(
              startDate.get(Calendar.MONTH) < selectedDate.get(Calendar.MONTH));
        }
        mobileDayOfMonth.setMonthYear(my.format(startDate.getTime()));
        mobileDayOfMonth.setDayOfWeek(startDate.get(Calendar.DAY_OF_WEEK));
        daysInMonth.put(sdf.format(startDate.getTime()), mobileDayOfMonth);
        startDate.add(Calendar.DATE, 1);
      }

      for (Iterator iterator = monthEvents.getEvents().entrySet().iterator();
          iterator.hasNext(); ) {
        Map.Entry<String, List<CalendarViewEvent>> entry =
            (Map.Entry<String, List<CalendarViewEvent>>) iterator.next();
        MobileDayOfMonth dayInMonth = daysInMonth.get(entry.getKey());
        dayInMonth.setHasEvents(true);
        dayInMonth.setEvents(entry.getValue());
      }
      uiModel.addAttribute("events", daysInMonth);

      Calendar previousCalendar = (Calendar) selectedDate.clone();
      previousCalendar.set(Calendar.DATE, 1);
      previousCalendar.getTime();
      previousCalendar.add(Calendar.MONTH, -1);

      Calendar nextCalendar = (Calendar) selectedDate.clone();
      nextCalendar.set(Calendar.DATE, 1);
      nextCalendar.getTime();
      nextCalendar.add(Calendar.MONTH, 1);

      uiModel.addAttribute("previousMonth", my.format(previousCalendar.getTime()));
      uiModel.addAttribute("nextMonth", my.format(nextCalendar.getTime()));
      uiModel.addAttribute("monthYear", my.format(selectedDate.getTime()));
      uiModel.addAttribute("today", sdf.format(new Date()));
      uiModel.addAttribute("filter", filter);
    } catch (PageLevelException pageLevelException) {
      uiModel.addAttribute("message", pageLevelException.getMessage());
      return "calendar/message";
    }
    return "calendar/month";
  }