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.
- Loading branch information
1 parent
ba1aa4a
commit c318511
Showing
14 changed files
with
294 additions
and
61 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
2 changes: 0 additions & 2 deletions
2
projects/prisoner-profile-and-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
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
30 changes: 28 additions & 2 deletions
30
...risoner-profile-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.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,25 +1,51 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import jakarta.annotation.PostConstruct | ||
import jakarta.persistence.EntityManager | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.event.ApplicationReadyEvent | ||
import org.springframework.context.ApplicationListener | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.ALLOCATED_PERSON | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.STAFF | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.TEAM | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.UNALLOCATED_PERSON | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.UNALLOCATED_STAFF | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.generateCommunityManager | ||
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator | ||
import uk.gov.justice.digital.hmpps.user.AuditUserRepository | ||
|
||
@Component | ||
@ConditionalOnProperty("seed.database") | ||
class DataLoader( | ||
private val auditUserRepository: AuditUserRepository | ||
private val auditUserRepository: AuditUserRepository, | ||
private val entityManager: EntityManager | ||
) : ApplicationListener<ApplicationReadyEvent> { | ||
|
||
@PostConstruct | ||
fun saveAuditUser() { | ||
auditUserRepository.save(UserGenerator.AUDIT_USER) | ||
} | ||
|
||
@Transactional | ||
override fun onApplicationEvent(are: ApplicationReadyEvent) { | ||
// Perform dev/test database setup here, using JPA repositories and generator classes... | ||
listOf( | ||
TEAM, | ||
UNALLOCATED_STAFF, | ||
STAFF, | ||
UNALLOCATED_PERSON, | ||
ALLOCATED_PERSON, | ||
generateCommunityManager( | ||
ALLOCATED_PERSON, | ||
STAFF | ||
), | ||
generateCommunityManager( | ||
UNALLOCATED_PERSON, | ||
UNALLOCATED_STAFF | ||
) | ||
).saveAll() | ||
} | ||
|
||
fun List<Any>.saveAll() = forEach { entityManager.persist(it) } | ||
} |
39 changes: 39 additions & 0 deletions
39
...s/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CommunityManagerGenerator.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,39 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.CommunityManager | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.Person | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.Staff | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.Team | ||
|
||
object CommunityManagerGenerator { | ||
val TEAM = generateTeam("N01PPT") | ||
val UNALLOCATED_STAFF = generateStaff("N01PPTU", "Unallocated", "Staff") | ||
val STAFF = generateStaff("N01PPTA", "James", "Brown") | ||
val ALLOCATED_PERSON = generatePerson("A123456", "A1234TD") | ||
val UNALLOCATED_PERSON = generatePerson("U123456", "U1234TD") | ||
|
||
fun generateTeam( | ||
code: String, | ||
description: String = "Description of $code", | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Team(code, description, id) | ||
|
||
fun generateStaff(code: String, forename: String, surname: String, id: Long = IdGenerator.getAndIncrement()) = | ||
Staff(code, forename, surname, id) | ||
|
||
fun generatePerson( | ||
crn: String, | ||
nomsId: String, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Person(crn, nomsId, softDeleted, id) | ||
|
||
fun generateCommunityManager( | ||
person: Person, | ||
staff: Staff, | ||
team: Team = TEAM, | ||
active: Boolean = true, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = CommunityManager(person, team, staff, active, softDeleted, id) | ||
} |
8 changes: 4 additions & 4 deletions
8
projects/prisoner-profile-and-delius/src/dev/resources/local-public-key.pub
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,6 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDo3hw1/oChbttEOxEH4NUDrH+Y | ||
n2x0DavAmDjMbhcSiQ6+/t8Nz/N03BauWzFOGBtftnQrHfnF+O7RAKj8zMjcbIq4 | ||
QrYeXEpnaFCGEwTtOBpxvSEWPrLEpr1gCarBQZDp67ag+SYqrDgkn2Vme/dMvMUQ | ||
xUO3DT6jg9921J6TlwIDAQAB | ||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDju2wS/xXRfjdRI9thM2yJ7xO4 | ||
cy5o8eJ1tljIrqJvKcdsmuflNv7IXGZP4OIQBhALkS3CQxIhBl9gNAtyu2AdYUdn | ||
bSlBS5qLtLg2EoPn2GyGSwRiZCmZcmDsHdn8DX0zNCgZN9i/B/yCL0gXgvHRGEqP | ||
QCtNM3Urqkvn97LVjQIDAQAB | ||
-----END PUBLIC KEY----- |
2 changes: 1 addition & 1 deletion
2
...soner-profile-and-delius/src/dev/resources/simulations/__files/hmpps-auth-token-body.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
76 changes: 76 additions & 0 deletions
76
...delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CommunityManagerIntTest.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,76 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.Arguments | ||
import org.junit.jupiter.params.provider.MethodSource | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.api.Manager | ||
import uk.gov.justice.digital.hmpps.api.Team | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.ALLOCATED_PERSON | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.STAFF | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.TEAM | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.UNALLOCATED_PERSON | ||
import uk.gov.justice.digital.hmpps.data.generator.CommunityManagerGenerator.UNALLOCATED_STAFF | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.name | ||
import uk.gov.justice.digital.hmpps.security.withOAuth2Token | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class CommunityManagerIntTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Autowired | ||
lateinit var wireMockServer: WireMockServer | ||
|
||
@Autowired | ||
lateinit var objectMapper: ObjectMapper | ||
|
||
@ParameterizedTest | ||
@MethodSource("communityManagers") | ||
fun `returns the community manager correctly`(nomsId: String, expected: Manager) { | ||
val res = mockMvc | ||
.perform( | ||
get("/probation-cases/$nomsId/community-manager") | ||
.withOAuth2Token(wireMockServer) | ||
) | ||
.andExpect(status().is2xxSuccessful) | ||
.andReturn().response.contentAsString | ||
|
||
val actual = objectMapper.readValue<Manager>(res) | ||
assertThat(actual, equalTo(expected)) | ||
} | ||
|
||
@Test | ||
fun `noms id not found throws 404`() { | ||
mockMvc | ||
.perform( | ||
get("/probation-cases/invalid/community-manager") | ||
.withOAuth2Token(wireMockServer) | ||
) | ||
.andExpect(status().isNotFound) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun communityManagers() = listOf( | ||
Arguments.of(ALLOCATED_PERSON.nomsId, Manager(STAFF.code, STAFF.name(), Team(TEAM.code, TEAM.description))), | ||
Arguments.of( | ||
UNALLOCATED_PERSON.nomsId, | ||
Manager(UNALLOCATED_STAFF.code, UNALLOCATED_STAFF.name(), Team(TEAM.code, TEAM.description)) | ||
) | ||
) | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
...ile-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...s/prisoner-profile-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/Manager.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,13 @@ | ||
package uk.gov.justice.digital.hmpps.api | ||
|
||
data class Manager( | ||
val code: String, | ||
val name: Name, | ||
val team: Team | ||
) { | ||
val unallocated = code.endsWith("U") | ||
} | ||
|
||
data class Name(val forename: String, val surname: String) | ||
|
||
data class Team(val code: String, val description: String) |
16 changes: 16 additions & 0 deletions
16
...er-profile-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/ManagerResource.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,16 @@ | ||
package uk.gov.justice.digital.hmpps.api | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestMethod | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.ManagerService | ||
|
||
@RestController | ||
@RequestMapping("probation-cases/{nomsId}") | ||
class ManagerResource(private val managerService: ManagerService) { | ||
@PreAuthorize("hasRole('PROBATION_API__PRISONER_PROFILE__CASE_DETAIL')") | ||
@RequestMapping("community-manager", method = [RequestMethod.GET]) | ||
fun findCommunityManager(@PathVariable nomsId: String): Manager = managerService.findCommunityManager(nomsId) | ||
} |
17 changes: 0 additions & 17 deletions
17
...ofile-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/ApiController.kt
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...rc/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/manager/ManagerService.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,18 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius.manager | ||
|
||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.api.Manager | ||
import uk.gov.justice.digital.hmpps.api.Name | ||
import uk.gov.justice.digital.hmpps.api.Team | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.CommunityManager | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.CommunityManagerRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.Staff | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.getByNomsId | ||
|
||
@Service | ||
class ManagerService(private val communityManagerRepository: CommunityManagerRepository) { | ||
fun findCommunityManager(nomsId: String) = communityManagerRepository.getByNomsId(nomsId).asManager() | ||
} | ||
|
||
fun CommunityManager.asManager() = Manager(staff.code, staff.name(), Team(team.code, team.description)) | ||
fun Staff.name() = Name(forename, surname) |
Oops, something went wrong.