/**
  * 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);
   }
 }
Beispiel #3
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();
  }
 /**
  * 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);
 }
  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;
  }