override fun run()

in intellij-plugin/educational-core/src/com/jetbrains/edu/learning/stepik/hyperskill/actions/DownloadDataset.kt [60:100]


  override fun run(indicator: ProgressIndicator) {
    if (!DownloadDatasetState.getInstance(project).isLocked) {
      processError(project, "Download dataset task is not locked")
      return
    }

    indicator.isIndeterminate = true

    if (task.id == 0) {
      processError(project, "Task is corrupted, there is no task id")
      return
    }

    val connector = task.getStepikBasedConnector()
    val attemptResult = if (submitNewAttempt) {
      connector.postAttempt(task)
    }
    else {
      connector.getActiveAttemptOrPostNew(task)
    }
    val retrievedAttempt = attemptResult.onError { error ->
      processError(project, "Error getting attempt for task with ${task.id} id: $error")
      return
    }
    ProgressManager.checkCanceled()

    val dataset = execCancelable { connector.getDataset(retrievedAttempt) }?.onError { error ->
      processError(project, "Error getting dataset for attempt with ${retrievedAttempt.id} id: $error")
      null
    } ?: return
    ProgressManager.checkCanceled()

    attempt = retrievedAttempt
    downloadedDataset = try {
      task.getOrCreateDataset(project, dataset)
    }
    catch (e: IOException) {
      processError(project, exception = e)
      return
    }
  }