Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/dot-github/actions…
Browse files Browse the repository at this point in the history
…/app-insights-to-slack/slackapi/slack-github-action-2.0.0
  • Loading branch information
achimber-moj authored Nov 22, 2024
2 parents 43688cc + 679324c commit 45e95de
Show file tree
Hide file tree
Showing 112 changed files with 3,070 additions and 216 deletions.
1 change: 1 addition & 0 deletions .github/workflows/access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ on:
- '["ims-and-delius"]'
- '["appointment-reminders-and-delius"]'
- '["justice-email-and-delius"]'
- '["assess-for-early-release-and-delius"]'
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
- ims-and-delius
- appointment-reminders-and-delius
- justice-email-and-delius
- assess-for-early-release-and-delius
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ on:
- '["ims-and-delius"]'
- '["appointment-reminders-and-delius"]'
- '["justice-email-and-delius"]'
- '["assess-for-early-release-and-delius"]'
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/readonly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ jobs:
- block-pipeline
steps:
- name: Send message to Slack
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
if: ${{ !contains(needs.*.result, 'failure') }}
with:
channel-id: probation-integration-notifications
Expand Down Expand Up @@ -263,7 +263,7 @@ jobs:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

- name: Send failure message to Slack
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
if: ${{ contains(needs.*.result, 'failure') }}
with:
channel-id: probation-integration-notifications
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reminders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:

