public ProjectImportResults doImport(
      final JiraServiceContext jiraServiceContext,
      final ProjectImportOptions projectImportOptions,
      final BackupProject backupProject,
      final BackupSystemInformation backupSystemInformation,
      final ProjectImportData projectImportData,
      final TaskProgressInterval taskProgressInterval) {
    Null.not("projectImportOptions", projectImportOptions);
    Null.not("backupSystemInformation", backupSystemInformation);
    Null.not("projectImportData", projectImportData);
    Null.not("backupProject", backupProject);
    validateJiraServiceContext(jiraServiceContext);
    final ErrorCollection errorCollection = jiraServiceContext.getErrorCollection();
    final I18nHelper i18n = jiraServiceContext.getI18nBean();

    // Get the expected number of users that we will create
    final int usersToCreate =
        (isExternalUserManagementEnabled())
            ? 0
            : projectImportData
                .getProjectImportMapper()
                .getUserMapper()
                .getUsersToAutoCreate()
                .size();

    final ProjectImportResults projectImportResults =
        getInitialImportResults(projectImportData, i18n, usersToCreate);

    // The user must have the system administrator permission to perform a project import
    if (!userHasSysAdminPermission(jiraServiceContext.getUser())) {
      errorCollection.addErrorMessage(getText(i18n, "admin.errors.project.import.must.be.admin"));
      return projectImportResults;
    }

    try {
      log.info(
          "Starting project import for project '" + backupProject.getProject().getKey() + "'.");
      if (isExternalUserManagementEnabled()) {
        log.info("External user management is enabled. No users will be imported.");
      } else {
        log.info(
            "Creating missing users. Attempting to create "
                + projectImportResults.getExpectedUsersCreatedCount()
                + " users.");
        // External User Management is OFF - create missing users that we can.
        // This will fill in subtask progress from 0% - 10% of the doImport task
        final TaskProgressInterval subInterval = getSubInterval(taskProgressInterval, 0, 10);
        projectImportManager.createMissingUsers(
            projectImportData.getProjectImportMapper().getUserMapper(),
            projectImportResults,
            subInterval);
        log.info(
            "Finished creating missing users. "
                + projectImportResults.getUsersCreatedCount()
                + " users created.");
      }

      // Create/Update the project, its details, components, versions, role membership
      try {
        // This will fill in subtask progress from 10% - 20% of the doImport task (Allow for
        // creating lots of Project Role members)
        final TaskProgressInterval subInterval = getSubInterval(taskProgressInterval, 10, 20);
        projectImportManager.importProject(
            projectImportOptions,
            projectImportData.getProjectImportMapper(),
            backupProject,
            projectImportResults,
            subInterval);
      } catch (final AbortImportException e) {
        // Add an error message
        errorCollection.addErrorMessage(
            i18n.getText("admin.error.project.import.project.update.error"));
        throw e;
      }

      // Import the issues and all their related values and reIndex the project once it is done
      try {
        // This will fill in subtask progress from 20% - 100% of the doImport task (Allow for
        // creating lots of Project Role members)
        final TaskProgressInterval subInterval = getSubInterval(taskProgressInterval, 20, 100);
        projectImportManager.doImport(
            projectImportOptions,
            projectImportData,
            backupProject,
            backupSystemInformation,
            projectImportResults,
            subInterval,
            i18n,
            jiraServiceContext.getUser());
        // Only set the completed flag once everything has finished
        projectImportResults.setImportCompleted(true);
      } catch (final IOException e) {
        log.error(
            "There was a problem accessing the partitioned XML files when performing a project import.",
            e);
        errorCollection.addErrorMessage(
            getText(
                i18n,
                "admin.errors.project.import.problem.reading.partitioned.xml",
                e.getMessage()));
      } catch (final AbortImportException aie) {
        // Note that AbortImportException extends SAXException, so we need to catch and handle
        // AbortImportException first.
        log.error("The import was aborted because there were too many errors.");
        errorCollection.addErrorMessage(i18n.getText("admin.errors.project.import.import.error"));
      } catch (final SAXException e) {
        log.error(
            "There was a problem accessing the partitioned XML files when performing a project import.",
            e);
        errorCollection.addErrorMessage(
            getText(
                i18n, "admin.errors.project.import.sax.problem.partitioned.xml", e.getMessage()));
      } catch (final IndexException e) {
        log.error("There was a problem reIndexing the newly imported project.", e);
        errorCollection.addErrorMessage(
            i18n.getText("admin.errors.project.import.reindex.problem", e.getMessage()));
      }
      log.info(
          "Finished project import for project '" + backupProject.getProject().getKey() + "'.");

    } catch (final AbortImportException aie) {
      log.error("The import was aborted because there were too many errors.");
      errorCollection.addErrorMessage(i18n.getText("admin.errors.project.import.import.error"));
    }

    // Clean up the temporary "partitioned" XML files.
    projectImportData.getTemporaryFiles().deleteTempFiles();

    // Always record the end of the import.
    projectImportResults.setEndTime(System.currentTimeMillis());
    logImportResults(projectImportResults);
    return projectImportResults;
  }