Skip to content

Commit a9e3353

Browse files
authored
APB-10738 submit application for risking (#201)
1 parent 62c21f0 commit a9e3353

21 files changed

+312
-144
lines changed

app/uk/gov/hmrc/agentregistration/shared/AgentApplication.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sealed trait AgentApplication:
6161

6262
val hasFinished: Boolean =
6363
applicationState match
64-
case ApplicationState.Submitted => true
64+
case ApplicationState.SentForRisking => true
6565
case ApplicationState.Started => false
6666
case ApplicationState.GrsDataReceived => false
6767

@@ -71,7 +71,7 @@ sealed trait AgentApplication:
7171
applicationState match
7272
case ApplicationState.Started => false
7373
case ApplicationState.GrsDataReceived => true
74-
case ApplicationState.Submitted => true
74+
case ApplicationState.SentForRisking => true
7575

7676
def getUserRole: UserRole = userRole.getOrElse(expectedDataNotDefinedError("userRole"))
7777

app/uk/gov/hmrc/agentregistration/shared/ApplicationState.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ enum ApplicationState:
2424

2525
case Started
2626
case GrsDataReceived
27-
case Submitted
27+
case SentForRisking
2828

2929
object ApplicationState:
3030

3131
given Format[ApplicationState] = JsonFormatsFactory.makeEnumFormat[ApplicationState]
3232

3333
extension (as: ApplicationState)
34-
def sentForRisking: Boolean = as === ApplicationState.Submitted
34+
def sentForRisking: Boolean = as === ApplicationState.SentForRisking

app/uk/gov/hmrc/agentregistrationfrontend/config/AppConfig.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class AppConfig @Inject() (
5757
val emailVerificationBaseUrl: String = servicesConfig.baseUrl("email-verification")
5858
val emailVerificationFrontendBaseUrl: String = ConfigHelper.readConfigAsValidUrlString("urls.email-verification-frontend", configuration)
5959
val agentAssuranceBaseUrl: String = servicesConfig.baseUrl("agent-assurance")
60+
val agentRegistrationRiskingBaseUrl: String = servicesConfig.baseUrl("agent-registration-risking")
6061

6162
val injectEmailVerificationPasscodesPage: Boolean = configuration
6263
.getOptional[Boolean]("inject-email-verification-passcodes-page")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2025 HM Revenue & Customs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package uk.gov.hmrc.agentregistrationfrontend.connectors
18+
19+
import uk.gov.hmrc.agentregistrationfrontend.config.AppConfig
20+
import uk.gov.hmrc.agentregistration.shared.risking.SubmitForRiskingRequest
21+
import uk.gov.hmrc.http.client.HttpClientV2
22+
23+
import javax.inject.Inject
24+
import javax.inject.Singleton
25+
import scala.concurrent.ExecutionContext
26+
27+
/** Connector to the companion backend microservice
28+
*/
29+
@Singleton
30+
class AgentRegistrationRiskingConnector @Inject() (
31+
httpClient: HttpClientV2,
32+
appConfig: AppConfig
33+
)(using
34+
ExecutionContext
35+
)
36+
extends Connector:
37+
38+
def submitForRisking(submitForRiskingRequest: SubmitForRiskingRequest)(using RequestHeader): Future[Unit] =
39+
val url: URL = url"$baseUrl/submit-for-risking/${submitForRiskingRequest.agentApplication.agentApplicationId.value}"
40+
httpClient
41+
.post(url)
42+
.withBody(Json.toJson(submitForRiskingRequest))
43+
.execute[HttpResponse]
44+
.map: response =>
45+
response.status match
46+
case Status.ACCEPTED => ()
47+
case other =>
48+
Errors.throwUpstreamErrorResponse(
49+
httpMethod = "POST",
50+
url = url,
51+
status = other,
52+
response = response,
53+
info = "submit for risking problem"
54+
)
55+
.andLogOnFailure(s"Failed to submit agent application for risking: ${submitForRiskingRequest.agentApplication.agentApplicationId.value}")
56+
57+
private val baseUrl: String = appConfig.agentRegistrationRiskingBaseUrl + "/agent-registration-risking"

app/uk/gov/hmrc/agentregistrationfrontend/controllers/applicant/DeclarationController.scala

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import play.api.mvc.AnyContent
2222
import play.api.mvc.MessagesControllerComponents
2323
import uk.gov.hmrc.agentregistration.shared.AgentApplication
2424
import uk.gov.hmrc.agentregistration.shared.ApplicationState
25-
import uk.gov.hmrc.agentregistration.shared.StateOfAgreement
26-
import uk.gov.hmrc.agentregistration.shared.util.SafeEquals.===
25+
import uk.gov.hmrc.agentregistration.shared.individual.IndividualProvidedDetails
26+
import uk.gov.hmrc.agentregistration.shared.risking.SubmitForRiskingRequest
27+
import uk.gov.hmrc.agentregistrationfrontend.model.taskListStatus
2728
import uk.gov.hmrc.agentregistrationfrontend.action.applicant.ApplicantActions
28-
import uk.gov.hmrc.agentregistrationfrontend.model.TaskListStatus
29-
import uk.gov.hmrc.agentregistrationfrontend.model.TaskStatus
3029
import uk.gov.hmrc.agentregistrationfrontend.services.applicant.AgentApplicationService
30+
import uk.gov.hmrc.agentregistrationfrontend.services.applicant.AgentRegistrationRiskingService
31+
import uk.gov.hmrc.agentregistrationfrontend.services.individual.IndividualProvideDetailsService
3132
import uk.gov.hmrc.agentregistrationfrontend.views.html.applicant.DeclarationPage
3233

3334
import javax.inject.Inject
@@ -38,14 +39,30 @@ class DeclarationController @Inject() (
3839
mcc: MessagesControllerComponents,
3940
actions: ApplicantActions,
4041
view: DeclarationPage,
41-
agentApplicationService: AgentApplicationService
42+
agentApplicationService: AgentApplicationService,
43+
individualProvideDetailsService: IndividualProvideDetailsService,
44+
agentRegistrationRiskingService: AgentRegistrationRiskingService
4245
)
4346
extends FrontendController(mcc, actions):
4447

45-
private val baseAction: ActionBuilderWithData[DataWithApplication] = actions
48+
private type DataWithIndividuals = List[IndividualProvidedDetails] *: AgentApplication *: DataWithAuth
49+
50+
private val baseAction: ActionBuilderWithData[DataWithIndividuals] = actions
4651
.getApplicationInProgress
52+
.refine:
53+
implicit request =>
54+
val agentApplication: AgentApplication = request.get
55+
individualProvideDetailsService
56+
.findAllByApplicationId(agentApplication.agentApplicationId)
57+
.map: individualsList =>
58+
request.add[List[IndividualProvidedDetails]](individualsList)
4759
.ensure(
48-
_.agentApplication.taskListStatus.declaration.canStart,
60+
condition =
61+
implicit request =>
62+
request.agentApplication
63+
.taskListStatus(request.get[List[IndividualProvidedDetails]])
64+
.declaration
65+
.canStart,
4966
implicit request =>
5067
logger.warn("Cannot start declaration whilst tasks are outstanding, redirecting to task list")
5168
Redirect(AppRoutes.apply.TaskListController.show)
@@ -62,57 +79,17 @@ extends FrontendController(mcc, actions):
6279
def submit: Action[AnyContent] = baseAction
6380
.async:
6481
implicit request =>
65-
agentApplicationService
66-
.upsert(
67-
request.agentApplication
68-
.modify(_.applicationState)
69-
.setTo(ApplicationState.Submitted)
70-
).map: _ =>
71-
Redirect(AppRoutes.apply.AgentApplicationController.applicationSubmitted)
72-
73-
extension (agentApplication: AgentApplication)
74-
75-
def taskListStatus: TaskListStatus = {
76-
val contactIsComplete = agentApplication.applicantContactDetails.exists(_.isComplete)
77-
val amlsDetailsCompleted = agentApplication.amlsDetails.exists(_.isComplete)
78-
val agentDetailsIsComplete = agentApplication.agentDetails.exists(_.isComplete)
79-
val hmrcStandardForAgentsAgreed = agentApplication.hmrcStandardForAgentsAgreed === StateOfAgreement.Agreed
80-
TaskListStatus(
81-
contactDetails = TaskStatus(
82-
canStart = true, // Contact details can be started at any time
83-
isComplete = contactIsComplete
84-
),
85-
amlsDetails = TaskStatus(
86-
canStart = true, // AMLS details can be started at any time
87-
isComplete = amlsDetailsCompleted
88-
),
89-
agentDetails = TaskStatus(
90-
canStart = contactIsComplete, // Agent details can be started only when contact details are complete
91-
isComplete = agentDetailsIsComplete
92-
),
93-
hmrcStandardForAgents = TaskStatus(
94-
canStart = true, // HMRC Standard for Agents can be started at any time
95-
isComplete = hmrcStandardForAgentsAgreed
96-
),
97-
listDetails = TaskStatus(
98-
canStart = true, // List details can be started any time
99-
isComplete = false // TODO: implement list details so completion check can be done
100-
),
101-
listShare = TaskStatus(
102-
canStart = false, // List sharing cannot be started until list details are completed
103-
isComplete = false // TODO: implement list share so completion check can be done
104-
),
105-
listTracking = TaskStatus(
106-
canStart = false, // List tracking cannot be started until list share is complete
107-
isComplete = false // TODO: implement list details so completion check can be done
108-
),
109-
declaration = TaskStatus(
110-
canStart =
111-
contactIsComplete
112-
&& amlsDetailsCompleted
113-
&& agentDetailsIsComplete
114-
&& hmrcStandardForAgentsAgreed, // Declaration can be started only when all prior tasks are complete
115-
isComplete = false // Declaration is never "complete" until submission
116-
)
117-
)
118-
}
82+
for
83+
_ <- agentRegistrationRiskingService.submitForRisking(
84+
SubmitForRiskingRequest(
85+
agentApplication = request.agentApplication,
86+
individuals = request.get[List[IndividualProvidedDetails]]
87+
)
88+
)
89+
_ <- agentApplicationService
90+
.upsert(
91+
request.agentApplication
92+
.modify(_.applicationState)
93+
.setTo(ApplicationState.SentForRisking)
94+
)
95+
yield Redirect(AppRoutes.apply.AgentApplicationController.applicationSubmitted)

app/uk/gov/hmrc/agentregistrationfrontend/controllers/applicant/TaskListController.scala

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ import play.api.mvc.AnyContent
2121
import play.api.mvc.MessagesControllerComponents
2222
import uk.gov.hmrc.agentregistration.shared.AgentApplication
2323
import uk.gov.hmrc.agentregistration.shared.BusinessPartnerRecordResponse
24-
import uk.gov.hmrc.agentregistration.shared.StateOfAgreement
2524
import uk.gov.hmrc.agentregistration.shared.hasCheckPassed
2625
import uk.gov.hmrc.agentregistration.shared.individual.IndividualProvidedDetails
27-
import uk.gov.hmrc.agentregistration.shared.individual.ProvidedDetailsState
28-
import uk.gov.hmrc.agentregistration.shared.lists.NumberOfRequiredKeyIndividuals
29-
import uk.gov.hmrc.agentregistration.shared.util.SafeEquals.*
26+
import uk.gov.hmrc.agentregistrationfrontend.model.taskListStatus
3027
import uk.gov.hmrc.agentregistrationfrontend.action.applicant.ApplicantActions
31-
import uk.gov.hmrc.agentregistrationfrontend.model.TaskListStatus
32-
import uk.gov.hmrc.agentregistrationfrontend.model.TaskStatus
33-
import uk.gov.hmrc.agentregistrationfrontend.views.html.applicant.TaskListPage
3428
import uk.gov.hmrc.agentregistrationfrontend.services.individual.IndividualProvideDetailsService
29+
import uk.gov.hmrc.agentregistrationfrontend.views.html.applicant.TaskListPage
3530

3631
import javax.inject.Inject
3732
import javax.inject.Singleton
@@ -74,66 +69,3 @@ extends FrontendController(mcc, actions):
7469
entityName = request.get[BusinessPartnerRecordResponse].getEntityName,
7570
agentApplication = agentApplication
7671
))
77-
78-
extension (agentApplication: AgentApplication)
79-
80-
def taskListStatus(existingList: List[IndividualProvidedDetails]): TaskListStatus = {
81-
val contactIsComplete = agentApplication.applicantContactDetails.exists(_.isComplete)
82-
val amlsDetailsCompleted = agentApplication.amlsDetails.exists(_.isComplete)
83-
val agentDetailsIsComplete = agentApplication.agentDetails.exists(_.isComplete)
84-
val hmrcStandardForAgentsAgreed = agentApplication.hmrcStandardForAgentsAgreed === StateOfAgreement.Agreed
85-
def otherRelevantIndividualsComplete(existingList: List[IndividualProvidedDetails]): Boolean =
86-
agentApplication.hasOtherRelevantIndividuals match
87-
case Some(true) => existingList.exists(!_.isPersonOfControl)
88-
case Some(false) => true
89-
case None => false
90-
def listDetailsCompleted(existingList: List[IndividualProvidedDetails]): Boolean =
91-
agentApplication match
92-
case a: AgentApplication.IsAgentApplicationForDeclaringNumberOfKeyIndividuals =>
93-
NumberOfRequiredKeyIndividuals.isKeyIndividualListComplete(existingList.count(_.isPersonOfControl), a.numberOfRequiredKeyIndividuals)
94-
&& otherRelevantIndividualsComplete(existingList)
95-
case _ => true
96-
val listProgressComplete = listDetailsCompleted(existingList) && existingList.forall(_.hasFinished)
97-
// any state other than Precreated indicates the link has been sent; require the list to be non-empty
98-
val listSharingComplete =
99-
listDetailsCompleted(existingList) &&
100-
existingList.forall(_.providedDetailsState =!= ProvidedDetailsState.Precreated)
101-
TaskListStatus(
102-
contactDetails = TaskStatus(
103-
canStart = true, // Contact details can be started at any time
104-
isComplete = contactIsComplete
105-
),
106-
amlsDetails = TaskStatus(
107-
canStart = true, // AMLS details can be started at any time
108-
isComplete = amlsDetailsCompleted
109-
),
110-
agentDetails = TaskStatus(
111-
canStart = contactIsComplete, // Agent details can be started only when contact details are complete
112-
isComplete = agentDetailsIsComplete
113-
),
114-
hmrcStandardForAgents = TaskStatus(
115-
canStart = true, // HMRC Standard for Agents can be started at any time
116-
isComplete = hmrcStandardForAgentsAgreed
117-
),
118-
listDetails = TaskStatus(
119-
canStart = contactIsComplete, // List details can be started only once we have a contact name
120-
isComplete = listDetailsCompleted(existingList)
121-
),
122-
listShare = TaskStatus(
123-
canStart = listDetailsCompleted(existingList), // List sharing cannot be started until list details are completed
124-
isComplete = listSharingComplete
125-
),
126-
listTracking = TaskStatus(
127-
canStart = listSharingComplete, // List tracking cannot be started until list share is complete
128-
isComplete = listProgressComplete
129-
),
130-
declaration = TaskStatus(
131-
canStart =
132-
contactIsComplete
133-
&& amlsDetailsCompleted
134-
&& agentDetailsIsComplete
135-
&& hmrcStandardForAgentsAgreed, // Declaration can be started only when all prior tasks are complete
136-
isComplete = false // Declaration is never "complete" until submission
137-
)
138-
)
139-
}

0 commit comments

Comments
 (0)