@@ -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 whatNextExclusionMpbikView : WhatNextExclusionMpbik ,
7073 removalConfirmationView : RemovalConfirmation ,
@@ -434,7 +437,8 @@ class ExclusionListController @Inject() (
434437 (authenticate andThen noSessionCheck).async { implicit request =>
435438 if (exclusionsAllowed) {
436439 val futureResult = formType match {
437- case ControllersReferenceDataCodes .FORM_TYPE_NINO => searchResultsByNino(isCurrentTaxYear, iabdType, formType)
440+ case ControllersReferenceDataCodes .FORM_TYPE_NINO =>
441+ searchResultsByNino(isCurrentTaxYear, iabdType, formType)
438442 case ControllersReferenceDataCodes .FORM_TYPE_NONINO =>
439443 searchResultsByPersonalDetails(isCurrentTaxYear, iabdType, formType)
440444 }
@@ -479,10 +483,11 @@ class ExclusionListController @Inject() (
479483 iabdType : IabdType ,
480484 currentExclusions : List [TracePersonResponse ]
481485 )(implicit request : AuthenticatedRequest [? ]): Result = {
486+ val uniqueMatch : Int = 1
482487 val uniqueListOfMatches : List [TracePersonResponse ] =
483488 exclusionService.searchResultsRemoveAlreadyExcluded(currentExclusions, listOfMatches)
484489 uniqueListOfMatches.size match {
485- case 0 =>
490+ case 0 =>
486491 logger.warn(" [ExclusionListController][searchResultsHandleValidResult] List of un-excluded matches is empty" )
487492 val message = Messages (" ExclusionSearch.Fail.Exists.P" )
488493 if (listOfMatches.nonEmpty) {
@@ -512,17 +517,37 @@ class ExclusionListController @Inject() (
512517 )
513518 )
514519 }
515- case _ =>
516- Ok (
517- searchResultsView(
518- controllersReferenceData.yearRange,
519- isCurrentTaxYear,
520- iabdType,
521- uniqueListOfMatches,
522- formMappings.individualSelectionForm,
523- formType
520+ case matches =>
521+ if (mpbikToggle) {
522+ if (matches == uniqueMatch) { // testing with n < 1
523+ Redirect (
524+ routes.ExclusionListController
525+ .declareEmployeeToExclude(isCurrentTaxYear, iabdType)
526+ )
527+ } else {
528+ Ok (
529+ searchResultsMPBIKView(
530+ controllersReferenceData.yearRange,
531+ isCurrentTaxYear,
532+ iabdType,
533+ uniqueListOfMatches,
534+ formMappings.individualSelectionForm,
535+ formType
536+ )
537+ )
538+ }
539+ } else {
540+ Ok (
541+ searchResultsView(
542+ controllersReferenceData.yearRange,
543+ isCurrentTaxYear,
544+ iabdType,
545+ uniqueListOfMatches,
546+ formMappings.individualSelectionForm,
547+ formType
548+ )
524549 )
525- )
550+ }
526551 }
527552 }
528553
@@ -534,29 +559,53 @@ class ExclusionListController @Inject() (
534559 .bindFromRequest()
535560 .fold(
536561 formWithErrors =>
537- Future .successful(
538- BadRequest (
539- searchResultsView(
540- controllersReferenceData.yearRange,
541- year,
542- iabdType,
543- session.get.listOfMatches.get.pbikExclusionList,
544- formWithErrors,
545- formType
562+ if (mpbikToggle) {
563+ Future .successful(
564+ BadRequest (
565+ searchResultsMPBIKView(
566+ controllersReferenceData.yearRange,
567+ year,
568+ iabdType,
569+ session.get.listOfMatches.get.pbikExclusionList,
570+ formWithErrors,
571+ formType
572+ )
546573 )
547574 )
548- ),
575+ } else {
576+ Future .successful(
577+ BadRequest (
578+ searchResultsView(
579+ controllersReferenceData.yearRange,
580+ year,
581+ iabdType,
582+ session.get.listOfMatches.get.pbikExclusionList,
583+ formWithErrors,
584+ formType
585+ )
586+ )
587+ )
588+ },
549589 values => {
550590 val individualsDetails : Option [TracePersonResponse ] =
551591 session.get.listOfMatches.get.pbikExclusionList
552592 .find(person => person.nationalInsuranceNumber == values.nino)
553- validateRequest(year, iabdType).flatMap { _ =>
554- commitExclusion (
555- year,
556- iabdType,
557- session.get.listOfMatches.get.updatedEmployerOptimisticLock,
558- individualsDetails
593+ if (mpbikToggle && individualsDetails.isDefined) {
594+ Future .successful (
595+ Redirect (
596+ routes. ExclusionListController
597+ .declareEmployeeToExclude(year, iabdType)
598+ )
559599 )
600+ } else {
601+ validateRequest(year, iabdType).flatMap { _ =>
602+ commitExclusion(
603+ year,
604+ iabdType,
605+ session.get.listOfMatches.get.updatedEmployerOptimisticLock,
606+ individualsDetails
607+ )
608+ }
560609 }
561610 }
562611 )
@@ -576,6 +625,22 @@ class ExclusionListController @Inject() (
576625 }
577626 }
578627
628+ def declareEmployeeToExclude (year : String , iabdType : IabdType ): Action [AnyContent ] =
629+ (authenticate andThen noSessionCheck).async { implicit request =>
630+ val resultFuture = for {
631+ _ <- validateRequest(year, iabdType)
632+ session <- sessionService.fetchPbikSession()
633+ } yield Ok (
634+ declareEmployeeMPBIKView(
635+ controllersReferenceData.yearRange,
636+ year,
637+ iabdType,
638+ session.get.listOfMatches.get.pbikExclusionList.head
639+ )
640+ )
641+ controllersReferenceData.responseErrorHandler(resultFuture)
642+ }
643+
579644 def commitExclusion (
580645 year : String ,
581646 iabdType : IabdType ,
0 commit comments