Skip to content

Commit

Permalink
PI-1441 WIP (#2391)
Browse files Browse the repository at this point in the history
* PI-1441 WIP

* PI-1441 WIP

* PI-1441 add contact when adding licence conditions

* PI-1441

* PI-1441 - add feature flag check

* deactivate handler until ready for use

* update court case to stabilize tests
  • Loading branch information
anthony-britton-moj authored Oct 19, 2023
1 parent 76cd18b commit 13f15c0
Show file tree
Hide file tree
Showing 37 changed files with 1,445 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.CaseNote
import java.time.LocalDate
import java.time.ZonedDateTime

object CourtCaseNoteGenerator {
Expand All @@ -10,8 +11,8 @@ object CourtCaseNoteGenerator {
PersonGenerator.CURRENTLY_MANAGED.id,
ContactTypeGenerator.CONTACT_TYPE,
"Existing notes",
ZonedDateTime.now(),
ZonedDateTime.now(),
LocalDate.now(),
ZonedDateTime.now().minusMinutes(1),
StaffGenerator.ALLOCATED.id,
StaffGenerator.ALLOCATED.id,
1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package uk.gov.justice.digital.hmpps

import com.github.tomakehurst.wiremock.WireMockServer
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyMap
import org.mockito.kotlin.eq
Expand Down Expand Up @@ -51,7 +51,7 @@ class CaseNotesIntegrationTest {
)

val caseNote = caseNoteRepository.findByExternalReferenceAndOffenderIdAndSoftDeletedIsFalse("1111", PersonGenerator.NEW_TO_PROBATION.id)
MatcherAssert.assertThat(caseNote!!.notes, Matchers.equalTo("Some new notes about the court case."))
assertThat(caseNote!!.notes, equalTo("Some new notes about the court case."))

verify(telemetryService).trackEvent(eq(COURT_CASE_NOTE_MERGED), anyMap(), anyMap())
}
Expand All @@ -65,7 +65,7 @@ class CaseNotesIntegrationTest {
)

val caseNote = caseNoteRepository.findByExternalReferenceAndOffenderIdAndSoftDeletedIsFalse("2222", PersonGenerator.CURRENTLY_MANAGED.id)
MatcherAssert.assertThat(caseNote!!.notes, Matchers.equalTo("Overwritten the existing notes about the court case."))
assertThat(caseNote!!.notes, equalTo("Overwritten the existing notes about the court case."))

verify(telemetryService).trackEvent(eq(COURT_CASE_NOTE_MERGED), anyMap(), anyMap())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.hibernate.type.YesNoConverter
import org.springframework.data.annotation.CreatedBy
import org.springframework.data.annotation.LastModifiedBy
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDate
import java.time.ZonedDateTime

@EntityListeners(AuditingEntityListener::class)
Expand All @@ -43,7 +44,7 @@ class CaseNote(
var notes: String,

@Column(name = "contact_date")
var date: ZonedDateTime,
var date: LocalDate,

@Column(name = "contact_start_time")
var startTime: ZonedDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DeliusIntegrationService(
val current = occurredAt.truncatedTo(ChronoUnit.SECONDS)
return if (last.isBefore(current)) {
notes = caseNote.notes
date = occurredAt
date = occurredAt.toLocalDate()
startTime = occurredAt
this
} else {
Expand All @@ -79,7 +79,7 @@ class DeliusIntegrationService(
offenderId = personId,
type = caseNoteType,
notes = notes,
date = occurredAt,
date = occurredAt.toLocalDate(),
startTime = occurredAt,
isSensitive = caseNoteType.isSensitive,
probationAreaId = comDetails.probationAreaId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ apply(plugin = "com.google.cloud.tools.jib")
dependencies {
implementation(project(":libs:audit"))
implementation(project(":libs:commons"))
implementation(project(":libs:messaging"))
implementation(project(":libs:oauth-client"))
implementation(project(":libs:oauth-server"))

implementation("org.springframework.boot:spring-boot-starter-actuator")
Expand All @@ -18,6 +20,7 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.springdoc)
implementation(libs.opentelemetry.annotations)
implementation(libs.openfeign)

dev(project(":libs:dev-tools"))
dev("com.unboundid:unboundid-ldapsdk")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ generic-service:

env:
SENTRY_ENVIRONMENT: dev
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/oauth/token
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
enabled: false # TODO set this to true when you're ready to deploy your service

generic-service:
ingress:
host: create-and-vary-a-licence-and-delius-preprod.hmpps.service.justice.gov.uk
Expand All @@ -9,6 +7,7 @@ generic-service:

env:
SENTRY_ENVIRONMENT: preprod
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/oauth/token
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
enabled: false # TODO set this to true when you're ready to deploy your service

generic-service:
ingress:
host: create-and-vary-a-licence-and-delius.hmpps.service.justice.gov.uk

env:
SENTRY_ENVIRONMENT: prod
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: https://sign-in.hmpps.service.justice.gov.uk/auth/oauth/token
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ generic-service:
SPRING_DATASOURCE_PASSWORD: DB_PASSWORD
create-and-vary-a-licence-and-delius-sentry:
SENTRY_DSN: SENTRY_DSN
create-and-vary-a-licence-and-delius-queue:
MESSAGING_CONSUMER_QUEUE: QUEUE_NAME

generic-prometheus-alerts:
targetApplication: create-and-vary-a-licence-and-delius
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator
import uk.gov.justice.digital.hmpps.data.generator.StaffGenerator
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CvlMapping
import uk.gov.justice.digital.hmpps.user.AuditUserRepository

@Component
Expand Down Expand Up @@ -47,20 +50,50 @@ class DataLoader(
entityManager.persist(StaffGenerator.DEFAULT)

entityManager.persist(StaffGenerator.DEFAULT_STAFF_USER)
entityManager.flush()

entityManager.persist(PersonGenerator.DEFAULT_PERSON)
entityManager.persist(PersonGenerator.DEFAULT_CM)

val person = PersonGenerator.generatePerson("N123456").also(entityManager::persist)
PersonGenerator.generateManager(person).also(entityManager::persist)
listOf(
entityManager.persistAll(
AddressGenerator.ADDRESS_STATUS_MAIN,
AddressGenerator.ADDRESS_STATUS_PREVIOUS,
AddressGenerator.ADDRESS_STATUS_OTHER,
AddressGenerator.ADDRESS_MAIN,
AddressGenerator.ADDRESS_PREVIOUS,
AddressGenerator.ADDRESS_OTHER,
AddressGenerator.ADDRESS_DELETED
).forEach(entityManager::persist)
)

createForAddingLicenceConditions()
}

private fun createForAddingLicenceConditions() {
entityManager.persistAll(
SentenceGenerator.SENTENCE_TYPE_SC,
ReferenceDataGenerator.DATASET_LC_SUB_CAT,
ReferenceDataGenerator.LC_STANDARD_CATEGORY,
ReferenceDataGenerator.LC_STANDARD_SUB_CATEGORY,
ReferenceDataGenerator.LC_BESPOKE_CATEGORY,
ReferenceDataGenerator.LC_BESPOKE_SUB_CATEGORY,
ReferenceDataGenerator.CONTACT_TYPE_LPOP,
PersonGenerator.PERSON_CREATE_LC,
SentenceGenerator.EVENT_CREATE_LC,
SentenceGenerator.SENTENCE_CREATE_LC,
PersonGenerator.generateManager(PersonGenerator.PERSON_CREATE_LC)
)
entityManager.saveCvlMappings(ReferenceDataGenerator.CVL_MAPPINGS)
}

private fun EntityManager.persistAll(vararg entities: Any) {
entities.forEach { persist(it) }
}

private fun EntityManager.saveCvlMappings(mappings: List<CvlMapping>) {
mappings.forEach {
persistAll(it.mainCategory, it.subCategory, it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ object PersonGenerator {
val DEFAULT_PERSON = generatePerson("T123456")
val DEFAULT_CM = generateManager(DEFAULT_PERSON)

val PERSON_CREATE_LC = generatePerson("L453621")

fun generatePerson(
crn: String,
softDeleted: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CvlMapping
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.Dataset
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceConditionCategory
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.ReferenceData

object ReferenceDataGenerator {
val DATASET_LC_SUB_CAT = generateDataset("LICENCE CONDITION SUB CATEGORY")
val LC_STANDARD_CATEGORY = generateLcCategory(CvlMapping.STANDARD_CATEGORY_CODE)
val LC_STANDARD_SUB_CATEGORY =
generateReferenceData(CvlMapping.STANDARD_SUB_CATEGORY_CODE, dataset = DATASET_LC_SUB_CAT)
val LC_BESPOKE_CATEGORY = generateLcCategory(CvlMapping.BESPOKE_CATEGORY_CODE)
val LC_BESPOKE_SUB_CATEGORY =
generateReferenceData(CvlMapping.BESPOKE_SUB_CATEGORY_CODE, dataset = DATASET_LC_SUB_CAT)
val CVL_MAPPINGS = listOf(
generateCvlMapping(
"AdditionalLcOne",
generateLcCategory("ADD1"),
generateLcSubCategory("ADD1S")
),
generateCvlMapping(
"AdditionalLcTwo",
generateLcCategory("ADD2"),
generateLcSubCategory("ADD2S")
)
)
val CONTACT_TYPE_LPOP = generateContactType(ContactType.LPOP)

fun generateLcCategory(code: String, id: Long = IdGenerator.getAndIncrement()) = LicenceConditionCategory(code, id)
fun generateDataset(code: String, id: Long = IdGenerator.getAndIncrement()) = Dataset(code, id)
fun generateReferenceData(
code: String,
description: String = "Description of $code",
dataset: Dataset,
id: Long = IdGenerator.getAndIncrement()
) = ReferenceData(code, description, dataset.id, id)

fun generateLcSubCategory(code: String, description: String = "LC SubCategory $code") =
generateReferenceData(code, description, DATASET_LC_SUB_CAT)

fun generateCvlMapping(
cvlCode: String,
mainCategory: LicenceConditionCategory,
subCategory: ReferenceData,
id: Long = IdGenerator.getAndIncrement()
) = CvlMapping(cvlCode, mainCategory, subCategory, id)

fun generateContactType(code: String, id: Long = IdGenerator.getAndIncrement()) = ContactType(code, id)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.Disposal
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.DisposalType
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.Event

object SentenceGenerator {
val SENTENCE_TYPE_SC = generateSentenceType("SC")
val EVENT_CREATE_LC = generateEvent("1", PersonGenerator.PERSON_CREATE_LC)
val SENTENCE_CREATE_LC = generate(EVENT_CREATE_LC)

fun generateSentenceType(sentenceType: String, id: Long = IdGenerator.getAndIncrement()) =
DisposalType(sentenceType, id)

fun generateEvent(
number: String,
person: Person,
disposal: Disposal? = null,
active: Boolean = true,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Event(number, person, disposal, active, softDeleted, id)

fun generate(
event: Event,
type: DisposalType = SENTENCE_TYPE_SC,
active: Boolean = true,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Disposal(event, type, active, softDeleted, id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import uk.gov.justice.digital.hmpps.set
object StaffGenerator {
val PDUHEAD = generateStaff("N01BDT2", "Bob", "Smith")
val DEFAULT_PDUSTAFF_USER = generateStaffUser("bob-smith", PDUHEAD)
var DEFAULT = generateStaff("N01BDT1", "John", "Smith")
var DEFAULT = generateStaff("N01BDT1", "John", "Smith", teams = listOf(ProviderGenerator.DEFAULT_TEAM))
val DEFAULT_STAFF_USER = generateStaffUser("john-smith", DEFAULT)

fun generateStaff(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"eventType": "create-and-vary-a-licence.licence.activated",
"version": 1,
"description": "A licence has been activated",
"detailUrl": "http://localhost:{wiremock.port}/cvl/events/licence-condition-applied/df2d3748-2619-4e27-b864-946e125ffb3e",
"occurredAt": "2022-12-04T10:42:43+00:00",
"personReference": {
"identifiers": [
{
"type": "CRN",
"value": "L453621"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"crn": "L453621",
"releaseDate": "2023-10-13",
"startDate": "2023-10-14",
"expiryDate": "2023-12-14",
"standardLicenceConditions": [
{
"code": "2891a984-b8a3-4584-8ae0-a1d327226a5f",
"description": "A Standard Condition",
"pssCondition": false
},
{
"code": "18a098f3-a4d5-4490-b623-287bab511542f",
"description": "Another Standard Condition",
"pssCondition": false
}
],
"additionalLicenceConditions": [
{
"code": "AdditionalLcOne",
"description": "Additional Licence Condition One",
"pssCondition": false
},
{
"code": "AdditionalLcTwo",
"description": "Additional Licence Condition Two",
"pssCondition": true
}
],
"bespokeLicenceConditions": [
{
"description": "First Bespoke Condition"
},
{
"description": "Second Bespoke Condition"
}
],
"prisonCode": "SWI"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"request": {
"method": "GET",
"urlPath": "/cvl/events/licence-condition-applied/df2d3748-2619-4e27-b864-946e125ffb3e"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "licence-activated-L453621.json"
}
}
Loading

0 comments on commit 13f15c0

Please sign in to comment.