/**
  * delete the event activity
  *
  * @param event
  * @param calendarId
  * @param eventType
  */
 private void deleteActivity(CalendarEvent event, String calendarId, String eventType) {
   try {
     Class.forName("org.exoplatform.social.core.space.spi.SpaceService");
   } catch (ClassNotFoundException e) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("eXo Social components not found!", e);
     }
     return;
   }
   if (calendarId == null
       || calendarId.indexOf(CalendarDataInitialize.SPACE_CALENDAR_ID_SUFFIX) < 0) {
     return;
   }
   try {
     ActivityManager activityM =
         (ActivityManager)
             PortalContainer.getInstance().getComponentInstanceOfType(ActivityManager.class);
     SpaceService spaceService =
         (SpaceService)
             PortalContainer.getInstance().getComponentInstanceOfType(SpaceService.class);
     String spaceGroupId = Utils.getSpaceGroupIdFromCalendarId(calendarId);
     Space space = spaceService.getSpaceByGroupId(spaceGroupId);
     if (space != null && event.getActivityId() != null) {
       activityM.deleteActivity(event.getActivityId());
     }
   } catch (ExoSocialException e) {
     if (LOG.isDebugEnabled())
       LOG.error("Can not delete Activity for space when event deleted ", e);
   }
 }
Exemplo n.º 2
1
 public static boolean isAllDayEvent(CalendarEvent eventCalendar) {
   Calendar cal1 = getInstanceOfCurrentCalendar();
   Calendar cal2 = getInstanceOfCurrentCalendar();
   cal1.setTime(eventCalendar.getFromDateTime());
   cal2.setTime(eventCalendar.getToDateTime());
   return (cal1.get(Calendar.HOUR_OF_DAY) == 0
       && cal1.get(Calendar.MINUTE) == 0
       && cal2.get(Calendar.HOUR_OF_DAY) == cal2.getActualMaximum(Calendar.HOUR_OF_DAY)
       && cal2.get(Calendar.MINUTE) == cal2.getActualMaximum(Calendar.MINUTE));
 }
Exemplo n.º 3
1
 @Override
 public LinkedHashMap<String, CalendarEvent> getDataMap() {
   LinkedHashMap<String, CalendarEvent> dataMap = new LinkedHashMap<String, CalendarEvent>();
   for (CalendarEvent ce : allDayEvent) {
     dataMap.put(ce.getId(), ce);
   }
   for (String key : eventData_.keySet()) {
     for (CalendarEvent ce : eventData_.get(key)) {
       dataMap.put(ce.getId(), ce);
     }
   }
   return dataMap;
 }
 /**
  * Make url for the event of the calendar application. Format of the url is:
  *
  * <ul>
  *   <li>/[portal]/[space]/[calendar]/[username]/invitation/detail/[event id]/[calendar type]
  * </ul>
  *
  * The format is used to utilize the invitation email feature implemented before. <br>
  * <strong>[NOTE]</strong> Keep in mind that this function calls {@link PortalRequestContext}
  * which is in webui layer while this function is usually invoked in the service layer. Need to be
  * improved in the future for ensuring the system design convention.
  *
  * @param event have to be not null
  * @return empty string if the process is failed.
  */
 private String makeEventLink(CalendarEvent event) {
   StringBuffer sb = new StringBuffer("");
   PortalRequestContext requestContext = Util.getPortalRequestContext();
   sb.append(requestContext.getPortalURI())
       .append(requestContext.getNodePath())
       .append(INVITATION_DETAIL)
       .append(ConversationState.getCurrent().getIdentity().getUserId())
       .append("/")
       .append(event.getId())
       .append("/")
       .append(event.getCalType());
   return sb.toString();
 }
  /**
   * publish a new event activity
   *
   * @param event
   * @param calendarId
   * @param eventType
   */
  private void publishActivity(CalendarEvent event, String calendarId, String eventType) {
    try {
      Class.forName("org.exoplatform.social.core.space.spi.SpaceService");
    } catch (ClassNotFoundException e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("eXo Social components not found!", e);
      }
      return;
    }
    if (calendarId == null
        || calendarId.indexOf(CalendarDataInitialize.SPACE_CALENDAR_ID_SUFFIX) < 0) {
      return;
    }
    try {
      IdentityManager identityM =
          (IdentityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(IdentityManager.class);
      ActivityManager activityM =
          (ActivityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(ActivityManager.class);
      SpaceService spaceService =
          (SpaceService)
              PortalContainer.getInstance().getComponentInstanceOfType(SpaceService.class);

      String spaceGroupId = Utils.getSpaceGroupIdFromCalendarId(calendarId);
      Space space = spaceService.getSpaceByGroupId(spaceGroupId);
      if (space != null) {
        String userId = ConversationState.getCurrent().getIdentity().getUserId();
        Identity spaceIdentity =
            identityM.getOrCreateIdentity(SpaceIdentityProvider.NAME, space.getPrettyName(), false);
        Identity userIdentity =
            identityM.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId, false);
        ExoSocialActivity activity = new ExoSocialActivityImpl();
        activity.setUserId(userIdentity.getId());
        activity.setTitle(event.getSummary());
        activity.setBody(event.getDescription());
        activity.setType("cs-calendar:spaces");
        activity.setTemplateParams(makeActivityParams(event, calendarId, eventType));
        activityM.saveActivityNoReturn(spaceIdentity, activity);
        event.setActivityId(activity.getId());
      }
    } catch (ExoSocialException e) {
      if (LOG.isDebugEnabled()) LOG.error("Can not record Activity for space when event added ", e);
    }
  }
 /**
  * publish new event activity
  *
  * @param newEvent
  * @param calendarId
  */
 public void updatePublicEvent(CalendarEvent newEvent, String calendarId) {
   String eventType =
       newEvent.getEventType().equalsIgnoreCase(CalendarEvent.TYPE_EVENT)
           ? EVENT_ADDED
           : TASK_ADDED;
   // Map<String, String> messagesParams = buildParams(oldEvent, newEvent);
   // updateToActivity(newEvent, calendarId, eventType, messagesParams);
   publishActivity(newEvent, calendarId, eventType);
 }
 /**
  * update existing event activity by creating a new comment in activity
  *
  * @param oldEvent
  * @param newEvent
  * @param calendarId
  */
 public void updatePublicEvent(CalendarEvent oldEvent, CalendarEvent newEvent, String calendarId) {
   LOG.info("updatePublicEvent");
   String eventType =
       newEvent.getEventType().equalsIgnoreCase(CalendarEvent.TYPE_EVENT)
           ? EVENT_ADDED
           : TASK_ADDED;
   Map<String, String> messagesParams = buildParams(oldEvent, newEvent);
   if (messagesParams.size() > 0) {
     updateToActivity(newEvent, calendarId, eventType, messagesParams);
   }
 }
 private boolean isAllDayEvent(CalendarEvent eventCalendar) {
   try {
     TimeZone tz = getUserTimeZone();
     Calendar cal1 = new GregorianCalendar(tz);
     Calendar cal2 = new GregorianCalendar(tz);
     cal1.setLenient(false);
     cal1.setTime(eventCalendar.getFromDateTime());
     // cal1.setTimeZone(tz);
     cal2.setLenient(false);
     cal2.setTime(eventCalendar.getToDateTime());
     // cal2.setTimeZone(tz);
     return (cal1.get(Calendar.HOUR_OF_DAY) == 0
         && cal1.get(Calendar.MINUTE) == 0
         && cal2.get(Calendar.HOUR_OF_DAY) == cal2.getActualMaximum(Calendar.HOUR_OF_DAY)
         && cal2.get(Calendar.MINUTE) == cal2.getActualMaximum(Calendar.MINUTE));
   } catch (Exception e) {
     if (LOG.isDebugEnabled()) LOG.error("Can not check all day event when event updated ", e);
   }
   return false;
 }
 private Map<String, String> makeActivityParams(
     CalendarEvent event, String calendarId, String eventType) {
   Map<String, String> params = new HashMap<String, String>();
   params.put(EVENT_TYPE_KEY, eventType);
   params.put(EVENT_ID_KEY, event.getId());
   params.put(CALENDAR_ID_KEY, calendarId);
   params.put(EVENT_SUMMARY_KEY, event.getSummary());
   params.put(EVENT_LOCALE_KEY, event.getLocation() != null ? event.getLocation() : "");
   params.put(EVENT_DESCRIPTION_KEY, event.getDescription() != null ? event.getDescription() : "");
   params.put(EVENT_STARTTIME_KEY, String.valueOf(event.getFromDateTime().getTime()));
   params.put(EVENT_ENDTIME_KEY, String.valueOf(event.getToDateTime().getTime()));
   params.put(EVENT_LINK_KEY, makeEventLink(event));
   return params;
 }
