override fun execute()

in intellij-plugin/educational-core/src/com/jetbrains/edu/learning/stepik/hyperskill/HyperskillRestService.kt [42:85]


  override fun execute(urlDecoder: QueryStringDecoder,
                       request: FullHttpRequest,
                       context: ChannelHandlerContext): String? {
    val uri = urlDecoder.uri()
    val hyperskillConnector = HyperskillConnector.getInstance()
    if (hyperskillConnector.getServicePattern("/info").matcher(uri).matches()) {
      sendPluginInfoResponse(request, context)
      return null
    }

    if (hyperskillConnector.getOAuthPattern("\\?error=(\\w+)").matcher(uri).matches()) {
      return sendErrorResponse(request, context, "Failed to login")
    }

    if (hyperskillConnector.getOAuthPattern().matcher(uri).matches()) {
      val code = getStringParameter(CODE_ARGUMENT, urlDecoder)!! // cannot be null because of pattern
      val success = hyperskillConnector.login(code)
      if (success) {
        LOG.info("$platformName: OAuth code is handled")
        val pageContent = getInternalTemplateText("hyperskill.redirectPage.html")
        createResponse(pageContent).send(context.channel(), request)
        return null
      }
      return sendErrorResponse(request, context, "Failed to login using provided code")
    }

    if (hasOpenDialogs(EduNames.JBA)) {
      sendOk(request, context)
      return null
    }

    if (hyperskillConnector.getServicePattern("""\?$STAGE_ID=.+&$PROJECT_ID=.+""").matcher(uri).matches()) {
      val userId = getIntParameter(USER_ID, urlDecoder)
      return withHyperskillAuthorization(userId) { openStage(urlDecoder, request, context) }
    }

    if (hyperskillConnector.getServicePattern("""\?$STEP_ID=.+""").matcher(uri).matches()) {
      val userId = getIntParameter(USER_ID, urlDecoder)
      return withHyperskillAuthorization(userId) { openProblem(urlDecoder, request, context) }
    }

    sendStatus(HttpResponseStatus.BAD_REQUEST, false, context.channel())
    return "Unknown command: $uri"
  }