From e9cf3d2fcd42c71ccdf509a0c4d1f61497673548 Mon Sep 17 00:00:00 2001 From: Anthony Britton <105213050+anthony-britton-moj@users.noreply.github.com> Date: Thu, 7 Mar 2024 11:20:55 +0000 Subject: [PATCH] PI-1957 (#3443) * PI-1957 --- .../deploy/templates/update-noms-numbers.yaml | 38 +++++++++++++++++++ .../deploy/values-dev.yml | 4 ++ .../deploy/values-preprod.yml | 6 ++- .../deploy/values-prod.yml | 4 ++ .../deploy/values.yaml | 6 ++- .../controller/PersonUpdateController.kt | 2 +- .../integrations/delius/entity/Person.kt | 3 ++ .../digital/hmpps/sevice/PersonService.kt | 3 +- 8 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 projects/prison-identifier-and-delius/deploy/templates/update-noms-numbers.yaml diff --git a/projects/prison-identifier-and-delius/deploy/templates/update-noms-numbers.yaml b/projects/prison-identifier-and-delius/deploy/templates/update-noms-numbers.yaml new file mode 100644 index 0000000000..d267c455bd --- /dev/null +++ b/projects/prison-identifier-and-delius/deploy/templates/update-noms-numbers.yaml @@ -0,0 +1,38 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: update-noms-numbers +spec: + schedule: {{ .Values.noms.update.schedule }} + concurrencyPolicy: Forbid + failedJobsHistoryLimit: 1 + successfulJobsHistoryLimit: 1 + jobTemplate: + spec: + template: + spec: + containers: + - name: update-noms-numbers + image: ghcr.io/ministryofjustice/hmpps-devops-tools + args: + - /bin/sh + - -c + - 'curl -fsSL -X POST "https://$BASE_URL/person/populate-noms-number?trialOnly=$TRIAL_ONLY" --header "Authorization: Bearer $(curl -fsSL --request POST "$AUTH_URL?grant_type=client_credentials" --user "$CLIENT_ID:$CLIENT_SECRET" | jq -r .access_token)" --header "Content-Type: application/json"' + env: + - name: AUTH_URL + value: {{ index .Values "generic-service" "env" "SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI" }} + - name: BASE_URL + value: {{ index .Values "generic-service" "ingress" "host" }} + - name: TRIAL_ONLY + value: '{{ index .Values "generic-service" "env" "NOMS_DRY_RUN" }}' + - name: CLIENT_ID + valueFrom: + secretKeyRef: + name: prison-identifier-and-delius-client-credentials + key: CLIENT_ID + - name: CLIENT_SECRET + valueFrom: + secretKeyRef: + name: prison-identifier-and-delius-client-credentials + key: CLIENT_SECRET + restartPolicy: Never \ No newline at end of file diff --git a/projects/prison-identifier-and-delius/deploy/values-dev.yml b/projects/prison-identifier-and-delius/deploy/values-dev.yml index f6a48d7c43..e67a9e18b1 100644 --- a/projects/prison-identifier-and-delius/deploy/values-dev.yml +++ b/projects/prison-identifier-and-delius/deploy/values-dev.yml @@ -19,3 +19,7 @@ generic-service: generic-prometheus-alerts: businessHoursOnly: true + +noms: + update: + schedule: 0 7 * * 1 diff --git a/projects/prison-identifier-and-delius/deploy/values-preprod.yml b/projects/prison-identifier-and-delius/deploy/values-preprod.yml index ac8f763889..d6c18c9afe 100644 --- a/projects/prison-identifier-and-delius/deploy/values-preprod.yml +++ b/projects/prison-identifier-and-delius/deploy/values-preprod.yml @@ -13,4 +13,8 @@ generic-service: INTEGRATIONS_PRISONER-SEARCH_URL: https://prisoner-search-preprod.prison.service.justice.gov.uk generic-prometheus-alerts: - businessHoursOnly: true \ No newline at end of file + businessHoursOnly: true + +noms: + update: + schedule: 0 7 * * 1 \ No newline at end of file diff --git a/projects/prison-identifier-and-delius/deploy/values-prod.yml b/projects/prison-identifier-and-delius/deploy/values-prod.yml index d4c020e8d9..2c8ed9bb43 100644 --- a/projects/prison-identifier-and-delius/deploy/values-prod.yml +++ b/projects/prison-identifier-and-delius/deploy/values-prod.yml @@ -8,3 +8,7 @@ generic-service: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer INTEGRATIONS_PRISONER-SEARCH_URL: https://prisoner-search.prison.service.justice.gov.uk + +noms: + update: + schedule: 0 7 * * 1 \ No newline at end of file diff --git a/projects/prison-identifier-and-delius/deploy/values.yaml b/projects/prison-identifier-and-delius/deploy/values.yaml index f44f677a24..777ee3e8ec 100644 --- a/projects/prison-identifier-and-delius/deploy/values.yaml +++ b/projects/prison-identifier-and-delius/deploy/values.yaml @@ -9,6 +9,9 @@ generic-service: ingress: tlsSecretName: prison-identifier-and-delius-cert + env: + NOMS_DRY_RUN: "true" + namespace_secrets: common: SPRING_DATASOURCE_URL: DB_URL @@ -24,5 +27,4 @@ generic-service: MESSAGING_CONSUMER_QUEUE: QUEUE_NAME generic-prometheus-alerts: - targetApplication: prison-identifier-and-delius - + targetApplication: prison-identifier-and-delius \ No newline at end of file diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/PersonUpdateController.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/PersonUpdateController.kt index b714824697..bb25da360e 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/PersonUpdateController.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/PersonUpdateController.kt @@ -17,6 +17,6 @@ class PersonUpdateController(private val personService: PersonService) { @RequestMapping(value = ["/populate-noms-number"], method = [RequestMethod.GET, RequestMethod.POST]) fun populateNomsNumbers( @RequestParam(defaultValue = "true") trialOnly: Boolean, - @Size(min = 1, max = 500, message = "Please provide between 1 and 500 crns") @RequestBody crns: List + @Size(min = 0, max = 500, message = "Please provide between 1 and 500 crns") @RequestBody crns: List ) = personService.populateNomsNumber(crns, trialOnly) } diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt index 32ba106ab5..d1cdad612f 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt @@ -123,6 +123,9 @@ interface PersonRepository : JpaRepository { ) fun findByCrn(crn: String): List fun findByNomsNumberAndSoftDeletedIsFalse(nomsNumber: String): Person? + + @Query("select p.crn from Person p where p.softDeleted = false") + fun findAllCrns(): List } interface SentencedPerson { diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/sevice/PersonService.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/sevice/PersonService.kt index b08bbc885a..9bbec877a2 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/sevice/PersonService.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/sevice/PersonService.kt @@ -26,8 +26,9 @@ class PersonService( ) { @Transactional fun populateNomsNumber(crns: List, trialOnly: Boolean): NomsUpdates { + val data = if (crns.isEmpty()) personRepository.findAllCrns() else crns return NomsUpdates( - crns.map { crn -> + data.map { crn -> val sentences = personRepository.findByCrn(crn) val person = sentences.firstOrNull()?.person val personMatch = getPersonMatch(crn, person, sentences.map { it.sentenceDate })