Exemplo n.º 10
0
  private CalendarEvent newCalendarEvent(
      String calendarId, String CalType, String type, boolean isPublic) {
    CalendarEvent categoryEvent = new CalendarEvent();
    categoryEvent.setCalendarId(calendarId);
    categoryEvent.setCalType(CalType);
    categoryEvent.setDescription(randomWords(20));
    if (!isPublic) {
      EventCategory eventCategory = randomEventCategory();
      categoryEvent.setEventCategoryId(eventCategory.getId());
      categoryEvent.setEventCategoryName(eventCategory.getName());
    }
    categoryEvent.setEventState(randomState());
    categoryEvent.setEventType(type);
    long time = randomDateTime(rand.nextInt(365), 0);
    categoryEvent.setFromDateTime(getTime(time));
    time = randomDateTime(rand.nextInt(5), time);
    categoryEvent.setToDateTime(getTime(time));

    categoryEvent.setLocation(DEFAULT_LOCATION);
    categoryEvent.setMessage(randomWords(30));

    categoryEvent.setInvitation(new String[] {EMPTY});
    categoryEvent.setParticipant(new String[] {currentUser});
    categoryEvent.setParticipantStatus(new String[] {currentUser + ":"});
    categoryEvent.setPriority(CalendarEvent.PRIORITY[rand.nextInt(CalendarEvent.PRIORITY.length)]);
    categoryEvent.setSendOption(CalendarSetting.ACTION_NEVER);
    categoryEvent.setStatus(EMPTY);
    categoryEvent.setTaskDelegator(EMPTY);
    categoryEvent.setRepeatType(
        CalendarEvent.REPEATTYPES[rand.nextInt(CalendarEvent.REPEATTYPES.length)]);

    categoryEvent.setSummary(calRandomWords(5));
    categoryEvent.setPrivate(!isPublic);
    return categoryEvent;
  }
Exemplo n.º 11
0
 @Override
 public void execute(Event<UIWeekView> event) throws Exception {
   UIWeekView calendarview = event.getSource();
   String eventId = event.getRequestContext().getRequestParameter(OBJECTID);
   String calendarId = event.getRequestContext().getRequestParameter(eventId + CALENDARID);
   String calType = event.getRequestContext().getRequestParameter(eventId + CALTYPE);
   String startTime = event.getRequestContext().getRequestParameter(eventId + START_TIME);
   String finishTime = event.getRequestContext().getRequestParameter(eventId + FINISH_TIME);
   Boolean isOccur = false;
   if (!Utils.isEmpty(event.getRequestContext().getRequestParameter(eventId + ISOCCUR))) {
     isOccur =
         Boolean.parseBoolean(event.getRequestContext().getRequestParameter(eventId + ISOCCUR));
   }
   String recurId = null;
   if (isOccur) recurId = event.getRequestContext().getRequestParameter(eventId + RECURID);
   try {
     String username = CalendarUtils.getCurrentUser();
     CalendarEvent eventCalendar = null;
     if (isOccur && !Utils.isEmpty(recurId)) {
       eventCalendar = calendarview.getRecurrenceMap().get(eventId).get(recurId);
     } else {
       eventCalendar = calendarview.getDataMap().get(eventId);
     }
     if (eventCalendar != null) {
       CalendarService calendarService = CalendarUtils.getCalendarService();
       Calendar calBegin = calendarview.getInstanceTempCalendar();
       Calendar calEnd = calendarview.getInstanceTempCalendar();
       long unit = 15 * 60 * 1000;
       calBegin.setTimeInMillis((Long.parseLong(startTime) / unit) * unit);
       eventCalendar.setFromDateTime(calBegin.getTime());
       calEnd.setTimeInMillis((Long.parseLong(finishTime) / unit) * unit);
       eventCalendar.setToDateTime(calEnd.getTime());
       if (eventCalendar.getToDateTime().before(eventCalendar.getFromDateTime())) {
         return;
       }
       org.exoplatform.calendar.service.Calendar calendar = null;
       if (CalendarUtils.PRIVATE_TYPE.equals(calType)) {
         calendar = calendarService.getUserCalendar(username, calendarId);
       } else if (CalendarUtils.SHARED_TYPE.equals(calType)) {
         if (calendarService.getSharedCalendars(username, true) != null)
           calendar =
               calendarService.getSharedCalendars(username, true).getCalendarById(calendarId);
       } else if (CalendarUtils.PUBLIC_TYPE.equals(calType)) {
         calendar = calendarService.getGroupCalendar(calendarId);
       }
       if (calendar == null) {
         event
             .getRequestContext()
             .getUIApplication()
             .addMessage(new ApplicationMessage("UICalendars.msg.have-no-calendar", null, 1));
       } else {
         if ((CalendarUtils.SHARED_TYPE.equals(calType)
                 && !CalendarUtils.canEdit(
                     calendarview.getApplicationComponent(OrganizationService.class),
                     Utils.getEditPerUsers(calendar),
                     username))
             || (CalendarUtils.PUBLIC_TYPE.equals(calType)
                 && !CalendarUtils.canEdit(
                     calendarview.getApplicationComponent(OrganizationService.class),
                     calendar.getEditPermission(),
                     username))) {
           event
               .getRequestContext()
               .getUIApplication()
               .addMessage(
                   new ApplicationMessage(
                       "UICalendars.msg.have-no-permission-to-edit-event", null, 1));
           calendarview.refresh();
           event.getRequestContext().addUIComponentToUpdateByAjax(calendarview.getParent());
           return;
         }
         // if it's a 'virtual' occurrence
         if (isOccur && !Utils.isEmpty(recurId)) {
           List<CalendarEvent> listEvent = new ArrayList<CalendarEvent>();
           listEvent.add(eventCalendar);
           calendarService.updateOccurrenceEvent(
               calendarId, calendarId, calType, calType, listEvent, username);
         } else {
           if (calType.equals(CalendarUtils.PRIVATE_TYPE)) {
             calendarService.saveUserEvent(username, calendarId, eventCalendar, false);
           } else if (calType.equals(CalendarUtils.SHARED_TYPE)) {
             calendarService.saveEventToSharedCalendar(
                 username, calendarId, eventCalendar, false);
           } else if (calType.equals(CalendarUtils.PUBLIC_TYPE)) {
             calendarService.savePublicEvent(calendarId, eventCalendar, false);
           }
         }
         calendarview.setLastUpdatedEventId(eventId);
         calendarview.refresh();
         UIMiniCalendar uiMiniCalendar =
             calendarview
                 .getAncestorOfType(UICalendarPortlet.class)
                 .findFirstComponentOfType(UIMiniCalendar.class);
         event.getRequestContext().addUIComponentToUpdateByAjax(uiMiniCalendar);
         event.getRequestContext().addUIComponentToUpdateByAjax(calendarview.getParent());
       }
     }
   } catch (Exception e) {
     if (log.isDebugEnabled()) {
       log.debug("Fail to save the event to the calendar", e);
     }
     return;
   }
 }
