generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e8b0883
commit a38e1d0
Showing
20 changed files
with
290 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
.idea/runConfigurations/risk_assessment_scores_to_delius.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
projects/risk-assessment-scores-to-delius/deploy/values-dev.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
environment_name: delius-test | ||
|
||
enabled: false # TODO set this to true when you're ready to deploy your service | ||
|
||
env: | ||
SENTRY_ENVIRONMENT: dev | ||
LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG |
2 changes: 0 additions & 2 deletions
2
projects/risk-assessment-scores-to-delius/deploy/values-preprod.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
environment_name: delius-pre-prod | ||
|
||
enabled: false # TODO set this to true when you're ready to deploy your service | ||
|
||
env: | ||
SENTRY_ENVIRONMENT: preprod |
2 changes: 0 additions & 2 deletions
2
projects/risk-assessment-scores-to-delius/deploy/values-prod.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
environment_name: delius-prod | ||
|
||
enabled: false # TODO set this to true when you're ready to deploy your service | ||
|
||
env: | ||
SENTRY_ENVIRONMENT: prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...sessment-scores-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/MessageGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import uk.gov.justice.digital.hmpps.message.HmppsEvent | ||
import uk.gov.justice.digital.hmpps.resourceloader.ResourceLoader | ||
|
||
object MessageGenerator { | ||
val RSR_SCORES_DETERMINED = ResourceLoader.message<HmppsEvent>("rsr-scores-determined") | ||
val OGRS_SCORES_DETERMINED = ResourceLoader.message<HmppsEvent>("ogrs-scores-determined") | ||
} |
4 changes: 4 additions & 0 deletions
4
projects/risk-assessment-scores-to-delius/src/dev/resources/db/h2.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
drop schema if exists pkg_triggersupport cascade; | ||
|
||
create schema pkg_triggersupport; | ||
create alias pkg_triggersupport.procRsrUpdateCas as 'void stub() {}'; |
38 changes: 38 additions & 0 deletions
38
projects/risk-assessment-scores-to-delius/src/dev/resources/db/oracle.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- As of 30/09/2022, the procedure is not yet available in the Delius OracleDB so I've left this SQL here to help with local testing. | ||
|
||
create or replace package pkg_triggersupport as | ||
procedure procRsrUpdateCas( | ||
p_crn in varchar2, | ||
p_event_number in int, | ||
p_rsr_assessor_date in timestamp, | ||
p_rsr_score in float, | ||
p_rsr_band in varchar2, | ||
p_osp_indecent_score in float, | ||
p_osp_indecent_band in varchar2, | ||
p_osp_contact_score in float, | ||
p_osp_contact_band in varchar2, | ||
p_error out varchar2 | ||
); | ||
end pkg_triggersupport; | ||
grant execute on pkg_triggersupport to delius_app_schema; | ||
|
||
create or replace package body pkg_triggersupport as | ||
procedure procRsrUpdateCas( | ||
p_crn in varchar2, | ||
p_event_number in int, | ||
p_rsr_assessor_date in timestamp, | ||
p_rsr_score in float, | ||
p_rsr_band in varchar2, | ||
p_osp_indecent_score in float, | ||
p_osp_indecent_band in varchar2, | ||
p_osp_contact_score in float, | ||
p_osp_contact_band in varchar2, | ||
p_error out varchar2 | ||
) is | ||
begin | ||
-- For testing: | ||
if length(p_crn) != 7 then p_error := 'Invalid CRN'; end if; | ||
-- ... | ||
end procRsrUpdateCas; | ||
end pkg_triggersupport; | ||
/ |
17 changes: 17 additions & 0 deletions
17
...s/risk-assessment-scores-to-delius/src/dev/resources/messages/ogrs-scores-determined.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"Type": "Notification", | ||
"MessageId": "", | ||
"TopicArn": "", | ||
"Message": "{\"eventType\":\"risk-assessment.scores.ogrs.determined\",\"version\":1,\"description\":\"Risk assessment scores have been determined\",\"detailUrl\":\"https://some-url-where-we-can-get-more-info-this-might-not-exist\",\"occurredAt\":\"2022-09-15T15:34:48+01:00\",\"additionalInformation\":{\"OGRS3Yr1\":4,\"OGRS3Yr2\":8,\"EventNumber\":1,\"AssessmentDate\":\"2022-09-15T15:34:48+01:00\"},\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"X552020\"}]}}", | ||
"Timestamp": "2022-09-15T14:34:48.123Z", | ||
"SignatureVersion": "1", | ||
"Signature": "", | ||
"SigningCertURL": "", | ||
"UnsubscribeURL": "", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "risk-assessment.scores.ogrs.determined" | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ts/risk-assessment-scores-to-delius/src/dev/resources/messages/rsr-scores-determined.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"Type": "Notification", | ||
"MessageId": "", | ||
"TopicArn": "", | ||
"Message": "{\"eventType\":\"risk-assessment.scores.rsr.determined\",\"version\":1,\"description\":\"Risk assessment scores have been determined\",\"detailUrl\":\"https://some-url-where-we-can-get-more-info-this-might-not-exist\",\"occurredAt\":\"2022-09-22T12:16:04+01:00\",\"additionalInformation\":{\"RSRScore\":45.33,\"RSRBand\":\"H\",\"RSRStaticOrDynamic\":\"STATIC\",\"OSPIndecentScore\":5.79,\"OSPIndecentBand\":\"H\",\"OSPContactScore\":38.7,\"OSPContactBand\":\"V\",\"EventNumber\":1,\"AssessmentDate\":\"2022-09-22T12:16:04+01:00\"},\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"X552020\"}]}}", | ||
"Timestamp": "2022-05-04T08:06:46.704Z", | ||
"SignatureVersion": "1", | ||
"Signature": "", | ||
"SigningCertURL": "", | ||
"UnsubscribeURL": "", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "risk-assessment.scores.rsr.determined" | ||
} | ||
} | ||
} |
23 changes: 22 additions & 1 deletion
23
...ores-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.mockito.kotlin.verify | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.jms.core.JmsTemplate | ||
import org.springframework.test.context.ActiveProfiles | ||
import uk.gov.justice.digital.hmpps.jms.convertSendAndWait | ||
import uk.gov.justice.digital.hmpps.listener.telemetryProperties | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("integration-test") | ||
internal class IntegrationTest { | ||
@Value("\${spring.jms.template.default-destination}") | ||
private lateinit var queueName: String | ||
|
||
@Autowired | ||
private lateinit var jmsTemplate: JmsTemplate | ||
|
||
@MockBean | ||
private lateinit var telemetryService: TelemetryService | ||
|
||
@Test | ||
fun `the context loads`() {} | ||
fun `successfully update RSR scores`() { | ||
val message = MessageGenerator.RSR_SCORES_DETERMINED | ||
jmsTemplate.convertSendAndWait(queueName, message) | ||
verify(telemetryService).trackEvent("RsrScoresUpdated", message.telemetryProperties()) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...elius/src/main/kotlin/uk/gov/justice/digital/hmpps/exception/FailureToUpdateRiskScores.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package uk.gov.justice.digital.hmpps.exception | ||
|
||
class FailureToUpdateRiskScores(override val message: String) : RuntimeException(message) |
41 changes: 41 additions & 0 deletions
41
...lius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius | ||
|
||
import org.springframework.jdbc.core.JdbcTemplate | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource | ||
import org.springframework.jdbc.core.simple.SimpleJdbcCall | ||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.exception.FailureToUpdateRiskScores | ||
import java.time.ZonedDateTime | ||
|
||
@Service | ||
class RiskScoreService(jdbcTemplate: JdbcTemplate) { | ||
private val updateRsrScoresProcedure = SimpleJdbcCall(jdbcTemplate) | ||
.withCatalogName("pkg_triggersupport") | ||
.withProcedureName("procRsrUpdateCas") | ||
|
||
fun updateRsrScores( | ||
crn: String, | ||
eventNumber: Int, | ||
assessmentDate: ZonedDateTime, | ||
rsrScore: Double, | ||
rsrBand: String, | ||
ospIndecentScore: Double, | ||
ospIndecentBand: String, | ||
ospContactScore: Double, | ||
ospContactBand: String, | ||
) { | ||
val result = updateRsrScoresProcedure.execute( | ||
MapSqlParameterSource() | ||
.addValue("p_crn", crn) | ||
.addValue("p_event_number", eventNumber) | ||
.addValue("p_rsr_assessor_date", assessmentDate) | ||
.addValue("p_rsr_score", rsrScore) | ||
.addValue("p_rsr_band", rsrBand) | ||
.addValue("p_osp_indecent_score", ospIndecentScore) | ||
.addValue("p_osp_indecent_band", ospIndecentBand) | ||
.addValue("p_osp_contact_score", ospContactScore) | ||
.addValue("p_osp_contact_band", ospContactBand) | ||
) | ||
result["P_ERROR"]?.let { throw FailureToUpdateRiskScores(it as String) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.