From e4bbeb3b4eddf592773ba2f7cb3209dfc220bcbf Mon Sep 17 00:00:00 2001 From: kgudel Date: Mon, 6 Jul 2026 13:49:08 -0400 Subject: [PATCH 1/3] clean up hmda reporting --- .../repository/InstitutionRepository.scala | 137 +++++++++++++++ .../repository/ModifiedLarRepository.scala | 20 +++ .../reporting/api/http/ReportingHttpApi.scala | 159 ++---------------- .../repository/InstitutionComponent.scala | 78 --------- 4 files changed, 175 insertions(+), 219 deletions(-) create mode 100644 common/src/main/scala/hmda/query/repository/InstitutionRepository.scala delete mode 100644 hmda-reporting/src/main/scala/hmda/reporting/repository/InstitutionComponent.scala diff --git a/common/src/main/scala/hmda/query/repository/InstitutionRepository.scala b/common/src/main/scala/hmda/query/repository/InstitutionRepository.scala new file mode 100644 index 0000000000..363fd1984d --- /dev/null +++ b/common/src/main/scala/hmda/query/repository/InstitutionRepository.scala @@ -0,0 +1,137 @@ +package hmda.query.repository + +import hmda.query.institution.InstitutionEntity +import hmda.query.DbConfiguration._ +import hmda.query.repository.TableRepository +import slick.basic.DatabaseConfig +import slick.jdbc.JdbcProfile + +trait InstitutionComponent { + + import dbConfig.profile.api._ + + class InstitutionsTable(tag: Tag, tableName: String) extends Table[InstitutionEntity](tag, tableName) { + def lei = column[String]("lei", O.PrimaryKey) + def activityYear = column[Int]("activity_year") + def agency = column[Int]("agency") + def institutionType = column[Int]("institution_type") + def id2017 = column[String]("id2017") + def taxId = column[String]("tax_id") + def rssd = column[Int]("rssd") + def respondentName = column[String]("respondent_name") + def respondentState = column[String]("respondent_state") + def respondentCity = column[String]("respondent_city") + def parentIdRssd = column[Int]("parent_id_rssd") + def parentName = column[String]("parent_name") + def assets = column[Long]("assets") + def otherLenderCode = column[Int]("other_lender_code") + def topHolderIdRssd = column[Int]("topholder_id_rssd") + def topHolderName = column[String]("topholder_name") + def hmdaFiler = column[Boolean]("hmda_filer") + + def * = + ( + lei, + activityYear, + agency, + institutionType, + id2017, + taxId, + rssd, + respondentName, + respondentState, + respondentCity, + parentIdRssd, + parentName, + assets, + otherLenderCode, + topHolderIdRssd, + topHolderName, + hmdaFiler + ) <> (InstitutionEntity.tupled, InstitutionEntity.unapply) + } + + class InstitutionRepository(val databaseConfig: DatabaseConfig[JdbcProfile]) { + import databaseConfig.profile.api._ + private val db = databaseConfig.db + + //dynamic institution tables + val institutionsTable2018 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2018")) + val table2018 = institutionsTable2018 + + val institutionsTable2019 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2019")) + val table2019 = institutionsTable2019 + + val institutionsTable2020 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2020")) + val table2020 = institutionsTable2020 + + val institutionsTable2021 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2021")) + val table2021 = institutionsTable2021 + + val institutionsTable2022 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2022")) + val table2022 = institutionsTable2022 + + val institutionsTable2023 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2023")) + val table2023 = institutionsTable2023 + + val institutionsTable2024 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2024")) + val table2024 = institutionsTable2024 + + val institutionsTable2025 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2025")) + val table2025 = institutionsTable2025 + + val institutionsTable2026 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2026")) + val table2026 = institutionsTable2026 + + //snapshot tables + val snapshotInstitutionsTable2024 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2024_snapshot_v3")) + val snapshotTable2024 = snapshotInstitutionsTable2024 + + val snapshotInstitutionsTable2025 = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, "institutions2025_snapshot_06012026_v2")) + val snapshotTable2025 = snapshotInstitutionsTable2025 + + + def fetchYearTable(year: Int, snapshot: Boolean) = + snapshot match { + case true => + year match { + case 2018 => table2018 + case 2019 => table2019 + case 2020 => table2020 + case 2021 => table2021 + case 2022 => table2022 + case 2023 => table2023 + case 2024 => snapshotTable2024 + case 2025 => snapshotTable2025 + case _ => table2025 + } + case false => + year match { + case 2018 => table2018 + case 2019 => table2019 + case 2020 => table2020 + case 2021 => table2021 + case 2022 => table2022 + case 2023 => table2023 + case 2024 => table2024 + case 2025 => table2025 + case 2026 => table2026 + case _ => table2025 + } + } + + def findByLei(lei: String, year: Int, snapshot: Boolean) = + db.run(fetchYearTable(year, snapshot).filter(_.lei === lei).result) + + def getAllFilers(year: Int, snapshot: Boolean) = + db.run(fetchYearTable(year, snapshot).filter(_.hmdaFiler === true).result) + + def getFilteredFilers(bankFilterList: Array[String], year: Int, snapshot: Boolean) = + db.run( + fetchYearTable(year, snapshot) + .filter(_.hmdaFiler === true) + .filterNot(_.lei.toUpperCase inSet bankFilterList) + .result + ) + } +} diff --git a/common/src/main/scala/hmda/query/repository/ModifiedLarRepository.scala b/common/src/main/scala/hmda/query/repository/ModifiedLarRepository.scala index 8bf5e92cfc..f1bbd17253 100644 --- a/common/src/main/scala/hmda/query/repository/ModifiedLarRepository.scala +++ b/common/src/main/scala/hmda/query/repository/ModifiedLarRepository.scala @@ -30,6 +30,19 @@ class ModifiedLarRepository(databaseConfig: DatabaseConfig[JdbcProfile]) { case _ => "modifiedlar2025" } + def fetchSnapshotYearTable(year: Int): String = + year match { + case 2018 => "modifiedlar2018" + case 2019 => "modifiedlar2019" + case 2020 => "modifiedlar2020" + case 2021 => "modifiedlar2021" + case 2022 => "modifiedlar2022" + case 2023 => "modifiedlar2023" + case 2024 => "modifiedlar2024_snapshot_v3" + case 2025 => "modifiedlar2025_snapshot_06022026" + case _ => "modifiedlar2025_snapshot_06022026" + } + /** * Deletes entries in the Modified LAR table by their LEI * @param lei @@ -41,6 +54,13 @@ class ModifiedLarRepository(databaseConfig: DatabaseConfig[JdbcProfile]) { FROM #${fetchYearTable(filingYear)} WHERE lei = ${lei.toUpperCase} AND msa_md <> 0 group by msa_md order by msa_md""" .as[(String, String)] } + + def msaMdsSnapshot(lei: String, filingYear: Int): Future[Vector[(String, String)]] = + db.run { + sql"""SELECT msa_md, case when msa_md = '99999' then 'NA' else max(msa_md_name) end + FROM #${fetchSnapshotYearTable(filingYear)} WHERE lei = ${lei.toUpperCase} AND msa_md <> 0 group by msa_md order by msa_md""" + .as[(String, String)] + } /** * Deletes entries in the Modified LAR table by their LEI diff --git a/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala b/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala index 0073f86088..8604f162ee 100644 --- a/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala +++ b/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala @@ -8,7 +8,7 @@ import com.typesafe.config.Config import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ import hmda.model.institution.{ HmdaFiler, HmdaFilerResponse, MsaMd, MsaMdResponse } import hmda.query.repository.ModifiedLarRepository -import hmda.reporting.repository.InstitutionComponent +import hmda.query.repository.InstitutionComponent import hmda.util.http.FilingResponseUtils.entityNotPresentResponse import io.circe.generic.auto._ import slick.basic.DatabaseConfig @@ -26,137 +26,28 @@ private class ReportingHttpApi(config: Config)(implicit ec: ExecutionContext) ex private val bankFilter = config.getConfig("filter") private val bankFilterList = bankFilter.getString("bank-filter-list").toUpperCase.split(",") private val databaseConfig = DatabaseConfig.forConfig[JdbcProfile]("db") - private val repo = new ModifiedLarRepository(databaseConfig) - private val institutionRepository2018 = new InstitutionRepository(databaseConfig, "institutions2018") - private val institutionRepository2019 = new InstitutionRepository(databaseConfig, "institutions2019") - private val institutionRepository2020 = new InstitutionRepository(databaseConfig, "institutions2020") - private val institutionRepository2021 = new InstitutionRepository(databaseConfig, "institutions2021") - private val institutionRepository2022 = new InstitutionRepository(databaseConfig, "institutions2022") - private val institutionRepository2023 = new InstitutionRepository(databaseConfig, "institutions2023") - private val institutionRepository2024 = new InstitutionRepository(databaseConfig, "institutions2024") - private val institutionRepository2025 = new InstitutionRepository(databaseConfig, "institutions2025") + private val modifiedLarRepository = new ModifiedLarRepository(databaseConfig) + private val institutionRepository = new InstitutionRepository(databaseConfig) private val filerListRoute: Route = { path("filers" / IntNumber) { filingYear => get { - val futFilerSet: Future[Set[HmdaFiler]] = filingYear match { - case 2018 => - institutionRepository2018 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) + val futFilerSet: Future[Set[HmdaFiler]] = { + institutionRepository + .getFilteredFilers(bankFilterList, filingYear, false) + .map(sheets => + sheets + .map(instituionEntity => + HmdaFiler( + instituionEntity.lei.toUpperCase, + instituionEntity.respondentName, + instituionEntity.activityYear.toString ) - .toSet - ) - case 2019 => - institutionRepository2019 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - case 2020 => - institutionRepository2020 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - case 2021 => - institutionRepository2021 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - - case 2022 => - institutionRepository2022 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - - case 2023 => - institutionRepository2023 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - case 2024 => - institutionRepository2024 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - case 2025 => - institutionRepository2025 - .getFilteredFilers(bankFilterList) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - case _ => Future(Set(HmdaFiler("", "", ""))) + ) + .toSet + ) } onComplete(futFilerSet) { @@ -169,23 +60,9 @@ private class ReportingHttpApi(config: Config)(implicit ec: ExecutionContext) ex } } ~ path("filers" / IntNumber / Segment / "msaMds") { (year, lei) => extractUri { uri => - val institutionRepository = - year match { - case 2018 => institutionRepository2018 - case 2019 => institutionRepository2019 - case 2020 => institutionRepository2020 - case 2021 => institutionRepository2021 - case 2022 => institutionRepository2022 - case 2023 => institutionRepository2023 - case 2024 => institutionRepository2024 - case 2025 => institutionRepository2025 - - - - } val resultset = for { - msaMdsResult <- repo.msaMds(lei, year) - institutionResult <- institutionRepository.findByLei(lei) + msaMdsResult <- modifiedLarRepository.msaMdsSnapshot(lei, year) + institutionResult <- institutionRepository.findByLei(lei, year, false) } yield { val msaMds = msaMdsResult.map(myEntity => MsaMd(myEntity._1, myEntity._2)).toSet diff --git a/hmda-reporting/src/main/scala/hmda/reporting/repository/InstitutionComponent.scala b/hmda-reporting/src/main/scala/hmda/reporting/repository/InstitutionComponent.scala deleted file mode 100644 index d66be44b7a..0000000000 --- a/hmda-reporting/src/main/scala/hmda/reporting/repository/InstitutionComponent.scala +++ /dev/null @@ -1,78 +0,0 @@ -package hmda.reporting.repository - -import hmda.query.institution.InstitutionEntity -import hmda.query.DbConfiguration._ -import hmda.query.repository.TableRepository -import slick.basic.DatabaseConfig -import slick.jdbc.JdbcProfile - -trait InstitutionComponent { - - import dbConfig.profile.api._ - - class InstitutionsTable(tag: Tag, tableName: String) extends Table[InstitutionEntity](tag, tableName) { - def lei = column[String]("lei", O.PrimaryKey) - def activityYear = column[Int]("activity_year") - def agency = column[Int]("agency") - def institutionType = column[Int]("institution_type") - def id2017 = column[String]("id2017") - def taxId = column[String]("tax_id") - def rssd = column[Int]("rssd") - def respondentName = column[String]("respondent_name") - def respondentState = column[String]("respondent_state") - def respondentCity = column[String]("respondent_city") - def parentIdRssd = column[Int]("parent_id_rssd") - def parentName = column[String]("parent_name") - def assets = column[Long]("assets") - def otherLenderCode = column[Int]("other_lender_code") - def topHolderIdRssd = column[Int]("topholder_id_rssd") - def topHolderName = column[String]("topholder_name") - def hmdaFiler = column[Boolean]("hmda_filer") - - def * = - ( - lei, - activityYear, - agency, - institutionType, - id2017, - taxId, - rssd, - respondentName, - respondentState, - respondentCity, - parentIdRssd, - parentName, - assets, - otherLenderCode, - topHolderIdRssd, - topHolderName, - hmdaFiler - ) <> (InstitutionEntity.tupled, InstitutionEntity.unapply) - } - - class InstitutionRepository(val config: DatabaseConfig[JdbcProfile], tableName: String) - extends TableRepository[InstitutionsTable, String] { - val institutionsTable = TableQuery[InstitutionsTable]((tag: Tag) => new InstitutionsTable(tag, tableName)) - val table = institutionsTable - def getId(table: InstitutionsTable) = table.lei - def deleteById(lei: String) = db.run(filterById(lei).delete) - - def createSchema() = db.run(table.schema.create) - def dropSchema() = db.run(table.schema.drop) - - def findByLei(lei: String) = - db.run(table.filter(_.lei === lei).result) - - def getAllFilers() = - db.run(table.filter(_.hmdaFiler === true).result) - - def getFilteredFilers(bankFilterList: Array[String]) = - db.run( - table - .filter(_.hmdaFiler === true) - .filterNot(_.lei.toUpperCase inSet bankFilterList) - .result - ) - } -} From 6545dba2a9ad07bbf9e74ce1c806813fcf4ee320 Mon Sep 17 00:00:00 2001 From: kgudel Date: Tue, 21 Jul 2026 14:08:38 -0400 Subject: [PATCH 2/3] add snapshot route for filers and msa endpoints --- .../component/InstitutionRepository.scala | 14 +++ .../reporting/api/http/ReportingHttpApi.scala | 116 ++++++++++-------- 2 files changed, 80 insertions(+), 50 deletions(-) diff --git a/hmda-data-publisher/src/main/scala/hmda/publisher/query/component/InstitutionRepository.scala b/hmda-data-publisher/src/main/scala/hmda/publisher/query/component/InstitutionRepository.scala index 4b96c770d9..29a4566b67 100644 --- a/hmda-data-publisher/src/main/scala/hmda/publisher/query/component/InstitutionRepository.scala +++ b/hmda-data-publisher/src/main/scala/hmda/publisher/query/component/InstitutionRepository.scala @@ -12,6 +12,20 @@ class InstitutionRepository( override val table: TableQuery[InstitutionsTable]) extends TableRepository[InstitutionsTable, String] { + def fetchYearTable(year: Int): String = + year match { + case 2018 => "institutions2018" + case 2019 => "institutions2019" + case 2020 => "institutions2020" + case 2021 => "institutions2021" + case 2022 => "institutions2022" + case 2023 => "institutions2023" + case 2024 => "institutions2024" + case 2025 => "institutions2025" + case 2026 => "institutions2026" + case _ => "institutions2025" + } + override def getId(row: InstitutionsTable): config.profile.api.Rep[Id] = row.lei diff --git a/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala b/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala index 8604f162ee..99f6915521 100644 --- a/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala +++ b/hmda-reporting/src/main/scala/hmda/reporting/api/http/ReportingHttpApi.scala @@ -13,6 +13,7 @@ import hmda.util.http.FilingResponseUtils.entityNotPresentResponse import io.circe.generic.auto._ import slick.basic.DatabaseConfig import slick.jdbc.JdbcProfile +import akka.http.scaladsl.model.Uri import scala.concurrent.{ ExecutionContext, Future } import scala.util.{ Failure, Success } @@ -30,69 +31,84 @@ private class ReportingHttpApi(config: Config)(implicit ec: ExecutionContext) ex private val institutionRepository = new InstitutionRepository(databaseConfig) - private val filerListRoute: Route = { - path("filers" / IntNumber) { filingYear => + private val filerReportingRoutes: Route = { + path("filers" / IntNumber) { year => get { - - val futFilerSet: Future[Set[HmdaFiler]] = { - institutionRepository - .getFilteredFilers(bankFilterList, filingYear, false) - .map(sheets => - sheets - .map(instituionEntity => - HmdaFiler( - instituionEntity.lei.toUpperCase, - instituionEntity.respondentName, - instituionEntity.activityYear.toString - ) - ) - .toSet - ) - } - - onComplete(futFilerSet) { - case Success(filerSet) => - complete(HmdaFilerResponse(filerSet)) - case Failure(error) => - complete(StatusCodes.BadRequest -> error.getLocalizedMessage) - } - + filersListRoute(year, false) + } + } ~ path("filers" / IntNumber / "snapshot") { year => + get { + filersListRoute(year, true) } } ~ path("filers" / IntNumber / Segment / "msaMds") { (year, lei) => extractUri { uri => - val resultset = for { - msaMdsResult <- modifiedLarRepository.msaMdsSnapshot(lei, year) - institutionResult <- institutionRepository.findByLei(lei, year, false) - } yield { - val msaMds = - msaMdsResult.map(myEntity => MsaMd(myEntity._1, myEntity._2)).toSet - MsaMdResponse( - new HmdaFiler( - institutionResult.head.lei.toUpperCase, - institutionResult.head.respondentName, - institutionResult.head.activityYear.toString - ), - msaMds - ) - } - - onComplete(resultset) { - case Success(leiMsaMds) => - complete(leiMsaMds) - case Failure(error) => - entityNotPresentResponse("institution", lei, uri) - } + filerMsaMdRoute(uri, year, lei, false) + } + } ~ path("filers" / IntNumber / Segment / "msaMds" / "snapshot") { (year, lei) => + extractUri { uri => + filerMsaMdRoute(uri, year, lei, true) } - } + } } def hmdaFilerRoutes: Route = handleRejections(corsRejectionHandler) { cors() { encodeResponse { - filerListRoute + filerReportingRoutes } } } + + private def filersListRoute(year: Int, snapshot: Boolean): Route = { + val futFilerSet: Future[Set[HmdaFiler]] = { + institutionRepository + .getFilteredFilers(bankFilterList, year, snapshot) + .map(sheets => + sheets + .map(instituionEntity => + HmdaFiler( + instituionEntity.lei.toUpperCase, + instituionEntity.respondentName, + instituionEntity.activityYear.toString + ) + ) + .toSet + ) + } + + onComplete(futFilerSet) { + case Success(filerSet) => + complete(HmdaFilerResponse(filerSet)) + case Failure(error) => + complete(StatusCodes.BadRequest -> error.getLocalizedMessage) + } + + } + + private def filerMsaMdRoute(uri: Uri, year: Int, lei: String, snapshot: Boolean): Route = { + val resultset = for { + msaMdsResult <- modifiedLarRepository.msaMdsSnapshot(lei, year) + institutionResult <- institutionRepository.findByLei(lei, year, snapshot) + } yield { + val msaMds = + msaMdsResult.map(myEntity => MsaMd(myEntity._1, myEntity._2)).toSet + MsaMdResponse( + new HmdaFiler( + institutionResult.head.lei.toUpperCase, + institutionResult.head.respondentName, + institutionResult.head.activityYear.toString + ), + msaMds + ) + } + + onComplete(resultset) { + case Success(leiMsaMds) => + complete(leiMsaMds) + case Failure(error) => + entityNotPresentResponse("institution", lei, uri) + } + } } \ No newline at end of file From c33a9f5e419e4edcd18e0672d8a610f6d2faabfa Mon Sep 17 00:00:00 2001 From: kgudel Date: Wed, 5 Aug 2026 13:10:17 -0400 Subject: [PATCH 3/3] fix tests for hmda reporting --- .../repository/InstitutionRepository.scala | 5 ++++- .../api/http/InstitutionComponentSpec.scala | 20 +++++++------------ .../api/http/ReportingHttpApiSpec.scala | 19 +++++++++--------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/common/src/main/scala/hmda/query/repository/InstitutionRepository.scala b/common/src/main/scala/hmda/query/repository/InstitutionRepository.scala index 363fd1984d..b2a1a237f3 100644 --- a/common/src/main/scala/hmda/query/repository/InstitutionRepository.scala +++ b/common/src/main/scala/hmda/query/repository/InstitutionRepository.scala @@ -91,7 +91,7 @@ trait InstitutionComponent { val snapshotTable2025 = snapshotInstitutionsTable2025 - def fetchYearTable(year: Int, snapshot: Boolean) = + private def fetchYearTable(year: Int, snapshot: Boolean) = snapshot match { case true => year match { @@ -120,6 +120,9 @@ trait InstitutionComponent { } } + def createSchema(year: Int) = db.run(fetchYearTable(year, false).schema.create) + def getYearTable(year: Int, snapshot: Boolean) = fetchYearTable(year, snapshot) + def findByLei(lei: String, year: Int, snapshot: Boolean) = db.run(fetchYearTable(year, snapshot).filter(_.lei === lei).result) diff --git a/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala b/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala index ef6a992b31..7b33020457 100644 --- a/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala +++ b/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala @@ -1,6 +1,7 @@ package hmda.reporting.repository import hmda.query.institution.InstitutionEntity +import hmda.query.repository.InstitutionComponent import hmda.utils.EmbeddedPostgres import org.scalatest.concurrent.ScalaFutures import org.scalatest.{ Matchers, WordSpec } @@ -13,32 +14,25 @@ class InstitutionComponentSpec extends WordSpec with EmbeddedPostgres with Insti import dbConfig._ import dbConfig.profile.api._ - val institutionRepo = new InstitutionRepository(dbConfig, "institutions_table") + val institutionRepo = new InstitutionRepository(dbConfig) override def bootstrapSqlFile: String = "" override def beforeAll(): Unit = { super.beforeAll() - Await.ready(institutionRepo.createSchema(), 30.seconds) - } - - override def afterAll(): Unit = { - Await.ready(institutionRepo.dropSchema(), 30.seconds) // just for test coverage - super.afterAll() + Await.ready(institutionRepo.createSchema(2018), 30.seconds) } "InstitutionRepository run-through" in { - whenReady(db.run(institutionRepo.table += InstitutionEntity("EXAMPLE-LEI-1", activityYear = 2018, hmdaFiler = true)))(_ shouldBe 1) + whenReady(db.run(institutionRepo.getYearTable(2018, false) += InstitutionEntity("EXAMPLE-LEI-1", activityYear = 2018, hmdaFiler = true)))(_ shouldBe 1) val test = for { - result <- institutionRepo.findByLei("EXAMPLE-LEI-1") + result <- institutionRepo.findByLei("EXAMPLE-LEI-1", 2018, false) _ = result should have length 1 - result <- institutionRepo.getAllFilers() + result <- institutionRepo.getAllFilers(2018, false) _ = result should have length 1 - _ <- institutionRepo.getFilteredFilers(Array.empty) + _ <- institutionRepo.getFilteredFilers(Array.empty, 2018, false) _ = result should have length 1 - _ <- institutionRepo.deleteById("EXAMPLE-LEI-1") - _ = institutionRepo.getId(institutionRepo.table.baseTableRow) } yield () whenReady(test)(_ => ()) diff --git a/hmda-reporting/src/test/scala/hmda/reporting/api/http/ReportingHttpApiSpec.scala b/hmda-reporting/src/test/scala/hmda/reporting/api/http/ReportingHttpApiSpec.scala index 1fb9f3f748..5a2cc45ff2 100644 --- a/hmda-reporting/src/test/scala/hmda/reporting/api/http/ReportingHttpApiSpec.scala +++ b/hmda-reporting/src/test/scala/hmda/reporting/api/http/ReportingHttpApiSpec.scala @@ -7,7 +7,7 @@ import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport import hmda.model.institution.{ HmdaFiler, HmdaFilerResponse, MsaMd, MsaMdResponse } import hmda.query.institution.InstitutionEntity import hmda.query.repository.ModifiedLarRepository -import hmda.reporting.repository.InstitutionComponent +import hmda.query.repository.InstitutionComponent import hmda.utils.EmbeddedPostgres import org.scalatest.concurrent.ScalaFutures import org.scalatest.{ Matchers, WordSpec } @@ -28,16 +28,15 @@ class ReportingHttpApiSpec import dbConfig._ import dbConfig.profile.api._ - val institutionRepo2018 = new InstitutionRepository(dbConfig, "institutions2018") - val institutionRepo2019 = new InstitutionRepository(dbConfig, "institutions2019") - val mlarRepo = new ModifiedLarRepository(dbConfig) + val institutionRepo = new InstitutionRepository(dbConfig) + val mlarRepo = new ModifiedLarRepository(dbConfig) override def bootstrapSqlFile: String = "modifiedlar.sql" override def beforeAll(): Unit = { super.beforeAll() - Await.ready(institutionRepo2018.createSchema(), 30.seconds) - Await.ready(institutionRepo2019.createSchema(), 30.seconds) + Await.ready(institutionRepo.createSchema(2018), 30.seconds) + Await.ready(institutionRepo.createSchema(2019), 30.seconds) } val routes: Route = ReportingHttpApi.create(system.settings.config) @@ -46,8 +45,8 @@ class ReportingHttpApiSpec "respond to filers/" in { whenReady( db.run( - (institutionRepo2018.institutionsTable += InstitutionEntity(lei = "EXAMPLE-LEI-1", activityYear = 2018, hmdaFiler = true)) >> - (institutionRepo2019.institutionsTable += InstitutionEntity(lei = "EXAMPLE-LEI-2", activityYear = 2019, hmdaFiler = true)) + (institutionRepo.getYearTable(2018, false) += InstitutionEntity(lei = "EXAMPLE-LEI-1", activityYear = 2018, hmdaFiler = true)) >> + (institutionRepo.getYearTable(2019, false) += InstitutionEntity(lei = "EXAMPLE-LEI-2", activityYear = 2019, hmdaFiler = true)) ) )(_ shouldBe 1) @@ -77,8 +76,8 @@ class ReportingHttpApiSpec whenReady( db.run( - (institutionRepo2018.institutionsTable += InstitutionEntity(lei = "EXAMPLE-LEI-10", activityYear = 2018, hmdaFiler = true)) >> - (institutionRepo2019.institutionsTable += InstitutionEntity(lei = "EXAMPLE-LEI-20", activityYear = 2019, hmdaFiler = true)) + (institutionRepo.getYearTable(2018, false) += InstitutionEntity(lei = "EXAMPLE-LEI-10", activityYear = 2018, hmdaFiler = true)) >> + (institutionRepo.getYearTable(2019, false) += InstitutionEntity(lei = "EXAMPLE-LEI-20", activityYear = 2019, hmdaFiler = true)) ) )(_ shouldBe 1)