protected Map<Locale, String> getCalendarResourceNameMap(
      PortletDataContext portletDataContext, CalendarResource calendarResource) throws Exception {

    String calendarResourceName = calendarResource.getName(LocaleUtil.getDefault());

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

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

      return calendarResource.getNameMap();
    }

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

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

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

    return calendarResourceNameMap;
  }
  @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;
  }
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, CalendarResource calendarResource) throws Exception {

    prepareLanguagesForImport(calendarResource);

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

    StagedModelDataHandlerUtil.importReferenceStagedModels(
        portletDataContext, calendarResource, Calendar.class);

    long classPK = getClassPK(portletDataContext, calendarResource, userId);
    Map<Locale, String> calendarResourceNameMap =
        getCalendarResourceNameMap(portletDataContext, calendarResource);

    ServiceContext serviceContext = portletDataContext.createServiceContext(calendarResource);

    CalendarResource importedCalendarResource = null;

    if (portletDataContext.isDataStrategyMirror()) {
      CalendarResource existingCalendarResource =
          CalendarResourceLocalServiceUtil.fetchCalendarResourceByUuidAndGroupId(
              calendarResource.getUuid(), portletDataContext.getScopeGroupId());

      if (existingCalendarResource == null) {
        existingCalendarResource =
            CalendarResourceLocalServiceUtil.fetchCalendarResource(
                calendarResource.getClassNameId(), classPK);
      }

      if (existingCalendarResource == null) {
        serviceContext.setUuid(calendarResource.getUuid());

        importedCalendarResource =
            CalendarResourceLocalServiceUtil.addCalendarResource(
                userId,
                portletDataContext.getScopeGroupId(),
                calendarResource.getClassNameId(),
                classPK,
                calendarResource.getClassUuid(),
                calendarResource.getCode(),
                calendarResourceNameMap,
                calendarResource.getDescriptionMap(),
                calendarResource.isActive(),
                serviceContext);
      } else {
        importedCalendarResource =
            CalendarResourceLocalServiceUtil.updateCalendarResource(
                existingCalendarResource.getCalendarResourceId(),
                calendarResource.getNameMap(),
                calendarResource.getDescriptionMap(),
                calendarResource.isActive(),
                serviceContext);
      }
    } else {
      importedCalendarResource =
          CalendarResourceLocalServiceUtil.addCalendarResource(
              userId,
              portletDataContext.getScopeGroupId(),
              calendarResource.getClassNameId(),
              classPK,
              calendarResource.getClassUuid(),
              calendarResource.getCode(),
              calendarResourceNameMap,
              calendarResource.getDescriptionMap(),
              calendarResource.isActive(),
              serviceContext);
    }

    updateCalendars(portletDataContext, calendarResource, importedCalendarResource);

    portletDataContext.importClassedModel(calendarResource, importedCalendarResource);
  }