Exemplo n.º 12
0
    @Override
    public void execute(Event<UIWeekView> event) throws Exception {

      UIWeekView calendarview = event.getSource();
      UICalendarPortlet uiCalendarPortlet = calendarview.getAncestorOfType(UICalendarPortlet.class);
      String eventId = event.getRequestContext().getRequestParameter(OBJECTID);
      String calendarId = event.getRequestContext().getRequestParameter(eventId + CALENDARID);
      String calType = event.getRequestContext().getRequestParameter(eventId + CALTYPE);
      String startTime = event.getRequestContext().getRequestParameter(eventId + START_TIME);
      String finishTime = event.getRequestContext().getRequestParameter(eventId + FINISH_TIME);
      String currentDate = event.getRequestContext().getRequestParameter(eventId + CURRENT_DATE);

      Boolean isOccur = false;
      if (!Utils.isEmpty(event.getRequestContext().getRequestParameter(eventId + ISOCCUR))) {
        isOccur =
            Boolean.parseBoolean(event.getRequestContext().getRequestParameter(eventId + ISOCCUR));
      }
      String recurId = null;
      if (isOccur) recurId = event.getRequestContext().getRequestParameter(eventId + RECURID);

      String username = CalendarUtils.getCurrentUser();
      CalendarService calendarService = CalendarUtils.getCalendarService();

      CalendarEvent eventCalendar = calendarview.getDataMap().get(eventId);
      if (isOccur && !Utils.isEmpty(recurId)) {
        eventCalendar = calendarview.getRecurrenceMap().get(eventId).get(recurId);
      }

      if (eventCalendar != null) {
        CalendarService calService = CalendarUtils.getCalendarService();
        boolean isMove = false;
        try {
          org.exoplatform.calendar.service.Calendar calendar = null;
          if (eventCalendar.getCalType().equals(CalendarUtils.PRIVATE_TYPE)) {
            calendar = calService.getUserCalendar(username, calendarId);
          } else if (eventCalendar.getCalType().equals(CalendarUtils.SHARED_TYPE)) {
            if (calService.getSharedCalendars(username, true) != null)
              calendar = calService.getSharedCalendars(username, true).getCalendarById(calendarId);
          } else if (eventCalendar.getCalType().equals(CalendarUtils.PUBLIC_TYPE)) {
            calendar = calService.getGroupCalendar(calendarId);
          }
          if (calendar == null) {
            event
                .getRequestContext()
                .getUIApplication()
                .addMessage(new ApplicationMessage("UICalendars.msg.have-no-calendar", null, 1));
          } else {
            Calendar cal = calendarview.getInstanceTempCalendar();
            int hoursBg = (Integer.parseInt(startTime) / 60);
            int minutesBg = (Integer.parseInt(startTime) % 60);
            int hoursEnd = (Integer.parseInt(finishTime) / 60);
            int minutesEnd = (Integer.parseInt(finishTime) % 60);
            try {
              cal.setTimeInMillis(Long.parseLong(currentDate));
              if (hoursBg < cal.getMinimum(Calendar.HOUR_OF_DAY)) {
                hoursBg = 0;
                minutesBg = 0;
              }
              cal.set(Calendar.HOUR_OF_DAY, hoursBg);
              cal.set(Calendar.MINUTE, minutesBg);
              isMove = (eventCalendar.getFromDateTime().getTime() != cal.getTimeInMillis());
              eventCalendar.setFromDateTime(cal.getTime());
              if (hoursEnd >= 24) {
                hoursEnd = 23;
                minutesEnd = 59;
              }
              cal.set(Calendar.HOUR_OF_DAY, hoursEnd);
              cal.set(Calendar.MINUTE, minutesEnd);
              eventCalendar.setToDateTime(cal.getTime());
            } catch (Exception e) {
              if (log.isDebugEnabled()) {
                log.debug("Fail when calculate the time for calendar", e);
              }
              return;
            }
            if (eventCalendar.getToDateTime().before(eventCalendar.getFromDateTime())) {
              return;
            }
            // if it's a 'virtual' occurrence
            if (isOccur && !Utils.isEmpty(recurId)) {
              if (!isMove) {
                UIPopupAction pAction = uiCalendarPortlet.getChild(UIPopupAction.class);
                UIConfirmForm confirmForm = pAction.activate(UIConfirmForm.class, 480);
                confirmForm.setConfirmMessage("update-recurrence-event-confirm-msg");
                confirmForm.setDelete(false);
                confirmForm.setConfig_id(calendarview.getId());
                calendarview.setCurrentOccurrence(eventCalendar);
                event.getRequestContext().addUIComponentToUpdateByAjax(pAction);
              } else {
                calService = CalendarUtils.getCalendarService();
                CalendarEvent originEvent = calService.getRepetitiveEvent(eventCalendar);
                calService.saveOneOccurrenceEvent(originEvent, eventCalendar, username);
              }
              // return;
              // List<CalendarEvent> listEvent = new ArrayList<CalendarEvent>();
              // listEvent.add(eventCalendar);
              // calendarService.updateOccurrenceEvent(calendarId, calendarId, calType, calType,
              // listEvent, username);
            } else {
              if (calType.equals(CalendarUtils.PRIVATE_TYPE)) {
                calendarService.saveUserEvent(username, calendarId, eventCalendar, false);
              } else if (calType.equals(CalendarUtils.SHARED_TYPE)) {
                calendarService.saveEventToSharedCalendar(
                    username, calendarId, eventCalendar, false);
              } else if (calType.equals(CalendarUtils.PUBLIC_TYPE)) {
                calendarService.savePublicEvent(calendarId, eventCalendar, false);
              }
            }
            calendarview.setLastUpdatedEventId(eventId);
            calendarview.refresh();
            UIMiniCalendar uiMiniCalendar =
                uiCalendarPortlet.findFirstComponentOfType(UIMiniCalendar.class);
            event.getRequestContext().addUIComponentToUpdateByAjax(uiMiniCalendar);
            if (isOccur) {
              event.getRequestContext().addUIComponentToUpdateByAjax(calendarview);
            } else {
              JavascriptManager jsManager = event.getRequestContext().getJavascriptManager();
              RequireJS requireJS = jsManager.getRequireJS();
              requireJS.require("PORTLET/calendar/CalendarPortlet", "cal");
              requireJS.addScripts("cal.UIWeekView.setSize();cal.UIWeekView.cleanUp();");
            }
          }
        } catch (PathNotFoundException e) {
          if (log.isDebugEnabled()) {
            log.debug("The calendar is not found", e);
          }
          event
              .getRequestContext()
              .getUIApplication()
              .addMessage(new ApplicationMessage("UICalendars.msg.have-no-calendar", null, 1));
        } catch (Exception ex) {
          if (log.isDebugEnabled()) {
            log.debug("The calendar is not found", ex);
          }
        }
      }
    }
