Beispiel #1
1
 public static List<org.exoplatform.calendar.service.Calendar> getAllOfCurrentUserCalendars()
     throws Exception {
   List<org.exoplatform.calendar.service.Calendar> list =
       new ArrayList<org.exoplatform.calendar.service.Calendar>();
   CalendarService calendarService = getCalendarService();
   String username = getCurrentUser();
   List<org.exoplatform.calendar.service.Calendar> calendars =
       calendarService.getUserCalendars(username, true);
   for (org.exoplatform.calendar.service.Calendar c : calendars) {
     list.add(c);
   }
   GroupCalendarData gcd = calendarService.getSharedCalendars(username, true);
   if (gcd != null) {
     for (org.exoplatform.calendar.service.Calendar c : gcd.getCalendars()) {
       if (Utils.hasPermission(Utils.getEditPerUsers(c))) {
         list.add(c);
       }
     }
   }
   List<GroupCalendarData> lgcd =
       calendarService.getGroupCalendars(CalendarUtils.getUserGroups(username), true, username);
   if (lgcd != null) {
     for (GroupCalendarData g : lgcd) {
       for (org.exoplatform.calendar.service.Calendar c : g.getCalendars()) {
         if (Utils.hasPermission(c.getEditPermission())) {
           list.add(c);
         }
       }
     }
   }
   return list;
 }
 /**
  * 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);
   }
 }
  /**
   * 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);
    }
  }
Beispiel #4
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;
   }
 }
Beispiel #5
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);
          }
        }
      }
    }
  /**
   * 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);
    }
  }
Beispiel #7
0
  /**
   * get all users calendars (private, public, shared)
   *
   * @return
   * @throws Exception
   */
  public static List<SelectItem> getCalendarOption() throws Exception {
    List<SelectItem> options = new ArrayList<SelectItem>();
    CalendarService calendarService = getCalendarService();
    String username = getCurrentUser();
    /*
     * hash map to check existence of a calendar in the list.
     */
    Map<String, String> hash = new HashMap<String, String>();
    /*
     * Modified by Philippe ([email protected])
     * Uses SelectItemOptionGroup to differienciate private, shared and public groups
     */

    // private calendars group
    SelectOptionGroup privGrp = new SelectOptionGroup(CalendarUtils.PRIVATE_CALENDARS);
    List<org.exoplatform.calendar.service.Calendar> calendars =
        calendarService.getUserCalendars(username, true);
    for (org.exoplatform.calendar.service.Calendar c : calendars) {
      if (!hash.containsKey(c.getId())) {
        hash.put(c.getId(), "");
        privGrp.addOption(
            new SelectOption(
                c.getName(), CalendarUtils.PRIVATE_TYPE + CalendarUtils.COLON + c.getId()));
      }
    }
    if (privGrp.getOptions().size() > 0) options.add(privGrp);
    // shared calendars group
    GroupCalendarData gcd = calendarService.getSharedCalendars(username, true);
    if (gcd != null) {
      SelectOptionGroup sharedGrp = new SelectOptionGroup(CalendarUtils.SHARED_CALENDARS);
      for (org.exoplatform.calendar.service.Calendar c : gcd.getCalendars()) {
        if (Utils.hasPermission(Utils.getEditPerUsers(c))) {
          if (!hash.containsKey(c.getId())) {
            hash.put(c.getId(), "");
            sharedGrp.addOption(
                new SelectOption(
                    c.getName(), CalendarUtils.SHARED_TYPE + CalendarUtils.COLON + c.getId()));
          }
        }
      }
      if (sharedGrp.getOptions().size() > 0) options.add(sharedGrp);
    }
    // public calendars group
    List<GroupCalendarData> lgcd =
        calendarService.getGroupCalendars(CalendarUtils.getUserGroups(username), true, username);

    if (lgcd != null) {
      SelectOptionGroup pubGrp = new SelectOptionGroup(CalendarUtils.PUBLIC_CALENDARS);
      for (GroupCalendarData g : lgcd) {
        for (org.exoplatform.calendar.service.Calendar c : g.getCalendars()) {
          if (Utils.hasPermission(c.getEditPermission())) {
            if (!hash.containsKey(c.getId())) {
              hash.put(c.getId(), "");
              pubGrp.addOption(
                  new SelectOption(
                      c.getName(), CalendarUtils.PUBLIC_TYPE + CalendarUtils.COLON + c.getId()));
            }
          }
        }
      }
      if (pubGrp.getOptions().size() > 0) options.add(pubGrp);
    }
    return options;
  }