Ejemplo n.º 1
1
  protected static List<CalendarBooking> filterCalendarBookings(
      List<CalendarBooking> calendarBookings, PermissionChecker permissionChecker, String actionId)
      throws PortalException, SystemException {

    calendarBookings = ListUtil.copy(calendarBookings);

    Iterator<CalendarBooking> itr = calendarBookings.iterator();

    while (itr.hasNext()) {
      CalendarBooking calendarBooking = itr.next();

      if (!CalendarPermission.contains(
          permissionChecker, calendarBooking.getCalendarId(), ACTION_VIEW_BOOKING_DETAILS)) {

        if (!CalendarPermission.contains(
            permissionChecker, calendarBooking.getCalendarId(), actionId)) {

          itr.remove();
        } else {
          filterCalendarBooking(calendarBooking, permissionChecker);
        }
      }
    }

    return calendarBookings;
  }
  public CalendarBooking updateCalendarBooking(
      long userId,
      long calendarBookingId,
      long calendarId,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      String location,
      long startDate,
      long endDate,
      boolean allDay,
      String recurrence,
      long firstReminder,
      String firstReminderType,
      long secondReminder,
      String secondReminderType,
      int status,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    CalendarBooking calendarBooking =
        calendarBookingPersistence.findByPrimaryKey(calendarBookingId);

    List<CalendarBooking> childCalendarBookings =
        calendarBookingPersistence.findByParentCalendarBookingId(calendarBookingId);

    long[] childCalendarIds = new long[childCalendarBookings.size()];

    for (int i = 0; i < childCalendarIds.length; i++) {
      CalendarBooking childCalendarBooking = childCalendarBookings.get(i);

      if (childCalendarBooking.getCalendarId() == calendarBooking.getCalendarId()) {

        childCalendarIds[i] = calendarId;
      } else {
        childCalendarIds[i] = childCalendarBooking.getCalendarId();
      }
    }

    return updateCalendarBooking(
        userId,
        calendarBookingId,
        calendarId,
        childCalendarIds,
        titleMap,
        descriptionMap,
        location,
        startDate,
        endDate,
        allDay,
        recurrence,
        firstReminder,
        firstReminderType,
        secondReminder,
        secondReminderType,
        status,
        serviceContext);
  }
Ejemplo n.º 3
0
  public CalendarBooking deleteCalendarBooking(long calendarBookingId)
      throws PortalException, SystemException {

    CalendarBooking calendarBooking =
        calendarBookingPersistence.findByPrimaryKey(calendarBookingId);

    CalendarPermission.check(
        getPermissionChecker(), calendarBooking.getCalendarId(), ActionKeys.MANAGE_BOOKINGS);

    return calendarBookingLocalService.deleteCalendarBooking(calendarBookingId);
  }
Ejemplo n.º 4
0
  public void invokeTransition(
      long calendarBookingId, String transitionName, ServiceContext serviceContext)
      throws PortalException, SystemException {

    CalendarBooking calendarBooking =
        calendarBookingPersistence.findByPrimaryKey(calendarBookingId);

    CalendarPermission.check(
        getPermissionChecker(), calendarBooking.getCalendarId(), ActionKeys.MANAGE_BOOKINGS);

    calendarBookingApprovalWorkflow.invokeTransition(
        getUserId(), calendarBookingId, transitionName, serviceContext);
  }
Ejemplo n.º 5
0
  protected CalendarBooking filterCalendarBooking(CalendarBooking calendarBooking)
      throws PortalException, SystemException {

    if (!CalendarPermission.contains(
        getPermissionChecker(), calendarBooking.getCalendarId(), ActionKeys.VIEW_BOOKING_DETAILS)) {

      calendarBooking.setTitle(StringPool.BLANK);
      calendarBooking.setDescription(StringPool.BLANK);
      calendarBooking.setLocation(StringPool.BLANK);
    }

    return calendarBooking;
  }
  @Override
  public boolean hasPermission(PermissionChecker permissionChecker, long classPK, String actionId)
      throws Exception {

    CalendarBooking calendarBooking = _calendarBookingLocalService.getCalendarBooking(classPK);

    if (actionId.equals(ActionKeys.DELETE) || actionId.equals(ActionKeys.UPDATE)) {

      actionId = CalendarActionKeys.MANAGE_BOOKINGS;
    }

    return CalendarPermission.contains(
        permissionChecker, calendarBooking.getCalendarId(), actionId);
  }
  @Override
  public void onAfterRemove(CalendarBooking calendarBooking) {
    if (calendarBooking == null) {
      return;
    }

    CalEvent calEvent =
        _calEventLocalService.fetchCalEventByUuidAndGroupId(
            calendarBooking.getUuid(), calendarBooking.getGroupId());

    if (calEvent != null) {
      _calEventLocalService.deleteCalEvent(calEvent);
    }
  }