- name: Send message to Slack
if: steps.runs.outputs.pending != '[]'
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
channel-id: probation-integration-notifications
payload: ${{ steps.transform.outputs.result }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/service-catalogue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ on:
- '["ims-and-delius"]'
- '["appointment-reminders-and-delius"]'
- '["justice-email-and-delius"]'
- '["assess-for-early-release-and-delius"]'
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,24 @@ Docker or remote dependencies.

To set up your development environment:
1. Open the project in [IntelliJ IDEA](https://www.jetbrains.com/idea/). Select "Import project from external model", then "Gradle".
2. To run the tests for a service, right-click the `src/test` folder in the project view and select "Run tests" (See [Test](#test)).
2. To run the tests for a service, right-click the `src/test` or `src/integrationTest` folder in the project view and
select "Run tests" (See [Test](#test)).
3. To start the service, use the pre-defined run configuration in `.idea/runConfigurations` (See [Run](#run)).

## Code formatting

Kotlin code is formatted using IntelliJ IDEA's code formatter,
which follows the [Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html).

GitHub Actions will automatically fix any formatting issues when you open a pull request.
You can also use <strong title="Command">⌘</strong><strong title="Option">⌥</strong>**L** (macOS),
or **Ctrl+Alt+L** (Windows/Linux) to manually reformat your code in IntelliJ IDEA.
See [Reformat code](https://www.jetbrains.com/help/idea/reformat-and-rearrange-code.html).

Note: The code formatter does not remove unused imports by default. You should
enable [Optimise on save](https://www.jetbrains.com/help/idea/creating-and-optimizing-imports.html#optimize-on-save) in
your IntelliJ IDEA settings to ensure you do not commit unused imports.

# Build
IntelliJ will automatically build your code as needed. To build using Gradle, follow the instructions below.

Expand Down Expand Up @@ -97,15 +112,6 @@ To build Docker images locally, run:
./gradlew jibDockerBuild
```

## Code formatting
Kotlin code is formatted using IntelliJ IDEA's code formatter,
which follows the [Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html).

GitHub Actions will automatically fix any formatting issues when you open a pull request.
You can also use <strong title="Command">⌘</strong><strong title="Option">⌥</strong>**L** (macOS),
or **Ctrl+Alt+L** (Windows/Linux) to manually reformat your code in IntelliJ IDEA.
See [Reformat file](https://www.jetbrains.com/guide/java/tips/reformat-file/).

# Run
## IntelliJ
In IntelliJ IDEA, a Spring Boot [run configuration](https://www.jetbrains.com/help/idea/run-debug-configuration.html) is
Expand Down
1 change: 1 addition & 0 deletions doc/tech-docs/source/services.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ weight: 20
* [Ims And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/ims-and-delius)
* [Appointment Reminders And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/appointment-reminders-and-delius)
* [Justice Email And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/justice-email-and-delius)
* [Assess For Early Release And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/assess-for-early-release-and-delius)
<li style="display: none">^ add new projects here</li>
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=57dafb5c2622c6cc08b993c85b7c06956a2f53536432a30ead46166dbca0f1e9
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,30 @@ class ProbationCaseDataLoader(
)
)

listOf(
generateEventAndAddOffences(
ProbationCaseGenerator.CASE_COMPLEX,
eventId = 100001L,
mainOffence = Pair(200001L, LocalDate.parse("2024-10-11")),
additionalOffence = Pair(300001L, LocalDate.parse("2024-10-21"))
)
generateEventAndAddOffences(
ProbationCaseGenerator.CASE_X320741,
eventId = 100002L,
mainOffence = Pair(200002L, LocalDate.parse("2024-10-12")),
additionalOffence = Pair(300002L, LocalDate.parse("2024-10-22"))
)
generateEventAndAddOffences(
ProbationCaseGenerator.CASE_LAO_RESTRICTED,
eventId = 100003L,
mainOffence = Pair(200003L, LocalDate.parse("2024-10-13")),
additionalOffence = Pair(300003L, LocalDate.parse("2024-10-23"))
)
generateEventAndAddOffences(
ProbationCaseGenerator.CASE_LAO_EXCLUSION,
).forEach {
generateEventAndAddOffences(probationCase = it)
}
eventId = 100004L,
mainOffence = Pair(200004L, LocalDate.parse("2024-10-14")),
additionalOffence = Pair(300004L, LocalDate.parse("2024-10-24"))
)

personalCircumstanceTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_TYPES)
personalCircumstanceSubTypeRepository.saveAll(PersonalCircumstanceGenerator.PC_SUB_TYPES)
Expand All @@ -125,25 +141,33 @@ class ProbationCaseDataLoader(
exclusionRepository.save(LimitedAccessGenerator.generateExclusion(EXCLUDED_CASE.toLimitedAccessPerson()))
}

private fun generateEventAndAddOffences(probationCase: ProbationCase) {
private fun generateEventAndAddOffences(
probationCase: ProbationCase,
eventId: Long,
mainOffence: Pair<Long, LocalDate>,
additionalOffence: Pair<Long, LocalDate>,
) {
val event = PersonGenerator.generateEvent(
"1",
probationCase.id
probationCase.id,
id = eventId
).apply(eventRepository::save)

mainOffenceRepository.save(
OffenceGenerator.generateMainOffence(
event,
OffenceGenerator.OFFENCE_ONE,
LocalDate.now().minusDays(7)
id = mainOffence.first,
date = mainOffence.second
)
)

additionalOffenceRepository.save(
OffenceGenerator.generateAdditionalOffence(
event,
OffenceGenerator.OFFENCE_TWO,
LocalDate.now().minusDays(5)
id = additionalOffence.first,
date = additionalOffence.second
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Of
import java.time.LocalDate

object OffenceGenerator {
val OFFENCE_ONE = generate("OFF1", "Offence One")
val OFFENCE_TWO = generate("OFF2", "Offence Two")
val OFFENCE_ONE = generate("OFF1", "Murder - OFF1", "Murder", "Murder of spouse")
val OFFENCE_TWO = generate(
"OFF2",
"Burglary in a dwelling - OFF2",
"Burglary in a dwelling",
"Burglary (dwelling) with intent to commit, or the commission of, an offence triable only on indictment"
)

fun generate(code: String, description: String, id: Long = IdGenerator.getAndIncrement()) =
Offence(code, description, id)
fun generate(
code: String,
description: String,
mainCategoryDescription: String,
subCategoryDescription: String,
id: Long = IdGenerator.getAndIncrement()
) =
Offence(code, description, mainCategoryDescription, subCategoryDescription, id)

fun generateMainOffence(
event: Event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,22 @@ class ProbationCaseIntegrationTest {
assertThat(detail.mappaDetail?.level, equalTo(2))
assertThat(detail.registrations.map { it.description }, equalTo(listOf("Description of ARSO")))
val mainOffence = detail.offences.first { it.main }
assertThat(mainOffence.description, equalTo("Offence One"))
assertThat(mainOffence.id, equalTo("M200001"))
assertThat(mainOffence.description, equalTo("Murder - OFF1"))
assertThat(mainOffence.mainCategoryDescription, equalTo("Murder"))
assertThat(mainOffence.subCategoryDescription, equalTo("Murder of spouse"))
assertThat(mainOffence.date, equalTo(LocalDate.parse("2024-10-11")))
assertThat(mainOffence.eventId, equalTo(100001L))
val otherOffence = detail.offences.first { !it.main }
assertThat(otherOffence.description, equalTo("Offence Two"))
assertThat(otherOffence.id, equalTo("A300001"))
assertThat(otherOffence.description, equalTo("Burglary in a dwelling - OFF2"))
assertThat(otherOffence.mainCategoryDescription, equalTo("Burglary in a dwelling"))
assertThat(
otherOffence.subCategoryDescription,
equalTo("Burglary (dwelling) with intent to commit, or the commission of, an offence triable only on indictment")
)
assertThat(otherOffence.date, equalTo(LocalDate.parse("2024-10-21")))
assertThat(otherOffence.eventId, equalTo(100001L))
assertThat(detail.careLeaver, equalTo(false))
assertThat(detail.veteran, equalTo(true))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface CaseOffence {
val id: Long
val code: String
val description: String
val mainCategoryDescription: String
val subCategoryDescription: String
val date: LocalDate?
val main: Boolean
val eventNumber: String
Expand Down Expand Up @@ -79,6 +81,12 @@ class Offence(
@Column
val description: String,

@Column(name = "main_category_description")
private var mainCategoryDescription: String,

@Column(name = "sub_category_description")
private val subCategoryDescription: String,

@Id
@Column(name = "offence_id")
val id: Long
Expand All @@ -88,9 +96,11 @@ interface MainOffenceRepository : JpaRepository<MainOffence, Long> {
@Query(
"""
select
mo.offence.id as id,
mo.id as id,
mo.offence.code as code,
mo.offence.description as description,
mo.offence.mainCategoryDescription as mainCategoryDescription,
mo.offence.subCategoryDescription as subCategoryDescription,
mo.date as date,
true as main,
mo.event.number as eventNumber,
Expand All @@ -99,9 +109,11 @@ interface MainOffenceRepository : JpaRepository<MainOffence, Long> {
where mo.event.personId = :personId and mo.event.active = true
union all
select
ao.offence.id,
ao.id,
ao.offence.code,
ao.offence.description,
ao.offence.mainCategoryDescription as mainCategoryDescription,
ao.offence.subCategoryDescription as subCategoryDescription,
ao.date,
false,
ao.event.number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ data class MappaDetail(
)

data class Offence(
val id: Long,
val id: String,
val code: String,
val description: String,
val mainCategoryDescription: String,
val subCategoryDescription: String,
val date: LocalDate?,
val main: Boolean,
val eventId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,18 @@ fun CommunityManager.team() = Team(
team.endDate
)

fun CaseOffence.asOffence() = Offence(id, code, description, date, main, eventId, eventNumber)
fun CaseOffence.asOffence() =
Offence(
id = if (main) "M$id" else "A$id",
code,
description,
mainCategoryDescription,
subCategoryDescription,
date,
main,
eventId,
eventNumber
)

fun Registration.asRegistration() = uk.gov.justice.digital.hmpps.model.Registration(type.code, type.description, date)
fun Registration.asMappa() = MappaDetail(
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions projects/assess-for-early-release-and-delius/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# assess-for-early-release-and-delius

// TODO Describe the service
Loading

0 comments on commit 45e95de

Please sign in to comment.