@Override
  public CalendarResource addCalendarResource(
      long userId,
      long groupId,
      long classNameId,
      long classPK,
      String classUuid,
      String code,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException {

    // Calendar resource

    User user = userPersistence.findByPrimaryKey(userId);

    long calendarResourceId = counterLocalService.increment();

    if (classNameId == classNameLocalService.getClassNameId(CalendarResource.class)) {

      classPK = calendarResourceId;
    }

    if (PortletPropsValues.CALENDAR_RESOURCE_FORCE_AUTOGENERATE_CODE || Validator.isNull(code)) {

      code = String.valueOf(calendarResourceId);
    } else {
      code = code.trim();
      code = StringUtil.toUpperCase(code);
    }

    Date now = new Date();

    validate(groupId, classNameId, classPK, code, nameMap);

    CalendarResource calendarResource = calendarResourcePersistence.create(calendarResourceId);

    calendarResource.setUuid(serviceContext.getUuid());
    calendarResource.setGroupId(groupId);
    calendarResource.setCompanyId(user.getCompanyId());
    calendarResource.setUserId(user.getUserId());
    calendarResource.setUserName(user.getFullName());
    calendarResource.setCreateDate(serviceContext.getCreateDate(now));
    calendarResource.setModifiedDate(serviceContext.getModifiedDate(now));
    calendarResource.setClassNameId(classNameId);
    calendarResource.setClassPK(classPK);
    calendarResource.setClassUuid(classUuid);
    calendarResource.setCode(code);
    calendarResource.setNameMap(nameMap);
    calendarResource.setDescriptionMap(descriptionMap);
    calendarResource.setActive(active);

    calendarResourcePersistence.update(calendarResource);

    // Resources

    resourceLocalService.addModelResources(calendarResource, serviceContext);

    // Calendar

    if (!ExportImportThreadLocal.isImportInProcess()) {
      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      calendarLocalService.addCalendar(
          userId,
          calendarResource.getGroupId(),
          calendarResourceId,
          nameMap,
          descriptionMap,
          calendarResource.getTimeZoneId(),
          PortletPropsValues.CALENDAR_COLOR_DEFAULT,
          true,
          false,
          false,
          serviceContext);
    }

    // Asset

    updateAsset(
        calendarResource.getUserId(),
        calendarResource,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    return calendarResource;
  }