Skip to content

Commit

Permalink
GFORMS-3066 - Add country code and updated CSV (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmanson authored Dec 23, 2024
1 parent 9124803 commit 24fb634
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 235 deletions.
24 changes: 14 additions & 10 deletions app/uk/gov/hmrc/gform/LookupLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class LookupLoader {
priority: String,
priorityUk: String,
region: String,
countryCode: String,
mkLookupType: LocalisedLookupOptions => LookupType
): LookupType = {

Expand All @@ -111,7 +112,8 @@ class LookupLoader {
LookupKeywords,
LookupPriority,
LookupPriority,
LookupRegion
LookupRegion,
LookupCountryCode
)

val headerDecoder: HeaderDecoder[ColumnData] =
Expand All @@ -122,7 +124,8 @@ class LookupLoader {
keywords,
priority,
priorityUk,
region
region,
countryCode
)(
(
_: LookupLabel,
Expand All @@ -131,16 +134,17 @@ class LookupLoader {
_: LookupKeywords,
_: LookupPriority,
_: LookupPriority,
_: LookupRegion
_: LookupRegion,
_: LookupCountryCode
)
)

val csvWithColumns = CsvUtils.readCsvWithColumns(filename)
def processData(columnData: ColumnData)(index: Int): (LookupDetails, LookupDetails) = {
val (enLabel, cyLabel, id, keywords, priority, priorityUk, region) = columnData
val (enLabel, cyLabel, id, keywords, priority, priorityUk, region, countryCode) = columnData

val columns = csvWithColumns.find(_(idColumn) == id.id).get
val li = NationalityLookupInfo(id, index, keywords, priority, priorityUk, region, columns)
val li = NationalityLookupInfo(id, index, keywords, priority, priorityUk, region, countryCode, columns)
((enLabel, li), (cyLabel, li))
}

Expand Down Expand Up @@ -401,7 +405,7 @@ class LookupLoader {
private val origin = read("BCD-Origin.csv", "Id", "En", "Cy", mkAjaxLookup(ShowAll.Enabled))
private val agentComplaintCategories = readAgentComplaintCategories("BCD-AgentComplaintCategories.csv", "Code", "Name", "Name-cy", "KeyWords", mkAjaxLookup(ShowAll.Enabled))
private val country = readCountries("BCD-Country.csv", "CountryCode", "Name", "Name-cy", "KeyWords", "Priority", "PriorityUK", "Region", "InGibraltarEuEeaEfta", mkAjaxLookup(ShowAll.Enabled))
private val nationality = readNationalities("BCD-Nationality.csv", "NationalityId", "Name", "Name-cy", "Keywords", "Priority", "PriorityUK", "Region", mkAjaxLookup(ShowAll.Enabled))
private val nationality = readNationalities("BCD-Nationality.csv", "NationalityId", "Name", "Name-cy", "Keywords", "Priority", "PriorityUK", "Region", "CountryCode", mkAjaxLookup(ShowAll.Enabled))
private val currency = readCurrencies("BCD-Currency.csv", "CurrencyCode", "Name", "Name-cy", "KeyWords", "Priority", "CountryCode", mkAjaxLookup(ShowAll.Disabled))
private val port = readPorts("BCD-Port.csv", "PortCode", "Name", "Name-cy", "KeyWords", "Priority", "Region", "PortType", "CountryCode", "PortCode", mkAjaxLookup(ShowAll.Disabled))
private val sicCode = readSicCode("SicCode.csv", "SicCode", "Name", "Name-cy", "Section", mkAjaxLookup(ShowAll.Disabled))
Expand Down Expand Up @@ -449,10 +453,10 @@ object LookupLoader {
m.options map {
case (ll, DefaultLookupInfo(_, _)) =>
engine.add(new LookupRecord(ll.label, LookupPriority(1), LookupKeywords(None)))
case (ll, CountryLookupInfo(_, _, k, p, _, _, _, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, NationalityLookupInfo(_, _, k, p, _, _, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, CurrencyLookupInfo(_, _, k, p, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, PortLookupInfo(_, _, k, p, _, _, _, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, CountryLookupInfo(_, _, k, p, _, _, _, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, NationalityLookupInfo(_, _, k, p, _, _, _, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, CurrencyLookupInfo(_, _, k, p, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, PortLookupInfo(_, _, k, p, _, _, _, _)) => engine.add(new LookupRecord(ll.label, p, k))
case (ll, AgentComplaintCategoriesLookupInfo(_, _, k, _)) =>
engine.add(new LookupRecord(ll.label, LookupPriority(1), k))
case (ll, SicCodeLookupInfo(_, _, _)) =>
Expand Down
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/gform/lookup/LookupInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final case class NationalityLookupInfo(
priority: LookupPriority,
priorityUk: LookupPriority,
region: LookupRegion,
countryCode: LookupCountryCode,
columns: Map[String, String]
) extends LookupInfo

Expand Down
6 changes: 3 additions & 3 deletions app/uk/gov/hmrc/gform/lookup/LookupOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ case class LookupOptions(options: Map[LookupLabel, LookupInfo]) extends AnyVal {
case Some(priorityType) => if (priorityType === Uk) (priorityUk, label) else (priority, label)
case _ => (priority, label)
}
case (_, NationalityLookupInfo(LookupId(id), _, _, priority, priorityUk, _, _)) =>
case (_, NationalityLookupInfo(LookupId(id), _, _, priority, priorityUk, _, _, _)) =>
priorityType match {
case Some(priorityType) =>
if (priorityType === Uk) (priorityUk, LookupLabel(id)) else (priority, LookupLabel(id))
Expand All @@ -70,8 +70,8 @@ object LookupOptions {
case (CountryLookupInfo(_, _, _, _, _, _, inGibraltarEuEeaEfta, _), CsvColumnName.inGibraltarEuEeaEfta) => Some(inGibraltarEuEeaEfta.inGibraltarEuEeaEfta)
case (CountryLookupInfo(_, _, _, _, _, _, _, columns), column) =>
Some(columns.getOrElse(column, throw new Exception(s"Invalid column name $column")))
case (NationalityLookupInfo(_, _, _, _, _, region, _), CsvColumnName.region) => Some(region.region)
case (NationalityLookupInfo(_, _, _, _, _, _, columns), column) =>
case (NationalityLookupInfo(_, _, _, _, _, region, _, _), CsvColumnName.region) => Some(region.region)
case (NationalityLookupInfo(_, _, _, _, _, _, _, columns), column) =>
Some(columns.getOrElse(column, throw new Exception(s"Invalid column name $column")))
case (CurrencyLookupInfo(id, _, _, _, _), CsvColumnName.currencyCode) => Some(id.id)
case (CurrencyLookupInfo(_, _, _, _, countryCode), CsvColumnName.countryCode) => Some(countryCode.countryCode)
Expand Down
Loading

0 comments on commit 24fb634

Please sign in to comment.