<commit_before>package controllers

import play.api.mvc._
import models.view._
import services.submission.ClaimSubmissionService
import scala.concurrent.ExecutionContext
import ExecutionContext.Implicits.global
import play.api.{http, Logger}
import utils.helpers.{UnavailableTransactionIdException, UniqueTransactionId}
import services.submission.ClaimSubmission

object Submission extends Controller with CachedClaim {
  def submit = claiming {
    implicit claim => implicit request =>

    try {
      val id = UniqueTransactionId()
      Logger.info(s"Retrieved Id : $id")
      val claimXml = ClaimSubmission(claim, id).buildDwpClaim
      Async {
        ClaimSubmissionService.submitClaim(claimXml).map(
          response => {
            response.status match {
              case http.Status.OK =>
                val responseStr = response.body
                Logger.info(s"Received response : $responseStr")
                val responseXml = scala.xml.XML.loadString(responseStr)
                val result = (responseXml \\ "result").text
                Logger.info(s"Received result : $result")
                result match {
                  case "response" => Redirect(routes.ThankYou.present())
                  case "acknowledgement" => {
                    // Todo : put the correlation id into cache for retry
                    Redirect("/consentAndDeclaration/error")
                  }
                  case _ => Redirect("/error")
                }
              case http.Status.BAD_REQUEST =>
                Logger.error(s"BAD_REQUEST : ${response.status} : ${response.toString}")
                Redirect("/error")
              case http.Status.REQUEST_TIMEOUT =>
                Logger.error(s"REQUEST_TIMEOUT : ${response.status} : ${response.toString}")
                Redirect("/error")
              case http.Status.INTERNAL_SERVER_ERROR =>
                Logger.error(s"INTERNAL_SERVER_ERROR : ${response.status} : ${response.toString}")
                Redirect("/error")
              case _ =>
                Logger.error(s"Unexpected response ! ${response.status} : ${response.toString}")
                Redirect("/error")
            }
          }<commit_msg>store correlationId ready for retry<commit_after>package controllers

import play.api.mvc._
import models.view._
import services.submission.ClaimSubmissionService
import scala.concurrent.ExecutionContext
import ExecutionContext.Implicits.global
import play.api.{http, Logger}
import utils.helpers.{UnavailableTransactionIdException, UniqueTransactionId}
import services.submission.ClaimSubmission

object Submission extends Controller with CachedClaim {
  def submit = claiming {
    implicit claim => implicit request =>

    try {
      val id = UniqueTransactionId()
      Logger.info(s"Retrieved Id : $id")
      val claimXml = ClaimSubmission(claim, id).buildDwpClaim
      Async {
        ClaimSubmissionService.submitClaim(claimXml).map(
          response => {
            response.status match {
              case http.Status.OK =>
                val responseStr = response.body
                Logger.info(s"Received response : $responseStr")
                val responseXml = scala.xml.XML.loadString(responseStr)
                val result = (responseXml \\ "result").text
                Logger.info(s"Received result : $result")
                result match {
                  case "response" => Redirect(routes.ThankYou.present())
                  case "acknowledgement" => {
                    val correlationID = (response.xml \\ "CorrelationID").text
                    Redirect("/consentAndDeclaration/error").withSession("cid" -> correlationID)
                  }
                  case _ => Redirect("/error")
                }
              case http.Status.BAD_REQUEST =>
                Logger.error(s"BAD_REQUEST : ${response.status} : ${response.toString}")
                Redirect("/error")
              case http.Status.REQUEST_TIMEOUT =>
                Logger.error(s"REQUEST_TIMEOUT : ${response.status} : ${response.toString}")
                Redirect("/error")
              case http.Status.INTERNAL_SERVER_ERROR =>
                Logger.error(s"INTERNAL_SERVER_ERROR : ${response.status} : ${response.toString}")
                Redirect("/error")
              case _ =>
                Logger.error(s"Unexpected response ! ${response.status} : ${response.toString}")
                Redirect("/error")
            }
          }
{'fraction_non_alphanumeric': 0.10274125250724314, 'fraction_numerical': 0.0, 'mean_word_length': 2.073972602739726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '109928', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1067, 'n_words': 220}