From 565d7aaf3eb929ef5ed6595fc081b82f351e1091 Mon Sep 17 00:00:00 2001 From: avelx <3528155+avelx@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:59:07 +0000 Subject: [PATCH 1/6] MISUV-6801: * Initial commit --- ...ncomeSourceReportingMethodAuditModel.scala | 3 +- app/enums/BusinessTypeName.scala | 46 +++++++++++++++++++ .../IncomeSourceType.scala | 11 +++-- 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 app/enums/BusinessTypeName.scala diff --git a/app/audit/models/IncomeSourceReportingMethodAuditModel.scala b/app/audit/models/IncomeSourceReportingMethodAuditModel.scala index ca7b4bb868..cee05064b9 100644 --- a/app/audit/models/IncomeSourceReportingMethodAuditModel.scala +++ b/app/audit/models/IncomeSourceReportingMethodAuditModel.scala @@ -18,10 +18,11 @@ package audit.models import audit.Utilities import auth.MtdItUser +import enums.BusinessTypeName import play.api.libs.json.{JsObject, JsValue, Json} case class IncomeSourceReportingMethodAuditModel(isSuccessful: Boolean, - journeyType: String, + journeyType: BusinessTypeName, operationType: String, reportingMethodChangeTo: String, taxYear: String, diff --git a/app/enums/BusinessTypeName.scala b/app/enums/BusinessTypeName.scala new file mode 100644 index 0000000000..01b756d1fa --- /dev/null +++ b/app/enums/BusinessTypeName.scala @@ -0,0 +1,46 @@ +/* + * Copyright 2023 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 enums + +import scala.language.implicitConversions + +sealed trait BusinessTypeName { + val name: String +} + +case object UkPropertyBusinessName extends BusinessTypeName { + override val name: String = "UKPROPERTY" +} + +case object ForeignPropertyBusinessName extends BusinessTypeName { + override val name: String = "FOREIGNPROPERTY" +} + +case object SelfEmploymentBusinessName extends BusinessTypeName { + override val name: String = "SE" +} + +object BusinessTypeName { + implicit def businessTypeToString(in : BusinessTypeName) : String = in match { + case UkPropertyBusinessName => + UkPropertyBusinessName.name + case ForeignPropertyBusinessName => + ForeignPropertyBusinessName.name + case SelfEmploymentBusinessName => + SelfEmploymentBusinessName.name + } +} \ No newline at end of file diff --git a/app/enums/IncomeSourceJourney/IncomeSourceType.scala b/app/enums/IncomeSourceJourney/IncomeSourceType.scala index c984eb669f..968379ebcd 100644 --- a/app/enums/IncomeSourceJourney/IncomeSourceType.scala +++ b/app/enums/IncomeSourceJourney/IncomeSourceType.scala @@ -16,12 +16,14 @@ package enums.IncomeSourceJourney +import enums.{BusinessTypeName, ForeignPropertyBusinessName, + SelfEmploymentBusinessName, UkPropertyBusinessName} import play.api.libs.json.{JsObject, JsString, Json, Writes} import play.api.mvc.JavascriptLiteral sealed trait IncomeSourceType { val key: String - val journeyType: String + val journeyType: BusinessTypeName val startDateMessagesPrefix: String val addStartDateCheckMessagesPrefix: String val endDateMessagePrefix: String @@ -29,9 +31,10 @@ sealed trait IncomeSourceType { val ceaseCheckDetailsPrefix: String } + case object SelfEmployment extends IncomeSourceType { override val key = "SE" - override val journeyType: String = "SE" + override val journeyType: BusinessTypeName = SelfEmploymentBusinessName override val startDateMessagesPrefix: String = "add-business-start-date" override val addStartDateCheckMessagesPrefix: String = "add-business-start-date-check" override val endDateMessagePrefix: String = "incomeSources.cease.endDate.selfEmployment" @@ -41,7 +44,7 @@ case object SelfEmployment extends IncomeSourceType { case object UkProperty extends IncomeSourceType { override val key = "UK" - override val journeyType: String = "UKPROPERTY" + override val journeyType: BusinessTypeName = UkPropertyBusinessName override val startDateMessagesPrefix: String = "incomeSources.add.UKPropertyStartDate" override val addStartDateCheckMessagesPrefix: String = "add-uk-property-start-date-check" override val endDateMessagePrefix: String = "incomeSources.cease.endDate.ukProperty" @@ -52,7 +55,7 @@ case object UkProperty extends IncomeSourceType { case object ForeignProperty extends IncomeSourceType { override val key = "FP" - override val journeyType: String = "FOREIGNPROPERTY" + override val journeyType: BusinessTypeName = ForeignPropertyBusinessName override val startDateMessagesPrefix: String = "incomeSources.add.foreignProperty.startDate" override val addStartDateCheckMessagesPrefix: String = "add-foreign-property-start-date-check" override val endDateMessagePrefix: String = "incomeSources.cease.endDate.foreignProperty" From 6112698f00fe535801d5ac37aa9bded9452ae3c5 Mon Sep 17 00:00:00 2001 From: avelx <3528155+avelx@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:18:07 +0000 Subject: [PATCH 2/6] MISUV-6801: * rename BusinessNameType to IncomeSourceTypeName --- .../IncomeSourceReportingMethodAuditModel.scala | 4 ++-- app/enums/IncomeSourceJourney/IncomeSourceType.scala | 10 +++++----- ...nessTypeName.scala => IncomeSourceTypeName.scala} | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) rename app/enums/{BusinessTypeName.scala => IncomeSourceTypeName.scala} (74%) diff --git a/app/audit/models/IncomeSourceReportingMethodAuditModel.scala b/app/audit/models/IncomeSourceReportingMethodAuditModel.scala index cee05064b9..083950f1ee 100644 --- a/app/audit/models/IncomeSourceReportingMethodAuditModel.scala +++ b/app/audit/models/IncomeSourceReportingMethodAuditModel.scala @@ -18,11 +18,11 @@ package audit.models import audit.Utilities import auth.MtdItUser -import enums.BusinessTypeName +import enums.IncomeSourceTypeName import play.api.libs.json.{JsObject, JsValue, Json} case class IncomeSourceReportingMethodAuditModel(isSuccessful: Boolean, - journeyType: BusinessTypeName, + journeyType: IncomeSourceTypeName, operationType: String, reportingMethodChangeTo: String, taxYear: String, diff --git a/app/enums/IncomeSourceJourney/IncomeSourceType.scala b/app/enums/IncomeSourceJourney/IncomeSourceType.scala index 968379ebcd..86959830a5 100644 --- a/app/enums/IncomeSourceJourney/IncomeSourceType.scala +++ b/app/enums/IncomeSourceJourney/IncomeSourceType.scala @@ -16,14 +16,14 @@ package enums.IncomeSourceJourney -import enums.{BusinessTypeName, ForeignPropertyBusinessName, +import enums.{IncomeSourceTypeName, ForeignPropertyBusinessName, SelfEmploymentBusinessName, UkPropertyBusinessName} import play.api.libs.json.{JsObject, JsString, Json, Writes} import play.api.mvc.JavascriptLiteral sealed trait IncomeSourceType { val key: String - val journeyType: BusinessTypeName + val journeyType: IncomeSourceTypeName val startDateMessagesPrefix: String val addStartDateCheckMessagesPrefix: String val endDateMessagePrefix: String @@ -34,7 +34,7 @@ sealed trait IncomeSourceType { case object SelfEmployment extends IncomeSourceType { override val key = "SE" - override val journeyType: BusinessTypeName = SelfEmploymentBusinessName + override val journeyType: IncomeSourceTypeName = SelfEmploymentBusinessName override val startDateMessagesPrefix: String = "add-business-start-date" override val addStartDateCheckMessagesPrefix: String = "add-business-start-date-check" override val endDateMessagePrefix: String = "incomeSources.cease.endDate.selfEmployment" @@ -44,7 +44,7 @@ case object SelfEmployment extends IncomeSourceType { case object UkProperty extends IncomeSourceType { override val key = "UK" - override val journeyType: BusinessTypeName = UkPropertyBusinessName + override val journeyType: IncomeSourceTypeName = UkPropertyBusinessName override val startDateMessagesPrefix: String = "incomeSources.add.UKPropertyStartDate" override val addStartDateCheckMessagesPrefix: String = "add-uk-property-start-date-check" override val endDateMessagePrefix: String = "incomeSources.cease.endDate.ukProperty" @@ -55,7 +55,7 @@ case object UkProperty extends IncomeSourceType { case object ForeignProperty extends IncomeSourceType { override val key = "FP" - override val journeyType: BusinessTypeName = ForeignPropertyBusinessName + override val journeyType: IncomeSourceTypeName = ForeignPropertyBusinessName override val startDateMessagesPrefix: String = "incomeSources.add.foreignProperty.startDate" override val addStartDateCheckMessagesPrefix: String = "add-foreign-property-start-date-check" override val endDateMessagePrefix: String = "incomeSources.cease.endDate.foreignProperty" diff --git a/app/enums/BusinessTypeName.scala b/app/enums/IncomeSourceTypeName.scala similarity index 74% rename from app/enums/BusinessTypeName.scala rename to app/enums/IncomeSourceTypeName.scala index 01b756d1fa..f9fe34c923 100644 --- a/app/enums/BusinessTypeName.scala +++ b/app/enums/IncomeSourceTypeName.scala @@ -18,24 +18,24 @@ package enums import scala.language.implicitConversions -sealed trait BusinessTypeName { +sealed trait IncomeSourceTypeName { val name: String } -case object UkPropertyBusinessName extends BusinessTypeName { +case object UkPropertyBusinessName extends IncomeSourceTypeName { override val name: String = "UKPROPERTY" } -case object ForeignPropertyBusinessName extends BusinessTypeName { +case object ForeignPropertyBusinessName extends IncomeSourceTypeName { override val name: String = "FOREIGNPROPERTY" } -case object SelfEmploymentBusinessName extends BusinessTypeName { +case object SelfEmploymentBusinessName extends IncomeSourceTypeName { override val name: String = "SE" } -object BusinessTypeName { - implicit def businessTypeToString(in : BusinessTypeName) : String = in match { +object IncomeSourceTypeName { + implicit def businessTypeToString(in : IncomeSourceTypeName) : String = in match { case UkPropertyBusinessName => UkPropertyBusinessName.name case ForeignPropertyBusinessName => From 844b60dc6686c8a7b9cf60ebdd51731e0962e8af Mon Sep 17 00:00:00 2001 From: avelx <3528155+avelx@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:29:54 +0000 Subject: [PATCH 3/6] MISUV-6801: * create IncomeSourceTypeKey type --- .../IncomeSourceType.scala | 14 +++--- app/enums/IncomeSourceTypeKey.scala | 45 +++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 app/enums/IncomeSourceTypeKey.scala diff --git a/app/enums/IncomeSourceJourney/IncomeSourceType.scala b/app/enums/IncomeSourceJourney/IncomeSourceType.scala index 86959830a5..346e2014f9 100644 --- a/app/enums/IncomeSourceJourney/IncomeSourceType.scala +++ b/app/enums/IncomeSourceJourney/IncomeSourceType.scala @@ -16,14 +16,15 @@ package enums.IncomeSourceJourney -import enums.{IncomeSourceTypeName, ForeignPropertyBusinessName, - SelfEmploymentBusinessName, UkPropertyBusinessName} +import enums.{ForeignPropertyBusinessName, ForeignPropertyKey, IncomeSourceTypeKey, IncomeSourceTypeName, SelfEmploymentBusinessName, SelfEmploymentKey, UkPropertyBusinessName, UkPropertyKey} import play.api.libs.json.{JsObject, JsString, Json, Writes} import play.api.mvc.JavascriptLiteral sealed trait IncomeSourceType { - val key: String + val key: IncomeSourceTypeKey val journeyType: IncomeSourceTypeName + + // TODO: remove language specific fields val startDateMessagesPrefix: String val addStartDateCheckMessagesPrefix: String val endDateMessagePrefix: String @@ -33,7 +34,8 @@ sealed trait IncomeSourceType { case object SelfEmployment extends IncomeSourceType { - override val key = "SE" + override val key: IncomeSourceTypeKey = SelfEmploymentKey + override val journeyType: IncomeSourceTypeName = SelfEmploymentBusinessName override val startDateMessagesPrefix: String = "add-business-start-date" override val addStartDateCheckMessagesPrefix: String = "add-business-start-date-check" @@ -43,7 +45,7 @@ case object SelfEmployment extends IncomeSourceType { } case object UkProperty extends IncomeSourceType { - override val key = "UK" + override val key: IncomeSourceTypeKey= UkPropertyKey override val journeyType: IncomeSourceTypeName = UkPropertyBusinessName override val startDateMessagesPrefix: String = "incomeSources.add.UKPropertyStartDate" override val addStartDateCheckMessagesPrefix: String = "add-uk-property-start-date-check" @@ -54,7 +56,7 @@ case object UkProperty extends IncomeSourceType { } case object ForeignProperty extends IncomeSourceType { - override val key = "FP" + override val key: IncomeSourceTypeKey = ForeignPropertyKey override val journeyType: IncomeSourceTypeName = ForeignPropertyBusinessName override val startDateMessagesPrefix: String = "incomeSources.add.foreignProperty.startDate" override val addStartDateCheckMessagesPrefix: String = "add-foreign-property-start-date-check" diff --git a/app/enums/IncomeSourceTypeKey.scala b/app/enums/IncomeSourceTypeKey.scala new file mode 100644 index 0000000000..45dc086232 --- /dev/null +++ b/app/enums/IncomeSourceTypeKey.scala @@ -0,0 +1,45 @@ +/* + * Copyright 2023 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 enums + +import scala.language.implicitConversions + +sealed trait IncomeSourceTypeKey { + val key: String +} + +case object SelfEmploymentKey extends IncomeSourceTypeKey { + override val key: String = "SE" +} + +case object UkPropertyKey extends IncomeSourceTypeKey { + override val key: String = "UK" +} + +case object ForeignPropertyKey extends IncomeSourceTypeKey { + override val key: String = "FP" +} + +object IncomeSourceTypeKey { + implicit def incomeSourceTypeKeyToString(in: IncomeSourceTypeKey): String = { + in match { + case SelfEmploymentKey => SelfEmploymentKey.key + case UkPropertyKey => UkPropertyKey.key + case ForeignPropertyKey => ForeignPropertyKey.key + } + } +} \ No newline at end of file From c6d16346e9d6932ec0ee1931516a50453d85574d Mon Sep 17 00:00:00 2001 From: avelx <3528155+avelx@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:54:42 +0000 Subject: [PATCH 4/6] MISUV-6801: * create IncomeSourceTypeLang type: move all message field under this new type and alle other required changes (no tests fixes!) --- ...IncomeSourceStartDateCheckController.scala | 4 +- .../AddIncomeSourceStartDateController.scala | 4 +- ...seCheckIncomeSourceDetailsController.scala | 2 +- ...ReportingMethodChangeErrorController.scala | 2 +- .../IncomeSourceType.scala | 66 ++++++++++++------- .../cease/IncomeSourceEndDateForm.scala | 2 +- .../cease/IncomeSourceEndDate.scala.html | 2 +- 7 files changed, 52 insertions(+), 30 deletions(-) diff --git a/app/controllers/incomeSources/add/AddIncomeSourceStartDateCheckController.scala b/app/controllers/incomeSources/add/AddIncomeSourceStartDateCheckController.scala index 125288a6d6..001b53a7f8 100644 --- a/app/controllers/incomeSources/add/AddIncomeSourceStartDateCheckController.scala +++ b/app/controllers/incomeSources/add/AddIncomeSourceStartDateCheckController.scala @@ -95,7 +95,7 @@ class AddIncomeSourceStartDateCheckController @Inject()(authenticate: Authentica addIncomeSourceStartDateCheckView( isAgent = isAgent, backUrl = getBackUrl(incomeSourceType, isAgent, isChange), - form = form(incomeSourceType.addStartDateCheckMessagesPrefix), + form = form(incomeSourceType.lang.addStartDateCheckMessagesPrefix), postAction = getPostAction(incomeSourceType, isAgent, isChange), incomeSourceStartDate = longDate(startDate).toLongDate ) @@ -119,7 +119,7 @@ class AddIncomeSourceStartDateCheckController @Inject()(authenticate: Authentica isChange: Boolean) (implicit mtdItUser: MtdItUser[_]): Future[Result] = { - val messagesPrefix = incomeSourceType.addStartDateCheckMessagesPrefix + val messagesPrefix = incomeSourceType.lang.addStartDateCheckMessagesPrefix withIncomeSourcesFS { getStartDate(incomeSourceType).flatMap { case Some(startDate) => diff --git a/app/controllers/incomeSources/add/AddIncomeSourceStartDateController.scala b/app/controllers/incomeSources/add/AddIncomeSourceStartDateController.scala index ac7f811dfb..6ffa26073b 100644 --- a/app/controllers/incomeSources/add/AddIncomeSourceStartDateController.scala +++ b/app/controllers/incomeSources/add/AddIncomeSourceStartDateController.scala @@ -89,7 +89,7 @@ class AddIncomeSourceStartDateController @Inject()(authenticate: AuthenticationP isChange: Boolean) (implicit user: MtdItUser[_]): Future[Result] = { - val messagesPrefix = incomeSourceType.startDateMessagesPrefix + val messagesPrefix = incomeSourceType.lang.startDateMessagesPrefix withIncomeSourcesFSWithSessionCheck(JourneyType(Add, incomeSourceType)) { if (!isChange && incomeSourceType.equals(UkProperty) || !isChange && incomeSourceType.equals(ForeignProperty)) { @@ -125,7 +125,7 @@ class AddIncomeSourceStartDateController @Inject()(authenticate: AuthenticationP isChange: Boolean) (implicit user: MtdItUser[_]): Future[Result] = { - val messagesPrefix = incomeSourceType.startDateMessagesPrefix + val messagesPrefix = incomeSourceType.lang.startDateMessagesPrefix withIncomeSourcesFS { form(messagesPrefix).bindFromRequest().fold( diff --git a/app/controllers/incomeSources/cease/CeaseCheckIncomeSourceDetailsController.scala b/app/controllers/incomeSources/cease/CeaseCheckIncomeSourceDetailsController.scala index 3c0acbe999..e53b4fa2c3 100644 --- a/app/controllers/incomeSources/cease/CeaseCheckIncomeSourceDetailsController.scala +++ b/app/controllers/incomeSources/cease/CeaseCheckIncomeSourceDetailsController.scala @@ -89,7 +89,7 @@ class CeaseCheckIncomeSourceDetailsController @Inject()(val authenticate: Authen def handleRequest(sources: IncomeSourceDetailsModel, isAgent: Boolean, incomeSourceType: IncomeSourceType) (implicit user: MtdItUser[_]): Future[Result] = withIncomeSourcesFS { - val messagesPrefix = incomeSourceType.ceaseCheckDetailsPrefix + val messagesPrefix = incomeSourceType.lang.ceaseCheckDetailsPrefix val sessionDataFuture = getSessionData(incomeSourceType) sessionDataFuture.flatMap { diff --git a/app/controllers/incomeSources/manage/ReportingMethodChangeErrorController.scala b/app/controllers/incomeSources/manage/ReportingMethodChangeErrorController.scala index 397667a6a7..0283be3f4f 100644 --- a/app/controllers/incomeSources/manage/ReportingMethodChangeErrorController.scala +++ b/app/controllers/incomeSources/manage/ReportingMethodChangeErrorController.scala @@ -85,7 +85,7 @@ class ReportingMethodChangeErrorController @Inject()(val manageIncomeSources: Ma isAgent = isAgent, manageIncomeSourcesUrl = getManageIncomeSourcesUrl(isAgent), manageIncomeSourceDetailsUrl = getManageIncomeSourceDetailsUrl(id, isAgent, incomeSourceType), - messagesPrefix = incomeSourceType.reportingMethodChangeErrorPrefix + messagesPrefix = incomeSourceType.lang.reportingMethodChangeErrorPrefix ) ) case None => diff --git a/app/enums/IncomeSourceJourney/IncomeSourceType.scala b/app/enums/IncomeSourceJourney/IncomeSourceType.scala index 346e2014f9..a74ec2087e 100644 --- a/app/enums/IncomeSourceJourney/IncomeSourceType.scala +++ b/app/enums/IncomeSourceJourney/IncomeSourceType.scala @@ -16,15 +16,11 @@ package enums.IncomeSourceJourney -import enums.{ForeignPropertyBusinessName, ForeignPropertyKey, IncomeSourceTypeKey, IncomeSourceTypeName, SelfEmploymentBusinessName, SelfEmploymentKey, UkPropertyBusinessName, UkPropertyKey} +import enums._ import play.api.libs.json.{JsObject, JsString, Json, Writes} import play.api.mvc.JavascriptLiteral -sealed trait IncomeSourceType { - val key: IncomeSourceTypeKey - val journeyType: IncomeSourceTypeName - - // TODO: remove language specific fields +sealed trait IncomeSourceTypeLang { val startDateMessagesPrefix: String val addStartDateCheckMessagesPrefix: String val endDateMessagePrefix: String @@ -32,37 +28,63 @@ sealed trait IncomeSourceType { val ceaseCheckDetailsPrefix: String } +sealed trait IncomeSourceType { + val key: IncomeSourceTypeKey + val journeyType: IncomeSourceTypeName + val lang: IncomeSourceTypeLang +} + case object SelfEmployment extends IncomeSourceType { override val key: IncomeSourceTypeKey = SelfEmploymentKey - override val journeyType: IncomeSourceTypeName = SelfEmploymentBusinessName - override val startDateMessagesPrefix: String = "add-business-start-date" - override val addStartDateCheckMessagesPrefix: String = "add-business-start-date-check" - override val endDateMessagePrefix: String = "incomeSources.cease.endDate.selfEmployment" - override val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.businessReportingMethodError" - override val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseBusiness.checkDetails" + override val lang : IncomeSourceTypeLang = new IncomeSourceTypeLang { + val startDateMessagesPrefix: String = "add-business-start-date" + val addStartDateCheckMessagesPrefix: String = "add-business-start-date-check" + val endDateMessagePrefix: String = "incomeSources.cease.endDate.selfEmployment" + val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.businessReportingMethodError" + val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseBusiness.checkDetails" + } +// override val startDateMessagesPrefix: String = "add-business-start-date" +// override val addStartDateCheckMessagesPrefix: String = "add-business-start-date-check" +// override val endDateMessagePrefix: String = "incomeSources.cease.endDate.selfEmployment" +// override val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.businessReportingMethodError" +// override val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseBusiness.checkDetails" } case object UkProperty extends IncomeSourceType { override val key: IncomeSourceTypeKey= UkPropertyKey override val journeyType: IncomeSourceTypeName = UkPropertyBusinessName - override val startDateMessagesPrefix: String = "incomeSources.add.UKPropertyStartDate" - override val addStartDateCheckMessagesPrefix: String = "add-uk-property-start-date-check" - override val endDateMessagePrefix: String = "incomeSources.cease.endDate.ukProperty" - override val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.uKPropertyReportingMethodError" - override val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseUKProperty.checkDetails" + override val lang: IncomeSourceTypeLang = new IncomeSourceTypeLang { + val startDateMessagesPrefix: String = "incomeSources.add.UKPropertyStartDate" + val addStartDateCheckMessagesPrefix: String = "add-uk-property-start-date-check" + val endDateMessagePrefix: String = "incomeSources.cease.endDate.ukProperty" + val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.uKPropertyReportingMethodError" + val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseBusiness.checkDetails" + } +// override val startDateMessagesPrefix: String = "incomeSources.add.UKPropertyStartDate" +// override val addStartDateCheckMessagesPrefix: String = "add-uk-property-start-date-check" +// override val endDateMessagePrefix: String = "incomeSources.cease.endDate.ukProperty" +// override val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.uKPropertyReportingMethodError" +// override val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseUKProperty.checkDetails" } case object ForeignProperty extends IncomeSourceType { override val key: IncomeSourceTypeKey = ForeignPropertyKey override val journeyType: IncomeSourceTypeName = ForeignPropertyBusinessName - override val startDateMessagesPrefix: String = "incomeSources.add.foreignProperty.startDate" - override val addStartDateCheckMessagesPrefix: String = "add-foreign-property-start-date-check" - override val endDateMessagePrefix: String = "incomeSources.cease.endDate.foreignProperty" - override val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.foreignPropertyReportingMethodError" - override val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseForeignProperty.checkDetails" + override val lang: IncomeSourceTypeLang = new IncomeSourceTypeLang { + val startDateMessagesPrefix: String = "incomeSources.add.foreignProperty.startDate" + val addStartDateCheckMessagesPrefix: String = "add-foreign-property-start-date-check" + val endDateMessagePrefix: String = "incomeSources.cease.endDate.foreignProperty" + val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.foreignPropertyReportingMethodError" + val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseForeignProperty.checkDetails" + } +// override val startDateMessagesPrefix: String = "incomeSources.add.foreignProperty.startDate" +// override val addStartDateCheckMessagesPrefix: String = "add-foreign-property-start-date-check" +// override val endDateMessagePrefix: String = "incomeSources.cease.endDate.foreignProperty" +// override val reportingMethodChangeErrorPrefix: String = "incomeSources.manage.foreignPropertyReportingMethodError" +// override val ceaseCheckDetailsPrefix: String = "incomeSources.ceaseForeignProperty.checkDetails" } object IncomeSourceType { diff --git a/app/forms/incomeSources/cease/IncomeSourceEndDateForm.scala b/app/forms/incomeSources/cease/IncomeSourceEndDateForm.scala index 112c0df352..ae07f56261 100644 --- a/app/forms/incomeSources/cease/IncomeSourceEndDateForm.scala +++ b/app/forms/incomeSources/cease/IncomeSourceEndDateForm.scala @@ -44,7 +44,7 @@ class IncomeSourceEndDateForm @Inject()(val dateService: DateService) extends Cu def apply(incomeSourceType: IncomeSourceType, id: Option[String] = None)(implicit user: MtdItUser[_]): Form[DateFormElement] = { val currentDate: LocalDate = dateService.getCurrentDate() - val messagePrefix = incomeSourceType.endDateMessagePrefix + val messagePrefix = incomeSourceType.lang.endDateMessagePrefix val dateConstraints: List[Constraint[LocalDate]] = { val minimumDateConstraints = incomeSourceType match { diff --git a/app/views/incomeSources/cease/IncomeSourceEndDate.scala.html b/app/views/incomeSources/cease/IncomeSourceEndDate.scala.html index 215245d38b..a36f52e7ae 100644 --- a/app/views/incomeSources/cease/IncomeSourceEndDate.scala.html +++ b/app/views/incomeSources/cease/IncomeSourceEndDate.scala.html @@ -28,7 +28,7 @@ @(incomeSourceType: IncomeSourceType, incomeSourceEndDateForm: Form[_], postAction: Call, isAgent: Boolean = false, backUrl: String)(implicit user: auth.MtdItUser[_], messages: Messages) @getMessage(key: String, args: String*) = @{ - messages(s"${incomeSourceType.endDateMessagePrefix}.$key", args: _*) + messages(s"${incomeSourceType.lang.endDateMessagePrefix}.$key", args: _*) } @getHintContent = { From 66972c76b93d08c9dedf3c69b9c5a489eae82fce Mon Sep 17 00:00:00 2001 From: avelx <3528155+avelx@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:56:28 +0000 Subject: [PATCH 5/6] MISUV-6801: * create IncomeSourceTypeLang type: move all message field under this new type and alle other required changes (no tests fixes!) --- app/enums/IncomeSourceJourney/IncomeSourceType.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/app/enums/IncomeSourceJourney/IncomeSourceType.scala b/app/enums/IncomeSourceJourney/IncomeSourceType.scala index a74ec2087e..33887afd21 100644 --- a/app/enums/IncomeSourceJourney/IncomeSourceType.scala +++ b/app/enums/IncomeSourceJourney/IncomeSourceType.scala @@ -20,6 +20,7 @@ import enums._ import play.api.libs.json.{JsObject, JsString, Json, Writes} import play.api.mvc.JavascriptLiteral +// TODO: consider using case class here instead sealed trait IncomeSourceTypeLang { val startDateMessagesPrefix: String val addStartDateCheckMessagesPrefix: String From 4cc8e26c6af03dcbe677ded09aca5d9fb64b931a Mon Sep 17 00:00:00 2001 From: avelx <3528155+avelx@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:45:12 +0000 Subject: [PATCH 6/6] MISUV-6801: * add IncomeSourceT type: add example of it usage --- .../add/IncomeSourceAddedController.scala | 40 +++++++++---------- ...ncomeSourceReportingMethodController.scala | 31 +++++++------- app/models/core/IncomeSourceT.scala | 21 ++++++++++ app/services/IncomeSourceDetailsService.scala | 12 +++--- 4 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 app/models/core/IncomeSourceT.scala diff --git a/app/controllers/incomeSources/add/IncomeSourceAddedController.scala b/app/controllers/incomeSources/add/IncomeSourceAddedController.scala index f21bf228c2..bc3544246d 100644 --- a/app/controllers/incomeSources/add/IncomeSourceAddedController.scala +++ b/app/controllers/incomeSources/add/IncomeSourceAddedController.scala @@ -23,9 +23,9 @@ import controllers.agent.predicates.ClientConfirmedController import controllers.predicates._ import enums.IncomeSourceJourney.{ForeignProperty, IncomeSourceType, SelfEmployment, UkProperty} import enums.JourneyType.{Add, JourneyType} -import models.incomeSourceDetails.{AddIncomeSourceData, UIJourneySessionData} -import models.core.IncomeSourceId import models.core.IncomeSourceId.mkIncomeSourceId +import models.core.IncomeSourceT +import models.incomeSourceDetails.{AddIncomeSourceData, UIJourneySessionData} import play.api.Logger import play.api.i18n.I18nSupport import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Result} @@ -34,7 +34,6 @@ import uk.gov.hmrc.auth.core.AuthorisedFunctions import uk.gov.hmrc.http.HeaderCarrier import utils.{IncomeSourcesUtils, JourneyChecker} import views.html.incomeSources.add.IncomeSourceAddedObligations - import javax.inject.Inject import scala.concurrent.{ExecutionContext, Future} @@ -70,21 +69,19 @@ class IncomeSourceAddedController @Inject()(authenticate: AuthenticationPredicat } } - private def handleRequest(isAgent: Boolean, incomeSourceType: IncomeSourceType)(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = { - + private def handleRequest(isAgent: Boolean, + incomeSourceType: IncomeSourceType) + (implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = { withIncomeSourcesFSWithSessionCheck(JourneyType(Add, incomeSourceType)) { - sessionService.getMongoKeyTyped[String](AddIncomeSourceData.createdIncomeSourceIdField, JourneyType(Add, incomeSourceType)).flatMap { case Right(Some(id)) => - - val incomeSourceId: IncomeSourceId = mkIncomeSourceId(id) - - incomeSourceDetailsService.getIncomeSourceFromUser(incomeSourceType, incomeSourceId) match { + val iss = IncomeSourceT( mkIncomeSourceId(id), incomeSourceType ) + incomeSourceDetailsService.getIncomeSourceFromUser( iss ) match { case Some((startDate, businessName)) => val showPreviousTaxYears: Boolean = startDate.isBefore(dateService.getCurrentTaxYearStart()) - handleSuccess(incomeSourceId, incomeSourceType, businessName, showPreviousTaxYears, isAgent) + handleSuccess(iss, businessName, showPreviousTaxYears, isAgent) case None => Logger("application").error( - s"${if (isAgent) "[Agent]"}" + s"[IncomeSourceAddedController][handleRequest] - unable to find incomeSource by id: $incomeSourceId, IncomeSourceType: $incomeSourceType") + s"${if (isAgent) "[Agent]"}" + s"[IncomeSourceAddedController][handleRequest] - unable to find incomeSource by id: ${iss.id}, IncomeSourceType: $incomeSourceType") if (isAgent) Future(itvcErrorHandlerAgent.showInternalServerError()) else Future(itvcErrorHandler.showInternalServerError()) } @@ -101,28 +98,31 @@ class IncomeSourceAddedController @Inject()(authenticate: AuthenticationPredicat } } - def handleSuccess(incomeSourceId: IncomeSourceId, incomeSourceType: IncomeSourceType, businessName: Option[String], showPreviousTaxYears: Boolean, isAgent: Boolean)(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = { - updateMongoAdded(incomeSourceType).flatMap { + def handleSuccess(incomeSource: IncomeSourceT, + businessName: Option[String], + showPreviousTaxYears: Boolean, + isAgent: Boolean)(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = { + updateMongoAdded(incomeSource.incomeSourceType).flatMap { case false => Logger("application").error(s"${if (isAgent) "[Agent]"}" + - s"Error retrieving data from session, IncomeSourceType: $incomeSourceType") + s"Error retrieving data from session, IncomeSourceType: $incomeSource.incomeSourceType") Future.successful { if (isAgent) itvcErrorHandlerAgent.showInternalServerError() else itvcErrorHandler.showInternalServerError() } - case true => incomeSourceType match { + case true => incomeSource.incomeSourceType match { case SelfEmployment => businessName match { - case Some(businessName) => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel => + case Some(businessName) => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel => Ok(obligationsView(businessName = Some(businessName), sources = viewModel, isAgent = isAgent, incomeSourceType = SelfEmployment)) } - case None => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel => + case None => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel => Ok(obligationsView(sources = viewModel, isAgent = isAgent, incomeSourceType = SelfEmployment)) } } - case UkProperty => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel => + case UkProperty => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel => Ok(obligationsView(viewModel, isAgent = isAgent, incomeSourceType = UkProperty)) } - case ForeignProperty => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel => + case ForeignProperty => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel => Ok(obligationsView(viewModel, isAgent = isAgent, incomeSourceType = ForeignProperty)) } } diff --git a/app/controllers/incomeSources/add/IncomeSourceReportingMethodController.scala b/app/controllers/incomeSources/add/IncomeSourceReportingMethodController.scala index 8b1e7e08cc..29a21ba0ee 100644 --- a/app/controllers/incomeSources/add/IncomeSourceReportingMethodController.scala +++ b/app/controllers/incomeSources/add/IncomeSourceReportingMethodController.scala @@ -26,7 +26,7 @@ import controllers.predicates._ import enums.IncomeSourceJourney.{IncomeSourceType, SelfEmployment} import enums.JourneyType.{Add, JourneyType} import forms.incomeSources.add.IncomeSourceReportingMethodForm -import models.core.IncomeSourceId +import models.core.{IncomeSourceId, IncomeSourceT} import models.core.IncomeSourceId.mkIncomeSourceId import models.incomeSourceDetails.viewmodels.IncomeSourceReportingMethodViewModel import models.incomeSourceDetails.{AddIncomeSourceData, LatencyDetails, LatencyYear} @@ -109,7 +109,8 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti sessionService.getMongoKeyTyped[String](AddIncomeSourceData.createdIncomeSourceIdField, JourneyType(Add, incomeSourceType)).flatMap { case Right(Some(id)) => - handleIncomeSourceIdRetrievalSuccess(incomeSourceType = incomeSourceType, id = id, isAgent = isAgent) + val iss : IncomeSourceT = IncomeSourceT(mkIncomeSourceId(id), incomeSourceType) + handleIncomeSourceIdRetrievalSuccess(iss, isAgent = isAgent) case Right(_) => Future.failed(new Error("[IncomeSourceReportingMethodController][handleSubmit] Could not find an incomeSourceId in session data")) case Left(ex) => Future.failed(ex) }.recover { @@ -123,14 +124,14 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti } - private def handleIncomeSourceIdRetrievalSuccess(incomeSourceType: IncomeSourceType, id: String, isAgent: Boolean)(implicit user: MtdItUser[_], hc: HeaderCarrier): Future[Result] = { + private def handleIncomeSourceIdRetrievalSuccess(iss: IncomeSourceT, isAgent: Boolean) + (implicit user: MtdItUser[_], hc: HeaderCarrier): Future[Result] = { - val cannotGoBackRedirect = if (isAgent) controllers.incomeSources.add.routes.YouCannotGoBackErrorController.showAgent(incomeSourceType) else - controllers.incomeSources.add.routes.YouCannotGoBackErrorController.show(incomeSourceType) + val cannotGoBackRedirect = if (isAgent) controllers.incomeSources.add.routes.YouCannotGoBackErrorController.showAgent(iss.incomeSourceType) else + controllers.incomeSources.add.routes.YouCannotGoBackErrorController.show(iss.incomeSourceType) val errorHandler = if (isAgent) itvcErrorHandlerAgent else itvcErrorHandler - val incomeSourceId: IncomeSourceId = mkIncomeSourceId(id) - sessionService.getMongoKeyTyped[Boolean](AddIncomeSourceData.hasBeenAddedField, JourneyType(Add, incomeSourceType)).flatMap { + sessionService.getMongoKeyTyped[Boolean](AddIncomeSourceData.hasBeenAddedField, JourneyType(Add, iss.incomeSourceType)).flatMap { case Left(ex) => Logger("application").error(s"${if (isAgent) "[Agent]"}" + s"Error getting hasBeenAdded field from session: ${ex.getMessage}") Future.successful(errorHandler.showInternalServerError()) @@ -139,19 +140,19 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti case _ => itsaStatusService.hasMandatedOrVoluntaryStatusCurrentYear.flatMap { case true => - getViewModel(incomeSourceType, incomeSourceId).map { + getViewModel(iss).map { case Some(viewModel) => Ok(view( incomeSourceReportingMethodForm = IncomeSourceReportingMethodForm.form, incomeSourceReportingViewModel = viewModel, - postAction = submitUrl(isAgent, incomeSourceType), + postAction = submitUrl(isAgent, iss.incomeSourceType), isAgent = isAgent)) case None => - Redirect(redirectUrl(isAgent, incomeSourceType)) + Redirect(redirectUrl(isAgent, iss.incomeSourceType)) } case false => Future.successful { - Redirect(redirectUrl(isAgent, incomeSourceType)) + Redirect(redirectUrl(isAgent, iss.incomeSourceType)) } } } @@ -162,10 +163,10 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti user.incomeSources.getLatencyDetails(incomeSourceType, incomeSourceId) } - private def getViewModel(incomeSourceType: IncomeSourceType, incomeSourceId: IncomeSourceId) + private def getViewModel(iss: IncomeSourceT) (implicit user: MtdItUser[_], hc: HeaderCarrier, ec: ExecutionContext): Future[Option[IncomeSourceReportingMethodViewModel]] = { val currentTaxYear = dateService.getCurrentTaxYearEnd(isEnabled(TimeMachineAddYear)) - val latencyDetails = getLatencyDetails(incomeSourceType, incomeSourceId.value) + val latencyDetails = getLatencyDetails(iss.incomeSourceType, iss.id.value) latencyDetails match { @@ -216,8 +217,8 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti (implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = { val updatedForm = IncomeSourceReportingMethodForm.updateErrorMessagesWithValues(form) - - getViewModel(incomeSourceType, id).map { + val iss: IncomeSourceT = IncomeSourceT( id, incomeSourceType) + getViewModel(iss).map { case Some(viewModel) => BadRequest(view( incomeSourceReportingMethodForm = updatedForm, diff --git a/app/models/core/IncomeSourceT.scala b/app/models/core/IncomeSourceT.scala new file mode 100644 index 0000000000..7501faf08f --- /dev/null +++ b/app/models/core/IncomeSourceT.scala @@ -0,0 +1,21 @@ +/* + * Copyright 2023 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 models.core + +import enums.IncomeSourceJourney.IncomeSourceType + +final case class IncomeSourceT(id: IncomeSourceId, incomeSourceType: IncomeSourceType) \ No newline at end of file diff --git a/app/services/IncomeSourceDetailsService.scala b/app/services/IncomeSourceDetailsService.scala index fda1a12952..1463aeb11c 100644 --- a/app/services/IncomeSourceDetailsService.scala +++ b/app/services/IncomeSourceDetailsService.scala @@ -19,7 +19,7 @@ package services import auth.{MtdItUser, MtdItUserOptionNino, MtdItUserWithNino} import connectors.BusinessDetailsConnector import enums.IncomeSourceJourney.{ForeignProperty, IncomeSourceType, SelfEmployment, UkProperty} -import models.core.{AddressModel, IncomeSourceId} +import models.core.{AddressModel, IncomeSourceId, IncomeSourceT} import IncomeSourceId.mkIncomeSourceId import models.incomeSourceDetails.viewmodels._ import models.incomeSourceDetails.{IncomeSourceDetailsModel, IncomeSourceDetailsResponse} @@ -250,11 +250,11 @@ class IncomeSourceDetailsService @Inject()(val businessDetailsConnector: Busines viewModelsForCeasedSEBusinesses ++ viewModelsForCeasedPropertyBusinesses } - def getIncomeSourceFromUser(incomeSourceType: IncomeSourceType, incomeSourceId: IncomeSourceId)(implicit user: MtdItUser[_]): Option[(LocalDate, Option[String])] = { - incomeSourceType match { + def getIncomeSourceFromUser(iss: IncomeSourceT)(implicit user: MtdItUser[_]): Option[(LocalDate, Option[String])] = { + iss.incomeSourceType match { case SelfEmployment => user.incomeSources.businesses - .find(m => mkIncomeSourceId(m.incomeSourceId) == incomeSourceId ) + .find(m => mkIncomeSourceId(m.incomeSourceId) == iss.id ) .flatMap { addedBusiness => for { businessName <- addedBusiness.tradingName @@ -265,14 +265,14 @@ class IncomeSourceDetailsService @Inject()(val businessDetailsConnector: Busines for { newlyAddedProperty <- user.incomeSources.properties .find(incomeSource => - mkIncomeSourceId(incomeSource.incomeSourceId) == incomeSourceId && incomeSource.isUkProperty + mkIncomeSourceId(incomeSource.incomeSourceId) == iss.id && incomeSource.isUkProperty ) startDate <- newlyAddedProperty.tradingStartDate } yield (startDate, None) case ForeignProperty => for { newlyAddedProperty <- user.incomeSources.properties.find(incomeSource => - mkIncomeSourceId(incomeSource.incomeSourceId) == incomeSourceId && incomeSource.isForeignProperty + mkIncomeSourceId(incomeSource.incomeSourceId) == iss.id && incomeSource.isForeignProperty ) startDate <- newlyAddedProperty.tradingStartDate } yield (startDate, None)