public File exportLayoutsAsFile(
      long groupId,
      boolean privateLayout,
      long[] layoutIds,
      Map<String, String[]> parameterMap,
      Date startDate,
      Date endDate)
      throws Exception {

    try {
      ExportImportThreadLocal.setLayoutExportInProcess(true);

      return doExportLayoutsAsFile(
          groupId, privateLayout, layoutIds, parameterMap, startDate, endDate);
    } finally {
      ExportImportThreadLocal.setLayoutExportInProcess(false);
    }
  }
  @Override
  public BackgroundTaskResult execute(BackgroundTask backgroundTask) {
    ExportImportConfiguration exportImportConfiguration =
        getExportImportConfiguration(backgroundTask);

    clearBackgroundTaskStatus(backgroundTask);

    MissingReferences missingReferences = null;

    try {
      ExportImportThreadLocal.setLayoutStagingInProcess(true);

      ExportImportLifecycleManager.fireExportImportLifecycleEvent(
          ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_REMOTE_STARTED,
          exportImportConfiguration);

      missingReferences =
          TransactionHandlerUtil.invoke(
              transactionAttribute,
              new LayoutRemoteStagingCallable(
                  backgroundTask.getBackgroundTaskId(), exportImportConfiguration));

      ExportImportLifecycleManager.fireExportImportLifecycleEvent(
          ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_REMOTE_SUCCEEDED,
          exportImportConfiguration);
    } catch (Throwable t) {
      ExportImportLifecycleManager.fireExportImportLifecycleEvent(
          ExportImportLifecycleConstants.EVENT_PUBLICATION_LAYOUT_REMOTE_FAILED,
          exportImportConfiguration);

      if (_log.isDebugEnabled()) {
        _log.debug(t, t);
      } else if (_log.isWarnEnabled()) {
        _log.warn("Unable to publish layout: " + t.getMessage());
      }

      throw new SystemException(t);
    } finally {
      ExportImportThreadLocal.setLayoutStagingInProcess(false);
    }

    return processMissingReferences(backgroundTask.getBackgroundTaskId(), missingReferences);
  }
  public void validate(long groupId, String className, long[] categoryIds, String[] tagNames)
      throws PortalException, SystemException {

    if (ExportImportThreadLocal.isImportInProcess()) {
      return;
    }

    AssetEntryValidator validator =
        (AssetEntryValidator) InstancePool.get(PropsValues.ASSET_ENTRY_VALIDATOR);

    validator.validate(groupId, className, categoryIds, tagNames);
  }
  @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;
  }