Skip to content

Commit 176f9ac

Browse files
author
Nick Grippin
committed
connection working, smtp server needs setup
1 parent 163fc97 commit 176f9ac

File tree

6 files changed

+86
-17
lines changed

6 files changed

+86
-17
lines changed

api/src/main/resources/application.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ hmda {
2727
timeout = 10
2828
timeout = ${?HMDA_HTTP_TIMEOUT}
2929
}
30+
mail {
31+
host = "mail_dev"
32+
host = ${?HMDA_MAIL_HOST}
33+
port = "25"
34+
port = ${?HMDA_MAIL_PORT}
35+
}
3036
isDemo = false
3137
isDemo = ${?HMDA_IS_DEMO}
3238
}

api/src/main/scala/hmda/api/http/institutions/submissions/SubmissionSignPaths.scala

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ import scala.concurrent.{ ExecutionContext, Future }
2828
import javax.mail._
2929
import javax.mail.internet.{ InternetAddress, MimeMessage }
3030

31+
import com.typesafe.config.ConfigFactory
32+
import hmda.query.repository.KeyCloakRepository
3133
/*
3234
Questions
3335
- Which email library to use (Javax)?
3436
- Which email/port to send from (no-reply)?
3537
- Send all emails using CC/BCC, or separate (separate)?
36-
- Strategy of using Institution Persistance to retrieve emails (it's ok)?
3738
*/
3839

