Skip to content

Commit

Permalink
Merge branch 'main' into MAN-104-display-of-next-activity-in-my-cases…
Browse files Browse the repository at this point in the history
…-page
  • Loading branch information
achimber-moj authored Oct 15, 2024
2 parents 86ac0d0 + b655bc2 commit 4f27a2d
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
echo >> projects/${{ matrix.project }}/.trivyignore
- name: Scan image
uses: aquasecurity/trivy-action@6e7b7d1fd3e4fef0c5fa8cce1229c54b2c9bd0d8 # v0.24.0
uses: aquasecurity/trivy-action@5681af892cd0f4997658e2bacc62bd0a894cf564 # v0.27.0
with:
image-ref: 'ghcr.io/ministryofjustice/hmpps-probation-integration-services/${{ matrix.project }}:latest'
ignore-unfixed: true
Expand All @@ -56,7 +56,7 @@ jobs:
sarif_file: 'trivy-results.sarif'

- name: Get Trivy results
uses: aquasecurity/trivy-action@6e7b7d1fd3e4fef0c5fa8cce1229c54b2c9bd0d8 # v0.24.0
uses: aquasecurity/trivy-action@5681af892cd0f4997658e2bacc62bd0a894cf564 # v0.27.0
with:
image-ref: 'ghcr.io/ministryofjustice/hmpps-probation-integration-services/${{ matrix.project }}:latest'
ignore-unfixed: true
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import uk.gov.justice.digital.hmpps.plugins.ClassPathPlugin
import uk.gov.justice.digital.hmpps.plugins.JibConfigPlugin

