Skip to content

Commit 287927a

Browse files
committed
Include InstitutionName in D5-1 results
1 parent 733bd57 commit 287927a

File tree

4 files changed

+52
-20
lines changed

4 files changed

+52
-20
lines changed

model/shared/src/main/scala/hmda/model/institution/Institution.scala

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ import hmda.model.institution.InstitutionType.UndeterminedInstitutionType
88
* A financial institution, geared towards requirements for filing HMDA data.
99
*/
1010
case class Institution(
11-
id: String,
12-
agency: Agency,
13-
activityYear: Int,
14-
institutionType: InstitutionType,
15-
cra: Boolean,
16-
externalIds: Set[ExternalId],
17-
emailDomains: Set[String],
18-
respondent: Respondent,
19-
hmdaFilerFlag: Boolean,
20-
parent: Parent,
21-
assets: Int,
22-
otherLenderCode: Int,
23-
topHolder: TopHolder
24-
)
11+
id: String,
12+
agency: Agency,
13+
activityYear: Int,
14+
institutionType: InstitutionType,
15+
cra: Boolean,
16+
externalIds: Set[ExternalId],
17+
emailDomains: Set[String],
18+
respondent: Respondent,
19+
hmdaFilerFlag: Boolean,
20+
parent: Parent,
21+
assets: Int,
22+
otherLenderCode: Int,
23+
topHolder: TopHolder
24+
) {
25+
def respondentId: String = respondent.externalId.value
26+
}
27+
2528
case object Institution {
2629
def empty: Institution = Institution(
2730
"",

publication/src/main/scala/hmda/publication/reports/disclosure/D51.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ object D51 {
6666
// Loan Type 2,3,4
6767
// Property Type 1,2
6868
// Purpose of Loan 1
69-
def generate[ec: EC, mat: MAT, as: AS](larSource: Source[LoanApplicationRegisterQuery, NotUsed], fipsCode: Int, respId: String): Future[D51] = {
69+
def generate[ec: EC, mat: MAT, as: AS](
70+
larSource: Source[LoanApplicationRegisterQuery, NotUsed],
71+
fipsCode: Int,
72+
respId: String,
73+
institutionNameF: Future[String]
74+
): Future[D51] = {
7075

7176
val lars = larSource
7277
.filter(lar => lar.respondentId == respId)
@@ -96,6 +101,7 @@ object D51 {
96101
lars100To120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(Between100And119PercentOfMSAMedian)
97102
lars120BorrowerCharacteristics <- borrowerCharacteristicsByIncomeF(GreaterThan120PercentOfMSAMedian)
98103

104+
institutionName <- institutionNameF
99105
date <- dateF
100106
total <- totalF
101107
} yield {
@@ -122,7 +128,7 @@ object D51 {
122128

123129
D51(
124130
respId,
125-
"",
131+
institutionName,
126132
date,
127133
formatDate(Calendar.getInstance().toInstant),
128134
msa,
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
11
package hmda.publication.reports.disclosure
22

3-
import akka.actor.ActorSystem
3+
import akka.actor.{ ActorRef, ActorSystem }
4+
import akka.pattern.ask
45
import akka.stream.ActorMaterializer
6+
import akka.util.Timeout
7+
import com.typesafe.config.ConfigFactory
8+
import hmda.model.institution.Institution
9+
import hmda.persistence.model.HmdaSupervisorActor.FindActorByName
510
import hmda.publication.reports.protocol.disclosure.D51Protocol._
611
import hmda.query.repository.filing.FilingCassandraRepository
12+
import hmda.query.view.institutions.InstitutionView
13+
import hmda.query.view.institutions.InstitutionView.GetInstitutionByRespondentId
714

815
import scala.concurrent.Future
16+
import scala.concurrent.duration._
917
import spray.json._
1018

1119
class DisclosureReports(val sys: ActorSystem, val mat: ActorMaterializer) extends FilingCassandraRepository {
1220

1321
override implicit def system: ActorSystem = sys
1422
override implicit def materializer: ActorMaterializer = mat
23+
val config = ConfigFactory.load()
24+
val duration = config.getInt("hmda.actor-lookup-timeout")
25+
implicit val timeout = Timeout(duration.seconds)
1526

1627
val larSource = readData(1000)
1728

1829
def generateReports(fipsCode: Int, respId: String): Future[Unit] = {
19-
val d51F = D51.generate(larSource, fipsCode, respId)
30+
val institutionNameF = institutionName(respId)
31+
32+
val d51F = D51.generate(larSource, fipsCode, respId, institutionNameF)
2033
d51F.map { d51 =>
2134
println(d51.toJson.prettyPrint)
2235
}
2336
}
2437

38+
private def institutionName(respondentId: String): Future[String] = {
39+
val querySupervisor = system.actorSelection("/user/query-supervisor")
40+
val fInstitutionsActor = (querySupervisor ? FindActorByName(InstitutionView.name)).mapTo[ActorRef]
41+
for {
42+
a <- fInstitutionsActor
43+
i <- (a ? GetInstitutionByRespondentId(respondentId)).mapTo[Institution]
44+
} yield i.respondent.name
45+
}
46+
2547
}

publication/src/test/scala/hmda/publication/reports/disclosure/D51Spec.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import hmda.query.repository.filing.LarConverter._
1313
import org.scalacheck.Gen
1414
import org.scalatest.{ MustMatchers, WordSpec }
1515

16-
import scala.concurrent.Await
16+
import scala.concurrent.{ Await, Future }
1717
import scala.concurrent.duration._
1818

1919
class D51Spec extends WordSpec with MustMatchers with LarGenerators {
@@ -40,11 +40,12 @@ class D51Spec extends WordSpec with MustMatchers with LarGenerators {
4040
val expectedDispositions = List(ApplicationReceived, LoansOriginated, ApprovedButNotAccepted, ApplicationsDenied, ApplicationsWithdrawn, ClosedForIncompleteness)
4141

4242
"Generate a Disclosure 5-1 report" in {
43-
val result = Await.result(D51.generate(source, fips, respId), 5.seconds)
43+
val result = Await.result(D51.generate(source, fips, respId, Future("Corvallis Test Bank")), 5.seconds)
4444

4545
result.msa mustBe MSAReport("18700", "Corvallis, OR", "OR", "Oregon")
4646
result.table mustBe "5-1"
4747
result.respondentId mustBe "98765"
48+
result.institutionName mustBe "Corvallis Test Bank"
4849
result.applicantIncomes.size mustBe 5
4950

5051
val lowestIncome = result.applicantIncomes.head

0 commit comments

Comments
 (0)