@@ -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 }
@@ -511,17 +515,37 @@ class ExclusionListController @Inject() (
511515 )
512516 )
513517 }
514- case _ =>
515- Ok (
516- searchResultsView(
517- controllersReferenceData.yearRange,
518- isCurrentTaxYear,
519- iabdType,
520- uniqueListOfMatches,
521- formMappings.individualSelectionForm,
522- formType
518+ case n =>
519+ if (mpbikToggle) {
520+ if (n == 1 ) { // testing with n < 1
521+ Redirect (
522+ routes.ExclusionListController
523+ .declareEmployeeToExclude(isCurrentTaxYear, iabdType)
524+ )
525+ } else {
526+ Ok (
527+ searchResultsMPBIKView(
528+ controllersReferenceData.yearRange,
529+ isCurrentTaxYear,
530+ iabdType,
531+ uniqueListOfMatches,
532+ formMappings.individualSelectionForm,
533+ formType
534+ )
535+ )
536+ }
537+ } else {
538+ Ok (
539+ searchResultsView(
540+ controllersReferenceData.yearRange,
541+ isCurrentTaxYear,
542+ iabdType,
543+ uniqueListOfMatches,
544+ formMappings.individualSelectionForm,
545+ formType
546+ )
523547 )
524- )
548+ }
525549 }
526550 }
527551
@@ -533,29 +557,53 @@ class ExclusionListController @Inject() (
533557 .bindFromRequest()
534558 .fold(
535559 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
560+ if (mpbikToggle) {
561+ Future .successful(
562+ BadRequest (
563+ searchResultsMPBIKView(
564+ controllersReferenceData.yearRange,
565+ year,
566+ iabdType,
567+ session.get.listOfMatches.get.pbikExclusionList,
568+ formWithErrors,
569+ formType
570+ )
545571 )
546572 )
547- ),
573+ } else {
574+ Future .successful(
575+ BadRequest (
576+ searchResultsView(
577+ controllersReferenceData.yearRange,
578+ year,
579+ iabdType,
580+ session.get.listOfMatches.get.pbikExclusionList,
581+ formWithErrors,
582+ formType
583+ )
584+ )
585+ )
586+ },
548587 values => {
549588 val individualsDetails : Option [TracePersonResponse ] =
550589 session.get.listOfMatches.get.pbikExclusionList
551590 .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
591+ if (mpbikToggle && individualsDetails.isDefined) {
592+ Future .successful (
593+ Redirect (
594+ routes. ExclusionListController
595+ .declareEmployeeToExclude(year, iabdType)
596+ )
558597 )
598+ } else {
599+ validateRequest(year, iabdType).flatMap { _ =>
600+ commitExclusion(
601+ year,
602+ iabdType,
603+ session.get.listOfMatches.get.updatedEmployerOptimisticLock,
604+ individualsDetails
605+ )
606+ }
559607 }
560608 }
561609 )
@@ -575,6 +623,22 @@ class ExclusionListController @Inject() (
575623 }
576624 }
577625
626+ def declareEmployeeToExclude (year : String , iabdType : IabdType ): Action [AnyContent ] =
627+ (authenticate andThen noSessionCheck).async { implicit request =>
628+ val resultFuture = for {
629+ _ <- validateRequest(year, iabdType)
630+ session <- sessionService.fetchPbikSession()
631+ } yield Ok (
632+ declareEmployeeMPBIKView(
633+ controllersReferenceData.yearRange,
634+ year,
635+ iabdType,
636+ session.get.listOfMatches.get.pbikExclusionList.head
637+ )
638+ )
639+ controllersReferenceData.responseErrorHandler(resultFuture)
640+ }
641+
578642 def commitExclusion (
579643 year : String ,
580644 iabdType : IabdType ,
0 commit comments