protected Map<Locale, String> getCalendarNameMap(
      PortletDataContext portletDataContext, Calendar calendar) throws Exception {

    String calendarName = calendar.getName(LocaleUtil.getDefault());

    Group sourceGroup = GroupLocalServiceUtil.fetchGroup(portletDataContext.getSourceGroupId());

    if ((sourceGroup == null) || !calendarName.equals(sourceGroup.getDescriptiveName())) {

      return calendar.getNameMap();
    }

    Map<Locale, String> calendarNameMap = new HashMap<>();

    Group scopeGroup = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId());

    calendarNameMap.put(LocaleUtil.getDefault(), scopeGroup.getName());

    return calendarNameMap;
  }
  @Override
  protected Document doGetDocument(Calendar calendar) throws Exception {
    Document document = getBaseModelDocument(CLASS_NAME, calendar);

    document.addLocalizedText(Field.DESCRIPTION, calendar.getDescriptionMap());
    document.addLocalizedText(Field.NAME, calendar.getNameMap());
    document.addKeyword("calendarId", calendar.getCalendarId());

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    document.addText("defaultLanguageId", defaultLanguageId);

    CalendarResource calendarResource = calendar.getCalendarResource();

    document.addLocalizedText("resourceName", calendarResource.getNameMap());

    return document;
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, Calendar calendar)
      throws Exception {

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

    Map<Long, Long> calendarResourceIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(CalendarResource.class);

    long calendarResourceId =
        MapUtil.getLong(
            calendarResourceIds,
            calendar.getCalendarResourceId(),
            calendar.getCalendarResourceId());

    Map<Locale, String> calendarNameMap = getCalendarNameMap(portletDataContext, calendar);

    ServiceContext serviceContext = portletDataContext.createServiceContext(calendar);

    Calendar importedCalendar = null;

    if (portletDataContext.isDataStrategyMirror()) {
      Calendar existingCalendar =
          fetchStagedModelByUuidAndGroupId(
              calendar.getUuid(), portletDataContext.getScopeGroupId());

      if (existingCalendar == null) {
        serviceContext.setUuid(calendar.getUuid());

        importedCalendar =
            CalendarLocalServiceUtil.addCalendar(
                userId,
                portletDataContext.getScopeGroupId(),
                calendarResourceId,
                calendarNameMap,
                calendar.getDescriptionMap(),
                calendar.getTimeZoneId(),
                calendar.getColor(),
                calendar.isDefaultCalendar(),
                calendar.isEnableComments(),
                calendar.isEnableRatings(),
                serviceContext);
      } else {
        importedCalendar =
            CalendarLocalServiceUtil.updateCalendar(
                existingCalendar.getCalendarId(),
                calendar.getNameMap(),
                calendar.getDescriptionMap(),
                calendar.getTimeZoneId(),
                calendar.getColor(),
                calendar.isDefaultCalendar(),
                calendar.isEnableComments(),
                calendar.isEnableRatings(),
                serviceContext);
      }
    } else {
      importedCalendar =
          CalendarLocalServiceUtil.addCalendar(
              userId,
              portletDataContext.getScopeGroupId(),
              calendarResourceId,
              calendarNameMap,
              calendar.getDescriptionMap(),
              calendar.getTimeZoneId(),
              calendar.getColor(),
              calendar.isDefaultCalendar(),
              calendar.isEnableComments(),
              calendar.isEnableRatings(),
              serviceContext);
    }

    portletDataContext.importClassedModel(calendar, importedCalendar);
  }