From 20bed92da1ab131fdc2b32d127160cdd6eecf9bd Mon Sep 17 00:00:00 2001 From: lchen-2101 <73617864+lchen-2101@users.noreply.github.com> Date: Mon, 10 Jan 2022 18:04:18 -0500 Subject: [PATCH] wip - blank lar enums --- .../filing/lar/enums/AutomatedUnderwritingResultEnum.scala | 5 +++-- .../filing/lar/enums/AutomatedUnderwritingSystemEnum.scala | 5 +++-- .../hmda/model/filing/lar/enums/DenialReasonEnum.scala | 5 +++-- .../scala/hmda/model/filing/lar/enums/EthnicityEnum.scala | 5 +++-- .../main/scala/hmda/model/filing/lar/enums/LarEnum.scala | 1 + .../main/scala/hmda/model/filing/lar/enums/RaceEnum.scala | 5 +++-- .../src/main/scala/hmda/parser/filing/lar/LarParser.scala | 7 +++++-- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingResultEnum.scala b/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingResultEnum.scala index fe0a2d50eb..9df6e884b6 100644 --- a/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingResultEnum.scala +++ b/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingResultEnum.scala @@ -4,11 +4,12 @@ sealed trait AutomatedUnderwritingResultEnum extends LarEnum object AutomatedUnderwritingResultEnum extends LarCodeEnum[AutomatedUnderwritingResultEnum] { - override val values = (0 to 24).toList :+ 1111 + override val values = (1 to 24).toList :+ 1111 + + override def blankValue: AutomatedUnderwritingResultEnum = EmptyAUSResultValue override def valueOf(code: Int): AutomatedUnderwritingResultEnum = code match { - case 0 => EmptyAUSResultValue case 1 => ApproveEligible case 2 => ApproveIneligible case 3 => ReferEligilbe diff --git a/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingSystemEnum.scala b/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingSystemEnum.scala index f70fd6e634..8b36ac41c1 100644 --- a/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingSystemEnum.scala +++ b/common/src/main/scala/hmda/model/filing/lar/enums/AutomatedUnderwritingSystemEnum.scala @@ -4,11 +4,12 @@ sealed trait AutomatedUnderwritingSystemEnum extends LarEnum object AutomatedUnderwritingSystemEnum extends LarCodeEnum[AutomatedUnderwritingSystemEnum] { - override val values = List(0, 1, 2, 3, 4, 5, 6, 7, 1111) + override val values = List(1, 2, 3, 4, 5, 6, 7, 1111) + + override def blankValue: AutomatedUnderwritingSystemEnum = EmptyAUSValue override def valueOf(code: Int): AutomatedUnderwritingSystemEnum = code match { - case 0 => EmptyAUSValue case 1 => DesktopUnderwriter case 2 => LoanProspector case 3 => TechnologyOpenToApprovedLenders diff --git a/common/src/main/scala/hmda/model/filing/lar/enums/DenialReasonEnum.scala b/common/src/main/scala/hmda/model/filing/lar/enums/DenialReasonEnum.scala index 123c79f118..5c2813c2c4 100644 --- a/common/src/main/scala/hmda/model/filing/lar/enums/DenialReasonEnum.scala +++ b/common/src/main/scala/hmda/model/filing/lar/enums/DenialReasonEnum.scala @@ -3,11 +3,12 @@ package hmda.model.filing.lar.enums sealed trait DenialReasonEnum extends LarEnum object DenialReasonEnum extends LarCodeEnum[DenialReasonEnum] { - val values = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1111) + val values = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1111) + + override def blankValue: DenialReasonEnum = EmptyDenialValue def valueOf(code: Int): DenialReasonEnum = code match { - case 0 => EmptyDenialValue case 1 => DebtToIncomeRatio case 2 => EmploymentHistory case 3 => CreditHistory diff --git a/common/src/main/scala/hmda/model/filing/lar/enums/EthnicityEnum.scala b/common/src/main/scala/hmda/model/filing/lar/enums/EthnicityEnum.scala index b13f0d4195..c38a722dd4 100644 --- a/common/src/main/scala/hmda/model/filing/lar/enums/EthnicityEnum.scala +++ b/common/src/main/scala/hmda/model/filing/lar/enums/EthnicityEnum.scala @@ -3,11 +3,12 @@ package hmda.model.filing.lar.enums sealed trait EthnicityEnum extends LarEnum object EthnicityEnum extends LarCodeEnum[EthnicityEnum] { - override val values = List(0, 1, 11, 12, 13, 14, 2, 3, 4, 5) + override val values = List(1, 11, 12, 13, 14, 2, 3, 4, 5) + + override def blankValue: EthnicityEnum = EmptyEthnicityValue override def valueOf(code: Int): EthnicityEnum = code match { - case 0 => EmptyEthnicityValue case 1 => HispanicOrLatino case 11 => Mexican case 12 => PuertoRican diff --git a/common/src/main/scala/hmda/model/filing/lar/enums/LarEnum.scala b/common/src/main/scala/hmda/model/filing/lar/enums/LarEnum.scala index 21559f4351..8a63b687ec 100644 --- a/common/src/main/scala/hmda/model/filing/lar/enums/LarEnum.scala +++ b/common/src/main/scala/hmda/model/filing/lar/enums/LarEnum.scala @@ -14,5 +14,6 @@ object LarEnum { trait LarCodeEnum[+A] { val values: List[Int] + def blankValue: A = throw new NotImplementedError def valueOf(code: Int): A } \ No newline at end of file diff --git a/common/src/main/scala/hmda/model/filing/lar/enums/RaceEnum.scala b/common/src/main/scala/hmda/model/filing/lar/enums/RaceEnum.scala index e7285707e2..b540c5e5a6 100644 --- a/common/src/main/scala/hmda/model/filing/lar/enums/RaceEnum.scala +++ b/common/src/main/scala/hmda/model/filing/lar/enums/RaceEnum.scala @@ -4,11 +4,12 @@ sealed trait RaceEnum extends LarEnum object RaceEnum extends LarCodeEnum[RaceEnum] { override val values = - List(0, 1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, 6, 7, 8) + List(1, 2, 21, 22, 23, 24, 25, 26, 27, 3, 4, 41, 42, 43, 44, 5, 6, 7, 8) + + override def blankValue: RaceEnum = EmptyRaceValue override def valueOf(code: Int): RaceEnum = code match { - case 0 => EmptyRaceValue case 1 => AmericanIndianOrAlaskaNative case 2 => Asian case 21 => AsianIndian diff --git a/common/src/main/scala/hmda/parser/filing/lar/LarParser.scala b/common/src/main/scala/hmda/parser/filing/lar/LarParser.scala index 32f0493c5b..600830d1c1 100644 --- a/common/src/main/scala/hmda/parser/filing/lar/LarParser.scala +++ b/common/src/main/scala/hmda/parser/filing/lar/LarParser.scala @@ -121,8 +121,11 @@ trait LarParser { def validateLarCodeOrEmptyField[A](larCodeEnum: LarCodeEnum[A], value: String, parserValidationError: ParserValidationError): LarParserValidationResult[A] = - if (value == "") { - larCodeEnum.valueOf(0).validNel + if (value.isBlank) { + Try(larCodeEnum.blankValue) match { + case Success(enum) => enum.validNel + case Failure(_) => parserValidationError.invalidNel + } } else { validateLarCode(larCodeEnum, value, parserValidationError) }