@@ -19,16 +19,16 @@ package controllers
1919import config .PbikAppConfig
2020import connectors .PbikConnector
2121import controllers .actions .{AuthAction , NoSessionCheckAction }
22- import models ._
22+ import models .*
2323import models .auth .AuthenticatedRequest
2424import models .form .MandatoryRadioButton
2525import models .v1 .IabdType .IabdType
26- import models .v1 .exclusion ._
26+ import models .v1 .exclusion .*
2727import models .v1 .trace .{TracePeopleByNinoRequest , TracePeopleByPersonalDetailsRequest , TracePersonResponse }
2828import play .api .Logging
2929import play .api .data .Form
3030import play .api .i18n .{I18nSupport , Messages , MessagesApi }
31- import play .api .mvc ._
31+ import play .api .mvc .*
3232import services .{BikListService , ExclusionService , SessionService }
3333import uk .gov .hmrc .domain .EmpRef
3434import uk .gov .hmrc .http .HeaderCarrier
@@ -37,10 +37,11 @@ import uk.gov.hmrc.play.bootstrap.controller.WithUnsafeDefaultFormBinding
3737import uk .gov .hmrc .play .bootstrap .frontend .controller .FrontendController
3838import uk .gov .hmrc .play .http .HeaderCarrierConverter
3939import utils .Exceptions .InvalidBikTypeException
40- import utils ._
40+ import utils .*
4141import views .html .ErrorPage
42- import views .html .exclusion ._
42+ import views .html .exclusion .*
4343
44+ import java .lang .ProcessBuilder
4445import javax .inject .{Inject , Singleton }
4546import scala .concurrent .{ExecutionContext , Future }
4647
@@ -65,6 +66,8 @@ class ExclusionListController @Inject() (
6566 ninoExclusionSearchFormView : NinoExclusionSearchForm ,
6667 noNinoExclusionSearchFormView : NoNinoExclusionSearchForm ,
6768 searchResultsView : SearchResults ,
69+ searchResultsMPBIKView : SearchResultsMPBIK ,
70+ declareEmployeeMPBIKView : DeclareEmployeeMPBIK ,
6871 whatNextExclusionView : WhatNextExclusion ,
6972 removalConfirmationView : RemovalConfirmation ,
7073 whatNextRescindView : WhatNextRescind
@@ -433,7 +436,8 @@ class ExclusionListController @Inject() (
433436 (authenticate andThen noSessionCheck).async { implicit request =>
434437 if (exclusionsAllowed) {
435438 val futureResult = formType match {
436- case ControllersReferenceDataCodes .FORM_TYPE_NINO => searchResultsByNino(isCurrentTaxYear, iabdType, formType)
439+ case ControllersReferenceDataCodes .FORM_TYPE_NINO =>
440+ searchResultsByNino(isCurrentTaxYear, iabdType, formType)
437441 case ControllersReferenceDataCodes .FORM_TYPE_NONINO =>
438442 searchResultsByPersonalDetails(isCurrentTaxYear, iabdType, formType)
439443 }
@@ -478,10 +482,11 @@ class ExclusionListController @Inject() (
478482 iabdType : IabdType ,
479483 currentExclusions : List [TracePersonResponse ]
480484 )(implicit request : AuthenticatedRequest [? ]): Result = {
485+ val uniqueMatch : Int = 1
481486 val uniqueListOfMatches : List [TracePersonResponse ] =
482487 exclusionService.searchResultsRemoveAlreadyExcluded(currentExclusions, listOfMatches)
483488 uniqueListOfMatches.size match {
484- case 0 =>
489+ case 0 =>
485490 logger.warn(" [ExclusionListController][searchResultsHandleValidResult] List of un-excluded matches is empty" )
486491 val message = Messages (" ExclusionSearch.Fail.Exists.P" )
487492 if (listOfMatches.nonEmpty) {
@@ -511,17 +516,37 @@ class ExclusionListController @Inject() (
511516 )
512517 )
513518 }
514- case _ =>
515- Ok (
516- searchResultsView(
517- controllersReferenceData.yearRange,
518- isCurrentTaxYear,
519- iabdType,
520- uniqueListOfMatches,
521- formMappings.individualSelectionForm,
522- formType
519+ case matches =>
520+ if (mpbikToggle) {
521+ if (matches == uniqueMatch) { // testing with n < 1
522+ Redirect (
523+ routes.ExclusionListController
524+ .declareEmployeeToExclude(isCurrentTaxYear, iabdType)
525+ )
526+ } else {
527+ Ok (
528+ searchResultsMPBIKView(
529+ controllersReferenceData.yearRange,
530+ isCurrentTaxYear,
531+ iabdType,
532+ uniqueListOfMatches,
533+ formMappings.individualSelectionForm,
534+ formType
535+ )
536+ )
537+ }
538+ } else {
539+ Ok (
540+ searchResultsView(
541+ controllersReferenceData.yearRange,
542+ isCurrentTaxYear,
543+ iabdType,
544+ uniqueListOfMatches,
545+ formMappings.individualSelectionForm,
546+ formType
547+ )
523548 )
524- )
549+ }
525550 }
526551 }
527552
@@ -533,29 +558,53 @@ class ExclusionListController @Inject() (
533558 .bindFromRequest()
534559 .fold(
535560 formWithErrors =>
536- Future .successful(
537- BadRequest (
538- searchResultsView(
539- controllersReferenceData.yearRange,
540- year,
541- iabdType,
542- session.get.listOfMatches.get.pbikExclusionList,
543- formWithErrors,
544- formType
561+ if (mpbikToggle) {
562+ Future .successful(
563+ BadRequest (
564+ searchResultsMPBIKView(
565+ controllersReferenceData.yearRange,
566+ year,
567+ iabdType,
568+ session.get.listOfMatches.get.pbikExclusionList,
569+ formWithErrors,
570+ formType
571+ )
545572 )
546573 )
547- ),
574+ } else {
575+ Future .successful(
576+ BadRequest (
577+ searchResultsView(
578+ controllersReferenceData.yearRange,
579+ year,
580+ iabdType,
581+ session.get.listOfMatches.get.pbikExclusionList,
582+ formWithErrors,
583+ formType
584+ )
585+ )
586+ )
587+ },
548588 values => {
549589 val individualsDetails : Option [TracePersonResponse ] =
550590 session.get.listOfMatches.get.pbikExclusionList
551591 .find(person => person.nationalInsuranceNumber == values.nino)
552- validateRequest(year, iabdType).flatMap { _ =>
553- commitExclusion (
554- year,
555- iabdType,
556- session.get.listOfMatches.get.updatedEmployerOptimisticLock,
557- individualsDetails
592+ if (mpbikToggle && individualsDetails.isDefined) {
593+ Future .successful (
594+ Redirect (
595+ routes. ExclusionListController
596+ .declareEmployeeToExclude(year, iabdType)
597+ )
558598 )
599+ } else {
600+ validateRequest(year, iabdType).flatMap { _ =>
601+ commitExclusion(
602+ year,
603+ iabdType,
604+ session.get.listOfMatches.get.updatedEmployerOptimisticLock,
605+ individualsDetails
606+ )
607+ }
559608 }
560609 }
561610 )
@@ -575,6 +624,22 @@ class ExclusionListController @Inject() (
575624 }
576625 }
577626
627+ def declareEmployeeToExclude (year : String , iabdType : IabdType ): Action [AnyContent ] =
628+ (authenticate andThen noSessionCheck).async { implicit request =>
629+ val resultFuture = for {
630+ _ <- validateRequest(year, iabdType)
631+ session <- sessionService.fetchPbikSession()
632+ } yield Ok (
633+ declareEmployeeMPBIKView(
634+ controllersReferenceData.yearRange,
635+ year,
636+ iabdType,
637+ session.get.listOfMatches.get.pbikExclusionList.head
638+ )
639+ )
640+ controllersReferenceData.responseErrorHandler(resultFuture)
641+ }
642+
578643 def commitExclusion (
579644 year : String ,
580645 iabdType : IabdType ,
0 commit comments