1
- package uk.gov.justice.digital.hmpps.integrations.delius. service
1
+ package uk.gov.justice.digital.hmpps.service
2
2
3
3
import org.springframework.stereotype.Service
4
+ import uk.gov.justice.digital.hmpps.entity.PrisonStaff
4
5
import uk.gov.justice.digital.hmpps.exception.NotFoundException
5
6
import uk.gov.justice.digital.hmpps.exceptions.InvalidEstablishmentCodeException
6
- import uk.gov.justice.digital.hmpps.integrations.delius.entity.ProbationArea
7
- import uk.gov.justice.digital.hmpps.integrations.delius.entity.Staff
8
- import uk.gov.justice.digital.hmpps.integrations.delius.entity.Team
9
- import uk.gov.justice.digital.hmpps.integrations.delius.model.StaffName
10
- import uk.gov.justice.digital.hmpps.integrations.delius.repository.ProbationAreaRepository
11
- import uk.gov.justice.digital.hmpps.integrations.delius.repository.TeamRepository
7
+ import uk.gov.justice.digital.hmpps.model.StaffName
8
+ import uk.gov.justice.digital.hmpps.repository.PrisonProbationAreaRepository
9
+ import uk.gov.justice.digital.hmpps.repository.PrisonTeamRepository
12
10
import uk.gov.justice.digital.hmpps.retry.retry
11
+ import java.time.ZonedDateTime
13
12
14
13
@Service
15
14
class AssignmentService (
16
- private val probationAreaRepository : ProbationAreaRepository ,
17
- private val teamRepository : TeamRepository ,
15
+ private val probationAreaRepository : PrisonProbationAreaRepository ,
16
+ private val teamRepository : PrisonTeamRepository ,
18
17
private val staffService : StaffService
19
18
) {
20
19
@@ -27,14 +26,20 @@ class AssignmentService(
27
26
)
28
27
val team = teamRepository.findByCode(" ${pa.code} CSN" )
29
28
? : throw NotFoundException (" Team" , " code" , " ${pa.code} CSN" )
30
- val staff = getStaff(pa, team, staffName)
29
+ val staff = getStaff(pa.id, pa.code, team.id , staffName)
31
30
return Triple (pa.id, team.id, staff.id)
32
31
}
33
32
34
- private fun getStaff (probationArea : ProbationArea , team : Team , staffName : StaffName ): Staff {
35
- val findStaff = { staffService.findStaff(probationArea.id, staffName) }
33
+ fun getStaff (
34
+ probationAreaId : Long ,
35
+ probationAreaCode : String ,
36
+ teamId : Long ,
37
+ staffName : StaffName ,
38
+ allocationDate : ZonedDateTime ? = null
39
+ ): PrisonStaff {
40
+ val findStaff = { staffService.findStaff(probationAreaId, staffName) }
36
41
return retry(3 ) {
37
- findStaff() ? : staffService.create(probationArea, team, staffName)
42
+ findStaff() ? : staffService.create(probationAreaId, probationAreaCode, teamId, staffName, allocationDate )
38
43
}
39
44
}
40
45
}
0 commit comments