Exemplo n.º 13
0
  /** used in template */
  private String renderEventBoard() throws Exception {
    StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append("\n<div class=\"eventBoard\">");

    Calendar cl = getBeginDateOfWeek();
    int t = 0;
    int numberOfDays = isShowCustomView_ ? 5 : 7;
    String styleWidth = isShowCustomView_ ? "width:19.8%;*width:20%;" : "width:13.8%;*width:14%;";

    while (t++ < numberOfDays) {
      int day = cl.get(Calendar.DATE);
      int month = cl.get(Calendar.MONTH);
      int year = cl.get(Calendar.YEAR);
      String key = keyGen(day, month, year);
      int dayOfWeek = cl.get(Calendar.DAY_OF_WEEK);
      List<CalendarEvent> events = getEventData().get(key);
      if (events != null) {
        for (CalendarEvent event : events) {
          String eventId = event.getId();
          String begin = tf.format(event.getFromDateTime());
          String begindate = dtf.format(event.getFromDateTime());
          String end = tf.format(event.getToDateTime());
          Calendar cal = CalendarUtils.getInstanceTempCalendar();
          cal.setTime(event.getFromDateTime());
          int beginTime = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
          cal.setTime(event.getToDateTime());
          int endTime = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
          String color =
              getColors().get(event.getCalType() + CalendarUtils.COLON + event.getCalendarId());
          String actionLink = event("UpdateEvent", eventId);
          boolean isOccur =
              (event.getRepeatType() != null
                  && !CalendarEvent.RP_NOREPEAT.equals(event.getRepeatType())
                  && (event.getIsExceptionOccurrence() == null
                      || !event.getIsExceptionOccurrence()));
          String recurId = event.getRecurrenceId();
          boolean isEditable;
          if (!event.getCalType().equals(CalendarUtils.PRIVATE_TYPE))
            isEditable = isEventEditable(event);
          else isEditable = true;

          stringBuilder
              .append(
                  "\n<div class=\"eventContainerBorder weekViewEventBoxes "
                      + color
                      + "\" eventindex=\""
                      + dayOfWeek
                      + "\"")
              .append(
                  " style=\"position: absolute;display:none\" eventcat=\""
                      + event.getEventCategoryId()
                      + "\" caltype=\""
                      + event.getCalType()
                      + "\"")
              .append(
                  " eventid=\""
                      + eventId
                      + "\" calid=\""
                      + event.getCalendarId()
                      + "\" actionlink=\""
                      + actionLink
                      + "\" unselectable=\"on\"")
              .append(
                  " startTime=\""
                      + beginTime
                      + "\" endTime=\""
                      + endTime
                      + "\" isOccur=\""
                      + isOccur
                      + "\" recurId=\""
                      + recurId
                      + "\" isEditable=\""
                      + isEditable
                      + "\">");

          if (!eventList.contains(eventId)) {
            eventList.add(eventId);

            stringBuilder
                .append(
                    "\n<input type=\"hidden\" name=\""
                        + eventId
                        + "calType\" value=\""
                        + event.getCalType()
                        + "\" />")
                .append(
                    "\n<input type=\"hidden\" name=\""
                        + eventId
                        + "calendarId\" value=\""
                        + event.getCalendarId()
                        + "\" />")
                .append("\n<input type=\"hidden\" name=\"" + eventId + "startTime\" value=\"\" />")
                .append("\n<input type=\"hidden\" name=\"" + eventId + "finishTime\" value=\"\" />")
                .append(
                    "\n<input type=\"hidden\" name=\""
                        + eventId
                        + "isOccur\" value=\""
                        + isOccur
                        + "\" />")
                .append(
                    "\n<input type=\"hidden\" name=\""
                        + eventId
                        + "recurId\" value=\""
                        + recurId
                        + "\" />")
                .append(
                    "\n<input type=\"hidden\" name=\"" + eventId + "currentDate\" value=\"\" />");
          }

          /** display event duration */
          if (event.isEventDurationSmallerThanHalfHour()) {
              /** short event */
            stringBuilder
                .append("\n<div class=\"clearfix\">")
                .append(
                    "\n<div unselectable=\"on\" class=\"eventContainerBar eventTitle pull-left\" style=\" display: inline-block; \">");

            if (CalendarEvent.TYPE_TASK.equals(event.getEventType())) {
              stringBuilder.append("\n<i class=\"uiIconCalTaskMini\"></i>");
            } else {
              stringBuilder.append("\n<i class=\"uiIconCalClockMini\"></i>");
              // occurring icon
              if (isOccur) {
                stringBuilder.append("<i class=\"uiIconCalRecurring\"></i>");
              } else if (!isOccur && Boolean.TRUE.equals(event.getIsExceptionOccurrence())) {
                stringBuilder.append("<i class=\"uiIconCalEditRecurring\"></i>");
              }
            }

            stringBuilder.append(
                "\n<i class=\"uiIconCal"
                    + event.getPriority()
                    + "Priority\"></i>"
                    + begin
                    + "</div>");

            /** display event summary */
            if ((event.getEventType().equals(CalendarEvent.TYPE_TASK))
                && (event.getEventState().equals(CalendarEvent.COMPLETED))) {
              stringBuilder.append(
                  "\n<div unselectable=\"on\" class=\"eventContainer\" style=\"text-decoration:line-through; \">"
                      + event.getSummary()
                      + "</div>");
            } else {
              stringBuilder.append(
                  "\n<div class=\"eventContainer \" >" + event.getSummary() + "</div>");
            }
            stringBuilder.append("</div>");
          } else {

            stringBuilder.append(
                "\n<div unselectable=\"on\" class=\"eventContainerBar eventTitle\">");

            if (CalendarEvent.TYPE_TASK.equals(event.getEventType())) {
              stringBuilder.append("\n<i class=\"uiIconCalTaskMini\"></i>");
            } else {
              stringBuilder.append("\n<i class=\"uiIconCalClockMini\"></i>");
              // occurring icon
              if (isOccur) {
                stringBuilder.append("<i class=\"uiIconCalRecurring\"></i>");
              } else if (!isOccur && Boolean.TRUE.equals(event.getIsExceptionOccurrence())) {
                stringBuilder.append("<i class=\"uiIconCalEditRecurring\"></i>");
              }
            }

            stringBuilder
                .append("\n<i class=\"uiIconCal" + event.getPriority() + "Priority\"></i>")
                .append(begin + " - " + end + "</div>");

            if ((event.getEventType().equals(CalendarEvent.TYPE_TASK))
                && (event.getEventState().equals(CalendarEvent.COMPLETED))) {
              stringBuilder
                  .append(
                      "\n<div unselectable=\"on\" class=\"eventContainer\" style=\" text-decoration:line-through; \">")
                  .append(event.getSummary() + "</div>");
            } else {
              stringBuilder.append(
                  "\n<div class=\"eventContainer\">" + event.getSummary() + "</div>");
            }
          }

          stringBuilder
              .append("\n<div class=\"resizeEventContainer\" unselectable=\"on\">")
              .append("\n<span></span>\n</div>\n</div>");
        }
      }
      cl.add(Calendar.DATE, 1);
    }

    stringBuilder
        .append("\n</div>")
        .append(
            "\n<table style=\"table-layout:fixed;\" class=\"uiGrid table \" id=\"UIWeekViewGrid\" lastupdatedid=\""
                + getLastUpdatedEventId()
                + "\"")
        .append(" cellspacing=\"0\" cellpadding=\"0\">")
        .append("\n<tbody>");

    boolean flag = false;
    String style = isShowWorkingTime() ? "WorkOffTime" : "none";
    String styleClass;

    String tempTimeFormat = CalendarUtils.TIMEFORMATPATTERNS[0];
    if (getTimeFormat().startsWith("HH")) tempTimeFormat = CalendarUtils.TIMEFORMATPATTERNS[1];
    int counter = 0;
    String timeName = "Gray";
    for (String full : getDisplayTimes(tempTimeFormat, getTimeInterval(), Locale.ENGLISH)) {
      if ((counter % 4) == 0 || (counter % 4) == 1) {
        timeName = "OddRow";
      } else if ((counter % 4) == 2 || (counter % 4) == 3) {
        timeName = "EvenRow";
      }

      String time = full.substring(0, full.lastIndexOf("_"));
      String display = full.substring(full.lastIndexOf("_") + 1);
      if (isShowWorkingTime()) {
        if (time.equals(getStartTime())) {
          style = "";
        }
        if (time.equals(getEndTime())) {
          style = "WorkOffTime";
        }
      }

      if (flag) {
        styleClass = "tdDotLine";
      } else {
        styleClass = "tdLine";
      }

      stringBuilder.append("\n<tr class=\"" + style + " " + timeName + "\">");

      if (!flag) {
        stringBuilder.append("\n<td class=\"tdTime center\" style=\"width: 55px;\">");
      } else {
        stringBuilder.append("\n<td style=\"width: 55px;\">");
      }

      stringBuilder.append("\n<div>");
      if (!flag) {
        stringBuilder.append(display);
      } else {
        stringBuilder.append("&nbsp;");
      }

      stringBuilder.append("\n</div>\n</td>");

      cl = getBeginDateOfWeek();
      DateFormat dayFormat = new SimpleDateFormat(getDateFormat(), Locale.ENGLISH);
      DateFormat fullDateFormat =
          new SimpleDateFormat(getDateFormat() + " " + CalendarUtils.TIMEFORMAT, Locale.ENGLISH);
      dayFormat.setCalendar(cl);
      fullDateFormat.setCalendar(cl);

      t = 0;
      String cssClass;
      while (t++ < numberOfDays) {
        // df.setCalendar(cl) ;
        String startTime = dayFormat.format(cl.getTime()) + " " + time;
        // dtf.setCalendar(cl) ;
        fullDateFormat.setLenient(false);
        // add try-catch block to handle Daylight Saving Time problem
        try {
          cl.setTime(fullDateFormat.parse(startTime));
        } catch (ParseException e) {
          fullDateFormat.setLenient(true);
          cl.setTime(fullDateFormat.parse(startTime));
        }
        int dayOfWeek = cl.get(Calendar.DAY_OF_WEEK);
        if (isCurrentDay(cl.get(Calendar.DATE), cl.get(Calendar.MONTH), cl.get(Calendar.YEAR))) {
          cssClass = "today";
        } else if (dayOfWeek == 1 || dayOfWeek == 7) {
          cssClass = "Weekend";
        } else {
          cssClass = "Weekday";
        }

        stringBuilder
            .append(
                "\n<td startFull=\""
                    + tempFormat.format(cl.getTime())
                    + "\" startTime=\""
                    + cl.getTimeInMillis()
                    + "\"")
            .append(
                " eventindex=\""
                    + dayOfWeek
                    + "\" class=\""
                    + styleClass
                    + " "
                    + cssClass
                    + " "
                    + style
                    + "\" style=\""
                    + styleWidth
                    + "\">")
            .append("\n<span></span>\n</td>");
        cl.add(Calendar.DATE, 1);
      }
      flag = !flag;

      stringBuilder.append("</tr>");
      counter++;
    }
    stringBuilder.append("\n</tbody>\n</table>");

    return stringBuilder.toString();
  }
