Skip to content

Commit

Permalink
PI-2584 Add missing LDAP username + add more Telemetry (#4394)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Nov 6, 2024
1 parent 604c092 commit 8ef5f5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions projects/justice-email-and-delius/deploy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ generic-service:
common:
SPRING_DATASOURCE_URL: DB_URL
SPRING_LDAP_URLS: LDAP_URL
SPRING_LDAP_USERNAME: LDAP_USERNAME
SPRING_LDAP_PASSWORD: LDAP_PASSWORD
justice-email-and-delius-database:
SPRING_DATASOURCE_USERNAME: DB_USERNAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ import uk.gov.justice.digital.hmpps.message.MessageAttributes
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.messaging.EmailMessage
import uk.gov.justice.digital.hmpps.publisher.NotificationPublisher
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService

@Service
class MailboxService(
@Value("\${microsoft-graph.email-address}")
private val emailAddress: String,
private val graphServiceClient: GraphServiceClient,
private val notificationPublisher: NotificationPublisher
private val notificationPublisher: NotificationPublisher,
private val telemetryService: TelemetryService,
) {
@WithSpan("POLL mailbox", kind = SpanKind.SERVER)
fun publishUnreadMessagesToQueue() {
getUnreadMessages().forEach { message ->
notificationPublisher.publish(message.asNotification())
message.markAsRead()
}
getUnreadMessages()
.also { telemetryService.trackEvent("ReceivedMessages", mapOf("count" to it.size.toString())) }
.forEach {
notificationPublisher.publish(it.asNotification())
it.markAsRead()
}
}

private fun getUnreadMessages() = graphServiceClient
Expand All @@ -37,7 +41,7 @@ class MailboxService(
request.queryParameters.filter = "isRead ne true"
request.queryParameters.select = arrayOf("subject", "from", "id", "receivedDateTime", "body", "isRead")
request.queryParameters.orderby = arrayOf("receivedDateTime DESC")
}.value
}.value ?: emptyList()

private fun Message.markAsRead() {
graphServiceClient
Expand Down

0 comments on commit 8ef5f5e

Please sign in to comment.