Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Mar 7, 2024
1 parent 9100f01 commit e9cf3d2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions projects/prison-identifier-and-delius/deploy/values-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ generic-service:

generic-prometheus-alerts:
businessHoursOnly: true

noms:
update:
schedule: 0 7 * * 1
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ generic-service:
INTEGRATIONS_PRISONER-SEARCH_URL: https://prisoner-search-preprod.prison.service.justice.gov.uk

generic-prometheus-alerts:
businessHoursOnly: true
businessHoursOnly: true

noms:
update:
schedule: 0 7 * * 1
4 changes: 4 additions & 0 deletions projects/prison-identifier-and-delius/deploy/values-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions projects/prison-identifier-and-delius/deploy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,5 +27,4 @@ generic-service:
MESSAGING_CONSUMER_QUEUE: QUEUE_NAME

generic-prometheus-alerts:
targetApplication: prison-identifier-and-delius

targetApplication: prison-identifier-and-delius
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
@Size(min = 0, max = 500, message = "Please provide between 1 and 500 crns") @RequestBody crns: List<String>
) = personService.populateNomsNumber(crns, trialOnly)
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ interface PersonRepository : JpaRepository<Person, Long> {
)
fun findByCrn(crn: String): List<SentencedPerson>
fun findByNomsNumberAndSoftDeletedIsFalse(nomsNumber: String): Person?

@Query("select p.crn from Person p where p.softDeleted = false")
fun findAllCrns(): List<String>
}

interface SentencedPerson {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class PersonService(
) {
@Transactional
fun populateNomsNumber(crns: List<String>, 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 })
Expand Down

0 comments on commit e9cf3d2

Please sign in to comment.