Ejemplo n.º 8
0
  protected static CalendarBooking filterCalendarBooking(
      CalendarBooking calendarBooking, PermissionChecker permissionChecker)
      throws PortalException, SystemException {

    if (!CalendarPermission.contains(
        permissionChecker, calendarBooking.getCalendarId(), ACTION_VIEW_BOOKING_DETAILS)) {

      calendarBooking.setTitle(StringPool.BLANK);
      calendarBooking.setDescription(StringPool.BLANK);
      calendarBooking.setLocation(StringPool.BLANK);
    }

    return calendarBooking;
  }
  /**
   * Adds the calendar booking to the database. Also notifies the appropriate model listeners.
   *
   * @param calendarBooking the calendar booking
   * @return the calendar booking that was added
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  public CalendarBooking addCalendarBooking(CalendarBooking calendarBooking)
      throws SystemException {
    calendarBooking.setNew(true);

    return calendarBookingPersistence.update(calendarBooking);
  }
  protected void importCalendarBookingResourcePermission(
      ResourcePermission resourcePermission, long calendarBookingId)
      throws PortalException, SystemException {

    CalendarBooking calendarBooking =
        calendarBookingPersistence.findByPrimaryKey(calendarBookingId);

    long actionIds =
        getActionIds(resourcePermission, CalEvent.class.getName(), CalendarBooking.class.getName());

    resourceBlockLocalService.updateIndividualScopePermissions(
        calendarBooking.getCompanyId(),
        calendarBooking.getGroupId(),
        CalendarBooking.class.getName(),
        calendarBooking,
        resourcePermission.getRoleId(),
        actionIds,
        ResourceBlockConstants.OPERATOR_SET);
  }
  @Test
  public void testRecurrenceIsNull() throws ParseException {
    Calendar calendar = Calendar.getInstance();

    CalendarBooking calendarBooking = new CalendarBookingImpl();

    calendarBooking.setStartTime(calendar.getTimeInMillis());
    calendarBooking.setRecurrence(null);

    CalendarBookingIterator calendarBookingIterator = new CalendarBookingIterator(calendarBooking);

    int count = 0;

    while (calendarBookingIterator.hasNext()) {
      calendarBookingIterator.next();

      count++;
    }

    Assert.assertEquals(1, count);
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    CalendarBooking calendarBooking = null;

    try {
      calendarBooking = (CalendarBooking) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = calendarBooking.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  public int compareTo(CalendarBooking calendarBooking) {
    int value = 0;

    if (getStartTime() < calendarBooking.getStartTime()) {
      value = -1;
    } else if (getStartTime() > calendarBooking.getStartTime()) {
      value = 1;
    } else {
      value = 0;
    }

    if (value != 0) {
      return value;
    }

    value = getTitle().compareToIgnoreCase(calendarBooking.getTitle());

    if (value != 0) {
      return value;
    }

    return 0;
  }
  public void deleteCalendarBookingInstance(
      long calendarBookingId, long startDate, boolean allFollowing)
      throws PortalException, SystemException {

    CalendarBooking calendarBooking =
        calendarBookingPersistence.findByPrimaryKey(calendarBookingId);

    java.util.Calendar jCalendar = JCalendarUtil.getJCalendar(startDate);

    Recurrence recurrenceObj = calendarBooking.getRecurrenceObj();

    if (allFollowing) {
      jCalendar.add(java.util.Calendar.DATE, -1);

      recurrenceObj.setUntilJCalendar(jCalendar);
    } else {
      recurrenceObj.addExceptionDate(jCalendar);
    }

    calendarBooking.setRecurrence(RecurrenceSerializer.serialize(recurrenceObj));

    calendarBookingPersistence.update(calendarBooking, false);
  }
  @Test
  public void testRecurrenceStartsMondayRepeatsWednesday() throws ParseException {

    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

    CalendarBooking calendarBooking = new CalendarBookingImpl();

    calendarBooking.setStartTime(calendar.getTimeInMillis());
    calendarBooking.setRecurrence("RRULE:FREQ=WEEKLY;COUNT=2;INTERVAL=1;BYDAY=WE");

    CalendarBookingIterator calendarBookingIterator = new CalendarBookingIterator(calendarBooking);

    int count = 0;

    while (calendarBookingIterator.hasNext()) {
      calendarBookingIterator.next();

      count++;
    }

    Assert.assertEquals(2, count);
  }
  @Override
  public CalendarBooking deleteCalendarBooking(CalendarBooking calendarBooking)
      throws PortalException, SystemException {

    // Calendar booking

    calendarBookingPersistence.remove(calendarBooking);

    // Calendar bookings

    List<CalendarBooking> childCalendarBookings =
        getChildCalendarBookings(calendarBooking.getCalendarBookingId());

    for (CalendarBooking childCalendarBooking : childCalendarBookings) {
      deleteCalendarBooking(childCalendarBooking);
    }

    return calendarBooking;
  }
  /**
   * Adds the calendar booking to the database. Also notifies the appropriate model listeners.
   *
   * @param calendarBooking the calendar booking
   * @return the calendar booking that was added
   * @throws SystemException if a system exception occurred
   */
  public CalendarBooking addCalendarBooking(CalendarBooking calendarBooking)
      throws SystemException {
    calendarBooking.setNew(true);

    calendarBooking = calendarBookingPersistence.update(calendarBooking, false);

    Indexer indexer = IndexerRegistryUtil.getIndexer(getModelClassName());

    if (indexer != null) {
      try {
        indexer.reindex(calendarBooking);
      } catch (SearchException se) {
        if (_log.isWarnEnabled()) {
          _log.warn(se, se);
        }
      }
    }

    return calendarBooking;
  }
  public CalendarBooking updateStatus(
      long userId, long calendarBookingId, int status, ServiceContext serviceContext)
      throws PortalException, SystemException {

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    CalendarBooking calendarBooking =
        calendarBookingPersistence.findByPrimaryKey(calendarBookingId);

    calendarBooking.setModifiedDate(serviceContext.getModifiedDate(now));
    calendarBooking.setStatus(status);
    calendarBooking.setStatusByUserId(user.getUserId());
    calendarBooking.setStatusByUserName(user.getFullName());
    calendarBooking.setStatusDate(serviceContext.getModifiedDate(now));

    calendarBookingPersistence.update(calendarBooking, false);

    return calendarBooking;
  }
  protected void addCalendarBooking(
      String uuid,
      long calendarBookingId,
      long companyId,
      long groupId,
      long userId,
      String userName,
      Date createDate,
      Date modifiedDate,
      long calendarId,
      long calendarResourceId,
      String title,
      String description,
      String location,
      long startTime,
      long endTime,
      boolean allDay,
      String recurrence,
      int firstReminder,
      NotificationType firstReminderType,
      int secondReminder,
      NotificationType secondReminderType)
      throws SystemException {

    CalendarBooking calendarBooking = calendarBookingPersistence.create(calendarBookingId);

    calendarBooking.setUuid(uuid);
    calendarBooking.setCompanyId(companyId);
    calendarBooking.setGroupId(groupId);
    calendarBooking.setUserId(userId);
    calendarBooking.setUserName(userName);
    calendarBooking.setCreateDate(createDate);
    calendarBooking.setModifiedDate(modifiedDate);
    calendarBooking.setCalendarId(calendarId);
    calendarBooking.setCalendarResourceId(calendarResourceId);
    calendarBooking.setParentCalendarBookingId(calendarBookingId);
    calendarBooking.setTitle(title);
    calendarBooking.setDescription(description);
    calendarBooking.setLocation(location);
    calendarBooking.setStartTime(startTime);
    calendarBooking.setEndTime(endTime);
    calendarBooking.setAllDay(allDay);
    calendarBooking.setRecurrence(recurrence);
    calendarBooking.setFirstReminder(firstReminder);
    calendarBooking.setFirstReminderType(firstReminderType.toString());
    calendarBooking.setSecondReminder(secondReminder);
    calendarBooking.setSecondReminderType(secondReminderType.toString());
    calendarBooking.setStatus(WorkflowConstants.STATUS_APPROVED);
    calendarBooking.setStatusByUserId(userId);
    calendarBooking.setStatusByUserName(userName);
    calendarBooking.setStatusDate(createDate);

    calendarBookingPersistence.update(calendarBooking);
  }
  protected void addChildCalendarBookings(
      CalendarBooking calendarBooking, long[] childCalendarIds, ServiceContext serviceContext)
      throws PortalException, SystemException {

    if (!calendarBooking.isMasterBooking()) {
      return;
    }

    List<CalendarBooking> childCalendarBookings =
        calendarBookingPersistence.findByParentCalendarBookingId(
            calendarBooking.getCalendarBookingId());

    for (CalendarBooking childCalendarBooking : childCalendarBookings) {
      if (childCalendarBooking.isMasterBooking()
          || ArrayUtil.contains(childCalendarIds, childCalendarBooking.getCalendarId())) {

        continue;
      }

      deleteCalendarBooking(childCalendarBooking.getCalendarBookingId());
    }

    for (long calendarId : childCalendarIds) {
      int count =
          calendarBookingPersistence.countByC_P(calendarId, calendarBooking.getCalendarBookingId());

      if (count > 0) {
        continue;
      }

      CalendarBooking childCalendarBooking =
          addCalendarBooking(
              calendarBooking.getUserId(),
              calendarId,
              new long[0],
              calendarBooking.getCalendarBookingId(),
              calendarBooking.getTitleMap(),
              calendarBooking.getDescriptionMap(),
              calendarBooking.getLocation(),
              calendarBooking.getStartDate(),
              calendarBooking.getEndDate(),
              calendarBooking.getAllDay(),
              calendarBooking.getRecurrence(),
              calendarBooking.getFirstReminder(),
              calendarBooking.getFirstReminderType(),
              calendarBooking.getSecondReminder(),
              calendarBooking.getSecondReminderType(),
              serviceContext);

      try {
        NotificationType notificationType =
            NotificationType.parse(PortletPropsValues.CALENDAR_NOTIFICATION_DEFAULT_TYPE);

        NotificationUtil.notifyCalendarBookingInvites(childCalendarBooking, notificationType);
      } catch (Exception e) {
      }
    }
  }
  public CalendarBooking addCalendarBooking(
      long userId,
      long calendarId,
      long[] childCalendarIds,
      long parentCalendarBookingId,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      String location,
      long startDate,
      long endDate,
      boolean allDay,
      String recurrence,
      long firstReminder,
      String firstReminderType,
      long secondReminder,
      String secondReminderType,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Calendar booking

    User user = userPersistence.findByPrimaryKey(userId);
    Calendar calendar = calendarPersistence.findByPrimaryKey(calendarId);

    java.util.Calendar startDateJCalendar = JCalendarUtil.getJCalendar(startDate);
    java.util.Calendar endDateJCalendar = JCalendarUtil.getJCalendar(endDate);

    if (allDay) {
      startDateJCalendar = JCalendarUtil.toMidnightJCalendar(startDateJCalendar);
      endDateJCalendar = JCalendarUtil.toLastHourJCalendar(endDateJCalendar);
    }

    if (firstReminder < secondReminder) {
      long originalSecondReminder = secondReminder;

      secondReminder = firstReminder;
      firstReminder = originalSecondReminder;
    }

    Date now = new Date();

    validate(titleMap, startDateJCalendar, endDateJCalendar);

    long calendarBookingId = counterLocalService.increment();

    CalendarBooking calendarBooking = calendarBookingPersistence.create(calendarBookingId);

    calendarBooking.setUuid(serviceContext.getUuid());
    calendarBooking.setGroupId(calendar.getGroupId());
    calendarBooking.setCompanyId(user.getCompanyId());
    calendarBooking.setUserId(user.getUserId());
    calendarBooking.setUserName(user.getFullName());
    calendarBooking.setCreateDate(serviceContext.getCreateDate(now));
    calendarBooking.setModifiedDate(serviceContext.getModifiedDate(now));
    calendarBooking.setCalendarId(calendarId);
    calendarBooking.setCalendarResourceId(calendar.getCalendarResourceId());

    if (parentCalendarBookingId > 0) {
      calendarBooking.setParentCalendarBookingId(parentCalendarBookingId);
    } else {
      calendarBooking.setParentCalendarBookingId(calendarBookingId);
    }

    calendarBooking.setTitleMap(titleMap);
    calendarBooking.setDescriptionMap(descriptionMap);
    calendarBooking.setLocation(location);
    calendarBooking.setStartDate(startDateJCalendar.getTimeInMillis());
    calendarBooking.setEndDate(endDateJCalendar.getTimeInMillis());
    calendarBooking.setAllDay(allDay);
    calendarBooking.setRecurrence(recurrence);
    calendarBooking.setFirstReminder(firstReminder);
    calendarBooking.setFirstReminderType(firstReminderType);
    calendarBooking.setSecondReminder(secondReminder);
    calendarBooking.setSecondReminderType(secondReminderType);

    int status = CalendarBookingWorkflowConstants.STATUS_PENDING;

    if (parentCalendarBookingId == 0) {
      status = CalendarBookingWorkflowConstants.STATUS_APPROVED;
    }

    calendarBooking.setStatus(status);

    calendarBooking.setStatusDate(serviceContext.getModifiedDate(now));

    calendarBookingPersistence.update(calendarBooking, false);

    addChildCalendarBookings(calendarBooking, childCalendarIds, serviceContext);

    // Workflow

    calendarBookingApprovalWorkflow.startWorkflow(userId, calendarBookingId, serviceContext);

    return calendarBooking;
  }
  public CalendarBooking updateCalendarBooking(
      long userId,
      long calendarBookingId,
      long calendarId,
      long[] childCalendarIds,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      String location,
      long startDate,
      long endDate,
      boolean allDay,
      String recurrence,
      long firstReminder,
      String firstReminderType,
      long secondReminder,
      String secondReminderType,
      int status,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Calendar booking

    User user = userPersistence.findByPrimaryKey(userId);
    CalendarBooking calendarBooking =
        calendarBookingPersistence.findByPrimaryKey(calendarBookingId);

    java.util.Calendar startDateJCalendar = JCalendarUtil.getJCalendar(startDate);
    java.util.Calendar endDateJCalendar = JCalendarUtil.getJCalendar(endDate);

    if (allDay) {
      startDateJCalendar = JCalendarUtil.toMidnightJCalendar(startDateJCalendar);
      endDateJCalendar = JCalendarUtil.toLastHourJCalendar(endDateJCalendar);
    }

    if (firstReminder < secondReminder) {
      long originalSecondReminder = secondReminder;

      secondReminder = firstReminder;
      firstReminder = originalSecondReminder;
    }

    validate(titleMap, startDateJCalendar, endDateJCalendar);

    calendarBooking.setCompanyId(user.getCompanyId());
    calendarBooking.setUserId(user.getUserId());
    calendarBooking.setUserName(user.getFullName());
    calendarBooking.setModifiedDate(serviceContext.getModifiedDate(null));
    calendarBooking.setCalendarId(calendarId);
    calendarBooking.setTitleMap(titleMap);
    calendarBooking.setDescriptionMap(descriptionMap);
    calendarBooking.setLocation(location);
    calendarBooking.setStartDate(startDateJCalendar.getTimeInMillis());
    calendarBooking.setEndDate(endDateJCalendar.getTimeInMillis());
    calendarBooking.setAllDay(allDay);
    calendarBooking.setRecurrence(recurrence);
    calendarBooking.setFirstReminder(firstReminder);
    calendarBooking.setFirstReminderType(firstReminderType);
    calendarBooking.setSecondReminder(secondReminder);
    calendarBooking.setSecondReminderType(secondReminderType);

    calendarBookingPersistence.update(calendarBooking, false);

    addChildCalendarBookings(calendarBooking, childCalendarIds, serviceContext);

    // Workflow

    calendarBookingApprovalWorkflow.invokeTransition(
        userId,
        calendarBookingId,
        CalendarBookingWorkflowConstants.toLabel(status),
        serviceContext);

    return calendarBooking;
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static CalendarBooking toModel(CalendarBookingSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    CalendarBooking model = new CalendarBookingImpl();

    model.setUuid(soapModel.getUuid());
    model.setCalendarBookingId(soapModel.getCalendarBookingId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setCalendarId(soapModel.getCalendarId());
    model.setCalendarResourceId(soapModel.getCalendarResourceId());
    model.setParentCalendarBookingId(soapModel.getParentCalendarBookingId());
    model.setTitle(soapModel.getTitle());
    model.setDescription(soapModel.getDescription());
    model.setLocation(soapModel.getLocation());
    model.setStartTime(soapModel.getStartTime());
    model.setEndTime(soapModel.getEndTime());
    model.setAllDay(soapModel.getAllDay());
    model.setRecurrence(soapModel.getRecurrence());
    model.setFirstReminder(soapModel.getFirstReminder());
    model.setFirstReminderType(soapModel.getFirstReminderType());
    model.setSecondReminder(soapModel.getSecondReminder());
    model.setSecondReminderType(soapModel.getSecondReminderType());
    model.setStatus(soapModel.getStatus());
    model.setStatusByUserId(soapModel.getStatusByUserId());
    model.setStatusByUserName(soapModel.getStatusByUserName());
    model.setStatusDate(soapModel.getStatusDate());

    return model;
  }