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);
  }