Exemplo n.º 14
0
  /** used in template */
  private String renderAllDayGrid() throws Exception {
    int numberOfDays = isShowCustomView_ ? 5 : 7;
    String styleWidth = isShowCustomView_ ? "width:19.8%;*width:20%;" : "width:13.8%;*width:14%;";

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder
        .append(
            "\n<div id=\"UIWeekViewGridAllDay\" class=\"eventAllDay\" numberOfDays=\""
                + numberOfDays
                + "\">")
        .append("\n<div class=\"eventAlldayBoard\" style=\"position:relative\">")
        .append(
            "\n<table style=\"table-layout:fixed;\" class=\"uiGrid table allDayTable \" cellspacing=\"0\" cellpadding=\"0\">")
        .append("\n<tr>")
        .append("\n<td style=\"width: 55px;\"></td>");

    Calendar cl = getBeginDateOfWeek();
    int t = 0;
    while (t++ < numberOfDays) {

      stringBuilder.append(
          "\n<td class=\"whiteTd\" style=\""
              + styleWidth
              + "\" startTimeFull=\""
              + tempFormat.format(cl.getTime())
              + "\"></td>");
      cl.add(Calendar.DATE, 1);
    }
    stringBuilder.append("\n</tr>").append("\n</table>");

    for (CalendarEvent event : allDayEvent) {
      long begindate = event.getFromDateTime().getTime();
      long enddate = event.getToDateTime().getTime();
      // long startTime  = event.getFromDateTime().getTime() ;
      // long finishTime = event.getToDateTime().getTime() ;
      String eventId = event.getId();
      String calType = event.getCalType();
      String calendarId = event.getCalendarId();
      String color = getColors().get(calType + CalendarUtils.COLON + calendarId);
      // String title    = tf.format(event.getFromDateTime()) + "->" +
      // tf.format(event.getToDateTime())+ ":&#013; " + event.getSummary() ;
      String actionLink = event("UpdateAllDayEvent", eventId);
      boolean isOccur =
          (event.getRepeatType() != null
              && !CalendarEvent.RP_NOREPEAT.equals(event.getRepeatType())
              && (event.getIsExceptionOccurrence() == null || !event.getIsExceptionOccurrence()));
      String recurId = event.getRecurrenceId();
      boolean isEditable;
      if (!event.getCalType().equals(CalendarUtils.PRIVATE_TYPE))
        isEditable = isEventEditable(event);
      else isEditable = true;

      stringBuilder
          .append(
              "\n<div class=\"eventContainer eventAlldayContainer weekViewEventBoxes clearfix\" eventcat=\""
                  + event.getEventCategoryId()
                  + "\" style=\"position:absolute;display:none;\"")
          .append(
              "\n caltype=\""
                  + calType
                  + "\" eventid=\""
                  + eventId
                  + "\" isOccur=\""
                  + isOccur
                  + "\" recurId=\""
                  + recurId
                  + "\"")
          .append(
              "\n calid=\""
                  + calendarId
                  + "\" startTime=\""
                  + begindate
                  + "\" endTime=\""
                  + enddate
                  + "\"")
          .append(
              "\n startTimeFull=\""
                  + tempFormat.format(event.getFromDateTime())
                  + "\" endTimeFull=\""
                  + tempFormat.format(event.getToDateTime())
                  + "\"")
          .append("\n actionlink=\"" + actionLink + "\" isEditable=\"" + isEditable + "\">");

      if (!eventList.contains(eventId)) {
        eventList.add(eventId);

        stringBuilder
            .append(
                "\n<input type=\"hidden\" name=\""
                    + eventId
                    + "calType\" value=\""
                    + calType
                    + "\" />")
            .append(
                "\n<input type=\"hidden\" name=\""
                    + eventId
                    + "calendarId\" value=\""
                    + calendarId
                    + "\" />")
            .append("\n<input type=\"hidden\" name=\"" + eventId + "startTime\" value=\"\" />")
            .append("\n<input type=\"hidden\" name=\"" + eventId + "finishTime\" value=\"\" />")
            .append(
                "\n<input type=\"hidden\" name=\""
                    + eventId
                    + "isOccur\" value=\""
                    + isOccur
                    + "\" />")
            .append(
                "\n<input type=\"hidden\" name=\""
                    + eventId
                    + "recurId\" value=\""
                    + recurId
                    + "\" />")
            .append("\n<input type=\"hidden\" name=\"" + eventId + "currentDate\" value=\"\" />");
      }

      if (event.getFromDateTime().before(getBeginDateOfWeek().getTime())) {
        stringBuilder
            .append("\n<div class=\"leftContinueEvent  pull-left " + color + "\">")
            .append("\n<i class=\"uiIconMiniArrowLeft uiIconWhite\"></i>")
            .append("\n</div>");
      } else {
        stringBuilder
            .append(
                "\n<div class=\"leftResizeEvent LeftResizeEvent resizeEventContainer pull-left "
                    + color
                    + "\">")
            .append("\n<span></span>\n</div>");
      }

      if (event.getToDateTime().after(getEndDateOfWeek().getTime())) {
        stringBuilder
            .append("\n<div class=\"rightContinueEvent pull-right " + color + "\">")
            .append("\n<i class=\"uiIconMiniArrowRight uiIconWhite\"></i>\n</div>");
      } else {
        stringBuilder
            .append(
                "\n<div class=\"rightResizeEvent RightResizeEvent resizeEventContainer pull-right "
                    + color
                    + "\">")
            .append("\n<span></span>\n</div>");
      }

      stringBuilder
          .append(
              "\n<div class=\"eventAlldayContent " + color + "\">" + event.getSummary() + "</div>")
          .append("\n</div>");
    }
    stringBuilder.append("\n</div>\n</div>");

    return stringBuilder.toString();
  }
