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) {
      }
    }
  }
  @Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext,
      CalendarNotificationTemplate calendarNotificationTemplate)
      throws Exception {

    long userId = portletDataContext.getUserId(calendarNotificationTemplate.getUserUuid());

    Map<Long, Long> calendarIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Calendar.class);

    long calendarId =
        MapUtil.getLong(
            calendarIds,
            calendarNotificationTemplate.getCalendarId(),
            calendarNotificationTemplate.getCalendarId());

    NotificationType notificationType =
        NotificationType.parse(calendarNotificationTemplate.getNotificationType());
    NotificationTemplateType notificationTemplateType =
        NotificationTemplateType.parse(calendarNotificationTemplate.getNotificationTemplateType());

    ServiceContext serviceContext =
        portletDataContext.createServiceContext(calendarNotificationTemplate);

    CalendarNotificationTemplate importedCalendarNotificationTemplate = null;

    String body =
        ExportImportHelperUtil.replaceImportContentReferences(
            portletDataContext,
            calendarNotificationTemplate,
            calendarNotificationTemplate.getBody());

    if (portletDataContext.isDataStrategyMirror()) {
      CalendarNotificationTemplate existingCalendarNotificationTemplate =
          fetchStagedModelByUuidAndGroupId(
              calendarNotificationTemplate.getUuid(), portletDataContext.getScopeGroupId());

      if (existingCalendarNotificationTemplate == null) {
        serviceContext.setUuid(calendarNotificationTemplate.getUuid());

        importedCalendarNotificationTemplate =
            CalendarNotificationTemplateLocalServiceUtil.addCalendarNotificationTemplate(
                userId,
                calendarId,
                notificationType,
                calendarNotificationTemplate.getNotificationTypeSettings(),
                notificationTemplateType,
                calendarNotificationTemplate.getSubject(),
                body,
                serviceContext);
      } else {
        importedCalendarNotificationTemplate =
            CalendarNotificationTemplateLocalServiceUtil.updateCalendarNotificationTemplate(
                existingCalendarNotificationTemplate.getCalendarNotificationTemplateId(),
                calendarNotificationTemplate.getNotificationTypeSettings(),
                calendarNotificationTemplate.getSubject(),
                body,
                serviceContext);
      }
    } else {
      importedCalendarNotificationTemplate =
          CalendarNotificationTemplateLocalServiceUtil.addCalendarNotificationTemplate(
              userId,
              calendarId,
              notificationType,
              calendarNotificationTemplate.getNotificationTypeSettings(),
              notificationTemplateType,
              calendarNotificationTemplate.getSubject(),
              body,
              serviceContext);
    }

    portletDataContext.importClassedModel(
        calendarNotificationTemplate, importedCalendarNotificationTemplate);
  }