Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2584 Add missing LDAP username + add more Telemetry #4394

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -9,20 +9,24 @@ import org.springframework.stereotype.Service
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 @@ -36,7 +40,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
Loading