plugins {
kotlin("jvm") version "2.0.20"
kotlin("plugin.spring") version "2.0.20" apply false
kotlin("plugin.jpa") version "2.0.20" apply false
kotlin("jvm") version "2.0.21"
kotlin("plugin.spring") version "2.0.21" apply false
kotlin("plugin.jpa") version "2.0.21" apply false
id("org.springframework.boot") version "3.3.4" apply false
id("io.spring.dependency-management") version "1.1.6" apply false
id("com.gorylenko.gradle-git-properties") version "2.4.2" apply false
Expand All @@ -22,7 +22,7 @@ plugins {
val agentDeps: Configuration by configurations.creating

dependencies {
agentDeps("com.microsoft.azure:applicationinsights-agent:3.6.0")
agentDeps("com.microsoft.azure:applicationinsights-agent:3.6.1")
}

val copyAgentTask = project.tasks.register<Copy>("copyAgent") {
Expand Down
2 changes: 2 additions & 0 deletions projects/common-platform-and-delius/deploy/values-dev.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enabled: false

generic-service:
ingress:
host: common-platform-and-delius-dev.hmpps.service.justice.gov.uk
Expand Down
2 changes: 2 additions & 0 deletions projects/common-platform-and-delius/deploy/values-preprod.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enabled: false

generic-service:
ingress:
host: common-platform-and-delius-preprod.hmpps.service.justice.gov.uk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ object PersonGenerator {
val ECSLIRC_IN_CUSTODY = generate(NotificationGenerator.PRISONER_ECSLIRC_IN_CUSTODY.nomsId())
val ADMIN_MERGE = generate(NotificationGenerator.PRISONER_ADMIN_MERGE.nomsId())

fun generate(nomsNumber: String, id: Long = IdGenerator.getAndIncrement()) = Person(id, nomsNumber)
fun generate(nomsNumber: String, id: Long = IdGenerator.getAndIncrement()) =
Person(id, nomsNumber.reversed(), nomsNumber)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.hibernate.annotations.Immutable
import org.hibernate.annotations.SQLRestriction
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.ReferenceData

@Immutable
Expand All @@ -16,6 +17,9 @@ class Person(
@Column(name = "offender_id")
val id: Long,

@Column(columnDefinition = "char(7)")
val crn: String,

@Column(columnDefinition = "char(7)")
val nomsNumber: String,

Expand All @@ -25,8 +29,14 @@ class Person(

interface PersonRepository : JpaRepository<Person, Long> {
fun findByNomsNumberAndSoftDeletedIsFalse(nomsNumber: String): List<Person>

@Query("select p.nomsNumber from Person p where p.crn = :crn and p.softDeleted = false")
fun findNomsNumberByCrn(crn: String): String?
}

fun PersonRepository.getNomsNumberByCrn(crn: String) =
findNomsNumberByCrn(crn) ?: throw NotFoundException("NOMS number for case", "crn", crn)

@Immutable
@Entity
@SQLRestriction("soft_deleted = 0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.getNomsNumberByCrn
import uk.gov.justice.digital.hmpps.integrations.prison.Booking
import uk.gov.justice.digital.hmpps.integrations.prison.Movement
import uk.gov.justice.digital.hmpps.integrations.prison.PrisonApiClient
Expand All @@ -30,7 +32,8 @@ class Handler(
private val telemetryService: TelemetryService,
private val prisonApiClient: PrisonApiClient,
private val actionProcessor: ActionProcessor,
override val converter: NotificationConverter<HmppsDomainEvent>
private val personRepository: PersonRepository,
override val converter: NotificationConverter<HmppsDomainEvent>,
) : NotificationHandler<HmppsDomainEvent> {
private val configs = configContainer.configs

Expand All @@ -46,10 +49,12 @@ class Handler(
telemetryService.notificationReceived(notification)
val message = notification.message
val eventType = DomainEventType.of(message.eventType)
val nomsId = message.personReference.findNomsNumber()
?: personRepository.getNomsNumberByCrn(requireNotNull(message.personReference.findCrn()))

try {
val movement = when (eventType) {
IdentifierAdded, IdentifierUpdated, PrisonerReceived, PrisonerReleased -> {
val nomsId = message.personReference.findNomsNumber()!!
val booking = prisonApiClient.bookingFromNomsId(nomsId)
val movement = prisonApiClient.getLatestMovement(listOf(nomsId)).firstOrNull()
movement?.let { booking.prisonerMovement(it) }
Expand All @@ -63,7 +68,7 @@ class Handler(
if (movement == null) {
throw IgnorableMessageException(
"NoMovementInNomis", mapOf(
"nomsNumber" to message.personReference.findNomsNumber()!!
"nomsNumber" to nomsId
)
)
}
Expand Down Expand Up @@ -109,10 +114,7 @@ class Handler(
throw failure.exception
}
} catch (e: IgnorableMessageException) {
telemetryService.trackEvent(
e.message,
message.telemetryProperties() + e.additionalProperties
)
telemetryService.trackEvent(e.message, message.telemetryProperties(nomsId) + e.additionalProperties)
}
}

Expand All @@ -126,9 +128,9 @@ class Handler(

fun HmppsDomainEvent.prisonId() = additionalInformation["prisonId"] as String?
fun HmppsDomainEvent.details() = additionalInformation["details"] as String?
fun HmppsDomainEvent.telemetryProperties() = listOfNotNull(
fun HmppsDomainEvent.telemetryProperties(nomsId: String) = listOfNotNull(
"occurredAt" to occurredAt.toString(),
"nomsNumber" to personReference.findNomsNumber()!!,
"nomsNumber" to nomsId,
prisonId()?.let { "institution" to it },
details()?.let { "details" to it }
).toMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ prisoner.movement.configs:
# Do nothing for the following movement reasons
- MRG # Merged
- RE # Repatriated
- BL # Bailed
- BD # Bailed Detainee
- types:
- RELEASED
actionNames:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.data.generator.InstitutionGenerator
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository
import uk.gov.justice.digital.hmpps.integrations.prison.Booking
import uk.gov.justice.digital.hmpps.integrations.prison.Movement
import uk.gov.justice.digital.hmpps.integrations.prison.PrisonApiClient
Expand Down Expand Up @@ -40,6 +41,9 @@ internal class HandlerTest {
@Mock
lateinit var actionProcessor: ActionProcessor

@Mock
lateinit var personRepository: PersonRepository

private val configs = PrisonerMovementConfigs(
listOf(
PrisonerMovementConfig(
Expand All @@ -58,7 +62,15 @@ internal class HandlerTest {

@BeforeEach
fun setup() {
handler = Handler(configs, featureFlags, telemetryService, prisonApiClient, actionProcessor, converter)
handler = Handler(
configs,
featureFlags,
telemetryService,
prisonApiClient,
actionProcessor,
personRepository,
converter
)
}

private val notification = Notification(
Expand Down Expand Up @@ -292,6 +304,25 @@ internal class HandlerTest {
)
}

@Test
fun `lookup noms number by crn`() {
whenever(personRepository.findNomsNumberByCrn("X123456")).thenReturn("A1234AA")
whenever(prisonApiClient.getBookingByNomsId("A1234AA")).thenReturn(booking.copy(active = false))

handler.handle(
notification.copy(
message = notification.message.copy(
personReference = PersonReference(listOf(PersonIdentifier("CRN", "X123456"))),
)
)
)

verify(personRepository).findNomsNumberByCrn("X123456")
verify(telemetryService).trackEvent(eq("BookingInactive"), check {
assertThat(it["nomsNumber"], equalTo("A1234AA"))
}, any())
}

private fun Booking.movement() = Movement(
"OUT",
agencyId,
Expand Down
2 changes: 1 addition & 1 deletion projects/redrive-dead-letter-queues/container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/aws-cli/aws-cli:2.18.0
FROM public.ecr.aws/aws-cli/aws-cli:2.18.5

USER root
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
Expand Down
8 changes: 4 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ dependencyResolutionManagement {
library("aws-starter", "io.awspring.cloud:spring-cloud-aws-starter:3.2.0")
library("aws-sns", "io.awspring.cloud:spring-cloud-aws-starter-sns:3.2.0")
library("aws-sqs", "io.awspring.cloud:spring-cloud-aws-starter-sqs:3.2.0")
library("aws-sts", "software.amazon.awssdk:sts:2.28.16")
library("aws-query-protocol", "software.amazon.awssdk:aws-query-protocol:2.28.16")
library("aws-sts", "software.amazon.awssdk:sts:2.28.21")
library("aws-query-protocol", "software.amazon.awssdk:aws-query-protocol:2.28.21")
bundle(
"aws-messaging",
listOf("aws-autoconfigure", "aws-starter", "aws-sns", "aws-sqs", "aws-sts", "aws-query-protocol")
)
library("mockito-kotlin", "org.mockito.kotlin:mockito-kotlin:5.4.0")
library("mockito-inline", "org.mockito:mockito-inline:5.2.0")
bundle("mockito", listOf("mockito-kotlin", "mockito-inline"))
library("insights", "com.microsoft.azure:applicationinsights-web:3.6.0")
library("sentry", "io.sentry:sentry-spring-boot-starter-jakarta:7.14.0")
library("insights", "com.microsoft.azure:applicationinsights-web:3.6.1")
library("sentry", "io.sentry:sentry-spring-boot-starter-jakarta:7.15.0")
library(
"opentelemetry-annotations",
"io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations:2.8.0"
Expand Down

0 comments on commit 4f27a2d

Please sign in to comment.