From 650389dc0009535e82e914a0ad38c5c6cab5ae9d Mon Sep 17 00:00:00 2001 From: Pete Smith Date: Wed, 8 May 2024 13:54:44 +1000 Subject: [PATCH 1/2] [PS] CIR-619 - Read welsh country name data from third party/object-store --- app/Module.scala | 46 +++- .../AbpAddressLookupController.scala | 4 +- ...InternationalAddressLookupController.scala | 2 +- app/controllers/PingController.scala | 19 ++ app/health/HealthController.scala | 24 ++ app/model/Model.scala | 10 +- app/services/AddressService.scala | 4 +- app/services/CountryNamesDataSource.scala | 48 ++++ app/services/CountryService.scala | 93 +------ .../EnglishCountryNamesDataSource.scala | 63 +++++ app/services/ExtendedProxyConfig.scala | 7 + .../GovWalesCacheUpdateScheduler.scala | 52 ++++ .../WelshCountryNamesDataSource.scala | 186 +++++++++++++ app/views/abp/non_uk_mode_edit.scala.html | 7 +- app/views/international/edit.scala.html | 6 +- conf/application.conf | 21 ++ conf/prod.routes | 6 +- conf/test.routes | 2 +- conf/wco-countries-merged.csv | 251 ++++++++++++++++++ conf/wco-countries.csv | 4 +- conf/welsh-country-names.csv | 196 ++++++++++++++ .../international/SelectPageISpec.scala | 9 +- .../international/TooManyResultsISpec.scala | 3 +- .../config/IntegrationTestConstants.scala | 4 +- project/AppDependencies.scala | 4 +- test/model/ALFESpec.scala | 52 ++-- .../AddressLookupAddressServiceSpec.scala | 7 +- .../ForeignOfficeCountryServiceSpec.scala | 11 +- 28 files changed, 997 insertions(+), 144 deletions(-) create mode 100644 app/controllers/PingController.scala create mode 100644 app/health/HealthController.scala create mode 100644 app/services/CountryNamesDataSource.scala create mode 100644 app/services/EnglishCountryNamesDataSource.scala create mode 100644 app/services/ExtendedProxyConfig.scala create mode 100644 app/services/GovWalesCacheUpdateScheduler.scala create mode 100644 app/services/WelshCountryNamesDataSource.scala create mode 100644 conf/wco-countries-merged.csv create mode 100644 conf/welsh-country-names.csv diff --git a/app/Module.scala b/app/Module.scala index 8e143ed2..31a6f6fa 100644 --- a/app/Module.scala +++ b/app/Module.scala @@ -14,13 +14,53 @@ * limitations under the License. */ -import com.google.inject.AbstractModule +import com.google.inject.{AbstractModule, Provides} import controllers.RemoteMessagesApiProvider +import org.apache.pekko.stream.Materializer import play.api.libs.concurrent.PekkoGuiceSupport +import play.api.{Configuration, Environment, Logger} +import services._ +import uk.gov.hmrc.objectstore.client.play.PlayObjectStoreClient + +import javax.inject.Singleton +import scala.concurrent.ExecutionContext + +class Module(env: Environment, playConfig: Configuration) extends AbstractModule with PekkoGuiceSupport { -class Module() extends AbstractModule - with PekkoGuiceSupport { override def configure(): Unit = { bind(classOf[RemoteMessagesApiProvider]) + bind(classOf[GovWalesCacheUpdateScheduler]).asEagerSingleton() + } + + @Provides + @Singleton + private def provideWelshCountryNamesDataSource(english: EnglishCountryNamesDataSource, + objectStore: PlayObjectStoreClient, + ec: ExecutionContext, mat: Materializer) = { + val logger = Logger(this.getClass) + + val useLocal = + playConfig.getOptional[Boolean]("microservice.services.gov-wales.useLocal").getOrElse(true) + + if (useLocal) { + logger.info(s"Using local gov-wales country data") + new WelshCountryNamesDataSource(english) + } else { + logger.info(s"Using gov-wales country data from object-store") + + val proxyHost: Option[String] = playConfig.getOptional[String]("proxy.host") + val proxyPort: Option[Int] = playConfig.getOptional[Int]("proxy.port") + val proxyUsername: Option[String] = playConfig.getOptional[String]("proxy.username") + val proxyPassword: Option[String] = playConfig.getOptional[String]("proxy.password") + + val proxyConfig: Option[ExtendedProxyConfig] = for { + pHost <- proxyHost + pPort <- proxyPort + pUserName <- proxyUsername + pPassword <- proxyPassword + } yield new ExtendedProxyConfig(pHost, pPort, "https", pUserName, pPassword) + + new WelshCountryNamesObjectStoreDataSource(english, objectStore, proxyConfig, ec, mat) + } } } diff --git a/app/controllers/AbpAddressLookupController.scala b/app/controllers/AbpAddressLookupController.scala index 3c0862d1..c51cefd7 100644 --- a/app/controllers/AbpAddressLookupController.scala +++ b/app/controllers/AbpAddressLookupController.scala @@ -411,7 +411,7 @@ class AbpAddressLookupController @Inject()( ( Some( journeyData.copy( - selectedAddress = Some(edit.toConfirmableAddress(id)) + selectedAddress = Some(edit.toConfirmableAddress(id, c => countryService.find(isWelsh, c))) ) ), requestWithWelshHeader(isWelsh) { @@ -448,7 +448,7 @@ class AbpAddressLookupController @Inject()( ( Some( journeyData.copy( - selectedAddress = Some(edit.toConfirmableAddress(id)) + selectedAddress = Some(edit.toConfirmableAddress(id, c => countryService.find(isWelsh, c))) ) ), requestWithWelshHeader(isWelsh) { diff --git a/app/controllers/InternationalAddressLookupController.scala b/app/controllers/InternationalAddressLookupController.scala index 01a8c990..42ae0e85 100644 --- a/app/controllers/InternationalAddressLookupController.scala +++ b/app/controllers/InternationalAddressLookupController.scala @@ -325,7 +325,7 @@ class InternationalAddressLookupController @Inject()( ( Some( journeyData.copy( - selectedAddress = Some(edit.toConfirmableAddress(id)) + selectedAddress = Some(edit.toConfirmableAddress(id, c => countryService.find(isWelsh, c))) ) ), requestWithWelshHeader(isWelsh) { diff --git a/app/controllers/PingController.scala b/app/controllers/PingController.scala new file mode 100644 index 00000000..879df10e --- /dev/null +++ b/app/controllers/PingController.scala @@ -0,0 +1,19 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + */ + +package controllers + +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController + +import javax.inject.Inject + +class PingController @Inject()(controllerComponents: MessagesControllerComponents) + extends FrontendController(controllerComponents) { + + def ping: Action[AnyContent] = Action { + Ok + } +} \ No newline at end of file diff --git a/app/health/HealthController.scala b/app/health/HealthController.scala new file mode 100644 index 00000000..21bf2028 --- /dev/null +++ b/app/health/HealthController.scala @@ -0,0 +1,24 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + */ + +package health + +import play.api.mvc.{Action, AnyContent, DefaultControllerComponents} +import play.api.{Configuration, Environment} +import services.WelshCountryNamesDataSource +import uk.gov.hmrc.play + +import javax.inject.{Inject, Singleton} + +@Singleton +class HealthController @Inject()(configuration: Configuration, environment: Environment, + dataSource: WelshCountryNamesDataSource, controllerComponents: DefaultControllerComponents) + extends play.health.HealthController(configuration, environment, controllerComponents) { + + override def ping: Action[AnyContent] = Action { + if (dataSource.isCacheReady) Ok + else ServiceUnavailable + } +} diff --git a/app/model/Model.scala b/app/model/Model.scala index 594ccb46..3ab41f3e 100644 --- a/app/model/Model.scala +++ b/app/model/Model.scala @@ -42,7 +42,7 @@ case class Edit(organisation: Option[String], postcode: String, countryCode: String = "GB") { - def toConfirmableAddress(auditRef: String): ConfirmableAddress = + def toConfirmableAddress(auditRef: String, findCountry: String => Option[Country]): ConfirmableAddress = ConfirmableAddress( auditRef, None, @@ -54,7 +54,7 @@ case class Edit(organisation: Option[String], if (postcode.isEmpty) None else if (countryCode == "GB") Postcode.cleanupPostcode(postcode).map(_.toString) else Some(postcode), - ForeignOfficeCountryService.find(code = countryCode) + findCountry(countryCode) ) ) } @@ -67,9 +67,7 @@ case class ProposedAddress(addressId: String, postcode: Option[String], town: Option[String], lines: List[String] = List.empty, - country: Country = ForeignOfficeCountryService - .find(code = "GB") - .getOrElse(Country("GB", "United Kingdom")), + country: Country = Country("GB", "United Kingdom"), poBox: Option[String] = None) { def toConfirmableAddress(auditRef: String): ConfirmableAddress = @@ -107,7 +105,7 @@ case class ConfirmableAddressDetails( lines: Seq[String] = Seq(), town: Option[String] = None, postcode: Option[String] = None, - country: Option[Country] = ForeignOfficeCountryService.find(code = "GB"), + country: Option[Country] = Some(Country("GB", "United Kingdom")), poBox: Option[String] = None ) { diff --git a/app/services/AddressService.scala b/app/services/AddressService.scala index db356897..0c7b1810 100644 --- a/app/services/AddressService.scala +++ b/app/services/AddressService.scala @@ -39,7 +39,7 @@ trait AddressService { } @Singleton -class AddressLookupAddressService @Inject()(frontendAppConfig: FrontendAppConfig, http: HttpClient)(implicit val +class AddressLookupAddressService @Inject()(frontendAppConfig: FrontendAppConfig, http: HttpClient, countryService: CountryService)(implicit val ec: ExecutionContext) extends AddressService { val endpoint = frontendAppConfig.addressReputationEndpoint @@ -100,7 +100,7 @@ ec: ExecutionContext) extends AddressService { s"${addr.city.getOrElse("")}", s"${addr.region.getOrElse("")}" ).filter(_.nonEmpty).toList, - ForeignOfficeCountryService.find(code = countryCode).get + countryService.find(code = countryCode).get ) } diff --git a/app/services/CountryNamesDataSource.scala b/app/services/CountryNamesDataSource.scala new file mode 100644 index 00000000..165313a9 --- /dev/null +++ b/app/services/CountryNamesDataSource.scala @@ -0,0 +1,48 @@ +/* + * Copyright 2024 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 services + +import address.v2.Country +import com.github.tototoshi.csv.CSVReader + +import scala.io.Source + +trait CountryNamesDataSource { + protected def allAliases(aliasFileClasspath: String) = + CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream(aliasFileClasspath), "UTF-8")) + .allWithOrderedHeaders()._2.sortBy(x => x("countryCode")) + .map { x => x("countryCode") -> (x("aliases").split("\\|").map(_.trim).toList) } + .map { case (c, as) => c -> as.map(a => Country(c, a)) } + .toMap + + protected def renameFields(m: Map[String, String]): Map[String, String] = { + mappings.flatMap { case (o, nm) => nm.map(n => n -> m(o)) } + } + + protected val mappings = Map( + "independent" -> None, + "alpha_3_code" -> None, + "full_name_en" -> Some("Official Name"), + "status" -> None, + "short_name_uppercase_en" -> None, + "numeric_code" -> None, + "short_name_en" -> Some("Name"), + "alpha_2_code" -> Some("Country") + ) + + protected val utfSorter = java.text.Collator.getInstance() +} diff --git a/app/services/CountryService.scala b/app/services/CountryService.scala index 1bf85ca6..ff08fc38 100644 --- a/app/services/CountryService.scala +++ b/app/services/CountryService.scala @@ -21,7 +21,7 @@ import com.github.tototoshi.csv._ import com.google.inject.ImplementedBy import play.api.libs.json.Json -import javax.inject.Singleton +import javax.inject.{Inject, Singleton} import scala.collection.immutable.SortedMap import scala.io.Source @@ -32,105 +32,26 @@ trait CountryService { // to match uk.gov.hmrc.address.v2.Countries and serve as a comprehensive replacement def find(welshFlag: Boolean = false, code: String): Option[Country] - } @Singleton -class ForeignOfficeCountryService extends CountryService { - +class ForeignOfficeCountryService @Inject() (english: EnglishCountryNamesDataSource, welsh: WelshCountryNamesDataSource) extends CountryService { implicit val fcoCountryFormat = Json.format[FcoCountry] - private val countriesENJson: Seq[Country] = Json.parse(getClass.getResourceAsStream("/countriesEN.json")).as[Map[String, FcoCountry]].map { country => - Country(country._2.country, country._2.name) - }.toSeq.sortWith(_.name < _.name) - - private val mappings = Map( - "independent" -> None, - "alpha_3_code" -> None, - "full_name_en" -> Some("Official Name"), - "status" -> None, - "short_name_uppercase_en" -> None, - "numeric_code" -> None, - "short_name_en" -> Some("Name"), - "alpha_2_code" -> Some("Country") - ) - - private def renameFields(m: Map[String, String]): Map[String, String] = { - mappings.flatMap { case (o, nm) => nm.map(n => n -> m(o)) } - } - - private val utfSorter = java.text.Collator.getInstance() - - private def allAliases(aliasFileClasspath: String) = - CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream(aliasFileClasspath), "UTF-8")) - .allWithOrderedHeaders()._2.sortBy(x => x("countryCode")) - .map { x => x("countryCode") -> (x("aliases").split("\\|").map(_.trim).toList) } - .map { case (c, as) => c -> as.map(a => Country(c, a)) } - .toMap - private val allAliasesEN = allAliases("/countryAliasesEN.csv") - private val allAliasesCY = allAliases("/countryAliasesCY.csv") - - private val allISORows = CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/iso-countries.csv"), "UTF-8")) - .allWithOrderedHeaders._2.sortBy(x => x("alpha_2_code")) - .map(renameFields) - .groupBy(_ ("Country")).view - .mapValues(v => v.head) - - private val allFCDORows = CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/fcdo_countries.csv"), "UTF-8")) - .allWithOrderedHeaders._2.sortBy(x => x("Country")) - .groupBy(_ ("Country")).view - .mapValues(v => v.head) - - private val allFCDOTRows = CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/fcdo_territories.csv"), "UTF-8")) - .allWithOrderedHeaders._2.sortBy(x => x("Country")) - .filterNot(m => m("Country") == "Not applicable") - .groupBy(_ ("Country")).view - .mapValues(v => v.head) - - private val allWCORows = CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/wco-countries.csv"), "UTF-8")) - .allWithOrderedHeaders._2.sortBy(x => x("Country")) - .groupBy(_ ("Country")) - .view.mapValues(v => v.head) - - private val countriesENFull: Seq[Country] = { - SortedMap.from(allISORows ++ allFCDORows ++ allFCDOTRows) - .map(Country.apply) - .toSeq.sortWith{ case (a, b) => utfSorter.compare(a.name, b.name) < 0 } - } - - private val countriesEN = countriesENFull.flatMap { country => - if(allAliasesEN.contains(country.code)) country +: allAliasesEN(country.code) - else Seq(country) - } - - private val countriesCYFull: Seq[Country] = { - SortedMap.from(allISORows ++ allFCDORows ++ allFCDOTRows ++ allWCORows) - .map(Country.apply) - .toSeq.sortWith{ case (a, b) => utfSorter.compare(a.name, b.name) < 0 } - } - - private val countriesCY = countriesCYFull.flatMap { country => - if (allAliasesCY.contains(country.code)) country +: allAliasesCY(country.code) - else Seq(country) - } - override def findAll(welshFlag: Boolean = false): Seq[Country] = - if (!welshFlag) countriesEN - else countriesCY + if (!welshFlag) english.countriesEN + else welsh.countriesCY override def find(welshFlag: Boolean = false, code: String): Option[Country] = { if (!welshFlag) { - val filtered = countriesEN.filter(_.code == code) + val filtered = english.countriesEN.filter(_.code == code) filtered.headOption } else { - val filtered = countriesCY.filter(_.code == code) + val filtered = welsh.countriesCY.filter(_.code == code) filtered.headOption } - } } -case class FcoCountry(country: String, name: String) - -object ForeignOfficeCountryService extends ForeignOfficeCountryService +case class FcoCountry(country: String, name: String) \ No newline at end of file diff --git a/app/services/EnglishCountryNamesDataSource.scala b/app/services/EnglishCountryNamesDataSource.scala new file mode 100644 index 00000000..8a4a4982 --- /dev/null +++ b/app/services/EnglishCountryNamesDataSource.scala @@ -0,0 +1,63 @@ +/* + * Copyright 2024 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 services + +import address.v2.Country +import com.github.tototoshi.csv.CSVReader + +import javax.inject.Singleton +import scala.collection.MapView +import scala.collection.immutable.SortedMap +import scala.io.Source + +@Singleton +class EnglishCountryNamesDataSource extends CountryNamesDataSource { + private val allAliasesEN = allAliases("/countryAliasesEN.csv") + + val allISORows: MapView[String, Map[String, String]] = + CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/iso-countries.csv"), "UTF-8")) + .allWithOrderedHeaders._2.sortBy(x => x("alpha_2_code")) + .map(renameFields) + .groupBy(_("Country")).view + .mapValues(v => v.head) + + val allFCDORows: MapView[String, Map[String, String]] = + CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/fcdo_countries.csv"), "UTF-8")) + .allWithOrderedHeaders._2.sortBy(x => x("Country")) + .groupBy(_("Country")).view + .mapValues(v => v.head) + + val allFCDOTRows: MapView[String, Map[String, String]] = + CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/fcdo_territories.csv"), "UTF-8")) + .allWithOrderedHeaders._2.sortBy(x => x("Country")) + .filterNot(m => m("Country") == "Not applicable") + .groupBy(_("Country")).view + .mapValues(v => v.head) + + private val countriesENFull: Seq[Country] = { + SortedMap.from(allISORows ++ allFCDORows ++ allFCDOTRows) + .map(Country.apply) + .toSeq.sortWith { case (a, b) => utfSorter.compare(a.name, b.name) < 0 } + } + + val countriesEN = countriesENFull.flatMap { country => + if (allAliasesEN.contains(country.code)) country +: allAliasesEN(country.code) + else Seq(country) + } + + +} \ No newline at end of file diff --git a/app/services/ExtendedProxyConfig.scala b/app/services/ExtendedProxyConfig.scala new file mode 100644 index 00000000..bcb60c91 --- /dev/null +++ b/app/services/ExtendedProxyConfig.scala @@ -0,0 +1,7 @@ +package services + +import org.htmlunit.ProxyConfig + +class ExtendedProxyConfig(host: String, port: Int, scheme: String, val username: String, + val password: String) extends ProxyConfig(host, port, scheme) { +} diff --git a/app/services/GovWalesCacheUpdateScheduler.scala b/app/services/GovWalesCacheUpdateScheduler.scala new file mode 100644 index 00000000..a51958b6 --- /dev/null +++ b/app/services/GovWalesCacheUpdateScheduler.scala @@ -0,0 +1,52 @@ +/* + * Copyright 2024 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 services + +import org.apache.pekko.actor.ActorSystem +import play.api.{Configuration, Logger} + +import javax.inject.{Inject, Singleton} +import scala.concurrent.ExecutionContext +import scala.concurrent.duration._ +import scala.util.Try + +@Singleton +class GovWalesCacheUpdateScheduler @Inject()(config: Configuration, dataSource: WelshCountryNamesDataSource)(implicit ec: ExecutionContext) { + val logger = Logger(this.getClass) + + val delay: FiniteDuration = config.getOptional[Int]("microservice.services.gov-wales.cache-schedule.initial-delay").map(_.seconds) + .getOrElse(throw new IllegalArgumentException("microservice.services.gov-wales.cache-schedule.initial-delay not set")) + val interval: FiniteDuration = config.getOptional[Int]("microservice.services.gov-wales.cache-schedule.interval").map(_.seconds) + .getOrElse(throw new IllegalArgumentException("microservice.services.gov-wales.cache-schedule.interval")) + + GovWalesCacheUpdateScheduler.system.getScheduler.scheduleAtFixedRate(delay, interval){ + () => Try { + logger.info("Gov Wales data update started") + + for { + _ <- dataSource.updateCache() + _ <- dataSource.retrieveAndStoreData() + } yield { + logger.info("Gov Wales data update finished") + } + } + }(ec) +} + +object GovWalesCacheUpdateScheduler { + val system: ActorSystem = ActorSystem("gov-wales-check-actor-system") +} diff --git a/app/services/WelshCountryNamesDataSource.scala b/app/services/WelshCountryNamesDataSource.scala new file mode 100644 index 00000000..2ae34888 --- /dev/null +++ b/app/services/WelshCountryNamesDataSource.scala @@ -0,0 +1,186 @@ +/* + * Copyright 2024 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 services + +import address.v2.Country +import com.github.tototoshi.csv.CSVReader +import net.ruippeixotog.scalascraper.browser.HtmlUnitBrowser +import org.apache.pekko.stream.Materializer +import org.htmlunit.{DefaultCredentialsProvider, UnexpectedPage} +import org.htmlunit.html.{HtmlAnchor, HtmlPage} +import play.api.Logger +import uk.gov.hmrc.http.HeaderCarrier +import uk.gov.hmrc.objectstore.client.Path +import uk.gov.hmrc.objectstore.client.play.Implicits._ +import uk.gov.hmrc.objectstore.client.play.PlayObjectStoreClient + +import java.io.InputStream +import javax.inject.{Inject, Singleton} +import scala.collection.immutable.SortedMap +import scala.concurrent.{ExecutionContext, Future} +import scala.io.Source +import scala.jdk.javaapi.CollectionConverters.asScala + + + +@Singleton +class WelshCountryNamesDataSource @Inject() (english: EnglishCountryNamesDataSource) extends CountryNamesDataSource { + + protected def streamToString(stream: InputStream): String = { + Source.fromInputStream(stream).getLines().toList.mkString("\n") + } + + protected val mutable: java.util.Deque[CachedData] = new java.util.concurrent.ConcurrentLinkedDeque() + + val localData = streamToString(getClass.getResourceAsStream("/welsh-country-names.csv")) + mutable.add(CachedData("", localData)) + + def isCacheReady: Boolean = Option(mutable.peekFirst()).isDefined + + def updateCache(): Future[Unit] = Future.successful() + + def retrieveAndStoreData(): Future[Unit] = Future.successful() + + private val allAliasesCY = allAliases("/countryAliasesCY.csv") + + private val allWCORows = CSVReader.open(Source.fromInputStream(getClass.getResourceAsStream("/wco-countries.csv"), "UTF-8")) + .allWithOrderedHeaders._2.sortBy(x => x("Country")) + .groupBy(_("Country")) + .view.mapValues(v => v.head) + + private def allGovWalesRows(govWalesData: String) = CSVReader.open(Source.fromString(govWalesData)) + .allWithOrderedHeaders._2.sortBy(x => x("Cod gwlad (Country code)")) + .groupBy(_("Cod gwlad (Country code)")) + .view.mapValues(v => v.head) + .map { case (k, m) => k -> Map("Country" -> m("Cod gwlad (Country code)"), "Name" -> m("Enw yn Gymraeg (Name in Welsh)")) } + + private def countriesCYFull(govWalesData: String): Seq[Country] = + SortedMap.from(english.allISORows ++ english.allFCDORows ++ english.allFCDOTRows ++ allWCORows ++ allGovWalesRows(govWalesData)) + .map(Country.apply) + .toSeq.sortWith { case (a, b) => utfSorter.compare(a.name, b.name) < 0 } + + protected def countriesWithAliases(govWalesData: String) = { + countriesCYFull(govWalesData).flatMap { country => + if (allAliasesCY.contains(country.code)) country +: allAliasesCY(country.code) + else Seq(country) + } + } + + def countriesCY: Seq[Country] = + countriesWithAliases(mutable.peekFirst().data) +} + + +@Singleton +class WelshCountryNamesObjectStoreDataSource @Inject() ( + englishCountryNamesDataSource: EnglishCountryNamesDataSource, objectStore: PlayObjectStoreClient, + proxyConfig: Option[ExtendedProxyConfig], implicit val ec: ExecutionContext, implicit val materializer: Materializer) + extends WelshCountryNamesDataSource(englishCountryNamesDataSource) { + + val logger = Logger(this.getClass) + + private val objectStorePath = Path.Directory("govwales").file("country-names.csv") + + override def retrieveAndStoreData: Future[Unit] = { + try { + val browser = new HtmlUnitBrowser(proxy = proxyConfig) + + if (proxyConfig.isDefined) { + val credentialsProvider = browser.underlying.getCredentialsProvider.asInstanceOf[DefaultCredentialsProvider] + credentialsProvider.addCredentials(proxyConfig.get.username, proxyConfig.get.password.toCharArray) + } + + val page = browser.underlying.getPage[HtmlPage]( + "https://www.gov.wales/bydtermcymru/international-place-names") + + var count = 0 + var link: Option[HtmlAnchor] = None + + while (count < 60 && link.isEmpty) { + link = asScala(page.getAnchors).toSeq.find(a => a.asNormalizedText().startsWith("Enwau gwledydd")) + count = count + 1 + + try { + // This is blocking but usually completes on the first try + Thread.sleep(500) + } + } + + val href = s"https://www.gov.wales/${link.get.getHrefAttribute}" + val download = browser.underlying.getPage[UnexpectedPage](href) + implicit val hc: HeaderCarrier = new HeaderCarrier() + + val d = download.getInputStream + val content = streamToString(d) + + val csv = CSVReader.open(Source.fromString(content)) + + // Check the integrity of the data file before caching it + if (csv.allWithHeaders().length > 1) { + mutable.addFirst(CachedData("", content)) + if (mutable.size() > 1) mutable.removeLast() + logger.info("Refreshed welsh country name data from third party source") + + objectStore.putObject(path = objectStorePath, content, contentType = Some("text/plain")) + .map(_ => logger.info("Wrote welsh country name data to object-store successfully")) + .recoverWith { case e => + logger.error("Could not write welsh country name data to object-store", e) + Future.successful() + } + } + else { + logger.info(s"Error parsing welsh country name data from third party, unexpected file contents") + Future.successful() + } + + } catch { + case e: Exception => + logger.error("Welsh country name data retrieval and storage failed", e) + Future.successful() + } + } + + override def updateCache(): Future[Unit] = { + try { + implicit val hc = new HeaderCarrier(); + + import uk.gov.hmrc.objectstore.client.play.Implicits.InMemoryReads._ + + objectStore.getObject[String](objectStorePath).map { + case Some(obj) => + val csv = CSVReader.open(Source.fromString(obj.content)) + + if (csv.allWithHeaders().length > 1) { + mutable.addFirst(CachedData("", obj.content)) + if (mutable.size() > 1) mutable.removeLast() + logger.info("Refreshed welsh country name data cache from object-store") + } + else { + logger.info(s"Error parsing welsh country name data cache from object-store, unexpected file contents") + } + case None => logger.info("Did not find welsh country name data in object-store (it may not have been initialised yet)") + } + + } catch { + case e: Exception => + logger.error("Welsh country name data cache initialisation failed", e) + Future.successful() + } + } +} + +case class CachedData(checksum: String, data: String) diff --git a/app/views/abp/non_uk_mode_edit.scala.html b/app/views/abp/non_uk_mode_edit.scala.html index 25833ad2..6d899cc4 100644 --- a/app/views/abp/non_uk_mode_edit.scala.html +++ b/app/views/abp/non_uk_mode_edit.scala.html @@ -18,11 +18,12 @@ @import model._ @import uk.gov.hmrc.govukfrontend.views.html.components @import views.html.templates.page_template -@import services.ForeignOfficeCountryService @import address.v2.Country @import views.ViewHelper +@import services.CountryService + +@this(form: FormWithCSRF, textarea: GovukTextarea, button: GovukButton, textInput: GovukInput, radios: GovukRadios, select: GovukSelect, page: page_template, govukFieldset: GovukFieldset, countryService: CountryService) -@this(form: FormWithCSRF, textarea: GovukTextarea, button: GovukButton, textInput: GovukInput, radios: GovukRadios, select: GovukSelect, page: page_template, govukFieldset: GovukFieldset) @(id: String, journeyData: JourneyDataV2, editForm: Form[Edit], countries: Seq[Country], isWelsh: Boolean, isUKMode: Boolean = false)(implicit request: Request[_], messages: Messages, appConfig: FrontendAppConfig) @{ @@ -106,7 +107,7 @@

@if(journeyData.countryCode.isDefined) { @textInput(Input(value = - editForm("countryCode").value.flatMap(c => ForeignOfficeCountryService.find(code = c)).map(_.name), + editForm("countryCode").value.flatMap(c => countryService.find(isWelsh, code = c)).map(_.name), attributes = Map("disabled" -> "disabled"), label = Label(content = HtmlContent(messages("editPage.countryLabel"))), formGroupClasses = "form-field-group", autocomplete = Some("country"), diff --git a/app/views/international/edit.scala.html b/app/views/international/edit.scala.html index 6c6cf2ce..3206c879 100644 --- a/app/views/international/edit.scala.html +++ b/app/views/international/edit.scala.html @@ -18,12 +18,12 @@ @import model._ @import uk.gov.hmrc.govukfrontend.views.html.components @import views.html.templates.page_template -@import services.ForeignOfficeCountryService +@import services.CountryService @import address.v2.Country @import views.ViewHelper @this(form: FormWithCSRF, textarea: GovukTextarea, button: GovukButton, textInput: GovukInput, radios: GovukRadios, -select: GovukSelect, page: page_template, govukFieldset: GovukFieldset) +select: GovukSelect, page: page_template, govukFieldset: GovukFieldset, countryService: CountryService) @(id: String, journeyData: JourneyDataV2, editForm: Form[Edit], countries: Seq[Country], isWelsh: Boolean, isUKMode: Boolean = false)(implicit request: Request[_], messages: Messages, appConfig: FrontendAppConfig) @resolvedConf = @{ @@ -111,7 +111,7 @@

@if(journeyData.countryCode.isDefined) { @textInput(Input(value = - editForm("countryCode").value.flatMap(c => ForeignOfficeCountryService.find(code = c)).map(_.name), + editForm("countryCode").value.flatMap(c => countryService.find(isWelsh, code = c)).map(_.name), attributes = Map("disabled" -> "disabled"), label = Label(content = HtmlContent(internationalMessage("editPage.countryLabel"))), formGroupClasses = "form-field-group", autocomplete = Some("country"), diff --git a/conf/application.conf b/conf/application.conf index a5b437ee..492119c8 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -21,6 +21,7 @@ play.http.router=prod.Routes play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientModule" play.modules.enabled += "uk.gov.hmrc.mongo.play.PlayMongoModule" +play.modules.enabled += "uk.gov.hmrc.objectstore.client.play.modules.ObjectStoreModule" # Custom error handler play.http.errorHandler = "config.AddressLookupFrontendErrorHandler" @@ -56,6 +57,10 @@ mongodb { ttl = "60 minutes" } +internal-auth.token = "2345" +object-store.default-retention-period = "10-years" + + microservice { hosts.allowList = ["tax.service.gov.uk", "www.tax.service.gov.uk", "admin.tax.service.gov.uk"] @@ -77,6 +82,22 @@ microservice { host = "localhost" port = 9022 } + + object-store { + host = localhost + port = 8464 + } + + gov-wales { + useLocal = true + + cache-schedule { + // no delay + initial-delay = 0 + // 24 hours + interval = 86400 + } + } } } diff --git a/conf/prod.routes b/conf/prod.routes index 4f939fc1..204bfc15 100644 --- a/conf/prod.routes +++ b/conf/prod.routes @@ -1,4 +1,8 @@ # Add all the application routes to the app.routes file -> /lookup-address app.Routes -> /api api.Routes --> / health.Routes + +GET /ping/ping @health.HealthController.ping + +# Re-enable the /ping endpoint +GET /ping controllers.PingController.ping diff --git a/conf/test.routes b/conf/test.routes index 54c8ecba..8a6d0877 100644 --- a/conf/test.routes +++ b/conf/test.routes @@ -1,4 +1,4 @@ -GET /v2/test-setup @controllers.testonly.StubController.showStubPageForJourneyInitV2 +GET /v2/test-setup @controllers.testonly.StubController.showStubPageForJourneyInitV2 POST /v2/test-setup @controllers.testonly.StubController.submitStubForNewJourneyV2 GET /end-of-journey/:id @controllers.testonly.StubController.showResultOfJourney(id: String) \ No newline at end of file diff --git a/conf/wco-countries-merged.csv b/conf/wco-countries-merged.csv new file mode 100644 index 00000000..5daf0327 --- /dev/null +++ b/conf/wco-countries-merged.csv @@ -0,0 +1,251 @@ +Country,Name,Cod gwlad (Country code),Enw yn Saesneg (Name in English),Enw yn Gymraeg (Name in Welsh),Enw swyddogol yn Saesneg (Official name in English),Enw swyddogol yn Gymraeg (Official name in Welsh) +AD,Andorra,AD,Andorra,Andorra,The Principality of Andorra,Tywysogaeth Andorra +AE,Yr Emiradau Arabaidd Unedig,AE,United Arab Emirates,Yr Emiradau Arabaidd Unedig,The United Arab Emirates,Yr Emiradau Arabaidd Unedig +AF,Affganistan,AF,Afghanistan,Affganistan,The Islamic Republic of Afghanistan,Gweriniaeth Islamaidd Affganistan +AG,Antigua a Barbuda,AG,Antigua and Barbuda,Antigua a Barbuda,Antigua and Barbuda,Antigua a Barbuda +AI,Anguilla,,,,, +AL,Albania,AL,Albania,Albania,The Republic of Albania,Gweriniaeth Albania +AM,Armenia,AM,Armenia,Armenia,The Republic of Armenia,Gweriniaeth Armenia +AO,Angola,AO,Angola,Angola,The Republic of Angola,Gweriniaeth Angola +AQ,Antarctica,,,,, +AR,Yr Ariannin,AR,Argentina,Yr Ariannin,The Argentine Republic,Gweriniaeth yr Ariannin +AS,Samoa Americanaidd,,,,, +AT,Awstria,AT,Austria,Awstria,The Republic of Austria,Gweriniaeth Awstria +AU,Awstralia,AU,Australia,Awstralia,The Commonwealth of Australia,Cymanwlad Awstralia +AW,Aruba,,,,, +AX,Ynysoedd Aland,,,,, +AZ,Azerbaijan,AZ,Azerbaijan,Azerbaijan,The Republic of Azerbaijan,Gweriniaeth Azerbaijan +BA,Bosnia a Herzegovina,BA,Bosnia and Herzegovina,Bosnia a Herzegovina,Bosnia and Herzegovina,Bosnia a Herzegovina +BB,Barbados,BB,Barbados,Barbados,Barbados,Barbados +BD,Bangladesh,BD,Bangladesh,Bangladesh,The People's Republic of Bangladesh,Gweriniaeth y Bobl Bangladesh +BE,Gwlad Belg,BE,Belgium,Gwlad Belg,The Kingdom of Belgium,Teyrnas Gwlad Belg +BF,Burkina Faso,BF,Burkina Faso,Burkina Faso,Burkina Faso,Burkina Faso +BG,Bwlgaria,BG,Bulgaria,Bwlgaria,The Republic of Bulgaria,Gweriniaeth Bwlgaria +BH,Bahrain,BH,Bahrain,Bahrain,The Kingdom of Bahrain,Teyrnas Bahrain +BI,Burundi,BI,Burundi,Burundi,The Republic of Burundi,Gweriniaeth Burundi +BJ,Benin,BJ,Benin,Benin,The Republic of Benin,Gweriniaeth Benin +BL,St Barthélemy,,,,, +BM,Bermuda,,,,, +BN,Brunei,BN,Brunei,Brunei,Brunei Darussalam,Brunei Darussalam +BO,Bolivia,BO,Bolivia,Bolivia,The Plurinational State of Bolivia,Gwladwriaeth Amlgenhedlig Bolivia +BQ,"Bonaire, Sint Eustatius a Saba",,,,, +BR,Brasil,BR,Brazil,Brasil,The Federative Republic of Brazil,Gweriniaeth Ffedereiddiol Brasil +BS,Y Bahamas,BS,The Bahamas,Y Bahamas,The Commonwealth of The Bahamas,Cymanwlad y Bahamas +BT,Bhutan,BT,Bhutan,Bhutan,The Kingdom of Bhutan,Teyrnas Bhutan +BV,Ynys Bouvet,,,,, +BW,Botswana,BW,Botswana,Botswana,The Republic of Botswana,Gweriniaeth Botswana +BY,Belarws,BY,Belarus,Belarws,The Republic of Belarus,Gweriniaeth Belarws +BZ,Belize,BZ,Belize,Belize,Belize,Belize +CA,Canada,CA,Canada,Canada,Canada,Canada +CC,Ynysoedd Cocos,,,,, +CD,Gweriniaeth Ddemocrataidd Congo,CD,Congo (Democratic Republic),Congo (Gweriniaeth Ddemocrataidd),The Democratic Republic of the Congo,Gweriniaeth Ddemocrataidd Congo +CF,Gweriniaeth Canolbarth Affrica,CF,Central African Republic,Gweriniaeth Canolbarth Affrica,The Central African Republic,Gweriniaeth Canolbarth Affrica +CG,Congo,CG,Congo,Congo,The Republic of the Congo,Gweriniaeth Congo +CH,Y Swistir,CH,Switzerland,Y Swistir,The Swiss Confederation,Cydffederasiwn y Swistir +CI,Y Traeth Ifori,CI,Ivory Coast,Y Traeth Ifori,The Republic of Côte D’Ivoire,Gweriniaeth Côte D’Ivoire +CK,Ynysoedd Cook,,,,, +CL,Chile,CL,Chile,Chile,The Republic of Chile,Gweriniaeth Chile +CM,Cameroon,CM,Cameroon,Cameroon,The Republic of Cameroon,Gweriniaeth Cameroon +CN,Tsieina,CN,China,Tsieina,The People's Republic of China,Gweriniaeth y Bobl Tsieina +CO,Colombia,CO,Colombia,Colombia,The Republic of Colombia,Gweriniaeth Colombia +CR,Costa Rica,CR,Costa Rica,Costa Rica,The Republic of Costa Rica,Gweriniaeth Costa Rica +CU,Ciwba,CU,Cuba,Ciwba,The Republic of Cuba,Gweriniaeth Ciwba +CV,Cape Verde,CV,Cape Verde,Cape Verde,The Republic of Cabo Verde,Gweriniaeth Cabo Verde +CW,Curaçao,,,,, +CX,Ynys y Nadolig,,,,, +CY,Cyprus,CY,Cyprus,Cyprus,The Republic of Cyprus,Gweriniaeth Cyprus +CZ,Tsiecia,CZ,Czechia,Tsiecia,The Czech Republic,Y Weriniaeth Tsiec +DE,Yr Almaen,DE,Germany,Yr Almaen,The Federal Republic of Germany,Gweriniaeth Ffederal yr Almaen +DJ,Djibouti,DJ,Djibouti,Djibouti,The Republic of Djibouti,Gweriniaeth Djibouti +DK,Denmarc,DK,Denmark,Denmarc,The Kingdom of Denmark,Teyrnas Denmarc +DM,Dominica,DM,Dominica,Dominica,The Commonwealth of Dominica,Cymanwlad Dominica +DO,Gweriniaeth Dominica,DO,Dominican Republic,Gweriniaeth Dominica,The Dominican Republic,Gweriniaeth Dominica +DZ,Algeria,DZ,Algeria,Algeria,The People's Democratic Republic of Algeria,Gweriniaeth Ddemocrataidd y Bobl Algeria +EC,Ecuador,EC,Ecuador,Ecuador ,The Republic of Ecuador,Gweriniaeth Ecuador +EE,Estonia,EE,Estonia,Estonia,The Republic of Estonia,Gweriniaeth Estonia +EG,Yr Aifft,EG,Egypt,Yr Aifft,The Arab Republic of Egypt,Gweriniaeth Arabaidd yr Aifft +EH,Gorllewin Sahara,ER,Eritrea,Eritrea,The State of Eritrea,Gwladwriaeth Eritrea +ER,Eritrea,ES,Spain,Sbaen,The Kingdom of Spain,Teyrnas Sbaen +ES,Sbaen,ET,Ethiopia,Ethiopia,The Federal Democratic Republic of Ethiopia,Gweriniaeth Ddemocrataidd Ffederal Ethiopia +ET,Ethiopia,FI,Finland,Y Ffindir,The Republic of Finland,Gweriniaeth y Ffindir +FI,Y Ffindir,,,,, +FJ,Ffiji,FJ,Fiji,Ffiji,The Republic of Fiji,Gweriniaeth Ffiji +FK,Ynysoedd Falkland,,,,, +FM,Micronesia,FM,Micronesia,Micronesia,The Federated States of Micronesia,Gwladwriaethau Ffedereiddiedig Micronesia +FO,Ynysoedd Ffaro,,,,, +FR,Ffrainc,FR,France,Ffrainc,The French Republic,Gweriniaeth Ffrainc +GA,Gabon,GA,Gabon,Gabon,The Gabonese Republic,Gweriniaeth Gabon +GB,Y Deyrnas Unedig,GB,United Kingdom,Y Deyrnas Unedig,The United Kingdom of Great Britain and Northern Ireland,Teyrnas Unedig Prydain Fawr a Gogledd Iwerddon +GD,Grenada,GD,Grenada,Grenada,Grenada,Grenada +GE,Georgia,GE,Georgia,Georgia,Georgia,Georgia +GF,Guiana Ffrengig,,,,, +GG,Guernsey,,,,, +GH,Ghana,GH,Ghana,Ghana,The Republic of Ghana,Gweriniaeth Ghana +GI,Gibraltar,,,,, +GL,Yr Ynys Las,,,,, +GM,Y Gambia,GM,The Gambia,Y Gambia,The Republic of The Gambia,Gweriniaeth y Gambia +GN,Guinea,GN,Guinea,Guinea,The Republic of Guinea,Gweriniaeth Guinea +GP,Guadeloupe,,,,, +GQ,Guinea Gyhydeddol,GQ,Equatorial Guinea,Guinea Gyhydeddol,The Republic of Equatorial Guinea,Gweriniaeth Guinea Gyhydeddol +GR,Gwlad Groeg,GR,Greece,Gwlad Groeg,The Hellenic Republic,Y Weriniaeth Helenaidd +GS,De Georgia ac Ynysoedd Sandwich y De,,,,, +GT,Guatemala,GT,Guatemala,Guatemala,The Republic of Guatemala,Gweriniaeth Guatemala +GU,Guam,,,,, +GW,Guinea-Bissau,GW,Guinea-Bissau,Guinea-Bissau,The Republic of Guinea-Bissau,Gweriniaeth Guinea-Bissau +GY,Guyana,GY,Guyana,Guyana,The Co-operative Republic of Guyana,Gweriniaeth Gydweithredol Guyana +HK,Hong Kong,,,,, +HM,Ynys Heard ac Ynysoedd McDonald,,,,, +HN,Honduras,HN,Honduras,Honduras ,The Republic of Honduras,Gweriniaeth Honduras +HR,Croatia,HR,Croatia,Croatia,The Republic of Croatia,Gweriniaeth Croatia +HT,Haiti,HT,Haiti,Haiti,The Republic of Haiti,Gweriniaeth Haiti +HU,Hwngari,HU,Hungary,Hwngari,Hungary,Hwngari +ID,Indonesia,ID,Indonesia,Indonesia,The Republic of Indonesia,Gweriniaeth Indonesia +IE,Iwerddon,IE,Ireland,Iwerddon,Ireland,Iwerddon +IL,Israel,IL,Israel,Israel,The State of Israel,Gwladwriaeth Israel +IM,Ynys Manaw,,,,, +IN,India,IN,India,India,The Republic of India,Gweriniaeth India +IO,Tiriogaeth Brydeinig Cefnfor India,,,,, +IQ,Irac,IQ,Iraq,Irac,The Republic of Iraq,Gweriniaeth Irac +IR,Iran,IR,Iran,Iran,The Islamic Republic of Iran,Gweriniaeth Islamaidd Iran +IS,Gwlad yr Iâ,IS,Iceland,Gwlad yr Iâ,Iceland,Gwlad yr Iâ +IT,Yr Eidal,IT,Italy,Yr Eidal,The Italian Republic,Gweriniaeth yr Eidal +JE,Jersey,,,,, +JM,Jamaica,JM,Jamaica,Jamaica,Jamaica,Jamaica +JO,Gwlad yr Iorddonen,JO,Jordan,Gwlad yr Iorddonen,The Hashemite Kingdom of Jordan,Teyrnas Hashimaidd Gwlad yr Iorddonen +JP,Japan,JP,Japan,Japan,Japan,Japan +KE,Kenya,KE,Kenya,Kenya,The Republic of Kenya,Gweriniaeth Kenya +KG,Kyrgyzstan,KG,Kyrgyzstan,Kyrgyzstan,The Kyrgyz Republic,Gweriniaeth Kyrgyzstan +KH,Cambodia,KH,Cambodia,Cambodia,The Kingdom of Cambodia,Teyrnas Cambodia +KI,Kiribati,KI,Kiribati,Kiribati,The Republic of Kiribati,Gweriniaeth Kiribati +KM,Comoros,KM,Comoros,Comoros,The Union of the Comoros,Undeb y Comoros +KN,St Kitts a Nevis,KN,St Kitts and Nevis,St Kitts a Nevis,The Federation of Saint Christopher and Nevis,Ffederasiwn Sant Christopher a Nevis +KP,Gogledd Korea,KP,North Korea,Gogledd Korea,The Democratic People's Republic of Korea,Gweriniaeth Ddemocrataidd y Bobl Korea +KR,De Korea,KR,South Korea,De Korea,The Republic of Korea,Gweriniaeth Korea +KW,Kuwait,KW,Kuwait,Kuwait,The State of Kuwait,Gwladwriaeth Kuwait +KY,Ynysoedd Cayman,,,,, +KZ,Kazakhstan,KZ,Kazakhstan,Kazakhstan,The Republic of Kazakhstan,Gweriniaeth Kazakhstan +LA,Laos,LA,Laos,Laos,The Lao People's Democratic Republic,Gweriniaeth Ddemocrataidd y Bobl Lao +LB,Libanus,LB,Lebanon,Libanus,The Lebanese Republic,Gweriniaeth Libanus +LC,St Lucia,LC,St Lucia,St Lucia,Saint Lucia,Santes Lucia +LI,Liechtenstein,LI,Liechtenstein,Liechtenstein,The Principality of Liechtenstein,Tywysogaeth Liechtenstein +LK,Sri Lanka,LK,Sri Lanka,Sri Lanka,The Democratic Socialist Republic of Sri Lanka,Gweriniaeth Sosialaidd Ddemocrataidd Sri Lanka +LR,Liberia,LR,Liberia,Liberia,The Republic of Liberia,Gweriniaeth Liberia +LS,Lesotho,LS,Lesotho,Lesotho,The Kingdom of Lesotho,Teyrnas Lesotho +LT,Lithwania,LT,Lithuania,Lithwania,The Republic of Lithuania,Gweriniaeth Lithwania +LU,Lwcsembwrg,LU,Luxembourg,Lwcsembwrg,The Grand Duchy of Luxembourg,Archddugiaeth Lwcsembwrg +LV,Latfia,LV,Latvia,Latfia,The Republic of Latvia,Gweriniaeth Latfia +LY,Libya,LY,Libya,Libya,Libya,Libya +MA,Morocco,MA,Morocco,Morocco,The Kingdom of Morocco,Teyrnas Morocco +MC,Monaco,MC,Monaco,Monaco,The Principality of Monaco,Tywysogaeth Monaco +MD,Moldofa,MD,Moldova,Moldofa,The Republic of Moldova,Gweriniaeth Moldofa +ME,Montenegro,ME,Montenegro,Montenegro,Montenegro,Montenegro +MF,Saint Martin,,,,, +MG,Madagascar,MG,Madagascar,Madagascar ,The Republic of Madagascar,Gweriniaeth Madagascar +MH,Ynysoedd Marshall,MH,Marshall Islands,Ynysoedd Marshall,The Republic of the Marshall Islands,Gweriniaeth Ynysoedd Marshall +MK,Gogledd Macedonia,MK,North Macedonia,Gogledd Macedonia,Republic of North Macedonia,Gweriniaeth Gogledd Macedonia +ML,Mali,ML,Mali,Mali,The Republic of Mali,Gweriniaeth Mali +MM,Myanmar,MM,Myanmar (Burma),Myanmar (Burma),The Republic of the Union of Myanmar,Gweriniaeth Undeb Myanmar +MN,Mongolia,MN,Mongolia,Mongolia,Mongolia,Mongolia +MO,Macao,,,,, +MP,Ynysoedd Gogledd Mariana,,,,, +MQ,Martinique,,,,, +MR,Mauritania,MR,Mauritania,Mauritania,The Islamic Republic of Mauritania,Gweriniaeth Islamaidd Mauritania +MS,Montserrat,,,,, +MT,Malta,MT,Malta,Malta,The Republic of Malta,Gweriniaeth Malta +MU,Mauritius,MU,Mauritius,Mauritius,The Republic of Mauritius,Gweriniaeth Mauritius +MV,Maldives,MV,Maldives,Maldives,The Republic of Maldives,Gweriniaeth Maldives +MW,Malawi,MW,Malawi,Malawi,The Republic of Malawi,Gweriniaeth Malawi +MX,Mecsico,MX,Mexico,Mecsico,The United Mexican States,Unol Daleithiau Mecsico +MY,Malaysia,MY,Malaysia,Malaysia,Malaysia,Malaysia +MZ,Mozambique,MZ,Mozambique,Mozambique,The Republic of Mozambique,Gweriniaeth Mozambique +NA,Namibia,NA,Namibia,Namibia,The Republic of Namibia,Gweriniaeth Namibia +NC,Caledonia Newydd,,,,, +NE,Niger,,,,, +NF,Ynys Norfolk,NE,Niger,Niger,The Republic of Niger,Gweriniaeth Niger +NG,Nigeria,NG,Nigeria,Nigeria,The Federal Republic of Nigeria,Gweriniaeth Ffederal Nigeria +NI,Nicaragua,NI,Nicaragua,Nicaragua,The Republic of Nicaragua,Gweriniaeth Nicaragua +NL,Yr Iseldiroedd,NL,Netherlands,Yr Iseldiroedd,The Kingdom of the Netherlands,Teyrnas yr Iseldiroedd +NO,Norwy,NO,Norway,Norwy,The Kingdom of Norway,Teyrnas Norwy +NP,Nepal,NP,Nepal,Nepal,Nepal,Nepal +NR,Nauru,NR,Nauru,Nauru,The Republic of Nauru,Gweriniaeth Nauru +NU,Niue,,,,, +NZ,Seland Newydd,NZ,New Zealand,Seland Newydd,New Zealand,Seland Newydd +OM,Oman,OM,Oman,Oman,The Sultanate of Oman,Swltaniaeth Oman +PA,Panama,PA,Panama,Panama,The Republic of Panama,Gwerinaeth Panama +PE,Periw,PE,Peru,Periw,The Republic of Peru,Gweriniaeth Periw +PF,Polynesia Ffrengig,,,,, +PG,Papua Guinea Newydd,PG,Papua New Guinea,Papua Guinea Newydd,The Independent State of Papua New Guinea,Gwladwriaeth Annibynnol Papua Guinea Newydd +PH,Ynysoedd Philippines,PH,Philippines,Ynysoedd Philippines,The Republic of the Philippines,Gweriniaeth y Philippines +PK,Pacistan,PK,Pakistan,Pacistan,The Islamic Republic of Pakistan,Gweriniaeth Islamaidd Pacistan +PL,Gwlad Pwyl,PL,Poland,Gwlad Pwyl,The Republic of Poland,Gweriniaeth Gwlad Pwyl +PM,St Pierre a Miquelon,,,,, +PN,"Ynysoedd Pitcairn, Henderson, Ducie ac Oeno",,,,, +PR,Puerto Rico,,,,, +PS,Tiriogaethau Meddianedig Palesteina,,,,, +PT,Portiwgal,PT,Portugal,Portiwgal,The Portuguese Republic,Gweriniaeth Portiwgal +PW,Palau,PW,Palau,Palau,The Republic of Palau,Gweriniaeth Palau +PY,Paraguay,PY,Paraguay,Paraguay,The Republic of Paraguay,Gweriniaeth Paraguay +QA,Qatar,QA,Qatar,Qatar,The State of Qatar,Gwladwriaeth Qatar +RE,Réunion,,,,, +RO,Rwmania,RO,Romania,Rwmania,Romania,Rwmania +RS,Serbia,RS,Serbia,Serbia,The Republic of Serbia,Gweriniaeth Serbia +RU,Rwsia,RU,Russia,Rwsia,The Russian Federation,Ffederasiwn Rwsia +RW,Rwanda,RW,Rwanda,Rwanda,The Republic of Rwanda,Gweriniaeth Rwanda +SA,Saudi Arabia,SA,Saudi Arabia,Saudi Arabia,The Kingdom of Saudi Arabia,Teyrnas Saudi Arabia +SB,Ynysoedd Solomon,SB,Solomon Islands,Ynysoedd Solomon,Solomon Islands,Ynysoedd Solomon +SC,Seychelles,SC,Seychelles,Seychelles,The Republic of Seychelles,Gweriniaeth Seychelles +SD,Sudan,SD,Sudan,Sudan,The Republic of the Sudan,Gweriniaeth Sudan +SE,Sweden,SE,Sweden,Sweden,The Kingdom of Sweden,Teyrnas Sweden +SG,Singapore,SG,Singapore,Singapore,The Republic of Singapore,Gweriniaeth Singapore +SH,"St Helena, Ascension a Tristan da Cunha",,,,, +SI,Slofenia,SI,Slovenia,Slofenia,The Republic of Slovenia,Gweriniaeth Slofenia +SJ,Svalbard a Jan Mayen,,,,, +SK,Slofacia,SK,Slovakia,Slofacia,The Slovak Republic,Y Weriniaeth Slofac +SL,Sierra Leone,SL,Sierra Leone,Sierra Leone,The Republic of Sierra Leone,Gweriniaeth Sierra Leone +SM,San Marino,SM,San Marino,San Marino,The Republic of San Marino,Gweriniaeth San Marino +SN,Senegal,SN,Senegal,Senegal,The Republic of Senegal,Gweriniaeth Senegal +SO,Somalia,SO,Somalia,Somalia,Federal Republic of Somalia,Gweriniaeth Ffederal Somalia +SR,Suriname,SR,Suriname,Suriname,The Republic of Suriname,Gweriniaeth Suriname +SS,De Sudan,SS,South Sudan,De Sudan,The Republic of South Sudan,Gweriniaeth De Sudan +ST,Sao Tome a Principe,ST,Sao Tome and Principe,Sao Tome a Principe,The Democratic Republic of Sao Tome and Principe,Gweriniaeth Ddemocrataidd Sao Tome a Principe +SV,El Salvador,SV,El Salvador,El Salvador ,The Republic of El Salvador,Gweriniaeth El Salvador +SX,Sint Maarten,,,,, +SY,Syria,SY,Syria,Syria,The Syrian Arab Republic,Gweriniaeth Arabaidd Syria +SZ,Eswatini,SZ,Eswatini,Eswatini,Kingdom of Eswatini,Teyrnas Eswatini +TC,Ynysoedd Turks a Caicos,,,,, +TD,Chad,TD,Chad,Chad,The Republic of Chad,Gweriniaeth Chad +TF,Y Tiriogaethau Deheuol Ffrengig,,,,, +TG,Togo,TG,Togo,Togo,The Togolese Republic,Gweriniaeth Togo +TH,Gwlad Thai,TH,Thailand,Gwlad Thai,The Kingdom of Thailand,Teyrnas Gwlad Thai +TJ,Tajikistan,TJ,Tajikistan,Tajikistan,The Republic of Tajikistan,Gweriniaeth Tajikistan +TK,Tokelau,,,,, +TL,Dwyrain Timor,TL,East Timor,Dwyrain Timor,The Democratic Republic of Timor-Leste,Gweriniaeth Ddemocrataidd Timor-Leste +TM,Turkmenistan,TM,Turkmenistan,Turkmenistan,Turkmenistan,Turkmenistan +TN,Tunisia,TN,Tunisia,Tunisia,The Tunisian Republic,Gweriniaeth Tunisia +TO,Tonga,TO,Tonga,Tonga,The Kingdom of Tonga,Teyrnas Tonga +TR,Twrci,TR,Turkey,Twrci,Republic of Türkiye,Gweriniaeth Türkiye +TT,Trinidad a Tobago,TT,Trinidad and Tobago,Trinidad a Tobago,The Republic of Trinidad and Tobago,Gweriniaeth Trinidad a Tobago +TV,Tuvalu,TV,Tuvalu,Tuvalu,Tuvalu,Tuvalu +TW,Taiwan,,,,, +TZ,Tanzania,TZ,Tanzania,Tanzania,The United Republic of Tanzania,Gweriniaeth Unedig Tanzania +UA,Wcráin,UA,Ukraine,Wcráin,Ukraine,Wcráin +UG,Uganda,UG,Uganda,Uganda,The Republic of Uganda,Gweriniaeth Uganda +UM,Mân-ynysoedd pellennig yr Unol Daleithiau,,,,, +US,Unol Daleithiau America,US,United States,Yr Unol Daleithiau,The United States of America,Unol Daleithiau America +UY,Uruguay,UY,Uruguay,Uruguay,The Oriental Republic of Uruguay,Gweriniaeth Ddwyreiniol Uruguay +UZ,Uzbekistan,UZ,Uzbekistan,Uzbekistan,The Republic of Uzbekistan,Gweriniaeth Uzbekistan +VA,Dinas y Fatican,VA,Vatican City,Dinas y Fatican,Vatican City State,Gwladwriaeth Dinas y Fatican +VC,St Vincent a'r Grenadines,VC,St Vincent,St Vincent,Saint Vincent and the Grenadines,Sant Vincent a'r Grenadines +VE,Venezuela,VE,Venezuela,Venezuela,The Bolivarian Republic of Venezuela,Gweriniaeth Bolivaraidd Venezuela +VG,Ynysoedd Prydeinig y Wyryf,,,,, +VI,Ynysoedd Americanaidd y Wyryf,,,,, +VN,Fietnam,VN,Vietnam,Fietnam,The Socialist Republic of Viet Nam,Gweriniaeth Sosialaidd Fiet Nam +VU,Vanuatu,VU,Vanuatu,Vanuatu,The Republic of Vanuatu,Gweriniaeth Vanuatu +WF,Wallis a Futuna,,,,, +WS,Samoa,WS,Samoa,Samoa,The Independent State of Samoa,Gwladwriaeth Annibynnol Samoa +XK,Kosovo,XK,Kosovo,Kosovo,The Republic of Kosovo,Gweriniaeth Kosovo +YE,Yemen,YE,Yemen,Yemen,The Republic of Yemen,Gweriniaeth Yemen +YT,Mayotte,,,,, +ZA,De Affrica,ZA,South Africa,De Affrica,The Republic of South Africa,Gweriniaeth De Affrica +ZM,Zambia,ZM,Zambia,Zambia,The Republic of Zambia,Gweriniaeth Zambia +ZW,Zimbabwe,ZW,Zimbabwe,Zimbabwe,The Republic of Zimbabwe,Gweriniaeth Zimbabwe diff --git a/conf/wco-countries.csv b/conf/wco-countries.csv index 903b4349..a8c3aa5e 100644 --- a/conf/wco-countries.csv +++ b/conf/wco-countries.csv @@ -38,9 +38,9 @@ BY,Belarws BZ,Belize CA,Canada CC,Ynysoedd Cocos -CD,Congo +CD,Gweriniaeth Ddemocrataidd Congo +CG,Congo CF,Gweriniaeth Canolbarth Affrica -CG,Gweriniaeth Ddemocrataidd Congo CH,Y Swistir CI,Y Traeth Ifori CK,Ynysoedd Cook diff --git a/conf/welsh-country-names.csv b/conf/welsh-country-names.csv new file mode 100644 index 00000000..66e68056 --- /dev/null +++ b/conf/welsh-country-names.csv @@ -0,0 +1,196 @@ +Cod gwlad (Country code),Enw yn Saesneg (Name in English),Enw yn Gymraeg (Name in Welsh),Enw swyddogol yn Saesneg (Official name in English),Enw swyddogol yn Gymraeg (Official name in Welsh) +AF,Afghanistan,Affganistan,The Islamic Republic of Afghanistan,Gweriniaeth Islamaidd Affganistan +AL,Albania,Albania,The Republic of Albania,Gweriniaeth Albania +DZ,Algeria,Algeria,The People's Democratic Republic of Algeria,Gweriniaeth Ddemocrataidd y Bobl Algeria +AD,Andorra,Andorra,The Principality of Andorra,Tywysogaeth Andorra +AO,Angola,Angola,The Republic of Angola,Gweriniaeth Angola +AG,Antigua and Barbuda,Antigua a Barbuda,Antigua and Barbuda,Antigua a Barbuda +AR,Argentina,Yr Ariannin,The Argentine Republic,Gweriniaeth yr Ariannin +AM,Armenia,Armenia,The Republic of Armenia,Gweriniaeth Armenia +AU,Australia,Awstralia,The Commonwealth of Australia,Cymanwlad Awstralia +AT,Austria,Awstria,The Republic of Austria,Gweriniaeth Awstria +AZ,Azerbaijan,Azerbaijan,The Republic of Azerbaijan,Gweriniaeth Azerbaijan +BH,Bahrain,Bahrain,The Kingdom of Bahrain,Teyrnas Bahrain +BD,Bangladesh,Bangladesh,The People's Republic of Bangladesh,Gweriniaeth y Bobl Bangladesh +BB,Barbados,Barbados,Barbados,Barbados +BY,Belarus,Belarws,The Republic of Belarus,Gweriniaeth Belarws +BE,Belgium,Gwlad Belg,The Kingdom of Belgium,Teyrnas Gwlad Belg +BZ,Belize,Belize,Belize,Belize +BJ,Benin,Benin,The Republic of Benin,Gweriniaeth Benin +BT,Bhutan,Bhutan,The Kingdom of Bhutan,Teyrnas Bhutan +BO,Bolivia,Bolivia,The Plurinational State of Bolivia,Gwladwriaeth Amlgenhedlig Bolivia +BA,Bosnia and Herzegovina,Bosnia a Herzegovina,Bosnia and Herzegovina,Bosnia a Herzegovina +BW,Botswana,Botswana,The Republic of Botswana,Gweriniaeth Botswana +BR,Brazil,Brasil,The Federative Republic of Brazil,Gweriniaeth Ffedereiddiol Brasil +BN,Brunei,Brunei,Brunei Darussalam,Brunei Darussalam +BG,Bulgaria,Bwlgaria,The Republic of Bulgaria,Gweriniaeth Bwlgaria +BF,Burkina Faso,Burkina Faso,Burkina Faso,Burkina Faso +BI,Burundi,Burundi,The Republic of Burundi,Gweriniaeth Burundi +KH,Cambodia,Cambodia,The Kingdom of Cambodia,Teyrnas Cambodia +CM,Cameroon,Cameroon,The Republic of Cameroon,Gweriniaeth Cameroon +CA,Canada,Canada,Canada,Canada +CV,Cape Verde,Cape Verde,The Republic of Cabo Verde,Gweriniaeth Cabo Verde +CF,Central African Republic,Gweriniaeth Canolbarth Affrica,The Central African Republic,Gweriniaeth Canolbarth Affrica +TD,Chad,Chad,The Republic of Chad,Gweriniaeth Chad +CL,Chile,Chile,The Republic of Chile,Gweriniaeth Chile +CN,China,Tsieina,The People's Republic of China,Gweriniaeth y Bobl Tsieina +CO,Colombia,Colombia,The Republic of Colombia,Gweriniaeth Colombia +KM,Comoros,Comoros,The Union of the Comoros,Undeb y Comoros +CG,Congo,Congo,The Republic of the Congo,Gweriniaeth Congo +CD,Congo (Democratic Republic),Congo (Gweriniaeth Ddemocrataidd),The Democratic Republic of the Congo,Gweriniaeth Ddemocrataidd Congo +CR,Costa Rica,Costa Rica,The Republic of Costa Rica,Gweriniaeth Costa Rica +HR,Croatia,Croatia,The Republic of Croatia,Gweriniaeth Croatia +CU,Cuba,Ciwba,The Republic of Cuba,Gweriniaeth Ciwba +CY,Cyprus,Cyprus,The Republic of Cyprus,Gweriniaeth Cyprus +CZ,Czechia,Tsiecia,The Czech Republic,Y Weriniaeth Tsiec +DK,Denmark,Denmarc,The Kingdom of Denmark,Teyrnas Denmarc +DJ,Djibouti,Djibouti,The Republic of Djibouti,Gweriniaeth Djibouti +DM,Dominica,Dominica,The Commonwealth of Dominica,Cymanwlad Dominica +DO,Dominican Republic,Gweriniaeth Dominica,The Dominican Republic,Gweriniaeth Dominica +TL,East Timor,Dwyrain Timor,The Democratic Republic of Timor-Leste,Gweriniaeth Ddemocrataidd Timor-Leste +EC,Ecuador,Ecuador ,The Republic of Ecuador,Gweriniaeth Ecuador +EG,Egypt,Yr Aifft,The Arab Republic of Egypt,Gweriniaeth Arabaidd yr Aifft +SV,El Salvador,El Salvador ,The Republic of El Salvador,Gweriniaeth El Salvador +GQ,Equatorial Guinea,Guinea Gyhydeddol,The Republic of Equatorial Guinea,Gweriniaeth Guinea Gyhydeddol +ER,Eritrea,Eritrea,The State of Eritrea,Gwladwriaeth Eritrea +EE,Estonia,Estonia,The Republic of Estonia,Gweriniaeth Estonia +SZ,Eswatini,Eswatini,Kingdom of Eswatini,Teyrnas Eswatini +ET,Ethiopia,Ethiopia,The Federal Democratic Republic of Ethiopia,Gweriniaeth Ddemocrataidd Ffederal Ethiopia +FJ,Fiji,Ffiji,The Republic of Fiji,Gweriniaeth Ffiji +FI,Finland,Y Ffindir,The Republic of Finland,Gweriniaeth y Ffindir +FR,France,Ffrainc,The French Republic,Gweriniaeth Ffrainc +GA,Gabon,Gabon,The Gabonese Republic,Gweriniaeth Gabon +GE,Georgia,Georgia,Georgia,Georgia +DE,Germany,Yr Almaen,The Federal Republic of Germany,Gweriniaeth Ffederal yr Almaen +GH,Ghana,Ghana,The Republic of Ghana,Gweriniaeth Ghana +GR,Greece,Gwlad Groeg,The Hellenic Republic,Y Weriniaeth Helenaidd +GD,Grenada,Grenada,Grenada,Grenada +GT,Guatemala,Guatemala,The Republic of Guatemala,Gweriniaeth Guatemala +GN,Guinea,Guinea,The Republic of Guinea,Gweriniaeth Guinea +GW,Guinea-Bissau,Guinea-Bissau,The Republic of Guinea-Bissau,Gweriniaeth Guinea-Bissau +GY,Guyana,Guyana,The Co-operative Republic of Guyana,Gweriniaeth Gydweithredol Guyana +HT,Haiti,Haiti,The Republic of Haiti,Gweriniaeth Haiti +HN,Honduras,Honduras ,The Republic of Honduras,Gweriniaeth Honduras +HU,Hungary,Hwngari,Hungary,Hwngari +IS,Iceland,Gwlad yr Iâ,Iceland,Gwlad yr Iâ +IN,India,India,The Republic of India,Gweriniaeth India +ID,Indonesia,Indonesia,The Republic of Indonesia,Gweriniaeth Indonesia +IR,Iran,Iran,The Islamic Republic of Iran,Gweriniaeth Islamaidd Iran +IQ,Iraq,Irac,The Republic of Iraq,Gweriniaeth Irac +IE,Ireland,Iwerddon,Ireland,Iwerddon +IL,Israel,Israel,The State of Israel,Gwladwriaeth Israel +IT,Italy,Yr Eidal,The Italian Republic,Gweriniaeth yr Eidal +CI,Ivory Coast,Y Traeth Ifori,The Republic of Côte D’Ivoire,Gweriniaeth Côte D’Ivoire +JM,Jamaica,Jamaica,Jamaica,Jamaica +JP,Japan,Japan,Japan,Japan +JO,Jordan,Gwlad yr Iorddonen,The Hashemite Kingdom of Jordan,Teyrnas Hashimaidd Gwlad yr Iorddonen +KZ,Kazakhstan,Kazakhstan,The Republic of Kazakhstan,Gweriniaeth Kazakhstan +KE,Kenya,Kenya,The Republic of Kenya,Gweriniaeth Kenya +KI,Kiribati,Kiribati,The Republic of Kiribati,Gweriniaeth Kiribati +XK,Kosovo,Kosovo,The Republic of Kosovo,Gweriniaeth Kosovo +KW,Kuwait,Kuwait,The State of Kuwait,Gwladwriaeth Kuwait +KG,Kyrgyzstan,Kyrgyzstan,The Kyrgyz Republic,Gweriniaeth Kyrgyzstan +LA,Laos,Laos,The Lao People's Democratic Republic,Gweriniaeth Ddemocrataidd y Bobl Lao +LV,Latvia,Latfia,The Republic of Latvia,Gweriniaeth Latfia +LB,Lebanon,Libanus,The Lebanese Republic,Gweriniaeth Libanus +LS,Lesotho,Lesotho,The Kingdom of Lesotho,Teyrnas Lesotho +LR,Liberia,Liberia,The Republic of Liberia,Gweriniaeth Liberia +LY,Libya,Libya,Libya,Libya +LI,Liechtenstein,Liechtenstein,The Principality of Liechtenstein,Tywysogaeth Liechtenstein +LT,Lithuania,Lithwania,The Republic of Lithuania,Gweriniaeth Lithwania +LU,Luxembourg,Lwcsembwrg,The Grand Duchy of Luxembourg,Archddugiaeth Lwcsembwrg +MG,Madagascar,Madagascar ,The Republic of Madagascar,Gweriniaeth Madagascar +MW,Malawi,Malawi,The Republic of Malawi,Gweriniaeth Malawi +MY,Malaysia,Malaysia,Malaysia,Malaysia +MV,Maldives,Maldives,The Republic of Maldives,Gweriniaeth Maldives +ML,Mali,Mali,The Republic of Mali,Gweriniaeth Mali +MT,Malta,Malta,The Republic of Malta,Gweriniaeth Malta +MH,Marshall Islands,Ynysoedd Marshall,The Republic of the Marshall Islands,Gweriniaeth Ynysoedd Marshall +MR,Mauritania,Mauritania,The Islamic Republic of Mauritania,Gweriniaeth Islamaidd Mauritania +MU,Mauritius,Mauritius,The Republic of Mauritius,Gweriniaeth Mauritius +MX,Mexico,Mecsico,The United Mexican States,Unol Daleithiau Mecsico +FM,Micronesia,Micronesia,The Federated States of Micronesia,Gwladwriaethau Ffedereiddiedig Micronesia +MD,Moldova,Moldofa,The Republic of Moldova,Gweriniaeth Moldofa +MC,Monaco,Monaco,The Principality of Monaco,Tywysogaeth Monaco +MN,Mongolia,Mongolia,Mongolia,Mongolia +ME,Montenegro,Montenegro,Montenegro,Montenegro +MA,Morocco,Morocco,The Kingdom of Morocco,Teyrnas Morocco +MZ,Mozambique,Mozambique,The Republic of Mozambique,Gweriniaeth Mozambique +MM,Myanmar (Burma),Myanmar (Burma),The Republic of the Union of Myanmar,Gweriniaeth Undeb Myanmar +NA,Namibia,Namibia,The Republic of Namibia,Gweriniaeth Namibia +NR,Nauru,Nauru,The Republic of Nauru,Gweriniaeth Nauru +NP,Nepal,Nepal,Nepal,Nepal +NL,Netherlands,Yr Iseldiroedd,The Kingdom of the Netherlands,Teyrnas yr Iseldiroedd +NZ,New Zealand,Seland Newydd,New Zealand,Seland Newydd +NI,Nicaragua,Nicaragua,The Republic of Nicaragua,Gweriniaeth Nicaragua +NE,Niger,Niger,The Republic of Niger,Gweriniaeth Niger +NG,Nigeria,Nigeria,The Federal Republic of Nigeria,Gweriniaeth Ffederal Nigeria +KP,North Korea,Gogledd Korea,The Democratic People's Republic of Korea,Gweriniaeth Ddemocrataidd y Bobl Korea +MK,North Macedonia,Gogledd Macedonia,Republic of North Macedonia,Gweriniaeth Gogledd Macedonia +NO,Norway,Norwy,The Kingdom of Norway,Teyrnas Norwy +OM,Oman,Oman,The Sultanate of Oman,Swltaniaeth Oman +PK,Pakistan,Pacistan,The Islamic Republic of Pakistan,Gweriniaeth Islamaidd Pacistan +PW,Palau,Palau,The Republic of Palau,Gweriniaeth Palau +PA,Panama,Panama,The Republic of Panama,Gwerinaeth Panama +PG,Papua New Guinea,Papua Guinea Newydd,The Independent State of Papua New Guinea,Gwladwriaeth Annibynnol Papua Guinea Newydd +PY,Paraguay,Paraguay,The Republic of Paraguay,Gweriniaeth Paraguay +PE,Peru,Periw,The Republic of Peru,Gweriniaeth Periw +PH,Philippines,Ynysoedd Philippines,The Republic of the Philippines,Gweriniaeth y Philippines +PL,Poland,Gwlad Pwyl,The Republic of Poland,Gweriniaeth Gwlad Pwyl +PT,Portugal,Portiwgal,The Portuguese Republic,Gweriniaeth Portiwgal +QA,Qatar,Qatar,The State of Qatar,Gwladwriaeth Qatar +RO,Romania,Rwmania,Romania,Rwmania +RU,Russia,Rwsia,The Russian Federation,Ffederasiwn Rwsia +RW,Rwanda,Rwanda,The Republic of Rwanda,Gweriniaeth Rwanda +WS,Samoa,Samoa,The Independent State of Samoa,Gwladwriaeth Annibynnol Samoa +SM,San Marino,San Marino,The Republic of San Marino,Gweriniaeth San Marino +ST,Sao Tome and Principe,Sao Tome a Principe,The Democratic Republic of Sao Tome and Principe,Gweriniaeth Ddemocrataidd Sao Tome a Principe +SA,Saudi Arabia,Saudi Arabia,The Kingdom of Saudi Arabia,Teyrnas Saudi Arabia +SN,Senegal,Senegal,The Republic of Senegal,Gweriniaeth Senegal +RS,Serbia,Serbia,The Republic of Serbia,Gweriniaeth Serbia +SC,Seychelles,Seychelles,The Republic of Seychelles,Gweriniaeth Seychelles +SL,Sierra Leone,Sierra Leone,The Republic of Sierra Leone,Gweriniaeth Sierra Leone +SG,Singapore,Singapore,The Republic of Singapore,Gweriniaeth Singapore +SK,Slovakia,Slofacia,The Slovak Republic,Y Weriniaeth Slofac +SI,Slovenia,Slofenia,The Republic of Slovenia,Gweriniaeth Slofenia +SB,Solomon Islands,Ynysoedd Solomon,Solomon Islands,Ynysoedd Solomon +SO,Somalia,Somalia,Federal Republic of Somalia,Gweriniaeth Ffederal Somalia +ZA,South Africa,De Affrica,The Republic of South Africa,Gweriniaeth De Affrica +KR,South Korea,De Korea,The Republic of Korea,Gweriniaeth Korea +SS,South Sudan,De Sudan,The Republic of South Sudan,Gweriniaeth De Sudan +ES,Spain,Sbaen,The Kingdom of Spain,Teyrnas Sbaen +LK,Sri Lanka,Sri Lanka,The Democratic Socialist Republic of Sri Lanka,Gweriniaeth Sosialaidd Ddemocrataidd Sri Lanka +KN,St Kitts and Nevis,St Kitts a Nevis,The Federation of Saint Christopher and Nevis,Ffederasiwn Sant Christopher a Nevis +LC,St Lucia,St Lucia,Saint Lucia,Santes Lucia +VC,St Vincent,St Vincent,Saint Vincent and the Grenadines,Sant Vincent a'r Grenadines +SD,Sudan,Sudan,The Republic of the Sudan,Gweriniaeth Sudan +SR,Suriname,Suriname,The Republic of Suriname,Gweriniaeth Suriname +SE,Sweden,Sweden,The Kingdom of Sweden,Teyrnas Sweden +CH,Switzerland,Y Swistir,The Swiss Confederation,Cydffederasiwn y Swistir +SY,Syria,Syria,The Syrian Arab Republic,Gweriniaeth Arabaidd Syria +TJ,Tajikistan,Tajikistan,The Republic of Tajikistan,Gweriniaeth Tajikistan +TZ,Tanzania,Tanzania,The United Republic of Tanzania,Gweriniaeth Unedig Tanzania +TH,Thailand,Gwlad Thai,The Kingdom of Thailand,Teyrnas Gwlad Thai +BS,The Bahamas,Y Bahamas,The Commonwealth of The Bahamas,Cymanwlad y Bahamas +GM,The Gambia,Y Gambia,The Republic of The Gambia,Gweriniaeth y Gambia +TG,Togo,Togo,The Togolese Republic,Gweriniaeth Togo +TO,Tonga,Tonga,The Kingdom of Tonga,Teyrnas Tonga +TT,Trinidad and Tobago,Trinidad a Tobago,The Republic of Trinidad and Tobago,Gweriniaeth Trinidad a Tobago +TN,Tunisia,Tunisia,The Tunisian Republic,Gweriniaeth Tunisia +TR,Turkey,Twrci,Republic of Türkiye,Gweriniaeth Türkiye +TM,Turkmenistan,Turkmenistan,Turkmenistan,Turkmenistan +TV,Tuvalu,Tuvalu,Tuvalu,Tuvalu +UG,Uganda,Uganda,The Republic of Uganda,Gweriniaeth Uganda +UA,Ukraine,Wcráin,Ukraine,Wcráin +AE,United Arab Emirates,Yr Emiradau Arabaidd Unedig,The United Arab Emirates,Yr Emiradau Arabaidd Unedig +GB,United Kingdom,Y Deyrnas Unedig,The United Kingdom of Great Britain and Northern Ireland,Teyrnas Unedig Prydain Fawr a Gogledd Iwerddon +US,United States,Yr Unol Daleithiau,The United States of America,Unol Daleithiau America +UY,Uruguay,Uruguay,The Oriental Republic of Uruguay,Gweriniaeth Ddwyreiniol Uruguay +UZ,Uzbekistan,Uzbekistan,The Republic of Uzbekistan,Gweriniaeth Uzbekistan +VU,Vanuatu,Vanuatu,The Republic of Vanuatu,Gweriniaeth Vanuatu +VA,Vatican City,Dinas y Fatican,Vatican City State,Gwladwriaeth Dinas y Fatican +VE,Venezuela,Venezuela,The Bolivarian Republic of Venezuela,Gweriniaeth Bolivaraidd Venezuela +VN,Vietnam,Fietnam,The Socialist Republic of Viet Nam,Gweriniaeth Sosialaidd Fiet Nam +YE,Yemen,Yemen,The Republic of Yemen,Gweriniaeth Yemen +ZM,Zambia,Zambia,The Republic of Zambia,Gweriniaeth Zambia +ZW,Zimbabwe,Zimbabwe,The Republic of Zimbabwe,Gweriniaeth Zimbabwe diff --git a/it/test/controllers/international/SelectPageISpec.scala b/it/test/controllers/international/SelectPageISpec.scala index 6c39943a..757ad58c 100644 --- a/it/test/controllers/international/SelectPageISpec.scala +++ b/it/test/controllers/international/SelectPageISpec.scala @@ -16,6 +16,7 @@ package controllers.international +import address.v2.Country import controllers.routes import itutil.IntegrationSpecBase import itutil.config.AddressRecordConstants._ @@ -48,7 +49,7 @@ class SelectPageISpec extends IntegrationSpecBase { stubGetAddressByCountry(addressJson = testResultsList, countryCode = "BM") await(cache.putV2(testJourneyId, - journeyDataV2ResultLimit.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, "BM")), countryCode = Some("BM")))) + journeyDataV2ResultLimit.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, Country("BM", "Bermuda"))), countryCode = Some("BM")))) val res = buildClientLookupAddress(path = s"international/select?filter=$testFilterValue", testJourneyId) .withHttpHeaders(HeaderNames.COOKIE -> sessionCookieWithCSRF, "Csrf-Token" -> "nocheck") @@ -90,7 +91,7 @@ class SelectPageISpec extends IntegrationSpecBase { stubGetAddressByCountry(addressJson = testResultsList, countryCode = "BM") await(cache.putV2(testJourneyId, - journeyDataV2SelectLabels.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, "BM")), countryCode = Some("BM")))) + journeyDataV2SelectLabels.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, Country("BM", "Bermuda"))), countryCode = Some("BM")))) val res = buildClientLookupAddress(path = s"international/select?filter=$testFilterValue", testJourneyId) .withHttpHeaders(HeaderNames.COOKIE -> sessionCookieWithCSRF, "Csrf-Token" -> "nocheck") @@ -185,7 +186,7 @@ class SelectPageISpec extends IntegrationSpecBase { stubGetAddressByCountry(addressJson = testResultsList, countryCode = "BM") await(cache.putV2(testJourneyId, - journeyDataV2DefaultWelshLabels.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, "BM")), countryCode = Some("BM")))) + journeyDataV2DefaultWelshLabels.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, Country("BM", "Bermuda"))), countryCode = Some("BM")))) val res = buildClientLookupAddress(path = s"international/select?filter=$testFilterValue", testJourneyId) .withHttpHeaders( @@ -216,7 +217,7 @@ class SelectPageISpec extends IntegrationSpecBase { stubGetAddressByCountry(addressJson = testResultsList, countryCode = "BM") await(cache.putV2(testJourneyId, - journeyData.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, "BM")), countryCode = Some("BM")))) + journeyData.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, Country("BM", "Bermuda"))), countryCode = Some("BM")))) val fResponse = buildClientLookupAddress(path = s"international/select?filter=$testFilterValue", testJourneyId) .withHttpHeaders(HeaderNames.COOKIE -> sessionCookieWithCSRF, "Csrf-Token" -> "nocheck") diff --git a/it/test/controllers/international/TooManyResultsISpec.scala b/it/test/controllers/international/TooManyResultsISpec.scala index 14f4a028..1ead552e 100644 --- a/it/test/controllers/international/TooManyResultsISpec.scala +++ b/it/test/controllers/international/TooManyResultsISpec.scala @@ -16,6 +16,7 @@ package controllers.international +import address.v2.Country import controllers.routes import itutil.config.AddressRecordConstants._ import itutil.config.IntegrationTestConstants._ @@ -168,7 +169,7 @@ class TooManyResultsISpec extends IntegrationSpecBase with PageContentHelper { stubGetAddressByCountry(addressJson = internationalAddressResultsListBySize(numberOfRepeats = addressAmount), countryCode = "BM") await(cache.putV2(testJourneyId, - journeyDataV2ResultLimit.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, "BM")), countryCode = Some("BM")))) + journeyDataV2ResultLimit.copy(proposals = Some(testInternationalProposedAddresses(addressAmount, Country("BM", "Bermuda"))), countryCode = Some("BM")))) val res = buildClientLookupAddress(path = s"international/select?filter=$testFilterValue", testJourneyId) .withHttpHeaders(HeaderNames.COOKIE -> sessionCookieWithCSRF, "Csrf-Token" -> "nocheck") diff --git a/it/test/itutil/config/IntegrationTestConstants.scala b/it/test/itutil/config/IntegrationTestConstants.scala index 1be051a2..e972fe06 100644 --- a/it/test/itutil/config/IntegrationTestConstants.scala +++ b/it/test/itutil/config/IntegrationTestConstants.scala @@ -79,7 +79,7 @@ object IntegrationTestConstants { ) } - def testInternationalProposedAddresses(amount: Int, countryCode: String = "GB"): Seq[ProposedAddress] = (1 to amount) map { n => + def testInternationalProposedAddresses(amount: Int, country: Country = Country("GB", "United Kingdom")): Seq[ProposedAddress] = (1 to amount) map { n => ProposedAddress( addressId = s"id$n", uprn = None, @@ -93,7 +93,7 @@ object IntegrationTestConstants { s"City $n", s"Region $n").toList, town = Some(s"City $n"), - country = ForeignOfficeCountryService.find(code = countryCode).get + country = country ) } diff --git a/project/AppDependencies.scala b/project/AppDependencies.scala index 5359ea32..e7c5e764 100644 --- a/project/AppDependencies.scala +++ b/project/AppDependencies.scala @@ -10,7 +10,9 @@ object AppDependencies { "uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "8.5.0", "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % "1.6.0", "uk.gov.hmrc" %% "play-conditional-form-mapping-play-30" % "2.0.0", - "com.github.tototoshi" %% "scala-csv" % "1.3.10" + "com.github.tototoshi" %% "scala-csv" % "1.3.10", + "net.ruippeixotog" %% "scala-scraper" % "3.1.1", + "uk.gov.hmrc.objectstore" %% "object-store-client-play-30" % "2.0.0" ).map(_.withSources()) def test: Seq[ModuleID] = Seq( diff --git a/test/model/ALFESpec.scala b/test/model/ALFESpec.scala index 159168e3..296408ed 100644 --- a/test/model/ALFESpec.scala +++ b/test/model/ALFESpec.scala @@ -16,6 +16,7 @@ package model +import address.v2.Country import fixtures.ALFEFixtures import org.scalatest.matchers.must.Matchers import org.scalatest.wordspec.AnyWordSpec @@ -24,10 +25,13 @@ import services.ForeignOfficeCountryService class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { + val gb = Country("GB", "United Kingdom") + val fr = Country("FR", "France") + "an edit" should { "transform to a confirmable address with a formatted postcode when countrycode is GB" in { - val edit = Edit(None, Some("line1"), Some("line2"), Some("line3"), Some("town"), "Z Z 1 1 Z Z", ForeignOfficeCountryService.find(code = "GB").get.code) - val conf = edit.toConfirmableAddress("audit ref") + val edit = Edit(None, Some("line1"), Some("line2"), Some("line3"), Some("town"), "Z Z 1 1 Z Z", gb.code) + val conf = edit.toConfirmableAddress("audit ref", _ => Some(gb)) val expected = ConfirmableAddress( "audit ref", None, None, None, None, None, @@ -36,14 +40,14 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { List("line1", "line2", "line3"), Some("town"), Some("ZZ1 1ZZ"), - ForeignOfficeCountryService.find(code = "GB"))) + Some(Country("GB", "United Kingdom")))) conf must be (expected) } "transform to a confirmable address leaving postcode as is when countrycode is not GB" in { - val edit = Edit(None, Some("line1"), Some("line2"), Some("line3"), Some("town"), "Z Z 1 1 Z Z", ForeignOfficeCountryService.find(code = "FR").get.code) - val conf = edit.toConfirmableAddress("audit ref") + val edit = Edit(None, Some("line1"), Some("line2"), Some("line3"), Some("town"), "Z Z 1 1 Z Z", fr.code) + val conf = edit.toConfirmableAddress("audit ref", _ => Some(fr)) val expected = ConfirmableAddress( "audit ref", None, None, None, None, None, @@ -52,14 +56,14 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { List("line1", "line2", "line3"), Some("town"), Some("Z Z 1 1 Z Z"), - ForeignOfficeCountryService.find(code = "FR"))) + Some(fr))) conf must be (expected) } "transform to a confirmable address and back again where isukMode == false" in { - val edit = Edit(None, Some("line1"), Some("line2"), Some("line3"), Some("town"), "ZZ1 1ZZ", ForeignOfficeCountryService.find(code = "GB").get.code) - val conf = edit.toConfirmableAddress("audit ref") + val edit = Edit(None, Some("line1"), Some("line2"), Some("line3"), Some("town"), "ZZ1 1ZZ", gb.code) + val conf = edit.toConfirmableAddress("audit ref", _ => Some(gb)) val expected = ConfirmableAddress( "audit ref", None, None, None, None, None, @@ -68,17 +72,17 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { List("line1", "line2", "line3"), Some("town"), Some("ZZ1 1ZZ"), - ForeignOfficeCountryService.find(code = "GB"))) + Some(gb))) conf must be (expected) val ed2 = conf.toEdit ed2 must be (edit) - ed2.toConfirmableAddress("audit ref") must be (expected) + ed2.toConfirmableAddress("audit ref", _ => Some(gb)) must be (expected) } "transform to a confirmable address and back again given less than three lines where isukMode == false" in { - val edit = Edit(None, Some("line1"), None, None, Some("town"), "ZZ1 1ZZ", ForeignOfficeCountryService.find(code = "GB").get.code) - val conf = edit.toConfirmableAddress("audit ref") + val edit = Edit(None, Some("line1"), None, None, Some("town"), "ZZ1 1ZZ", gb.code) + val conf = edit.toConfirmableAddress("audit ref", _ => Some(gb)) val expected = ConfirmableAddress( "audit ref", None, None, None, None, None, @@ -87,17 +91,17 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { List("line1"), Some("town"), Some("ZZ1 1ZZ"), - ForeignOfficeCountryService.find(code = "GB"))) + Some(gb))) conf must be (expected) val ed2 = conf.toEdit ed2 must be (edit) - ed2.toConfirmableAddress("audit ref") must be (expected) + ed2.toConfirmableAddress("audit ref", _ => Some(gb)) must be (expected) } "transform to a confirmable address and back again given less than three lines where isukMode == true" in { val edit = Edit(None, Some("line1"), None, None, Some("town"), "ZZ1 1ZZ", "GB") - val conf = edit.toConfirmableAddress("audit ref") + val conf = edit.toConfirmableAddress("audit ref", _ => Some(gb)) val expected = ConfirmableAddress( "audit ref", None, None, None, None, None, @@ -105,17 +109,17 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { None, List("line1"), Some("town"), postcode = Some("ZZ1 1ZZ"), - ForeignOfficeCountryService.find(code = "GB"))) + Some(gb))) conf must be (expected) val ed2 = conf.toEdit ed2 must be (edit) - ed2.toConfirmableAddress("audit ref") must be (expected) + ed2.toConfirmableAddress("audit ref", _ => Some(gb)) must be (expected) } "transform to a confirmable address and back where postcode is empty isukMode == true" in { val edit = Edit(None, Some("line1"), None, None, Some("town"), "", "FR") - val conf = edit.toConfirmableAddress("audit ref") + val conf = edit.toConfirmableAddress("audit ref", _ => Some(fr)) val expected = ConfirmableAddress( "audit ref", None, None, None, None, None, @@ -123,12 +127,12 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { None, List("line1"), Some("town"), postcode = None, - ForeignOfficeCountryService.find(code = "FR"))) + Some(fr))) conf must be (expected) val ed2 = conf.toEdit ed2 must be (edit) - ed2.toConfirmableAddress("audit ref") must be (expected) + ed2.toConfirmableAddress("audit ref", _ => Some(fr)) must be (expected) } } @@ -136,7 +140,7 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { "transform to a confirmable address where town is ignored" in { val auditRef = "audit ref" - val prop = ProposedAddress("GB1234567890", uprn = None, parentUprn = None, usrn = None, organisation = None, "postcode", "some-town", List("line1", "line2", "line3"), ForeignOfficeCountryService.find(code = "GB").get) + val prop = ProposedAddress("GB1234567890", uprn = None, parentUprn = None, usrn = None, organisation = None, "postcode", "some-town", List("line1", "line2", "line3"), gb) val conf = prop.toConfirmableAddress(auditRef) val expected = ConfirmableAddress( auditRef, @@ -153,7 +157,7 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { "transform to a confirmable address With all 4 address lines as town is None" in { val auditRef = "audit ref" - val prop = ProposedAddress("GB1234567890", uprn = None, parentUprn = None, usrn = None, organisation = None, "postcode", "some-town", List("line1", "line2", "line3"), ForeignOfficeCountryService.find(code = "GB").get) + val prop = ProposedAddress("GB1234567890", uprn = None, parentUprn = None, usrn = None, organisation = None, "postcode", "some-town", List("line1", "line2", "line3"), gb) val conf = prop.toConfirmableAddress(auditRef) val expected = ConfirmableAddress( auditRef, @@ -169,7 +173,7 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { } "be able to describe itself" in { - val prop = ProposedAddress("GB1234567890", uprn = None, parentUprn = None, usrn = None, organisation = None, "postcode", "some-town", List("line1", "line2", "line3"), ForeignOfficeCountryService.find(code = "GB").get) + val prop = ProposedAddress("GB1234567890", uprn = None, parentUprn = None, usrn = None, organisation = None, "postcode", "some-town", List("line1", "line2", "line3"), gb) val desc = prop.toDescription desc must be ("line1, line2, line3, some-town, postcode") } @@ -177,7 +181,7 @@ class ALFESpec extends AnyWordSpec with Matchers with ALFEFixtures { "a confirmable address" should { "default country to GB" in { - ConfirmableAddress("auditRef").address.country must be (ForeignOfficeCountryService.find(code = "GB")) + ConfirmableAddress("auditRef").address.country must be (Some(gb)) } } diff --git a/test/services/AddressLookupAddressServiceSpec.scala b/test/services/AddressLookupAddressServiceSpec.scala index a885a463..d6ea7481 100644 --- a/test/services/AddressLookupAddressServiceSpec.scala +++ b/test/services/AddressLookupAddressServiceSpec.scala @@ -45,7 +45,12 @@ class AddressLookupAddressServiceSpec extends PlaySpec with GuiceOneAppPerSuite when(httpClient.POST[LookupAddressByPostcode, List[AddressRecord]](anyString(), any(), any())(any(), any(), any() , any())).thenReturn(Future.successful(resp)) - val service = new AddressLookupAddressService(frontendAppConfig, httpClient) { + + val english = new EnglishCountryNamesDataSource() + val welsh = new WelshCountryNamesDataSource(english) + val fco = new ForeignOfficeCountryService(english, welsh) + + val service = new AddressLookupAddressService(frontendAppConfig, httpClient, fco) { override val endpoint = end } } diff --git a/test/services/ForeignOfficeCountryServiceSpec.scala b/test/services/ForeignOfficeCountryServiceSpec.scala index bfe5d87e..6c928875 100644 --- a/test/services/ForeignOfficeCountryServiceSpec.scala +++ b/test/services/ForeignOfficeCountryServiceSpec.scala @@ -16,6 +16,7 @@ package services +import address.v2.Country import com.codahale.metrics.SharedMetricRegistries import org.scalatestplus.play.PlaySpec import org.scalatestplus.play.guice.GuiceOneAppPerSuite @@ -24,7 +25,9 @@ class ForeignOfficeCountryServiceSpec extends PlaySpec with GuiceOneAppPerSuite class Scenario { SharedMetricRegistries.clear() - val service = new ForeignOfficeCountryService + val english = new EnglishCountryNamesDataSource() + val welsh = new WelshCountryNamesDataSource(english) + val service = new ForeignOfficeCountryService(english, welsh) } "find all in English" should { @@ -77,5 +80,11 @@ class ForeignOfficeCountryServiceSpec extends PlaySpec with GuiceOneAppPerSuite val gbs = service.findAll(welshFlag = true).filter(_.code == "GB") gbs.size mustBe >(1) } + + "merge country lists from gov.wales and wco" in new Scenario { + val usa = service.findAll(welshFlag = true).filter(_.code == "US") + usa.size mustBe > (1) + usa.head mustBe Country("US", "Yr Unol Daleithiau") + } } } From b3f29493f66684497e741714735826bf2343b333 Mon Sep 17 00:00:00 2001 From: Pete Smith Date: Wed, 11 Sep 2024 15:28:55 +0100 Subject: [PATCH 2/2] [PS] CIR-619 - Resolve PR bot suggestions --- app/Module.scala | 2 +- conf/logback-test.xml | 22 ---------------------- conf/logback.xml | 22 ---------------------- project/build.properties | 2 +- project/plugins.sbt | 6 +++--- 5 files changed, 5 insertions(+), 49 deletions(-) diff --git a/app/Module.scala b/app/Module.scala index 31a6f6fa..580208dc 100644 --- a/app/Module.scala +++ b/app/Module.scala @@ -36,7 +36,7 @@ class Module(env: Environment, playConfig: Configuration) extends AbstractModule @Singleton private def provideWelshCountryNamesDataSource(english: EnglishCountryNamesDataSource, objectStore: PlayObjectStoreClient, - ec: ExecutionContext, mat: Materializer) = { + ec: ExecutionContext, mat: Materializer): WelshCountryNamesDataSource = { val logger = Logger(this.getClass) val useLocal = diff --git a/conf/logback-test.xml b/conf/logback-test.xml index fa692eb5..19dee921 100644 --- a/conf/logback-test.xml +++ b/conf/logback-test.xml @@ -14,19 +14,6 @@ - - - %date{ISO8601} level=[%level] logger=[%logger] thread=[%thread] rid=[not-available] user=[not-available] message=[%message] %replace(exception=[%xException]){'^exception=\[\]$',''}%n - - - - - logs/access.log - - %message%n - - - logs/connector.log @@ -34,15 +21,6 @@ - - - - - - - - - diff --git a/conf/logback.xml b/conf/logback.xml index 9434e108..ffddf123 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -14,19 +14,6 @@ - - - %date{ISO8601} level=[%level] logger=[%logger] thread=[%thread] rid=[not-available] user=[not-available] message=[%message] %replace(exception=[%xException]){'^exception=\[\]$',''}%n - - - - - logs/access.log - - %message%n - - - logs/connector.log @@ -34,15 +21,6 @@ - - - - - - - - - diff --git a/project/build.properties b/project/build.properties index e8a1e246..04267b14 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.7 +sbt.version=1.9.9 diff --git a/project/plugins.sbt b/project/plugins.sbt index 239a8bc7..93eab0cf 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,8 +2,8 @@ resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefac resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns) resolvers += "Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases/" -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.18.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.4.0") -addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.1") +addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0") +addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.3") addSbtPlugin("io.github.irundaia" % "sbt-sassify" % "1.5.2")