Exemplo n.º 15
0
  @Override
  public void refresh() throws Exception {
    init();
    eventData_.clear();
    allDayEvent.clear();
    int i = 0;
    Calendar c = getBeginDateOfWeek();
    int maxDay = 7;
    if (isShowCustomView_) maxDay = 5;
    while (i++ < maxDay) {
      List<CalendarEvent> list = new ArrayList<CalendarEvent>();
      String key = keyGen(c.get(Calendar.DATE), c.get(Calendar.MONTH), c.get(Calendar.YEAR));
      eventData_.put(key, list);
      c.add(Calendar.DATE, 1);
    }
    CalendarService calendarService = CalendarUtils.getCalendarService();
    String username = CalendarUtils.getCurrentUser();
    EventQuery eventQuery = new EventQuery();
    eventQuery.setFromDate(getBeginDateOfWeek());
    Calendar endDateOfWeek = getEndDateOfWeek();
    Date toDate = endDateOfWeek.getTime();
    toDate.setTime(toDate.getTime() - 1);
    endDateOfWeek.setTime(toDate);
    eventQuery.setToDate(endDateOfWeek);
    eventQuery.setExcludeRepeatEvent(true);

    /** get all norepeat events */
    List<CalendarEvent> allEvents;
    String[] publicCalendars = getPublicCalendars();
    String[] privateCalendars = getPrivateCalendars().toArray(new String[] {});

    if (isInSpace()) {
      eventQuery.setCalendarId(publicCalendars);
      allEvents = calendarService.getPublicEvents(eventQuery);
    } else {
      allEvents =
          calendarService.getAllNoRepeatEventsSQL(
              username, eventQuery, privateCalendars, publicCalendars, emptyEventCalendars);
    }

    /** get exception occurrences, exclude original recurrence events */
    List<CalendarEvent> originalRecurEvents =
        calendarService.getHighLightOriginalRecurrenceEventsSQL(
            username,
            eventQuery.getFromDate(),
            eventQuery.getToDate(),
            eventQuery,
            privateCalendars,
            publicCalendars,
            emptyRecurrentEventCalendars);

    String timezone = CalendarUtils.getCurrentUserCalendarSetting().getTimeZone();
    if (originalRecurEvents != null && originalRecurEvents.size() > 0) {
      Iterator<CalendarEvent> recurEventsIter = originalRecurEvents.iterator();
      while (recurEventsIter.hasNext()) {
        CalendarEvent recurEvent = recurEventsIter.next();
        Map<String, CalendarEvent> tempMap =
            calendarService.getOccurrenceEvents(
                recurEvent, eventQuery.getFromDate(), eventQuery.getToDate(), timezone);
        if (tempMap != null) {
          recurrenceEventsMap.put(recurEvent.getId(), tempMap);
          allEvents.addAll(tempMap.values());
        }
      }
    }

    Iterator<CalendarEvent> iter = allEvents.iterator();
    while (iter.hasNext()) {
      CalendarEvent event = iter.next();
      Date beginEvent = event.getFromDateTime();
      Date endEvent = event.getToDateTime();
      long eventAmount = endEvent.getTime() - beginEvent.getTime();
      i = 0;
      c = getBeginDateOfWeek();
      while (i++ < maxDay) {
        String key = keyGen(c.get(Calendar.DATE), c.get(Calendar.MONTH), c.get(Calendar.YEAR));
        if (isSameDate(c.getTime(), beginEvent)
            && (isSameDate(c.getTime(), endEvent))
            && eventAmount < CalendarUtils.MILISECONS_OF_DAY) {
          eventData_.get(key).add(event);
          iter.remove();
        }
        c.add(Calendar.DATE, 1);
      }
    }

    for (CalendarEvent ce : allEvents) {
      allDayEvent.add(ce);
    }
  }
 /**
  * remove the event activity
  *
  * @param event
  * @param calendarId
  */
 public void deletePublicEvent(CalendarEvent event, String calendarId) {
   String eventType =
       event.getEventType().equalsIgnoreCase(CalendarEvent.TYPE_EVENT) ? EVENT_ADDED : TASK_ADDED;
   deleteActivity(event, calendarId, eventType);
 }
  /**
   * adds comment to existing event activity
   *
   * @param event
   * @param calendarId
   * @param eventType
   * @param messagesParams
   */
  private void updateToActivity(
      CalendarEvent event,
      String calendarId,
      String eventType,
      Map<String, String> messagesParams) {
    try {
      Class.forName("org.exoplatform.social.core.space.spi.SpaceService");
    } catch (ClassNotFoundException e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("eXo Social components not found!", e);
      }
      return;
    }
    if (calendarId == null
        || calendarId.indexOf(CalendarDataInitialize.SPACE_CALENDAR_ID_SUFFIX) < 0) {
      return;
    }
    try {
      IdentityManager identityM =
          (IdentityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(IdentityManager.class);
      ActivityManager activityM =
          (ActivityManager)
              PortalContainer.getInstance().getComponentInstanceOfType(ActivityManager.class);
      SpaceService spaceService =
          (SpaceService)
              PortalContainer.getInstance().getComponentInstanceOfType(SpaceService.class);

      String spaceGroupId = Utils.getSpaceGroupIdFromCalendarId(calendarId);
      Space space = spaceService.getSpaceByGroupId(spaceGroupId);
      if (space != null) {
        String userId = ConversationState.getCurrent().getIdentity().getUserId();
        Identity spaceIdentity =
            identityM.getOrCreateIdentity(SpaceIdentityProvider.NAME, space.getPrettyName(), false);
        Identity userIdentity =
            identityM.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId, false);

        ExoSocialActivity activity = null;

        if (event.getActivityId() != null) {
          activity = activityM.getActivity(event.getActivityId());
        }

        /*
         * if activity is still null, that means:
         * - activity was deleted
         * - or this event is a public event from plf 3.5, it has no activityId
         * In this case, we create new activity and add comments about the changes to the activity
         */
        if (activity == null) {

          // create activity
          ExoSocialActivity newActivity = new ExoSocialActivityImpl();
          newActivity.setUserId(userIdentity.getId());
          newActivity.setTitle(event.getSummary());
          newActivity.setBody(event.getDescription());
          newActivity.setType("cs-calendar:spaces");
          newActivity.setTemplateParams(makeActivityParams(event, calendarId, eventType));
          activityM.saveActivityNoReturn(spaceIdentity, newActivity);

          // add comments
          ExoSocialActivity newComment = createComment(userIdentity.getId(), messagesParams);
          activityM.saveComment(newActivity, newComment);

          // update activity id for event
          event.setActivityId(newActivity.getId());
          LOG.info(
              String.format(
                  "[CALENDAR] successfully re-created activity for event: %s", event.getSummary()));
        } else {
          activity.setTitle(event.getSummary());
          activity.setBody(event.getDescription());
          activity.setTemplateParams(makeActivityParams(event, calendarId, eventType));
          activityM.updateActivity(activity);
          ExoSocialActivity newComment = createComment(userIdentity.getId(), messagesParams);
          activityM.saveComment(activity, newComment);
          LOG.info(
              String.format(
                  "[CALENDAR] successfully added comment to activity of event: %s",
                  event.getSummary()));
        }
      }
    } catch (ExoSocialException e) {
      if (LOG.isDebugEnabled())
        LOG.error("Can not update Activity for space when event modified ", e);
    }
  }
  private Map<String, String> buildParams(CalendarEvent oldEvent, CalendarEvent newEvent) {
    Map<String, String> messagesParams = new LinkedHashMap<String, String>();
    try {
      if (CalendarEvent.TYPE_EVENT.equals(newEvent.getEventType())) {
        if (!oldEvent.getSummary().equals(newEvent.getSummary())) {
          messagesParams.put(SUMMARY_UPDATED, newEvent.getSummary());
        }

        /* change description */
        if (newEvent.getDescription() != null
            && !newEvent.getDescription().equals(oldEvent.getDescription())) {
          messagesParams.put(DESCRIPTION_UPDATED, newEvent.getDescription());
        }
        /* remove description */
        else if ((newEvent.getDescription() == null) && (oldEvent.getDescription() != null)) {
          messagesParams.put(DESCRIPTION_REMOVED, "");
        }

        /* change location */
        if (newEvent.getLocation() != null
            && !newEvent.getLocation().equals(oldEvent.getLocation())) {
          messagesParams.put(LOCATION_UPDATED, newEvent.getLocation());
        }
        /* remove location */
        else if ((newEvent.getLocation() == null) && (oldEvent.getLocation() != null)) {
          messagesParams.put(LOCATION_REMOVED, "");
        }

        if (newEvent.getPriority() != null
            && !newEvent.getPriority().equals(oldEvent.getPriority())) {
          messagesParams.put(PRIORITY_UPDATED, newEvent.getPriority());
        }
        if (newEvent.getAttachment() != null)
          if (oldEvent.getAttachment() == null) {
            messagesParams.put(ATTACH_UPDATED, "");
          } else if (newEvent.getAttachment().size() != oldEvent.getAttachment().size()) {
            messagesParams.put(ATTACH_UPDATED, "");
          }
        if (isAllDayEvent(newEvent)
            && !isAllDayEvent(oldEvent)
            && CalendarEvent.TYPE_EVENT.equals(oldEvent.getEventType())) {
          messagesParams.put(ALLDAY_UPDATED, "");
        } else if (!isAllDayEvent(newEvent)) {
          if (newEvent.getFromDateTime().compareTo(oldEvent.getFromDateTime()) != 0) {
            messagesParams.put(FROM_UPDATED, String.valueOf(newEvent.getFromDateTime().getTime()));
          }
          if (newEvent.getToDateTime().compareTo(oldEvent.getToDateTime()) != 0) {
            messagesParams.put(TO_UPDATED, String.valueOf(newEvent.getToDateTime().getTime()));
          }
        }

        /*=== compare the repeat type ===*/
        String repeatSummary = buildRepeatSummary(newEvent);
        if (!repeatSummary.equals(buildRepeatSummary(oldEvent))) {
          messagesParams.put(REPEAT_UPDATED, repeatSummary);
        }

        /*=== compare the activity id ===*/
        // oldEvent -- occurrence or instance of repetitive event -- no activity
        // newEvent -- repetitiveEvent - with activity
        if (!newEvent.getActivityId().equals(oldEvent.getActivityId())) {
          messagesParams.put(
              REPEAT_EVENT_INSTANCE_REMOVED,
              getDateFormattedAfterUserSetting(oldEvent.getRecurrenceId()));
        }

      } else {
        if (!oldEvent.getSummary().equals(newEvent.getSummary())) {
          messagesParams.put(NAME_UPDATED, newEvent.getSummary());
        }
        /* change note */
        if (newEvent.getDescription() != null
            && !newEvent.getDescription().equals(oldEvent.getDescription())) {
          messagesParams.put(NOTE_UPDATED, newEvent.getDescription());
        }
        /* removed note */
        else if ((newEvent.getDescription() == null) && (oldEvent.getDescription() != null)) {
          messagesParams.put(NOTE_REMOVED, "");
        }

        if (!isAllDayEvent(newEvent)) {
          if (newEvent.getFromDateTime().compareTo(oldEvent.getFromDateTime()) != 0) {
            messagesParams.put(FROM_UPDATED, String.valueOf(newEvent.getFromDateTime().getTime()));
          }
          if (newEvent.getToDateTime().compareTo(oldEvent.getToDateTime()) != 0) {
            messagesParams.put(TO_UPDATED, String.valueOf(newEvent.getToDateTime().getTime()));
          }
        }
        if (newEvent.getPriority() != null
            && !newEvent.getPriority().equals(oldEvent.getPriority())) {
          messagesParams.put(PRIORITY_UPDATED, newEvent.getPriority());
        }
        if (newEvent.getAttachment() != null)
          if (oldEvent.getAttachment() == null) {
            messagesParams.put(TASK_ATTACH_UPDATED, "");
          } else if (newEvent.getAttachment().size() != oldEvent.getAttachment().size()) {
            messagesParams.put(TASK_ATTACH_UPDATED, "");
          }
        if (newEvent.getEventState() != null
            && !newEvent.getEventState().equals(oldEvent.getEventState())) {
          if (CalendarEvent.NEEDS_ACTION.equals(newEvent.getEventState())) {
            messagesParams.put(TASK_NEED_ACTION, newEvent.getEventState());
          } else if (CalendarEvent.IN_PROCESS.equals(newEvent.getEventState())) {
            messagesParams.put(TASK_IN_PROCESS_ACTION, newEvent.getEventState());
          } else if (CalendarEvent.COMPLETED.equals(newEvent.getEventState())) {
            messagesParams.put(TASK_COMPLETED_ACTION, newEvent.getEventState());
          } else if (CalendarEvent.CANCELLED.equals(newEvent.getEventState())) {
            messagesParams.put(TASK_CANCELLED_ACTION, newEvent.getEventState());
          }
        }
      }
    } catch (Exception e) {
      if (LOG.isDebugEnabled()) LOG.error("Can not build message for space when event updated ", e);
    }
    return messagesParams;
  }
  /**
   * Build the repeating summary, i.e: daily every 2 days, until 02/03/2011. <br>
   * The summary structure is defined in resource bundle, it contains some parameters and </br> will
   * be replaced by values from repeatEvent. <br>
   *
   * <p>There are 6 parameters: {count}, {until}, {interval}, {byDays}, {theDay}, {theNumber}.<br>
   * Some labels in resource bundle to define numbers (the first, the second, ...) which were used
   * in summary
   *
   * @param repeatEvent the repeating event
   * @return summary string about repeating event
   * @throws Exception
   */
  public String buildRepeatSummary(CalendarEvent repeatEvent) {
    if (repeatEvent == null) return "";
    String repeatType = repeatEvent.getRepeatType();
    if (CalendarEvent.RP_NOREPEAT.equals(repeatType) || repeatType == null) return "";

    try {
      String userId = ConversationState.getCurrent().getIdentity().getUserId();
      calService_ =
          (CalendarService)
              PortalContainer.getInstance().getComponentInstance(CalendarService.class);
      CalendarSetting calSetting = calService_.getCalendarSetting(userId);
      WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();

      Locale locale = requestContext.getParentAppRequestContext().getLocale();
      DateFormat format = new SimpleDateFormat(calSetting.getDateFormat(), locale);
      DateFormatSymbols symbols = new DateFormatSymbols(locale);
      String[] dayOfWeeks = symbols.getWeekdays();

      int interval = (int) repeatEvent.getRepeatInterval();
      int count = (int) repeatEvent.getRepeatCount();
      Date until = repeatEvent.getRepeatUntilDate();
      String endType = RP_END_NEVER;
      if (count > 0) endType = RP_END_AFTER;
      if (until != null) endType = RP_END_BYDATE;

      StringBuilder pattern = new StringBuilder("");
      if (repeatType.equals(CalendarEvent.RP_DAILY)) {
        if (interval == 1) {
          // pattern = "Daily";
          pattern.append(CalendarUIActivity.getUICalendarLabel("daily"));
        } else {
          // pattern = "Every {interval} days";
          pattern.append(CalendarUIActivity.getUICalendarLabel("every-day"));
        }
        if (endType.equals(RP_END_AFTER)) {
          // pattern = "Daily, {count} times";
          // pattern = "Every {interval} days, {count} times";
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("count-times"));
        }
        if (endType.equals(RP_END_BYDATE)) {
          // pattern = "Daily, until {until}";
          // pattern = "Every {interval} days, until {until}";
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("until"));
        }

        return new String(pattern)
            .replace("{interval}", String.valueOf(interval))
            .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
            .replace(
                "{until}",
                repeatEvent.getRepeatUntilDate() == null
                    ? ""
                    : format.format(repeatEvent.getRepeatUntilDate()));
      }

      if (repeatType.equals(CalendarEvent.RP_WEEKLY)) {
        if (interval == 1) {
          // pattern = "Weekly on {byDays}";
          pattern.append(CalendarUIActivity.getUICalendarLabel("weekly"));
        } else {
          // pattern = "Every {interval} weeks on {byDays}";
          pattern.append(CalendarUIActivity.getUICalendarLabel("every-week"));
        }
        if (endType.equals(RP_END_AFTER)) {
          // pattern = "Weekly on {byDays}, {count} times";
          // pattern = "Every {interval} weeks on {byDays}, {count} times";
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("count-times"));
        }
        if (endType.equals(RP_END_BYDATE)) {
          // pattern = "Weekly on {byDays}, until {until}";
          // pattern = "Every {interval} weeks on {byDays}, until {until}";
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("until"));
        }

        String[] weeklyByDays = repeatEvent.getRepeatByDay();
        StringBuffer byDays = new StringBuffer();
        for (int i = 0; i < weeklyByDays.length; i++) {
          if (i == 0) {
            byDays.append(dayOfWeeks[convertToDayOfWeek(weeklyByDays[0])]);
          } else {
            byDays.append(", ");
            byDays.append(dayOfWeeks[convertToDayOfWeek(weeklyByDays[i])]);
          }
        }
        return new String(pattern)
            .replace("{interval}", String.valueOf(interval))
            .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
            .replace(
                "{until}",
                repeatEvent.getRepeatUntilDate() == null
                    ? ""
                    : format.format(repeatEvent.getRepeatUntilDate()))
            .replace("{byDays}", byDays.toString());
      }

      if (repeatType.equals(CalendarEvent.RP_MONTHLY)) {
        String monthlyType = RP_MONTHLY_BYMONTHDAY;
        if (repeatEvent.getRepeatByDay() != null && repeatEvent.getRepeatByDay().length > 0)
          monthlyType = RP_MONTHLY_BYDAY;

        if (interval == 1) {
          // pattern = "Monthly on"
          pattern.append(CalendarUIActivity.getUICalendarLabel("monthly"));
        } else {
          // pattern = "Every {interval} months on
          pattern.append(CalendarUIActivity.getUICalendarLabel("every-month"));
        }

        if (monthlyType.equals(RP_MONTHLY_BYDAY)) {
          // pattern = "Monthly on {theNumber} {theDay}
          // pattern = "Every {interval} months on {theNumber} {theDay}
          pattern.append(" " + CalendarUIActivity.getUICalendarLabel("monthly-by-day"));
        } else {
          // pattern = "Monthly on day {theDay}
          // pattern = "Every {interval} months on day {theDay}
          pattern.append(" " + CalendarUIActivity.getUICalendarLabel("monthly-by-month-day"));
        }

        if (endType.equals(RP_END_AFTER)) {
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("count-times"));
        }
        if (endType.equals(RP_END_BYDATE)) {
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("until"));
        }

        String theNumber = ""; // the first, the second, the third, ...
        String theDay =
            ""; // in monthly by day, it's Monday, Tuesday, ... (day of week), in monthly by
        // monthday, it's 1-31 (day of month)
        if (monthlyType.equals(RP_MONTHLY_BYDAY)) {
          java.util.Calendar temp = getCalendarInstanceBySetting(calSetting);
          temp.setTime(repeatEvent.getFromDateTime());
          int weekOfMonth = temp.get(java.util.Calendar.WEEK_OF_MONTH);
          java.util.Calendar temp2 = getCalendarInstanceBySetting(calSetting);
          temp2.setTime(temp.getTime());
          temp2.add(java.util.Calendar.DATE, 7);
          if (temp2.get(java.util.Calendar.MONTH) != temp.get(java.util.Calendar.MONTH))
            weekOfMonth = 5;
          int dayOfWeek = temp.get(java.util.Calendar.DAY_OF_WEEK);
          String[] weekOfMonths =
              new String[] {
                CalendarUIActivity.getUICalendarLabel("summary-the-first"),
                CalendarUIActivity.getUICalendarLabel("summary-the-second"),
                CalendarUIActivity.getUICalendarLabel("summary-the-third"),
                CalendarUIActivity.getUICalendarLabel("summary-the-fourth"),
                CalendarUIActivity.getUICalendarLabel("summary-the-last")
              };
          theNumber = weekOfMonths[weekOfMonth - 1];
          theDay = dayOfWeeks[dayOfWeek];
        } else {
          java.util.Calendar temp = getCalendarInstanceBySetting(calSetting);
          temp.setTime(repeatEvent.getFromDateTime());
          int dayOfMonth = temp.get(java.util.Calendar.DAY_OF_MONTH);
          theDay = String.valueOf(dayOfMonth);
        }
        return new String(pattern)
            .replace("{interval}", String.valueOf(interval))
            .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
            .replace(
                "{until}",
                repeatEvent.getRepeatUntilDate() == null
                    ? ""
                    : format.format(repeatEvent.getRepeatUntilDate()))
            .replace("{theDay}", theDay)
            .replace("{theNumber}", theNumber);
      }

      if (repeatType.equals(CalendarEvent.RP_YEARLY)) {
        if (interval == 1) {
          // pattern = "Yearly on {theDay}"
          pattern.append(CalendarUIActivity.getUICalendarLabel("yearly"));
        } else {
          // pattern = "Every {interval} years on {theDay}"
          pattern.append(CalendarUIActivity.getUICalendarLabel("every-year"));
        }

        if (endType.equals(RP_END_AFTER)) {
          // pattern = "Yearly on {theDay}, {count} times"
          // pattern = "Every {interval} years on {theDay}, {count} times"
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("count-times"));
        }
        if (endType.equals(RP_END_BYDATE)) {
          // pattern = "Yearly on {theDay}, until {until}"
          // pattern = "Every {interval} years on {theDay}, until {until}"
          pattern.append(", " + CalendarUIActivity.getUICalendarLabel("until"));
        }

        String theDay = format.format(repeatEvent.getFromDateTime()); //
        return new String(pattern)
            .replace("{interval}", String.valueOf(interval))
            .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
            .replace(
                "{until}",
                repeatEvent.getRepeatUntilDate() == null
                    ? ""
                    : format.format(repeatEvent.getRepeatUntilDate()))
            .replace("{theDay}", theDay);
      }
    } catch (Exception e) {
      LOG.info(e.getLocalizedMessage());
    }
    return null;
  }