3940
trait SubmissionSignPaths
@@ -43,7 +44,8 @@ trait SubmissionSignPaths
4344
with EditResultsProtocol
4445
with HmdaCustomDirectives
4546
with RequestVerificationUtils
46-
with ValidationErrorConverter {
47+
with ValidationErrorConverter
48+
with KeyCloakRepository {
4749

4850
implicit val system: ActorSystem
4951
implicit val materializer: ActorMaterializer
@@ -98,36 +100,45 @@ trait SubmissionSignPaths
98100

99101
onComplete(fSubmission) {
100102
case Success(sub) =>
101-
emailSignature(supervisor, sub)
103+
if (sub.status.code == 10) {
104+
emailSignature(supervisor, sub)
105+
}
102106
complete(ToResponseMarshallable(Receipt(sub.end, sub.receipt, sub.status)))
103107
case Failure(error) => completeWithInternalError(uri, error)
104108
}
105109
}
106110

107111
private def emailSignature(supervisor: ActorRef, submission: Submission)(implicit ec: ExecutionContext) = {
108-
/*
109-
TODO: Get email addresses!!!!
110-
*/
111-
val address = "PLACEHOLDER"
112-
sendMail(address, submission)
112+
val emails = findEmailsById(submission.id.institutionId)
113+
emails.map(emailSeq => {
114+
emailSeq.foreach(t => {
115+
val username = t._1 + " " + t._2
116+
sendMail(t._3, username, submission)
117+
})
118+
})
119+
}
120+
121+
private def sendMail(address: String, username: String, submission: Submission) = {
122+
val config = ConfigFactory.load()
123+
val host = config.getString("hmda.mail.host")
124+
val port = config.getString("hmda.mail.port")
113125

114-
private def sendMail(address: String, submission: Submission) = {
115126
val properties = System.getProperties
116-
properties.put("mail.smtp.host", "localhost")
127+
properties.put("mail.smtp.host", host)
128+
properties.put("mail.smtp.port", port)
129+
117130
val session = Session.getDefaultInstance(properties)
118131
val message = new MimeMessage(session)
119132

120-
val date = submission.end
121-
val text = s"Congratulations, you've completed filing your HMDA data for filing period ${submission.id.period}.\n" +
133+
val text = s"$username,\nCongratulations, you've completed filing your HMDA data for filing period ${submission.id.period}.\n" +
122134
s"We received your filing on: ${submission.end}\n" +
123135
s"Your receipt is:${submission.receipt}"
124-
message.setFrom(new InternetAddress("test@test.com"))
136+
message.setFrom(new InternetAddress("no-reply@test.com"))
125137
message.setRecipients(Message.RecipientType.TO, address)
126138
message.setSubject("HMDA Filing Successful")
127139
message.setText(text)
128140

129141
log.info(s"Sending message to $address with the message \n$text")
130-
131-
//Transport.send(message)
142+
Transport.send(message)
132143
}
133144
}

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ services:
4444
APP_URL: https://192.168.99.100
4545
HMDA_API: https://192.168.99.100:4443/hmda
4646
KEYCLOAK_URL: https://192.168.99.100:8443/auth/realms/hmda
47-
# lb settings
47+
# lb settings
4848
VIRTUAL_HOST: 'http://*:80/*, https://*:443/*'
4949
EXCLUDE_PORTS: '443' # use lb's ssl instead of ui's nginx
5050
FORCE_SSL: 'true' # redirect 80 to 443
@@ -81,6 +81,8 @@ services:
8181

8282
keycloak_db:
8383
image: postgres:9.6.1
84+
ports:
85+
- '5433:5432'
8486
environment:
8587
POSTGRES_DB: keycloak
8688
POSTGRES_USER: keycloak

persistence-model/src/main/scala/hmda/persistence/model/HmdaPersistentActor.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ abstract class HmdaPersistentActor extends PersistentActor with HmdaActor {
2424
}
2525

2626
override def receiveCommand: Receive = {
27-
case ReceiveTimeout =>
27+
case ReceiveTimeout => {
28+
log.info("Received Timeout, sending Shutdown message. Thread: " + Thread.currentThread().getName)
2829
self ! Shutdown
30+
}
2931

3032
case Shutdown =>
3133
context stop self

query/src/main/resources/application.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ hmda {
3636
// }
3737
//}
3838

39+
db {
40+
driver = "slick.driver.PostgresDriver$"
41+
db {
42+
driver = org.postgresql.Driver
43+
host = "192.168.99.100"
44+
host = ${?KEYCLOAK_HOST}
45+
port = "5433"
46+
port = ${?KEYCLOAK_PORT}
47+
database = "keycloak"
48+
database = ${?KEYCLOAK_DATABASE}
49+
url = "jdbc:postgresql://"${db.db.host}":"${db.db.port}"/"${db.db.database}
50+
url = ${?KEYCLOAK_URL_OVERRIDE}
51+
user = "keycloak"
52+
user = ${?KEYCLOAK_USER}
53+
password = "password"
54+
password = ${?KEYCLOAK_PASSWORD}
55+
connectionPool = disabled
56+
}
57+
}
58+
3959
cassandra {
4060
host = "192.168.99.100"
4161
host = ${?CASSANDRA_CLUSTER_HOSTS}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package hmda.query.repository
2+
3+
import slick.basic.DatabaseConfig
4+
import slick.jdbc.JdbcProfile
5+
import slick.jdbc.H2Profile.api._
6+
7+
import scala.concurrent.{ ExecutionContext, Future }
8+
9+
trait KeyCloakRepository {
10+
val dbConfig = DatabaseConfig.forConfig[JdbcProfile]("db")
11+
val db = dbConfig.db
12+
13+
def findEmailsById(id: String)(implicit ec: ExecutionContext): Future[Seq[(String, String, String)]] = {
14+
val query =
15+
sql"""SELECT ue.first_name, ue.last_name, ue.email
16+
FROM user_entity AS ue
17+
INNER JOIN user_attribute AS ua ON ua.user_id = ue.id
18+
WHERE ue.realm_id = 'hmda'
19+
AND ue.enabled = 't'
20+
AND ue.email_verified = 't'
21+
AND ua.name = 'institutions'
22+
AND (ua.value = '#$id'
23+
OR ua.value LIKE '#$id,%'
24+
OR ua.value LIKE '%,#$id'
25+
OR ua.value LIKE '%,#$id,%')"""
26+
db.run(query.as[(String, String, String)])
27+
}
28+
}

0 commit comments

Comments
 (0)