예제 #1
0
  /**
   * Retrieves the event object from storage
   *
   * @param mapping
   * @param form
   * @param config
   * @param req
   * @param res
   * @param user
   * @throws DotSecurityException
   * @throws DotDataException
   * @throws DotSecurityException
   * @throws DotDataException
   * @throws ParseException
   * @throws NumberFormatException
   */
  private void retrieveEvent(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig config,
      ActionRequest req,
      ActionResponse res,
      String command,
      User user)
      throws DotDataException, DotSecurityException, ParseException {
    Contentlet contentlet = (Contentlet) req.getAttribute(WebKeys.CONTENTLET_EDIT);
    if (InodeUtils.isSet(contentlet.getInode())) {
      Event ev = eventAPI.findbyInode(contentlet.getInode(), user, false);
      req.setAttribute(WebKeys.EVENT_EDIT, ev);

    } else {
      EventForm eventForm = (EventForm) form;
      eventForm.setRecurrenceEndsDate(new Date());
      eventForm.setRecurrenceOccurs("never");
      eventForm.setRecurrenceDayOfMonth("");
      eventForm.setNoEndDate(false);
      eventForm.setRecurrenceInterval(1);
      eventForm.setRecurrenceIntervalDaily(1);
      eventForm.setRecurrenceIntervalWeekly(1);
      eventForm.setRecurrenceIntervalMonthly(1);
      eventForm.setRecurrenceIntervalYearly(1);
      String[] daysOfWeekRecurrence = {
        String.valueOf(Calendar.MONDAY),
        String.valueOf(Calendar.TUESDAY),
        String.valueOf(Calendar.WEDNESDAY),
        String.valueOf(Calendar.THURSDAY),
        String.valueOf(Calendar.FRIDAY),
        String.valueOf(Calendar.SATURDAY),
        String.valueOf(Calendar.SUNDAY)
      };
      eventForm.setRecurrenceDaysOfWeek(daysOfWeekRecurrence);
      eventForm.setRecurrenceDayOfWeek(1);
      eventForm.setRecurrenceMonthOfYear(1);
      eventForm.setRecurrenceWeekOfMonth(1);
      eventForm.setSpecificDayOfMonthRecY("1");
      eventForm.setSpecificMonthOfYearRecY("1");
      eventForm.setSpecificDate(false);
      req.setAttribute(WebKeys.EVENT_EDIT, new Event());
    }
  }
예제 #2
0
  /**
   * Retrieves the event object from storage
   *
   * @param mapping
   * @param form
   * @param config
   * @param req
   * @param res
   * @param user
   * @throws DotSecurityException
   * @throws DotDataException
   * @throws NumberFormatException
   */
  private void editEvent(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig config,
      ActionRequest req,
      ActionResponse res,
      User user) {
    EventForm eventForm = (EventForm) form;
    Event event = (Event) req.getAttribute(WebKeys.EVENT_EDIT);
    if (!UtilMethods.isSet(event.getInode())) return;
    if (event.getRecurs()) {
      eventForm.setRecurrenceStartsDate(event.getRecurrenceStart());
      eventForm.setRecurrenceDayOfMonth(String.valueOf(event.getRecurrenceDayOfMonth()));
      eventForm.setRecurrenceDayOfWeek(event.getRecurrenceDayOfWeek());

      if (UtilMethods.isSet(event.getRecurrenceEnd())) {
        eventForm.setRecurrenceEndsDate(event.getRecurrenceEnd());
        eventForm.setNoEndDate(false);
      } else {
        eventForm.setNoEndDate(true);
      }
      String daysOfWeek = event.getRecurrenceDaysOfWeek();
      if (daysOfWeek == null) daysOfWeek = "";
      List<String> daysList = new ArrayList<String>();
      for (String day : daysOfWeek.split(",")) {
        if (UtilMethods.isSet(day)) {
          daysList.add(day);
        }
      }
      String[] daysListArr = new String[daysList.size()];
      for (int i = 0; i < daysList.size(); i++) daysListArr[i] = daysList.get(i);
      eventForm.setRecurrenceDaysOfWeek(daysListArr);
      eventForm.setRecurrenceInterval((int) event.getRecurrenceInterval());
      if (event.getOccursEnum() == Event.Occurrency.DAILY) {
        eventForm.setRecurrenceOccurs("daily");
      } else if (event.getOccursEnum() == Event.Occurrency.WEEKLY) {
        eventForm.setRecurrenceOccurs("weekly");
      } else if (event.getOccursEnum() == Event.Occurrency.MONTHLY) {
        eventForm.setRecurrenceOccurs("monthly");
        if (UtilMethods.isSet(event.getRecurrenceDayOfMonth())
            && event.getRecurrenceDayOfMonth() > 0) {
          eventForm.setRecurrenceDayOfMonth(String.valueOf(event.getRecurrenceDayOfMonth()));
          eventForm.setSpecificDate(true);
        } else {
          eventForm.setSpecificDate(false);
          eventForm.setRecurrenceMonthOfYear(event.getRecurrenceMonthOfYear());
          eventForm.setRecurrenceWeekOfMonth(event.getRecurrenceWeekOfMonth());
          eventForm.setRecurrenceDayOfMonth("");
        }
      } else if (event.getOccursEnum() == Event.Occurrency.ANNUALLY) {
        if (UtilMethods.isSet(event.getRecurrenceDayOfMonth())
            && event.getRecurrenceDayOfMonth() > 0) {
          eventForm.setSpecificDayOfMonthRecY(String.valueOf(event.getRecurrenceDayOfMonth()));
          eventForm.setSpecificMonthOfYearRecY(String.valueOf(event.getRecurrenceMonthOfYear()));
          eventForm.setSpecificDate(true);
        } else {
          eventForm.setSpecificDate(false);
          eventForm.setSpecificDayOfMonthRecY("");
          eventForm.setSpecificMonthOfYearRecY("");
          eventForm.setRecurrenceMonthOfYear(event.getRecurrenceMonthOfYear());
          eventForm.setRecurrenceWeekOfMonth(event.getRecurrenceWeekOfMonth());
        }
        eventForm.setRecurrenceOccurs("annually");
      }

    } else {
      eventForm.setRecurrenceStartsDate(new Date());
      eventForm.setRecurrenceEndsDate(new Date());
      eventForm.setNoEndDate(false);
      eventForm.setRecurrenceDayOfMonth("");
      GregorianCalendar cal = new GregorianCalendar();
      cal.setTime(new Date());
      eventForm.setRecurrenceWeekOfMonth(cal.get(Calendar.WEEK_OF_MONTH));
      eventForm.setRecurrenceDayOfWeek(cal.get(Calendar.DAY_OF_WEEK));
      eventForm.setRecurrenceMonthOfYear(cal.get(Calendar.MONTH) + 1);

      String[] daysOfWeekRecurrence = {
        String.valueOf(Calendar.MONDAY),
        String.valueOf(Calendar.TUESDAY),
        String.valueOf(Calendar.WEDNESDAY),
        String.valueOf(Calendar.THURSDAY),
        String.valueOf(Calendar.FRIDAY),
        String.valueOf(Calendar.SATURDAY),
        String.valueOf(Calendar.SUNDAY)
      };

      eventForm.setRecurrenceDaysOfWeek(daysOfWeekRecurrence);
      eventForm.setRecurrenceInterval(1);
      eventForm.setRecurrenceOccurs("never");
    }
  }