<commit_before>package controllers

import com.google.inject.Inject
import models.CacheKeyPrefix
import models.VehicleAndKeeperLookupFormModel
import models.VrmLockedViewModel
import org.joda.time.DateTime
import play.api.mvc.Action
import play.api.mvc.Controller
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.ClientSideSessionFactory
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichCookies
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichResult
import uk.gov.dvla.vehicles.presentation.common.LogFormats.DVLALogger
import uk.gov.dvla.vehicles.presentation.common.model.BruteForcePreventionModel
import uk.gov.dvla.vehicles.presentation.common.model.VehicleAndKeeperDetailsModel
import utils.helpers.Config
import views.vrm_assign.RelatedCacheKeys.removeCookiesOnExit
import views.vrm_assign.VehicleLookup.TransactionIdCacheKey

final class VrmLocked @Inject()()(implicit clientSideSessionFactory: ClientSideSessionFactory,
                                  config: Config,
                                  dateService: uk.gov.dvla.vehicles.presentation.common.services.DateService
                                  ) extends Controller with DVLALogger {

  def present = Action {
    implicit request =>
      val happyPath = for {
        transactionId <- request.cookies.getString(TransactionIdCacheKey)
        bruteForcePreventionModel <- request.cookies.getModel[BruteForcePreventionModel]
        viewModel <- List(
          request.cookies.getModel[VehicleAndKeeperDetailsModel].map(m => VrmLockedViewModel(m, _: String, _: Long)),
          request.cookies.getModel[VehicleAndKeeperLookupFormModel].map(m => VrmLockedViewModel(m, _: String, _: Long))
        ).flatten.headOption
      } yield {
          logMessage(request.cookies.trackingId, Debug, "VrmLocked - Displaying the vrm locked error page")
          val timeString = bruteForcePreventionModel.dateTimeISOChronology
          val javascriptTimestamp = DateTime.parse(timeString).getMillis
          Ok(views.html.vrm_assign.vrm_locked(transactionId, viewModel(timeString, javascriptTimestamp),
            request.cookies.getModel[VehicleAndKeeperLookupFormModel]))
        }

      happyPath.getOrElse {
        logMessage(request.cookies.trackingId, Debug, "VrmLocked - Can't find cookies")
        Redirect(routes.VehicleLookup.present())
      }
  }

  def exit = Action { implicit request =>
    Redirect(routes.LeaveFeedback.present()).
      discardingCookies(removeCookiesOnExit)
  }
}<commit_msg>US3890 Use VrmLockedBase as per VMs<commit_after>package controllers

import com.google.inject.Inject
import models.CacheKeyPrefix
import models.VehicleAndKeeperLookupFormModel
import models.VrmLockedViewModel
import org.joda.time.DateTime
import play.api.mvc.{Action, Request, Result}
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.ClientSideSessionFactory
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichCookies
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichResult
import uk.gov.dvla.vehicles.presentation.common.controllers.VrmLockedBase
import uk.gov.dvla.vehicles.presentation.common.model.BruteForcePreventionModel
import uk.gov.dvla.vehicles.presentation.common.model.VehicleAndKeeperDetailsModel
import utils.helpers.Config
import views.vrm_assign.RelatedCacheKeys.removeCookiesOnExit
import views.vrm_assign.VehicleLookup.TransactionIdCacheKey

final class VrmLocked @Inject()()(implicit clientSideSessionFactory: ClientSideSessionFactory,
                                  config: Config,
                                  dateService: uk.gov.dvla.vehicles.presentation.common.services.DateService
                                  ) extends VrmLockedBase {

  protected override def presentResult(model: BruteForcePreventionModel)(implicit request: Request[_]): Result = {
    val happyPath = for {
      transactionId <- request.cookies.getString(TransactionIdCacheKey)
      viewModel <- List(
        request.cookies.getModel[VehicleAndKeeperDetailsModel].map(m => VrmLockedViewModel(m, _: String, _: Long)),
        request.cookies.getModel[VehicleAndKeeperLookupFormModel].map(m => VrmLockedViewModel(m, _: String, _: Long))
      ).flatten.headOption
    } yield {
      logMessage(request.cookies.trackingId, Debug, "VrmLocked - Displaying the vrm locked error page")
      val timeString = model.dateTimeISOChronology
      val javascriptTimestamp = DateTime.parse(timeString).getMillis
      Ok(views.html.vrm_assign.vrm_locked(transactionId, viewModel(timeString, javascriptTimestamp),
        request.cookies.getModel[VehicleAndKeeperLookupFormModel]))
    }

    happyPath.getOrElse {
      logMessage(request.cookies.trackingId, Debug, "VrmLocked - Can't find cookies")
      Redirect(routes.VehicleLookup.present())
    }
  }

  protected override def missingBruteForcePreventionCookie(implicit request: Request[_]): Result = {
    logMessage(request.cookies.trackingId(), Debug,
      s"Missing BruceForcePreventionCookie. Redirecting to ${routes.VehicleLookup.present()}")
    Redirect(routes.VehicleLookup.present())
  }

  protected override def exitResult(implicit request: Request[_]): Result = {
    Redirect(routes.LeaveFeedback.present()).
      discardingCookies(removeCookiesOnExit)
  }

  // Not used for Assign
  protected override def tryAnotherResult(implicit request: Request[_]): Result = NotFound
}
{'fraction_non_alphanumeric': 0.08670415381824778, 'fraction_numerical': 0.0007255577725376383, 'mean_word_length': 4.216650898770104, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2339024', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1561, 'n_words': 245}