-
Notifications
You must be signed in to change notification settings - Fork 0
[APB-11045][APB-APB-11015] Success and FailedNonFixable emails #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gitwojciech
wants to merge
47
commits into
main
Choose a base branch
from
APB-11045
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 44 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7c02966
[APB-11100] model
paweldigital 4477295
[APB-11100] model
paweldigital 232a634
[WG][APB-11100] Do actions per Pav description
gitwojciech 1c4e007
Merge branch 'main' into APB-11100_2
gitwojciech d9d3647
[WG][APB-11100] Do actions per Pav description, merge main
gitwojciech f35b4f4
[WG][APB-11100] Do actions per Pav description, RiskingFile repo
gitwojciech 853c591
[WG][APB-11100] lastUpdatedAt - update when risking responce
gitwojciech c016314
[WG][APB-11100] lastUpdatedAt - update when risking responce 2
gitwojciech 86b63ef
[WG][APB-11100] lastUpdatedAt - update when risking responce PR comme…
gitwojciech d9be6f4
PP WG [APB-11100] alignement
paweldigital c5f5830
[WG][APB-11100] make code compile plus tests
gitwojciech d169df3
PP WG [APB-11100] readme
paweldigital fe20e1a
PP WG [APB-11100] comments
paweldigital 0a0b6f6
Merge branch 'main' into APB-11100
paweldigital 6c1d1a3
PP WG [APB-11100] fixes after merge
paweldigital 7dd4bc5
PP WG [APB-11100] fixes in tests
paweldigital 6059914
[WG][APB-11045] Risking outcomes - emails - success
gitwojciech e646367
[APB-11100] fixes after sync from FE
paweldigital d4099ae
[WG][APB-11015] Risking outcomes - emails - FailedNonFixable
gitwojciech 16b4cf0
[APB-11100] refactored production cod
paweldigital b05ea41
[WG][APB-11015] Risking outcomes - emails - FailedNonFixable, SoleTra…
gitwojciech 08ad1f1
Merge branch 'APB-11100_2' into APB-11045
gitwojciech 05e90e0
[DC-8799][APB-11045][APB-11015] agent registartion emails - success, …
gitwojciech 04d21ea
[APB-11100] tests commented out, wip
paweldigital 5f2e1de
[APB-11100] ProcessInSequenceSpec
paweldigital 33b9ad9
[APB-11100] Test Data for Risking POC
paweldigital 92720e9
Merge branch 'main' into APB-11100
paweldigital cb1cf32
[APB-11100] Test Data fixes
paweldigital 9de4d92
Merge branch 'APB-11100_2' into APB-11045
gitwojciech cb938ac
[APB-11045] agent registartion emails - remove testing
gitwojciech a0eb410
[APB-11100] More TD Fixes and compiling first test
paweldigital ff2a7e7
[APB-11100] first working test
paweldigital 246c12b
[APB-11100] small cleanup
paweldigital c3f7ba1
[APB-11100] getRiskingProgressForApplicant test
paweldigital c9b5789
[APB-11100] risking results for applicant
paweldigital aa08cd3
[APB-11100] sync
paweldigital 45cad5a
Merge branch 'APB-11100_2' into APB-11045
gitwojciech dd34816
Merge branch 'main' into APB-11045
gitwojciech 357f824
[APB-11045] agent registartion emails - after merge fix
gitwojciech 8023e25
[APB-11045] agent registartion emails - after merge fix2
gitwojciech c28f356
Merge branch 'main' into APB-11045
gitwojciech aa8850b
Merge branch 'main' into APB-11045
gitwojciech 63e98e9
[APB-11045] agent registartion emails - another merge fixes
gitwojciech 6cd0888
[APB-11045] agent registartion emails - PR comments
gitwojciech f4839cb
[APB-11045] agent registartion emails - PR comments 2
gitwojciech d2dcab6
[APB-11045] agent registartion emails - better emails for indyviduals
gitwojciech cb08a60
[APB-11045] agent registartion emails - more filters
gitwojciech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/uk/gov/hmrc/agentregistrationrisking/connectors/EmailConnector.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright 2026 HM Revenue & Customs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package uk.gov.hmrc.agentregistrationrisking.connectors | ||
|
|
||
| import play.api.http.Status.ACCEPTED | ||
| import uk.gov.hmrc.agentregistration.shared.util.Errors | ||
| import uk.gov.hmrc.agentregistrationrisking.config.AppConfig | ||
| import uk.gov.hmrc.agentregistrationrisking.model.SendEmailRequest | ||
| import uk.gov.hmrc.agentregistrationrisking.util.FutureUtil.andLogOnFailure | ||
| import uk.gov.hmrc.http.client.HttpClientV2 | ||
|
|
||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
| import scala.concurrent.ExecutionContext | ||
|
|
||
| @Singleton | ||
| class EmailConnector @Inject() ( | ||
| appConfig: AppConfig, | ||
| httpClient: HttpClientV2 | ||
| )(using ExecutionContext) | ||
| extends Connector: | ||
|
|
||
| def sendEmail(emailInformation: SendEmailRequest)(using RequestHeader): Future[Unit] = | ||
| val url: URL = url"$baseUrl/hmrc/email" | ||
| httpClient | ||
| .post(url) | ||
| .withBody(Json.toJson(emailInformation)) | ||
| .execute[HttpResponse] | ||
| .map: response => | ||
| response.status match | ||
| case ACCEPTED => () | ||
| case status => | ||
| Errors.throwUpstreamErrorResponse( | ||
| httpMethod = "POST", | ||
| url = url, | ||
| status = status, | ||
| response = response, | ||
| info = s"Failed to send email for template ${emailInformation.templateId}" | ||
| ) | ||
| .andLogOnFailure(s"Failed to send email for template ${emailInformation.templateId}") | ||
|
|
||
| private val baseUrl: String = appConfig.emailBaseUrl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/uk/gov/hmrc/agentregistrationrisking/model/EmailTemplateId.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright 2026 HM Revenue & Customs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package uk.gov.hmrc.agentregistrationrisking.model | ||
|
|
||
| import play.api.libs.json.JsString | ||
| import play.api.libs.json.Writes | ||
|
|
||
| enum EmailTemplateId(val id: String): | ||
| case RegistrationSuccess | ||
| extends EmailTemplateId("agent_registration_success") | ||
| case ApplicationNonFixableFailure | ||
| extends EmailTemplateId("agent_registration_application_non_fixable_failure") | ||
| case IndividualNonFixableFailure | ||
| extends EmailTemplateId("agent_registration_individual_non_fixable_failure") | ||
|
|
||
| object EmailTemplateId: | ||
|
|
||
| given Writes[EmailTemplateId] = Writes(o => JsString(o.id)) |
30 changes: 30 additions & 0 deletions
30
app/uk/gov/hmrc/agentregistrationrisking/model/SendEmailRequest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2026 HM Revenue & Customs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package uk.gov.hmrc.agentregistrationrisking.model | ||
|
|
||
| import play.api.libs.json.Json | ||
| import play.api.libs.json.OWrites | ||
| import uk.gov.hmrc.agentregistration.shared.EmailAddress | ||
|
|
||
| final case class SendEmailRequest( | ||
| to: Seq[EmailAddress], | ||
| templateId: EmailTemplateId, | ||
| parameters: Map[String, String] | ||
| ) | ||
|
|
||
| object SendEmailRequest: | ||
| given OWrites[SendEmailRequest] = Json.writes[SendEmailRequest] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/uk/gov/hmrc/agentregistrationrisking/services/ApplicationStatusService.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Copyright 2026 HM Revenue & Customs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package uk.gov.hmrc.agentregistrationrisking.services | ||
|
|
||
| import uk.gov.hmrc.agentregistration.shared.risking.RiskingOutcome | ||
| import uk.gov.hmrc.agentregistration.shared.util.SafeEquals.=== | ||
| import uk.gov.hmrc.agentregistrationrisking.model.* | ||
| import uk.gov.hmrc.agentregistrationrisking.repository.ApplicationForRiskingRepo | ||
| import uk.gov.hmrc.agentregistrationrisking.repository.IndividualForRiskingRepo | ||
| import uk.gov.hmrc.agentregistrationrisking.util.RequestAwareLogging | ||
| import uk.gov.hmrc.agentregistrationrisking.services.RiskingOutcomeHelper._ | ||
|
|
||
| import java.time.Clock | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
| import scala.concurrent.ExecutionContext | ||
| import scala.concurrent.Future | ||
|
|
||
| @Singleton | ||
| class ApplicationStatusService @Inject() ( | ||
| applicationForRiskingRepo: ApplicationForRiskingRepo, | ||
| individualForRiskingRepo: IndividualForRiskingRepo | ||
| )(using | ||
| ExecutionContext, | ||
| Clock | ||
| ) | ||
| extends RequestAwareLogging: | ||
|
|
||
| def findApprovedReadyToSubscribe(): Future[Seq[ApplicationForRisking]] = getApplicationsPendingActionWithIndividuals | ||
| .map(filterApprovedApplicationsWithIndividuals) | ||
| .map(_.map(_.application)) | ||
|
|
||
| def findNonFixableReadyForFailureEmail(): Future[Seq[ApplicationWithIndividuals]] = getApplicationsPendingActionWithIndividuals | ||
| .map(filterNonFixableApplicationsWithIndividuals) | ||
|
|
||
| private def getApplicationsPendingActionWithIndividuals: Future[Seq[ApplicationWithIndividuals]] = | ||
| for | ||
| applications <- applicationForRiskingRepo.findApplicationsPendingAction() | ||
| individuals <- individualForRiskingRepo.findByApplicationReferences(applications.map(_.applicationReference)) | ||
| yield ApplicationWithIndividuals | ||
| .merge(applications, individuals) | ||
| .filter(_.individuals.forall(_.individualRiskingResult.isDefined)) | ||
|
|
||
| private def filterApprovedApplicationsWithIndividuals(applicationsWithIndividuals: Seq[ApplicationWithIndividuals]): Seq[ApplicationWithIndividuals] = | ||
| applicationsWithIndividuals.filter: appWithIndividuals => | ||
| RiskingOutcomeHelper | ||
| .computeRiskingOutcome(appWithIndividuals) | ||
| .exists(_ === RiskingOutcome.Approved) | ||
|
|
||
| private def filterNonFixableApplicationsWithIndividuals(applicationsWithIndividuals: Seq[ApplicationWithIndividuals]): Seq[ApplicationWithIndividuals] = | ||
| applicationsWithIndividuals | ||
| .filter: appWithIndividuals => | ||
| RiskingOutcomeHelper | ||
| .computeRiskingOutcome(appWithIndividuals) | ||
| .exists(_ === RiskingOutcome.FailedNonFixable) | ||
| .map: appWithIndividuals => | ||
| val nonFixableIndividuals = appWithIndividuals.individuals.filter: individual => | ||
| individual.individualRiskingResult.exists(_.failures.outcome === RiskingOutcome.FailedNonFixable) | ||
| ApplicationWithIndividuals(appWithIndividuals.application, nonFixableIndividuals) | ||
|
|
||
| private def filterFixableApplicationsWithIndividuals(applicationsWithIndividuals: Seq[ApplicationWithIndividuals]): Seq[ApplicationWithIndividuals] = | ||
| applicationsWithIndividuals | ||
| .filter: appWithIndividuals => | ||
| RiskingOutcomeHelper | ||
| .computeRiskingOutcome(appWithIndividuals) | ||
| .exists(_ === RiskingOutcome.FailedFixable) | ||
| .map: appWithIndividuals => | ||
| val fixableIndividuals = appWithIndividuals.individuals.filter: individual => | ||
| individual.individualRiskingResult.exists(_.failures.outcome === RiskingOutcome.FailedFixable) | ||
| ApplicationWithIndividuals(appWithIndividuals.application, fixableIndividuals) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we consider using a
FieldNamesobject to define these fields? It makes them easier to manage and help avoid typos in queries, especially since this has already happened in the project before.