-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add batch job to load referral status (#2002)
* Add batch job to load referral status * Remove redundant job definition files following apply to prod --------- Co-authored-by: Andrew Hodgson <[email protected]>
- Loading branch information
1 parent
d7c2906
commit fbd4d92
Showing
12 changed files
with
127 additions
and
120 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
30 changes: 0 additions & 30 deletions
30
...pps/hmppsinterventionsservice/jobs/oneoff/loadendofsentence/LoadEndOfSentenceProcessor.kt
This file was deleted.
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
39 changes: 39 additions & 0 deletions
39
...ice/digital/hmpps/hmppsinterventionsservice/jobs/oneoff/loadstatus/LoadStatusProcessor.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.hmppsinterventionsservice.jobs.oneoff.loadstatus | ||
|
||
import mu.KLogging | ||
import net.logstash.logback.argument.StructuredArguments.kv | ||
import org.springframework.batch.core.configuration.annotation.JobScope | ||
import org.springframework.batch.item.ItemProcessor | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.entity.Referral | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.entity.Status | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.repository.DeliverySessionRepository | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.repository.ReferralRepository | ||
|
||
@Component | ||
@JobScope | ||
class LoadStatusProcessor( | ||
private val deliverySessionRepository: DeliverySessionRepository, | ||
private val referralRepository: ReferralRepository, | ||
) : ItemProcessor<Referral, Referral> { | ||
companion object : KLogging() | ||
|
||
override fun process(referral: Referral): Referral { | ||
logger.info("processing referral {} for status", kv("referralId", referral.id)) | ||
return updateReferralStatus(referral) | ||
} | ||
|
||
fun updateReferralStatus(referral: Referral): Referral { | ||
val status = if (deliveredFirstSubstantiveAppointment(referral)) Status.POST_ICA else Status.PRE_ICA | ||
referral.status = status | ||
return referralRepository.save(referral) | ||
} | ||
|
||
private fun countSessionsAttended(referral: Referral): Int { | ||
return deliverySessionRepository.countNumberOfAttendedSessions(referral.id) | ||
} | ||
|
||
private fun deliveredFirstSubstantiveAppointment(referral: Referral): Boolean { | ||
return countSessionsAttended(referral) > 0 | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...dendofsentence/LoadEndOfSentenceWriter.kt → ...obs/oneoff/loadstatus/LoadStatusWriter.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,11 +1,11 @@ | ||
package uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jobs.oneoff.transferreferrals | ||
package uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jobs.oneoff.loadstatus | ||
|
||
import org.springframework.batch.item.Chunk | ||
import org.springframework.batch.item.ItemWriter | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.entity.Referral | ||
|
||
@Component | ||
class LoadEndOfSentenceWriter : ItemWriter<Referral?> { | ||
class LoadStatusWriter : ItemWriter<Referral?> { | ||
override fun write(chunk: Chunk<out Referral?>) {} | ||
} |
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
56 changes: 0 additions & 56 deletions
56
...hmppsinterventionsservice/jobs/oneoff/loadendofsentence/LoadEndOfSentenceProcessorTest.kt
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...digital/hmpps/hmppsinterventionsservice/jobs/oneoff/loadstatus/LoadStatusProcessorTest.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,50 @@ | ||
package uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jobs.oneoff.loadstatus | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.AdditionalAnswers | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.entity.Referral | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.entity.Status | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.repository.DeliverySessionRepository | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.jpa.repository.ReferralRepository | ||
import uk.gov.justice.digital.hmpps.hmppsinterventionsservice.util.ReferralFactory | ||
|
||
internal class LoadStatusProcessorTest { | ||
|
||
private val referralRepository = mock<ReferralRepository>() | ||
private val deliverySessionRepository = mock<DeliverySessionRepository>() | ||
private val processor = LoadStatusProcessor( | ||
deliverySessionRepository, | ||
referralRepository, | ||
) | ||
|
||
private val referralFactory = ReferralFactory() | ||
|
||
private val referral = referralFactory.createSent(status = null) | ||
|
||
@BeforeEach | ||
fun setup() { | ||
whenever(referralRepository.save(any())).thenAnswer(AdditionalAnswers.returnsFirstArg<Referral>()) | ||
} | ||
|
||
@Test | ||
fun `referral status is set to PRE_ICA if first substantive appointment not delivered`() { | ||
whenever(deliverySessionRepository.countNumberOfAttendedSessions(referral.id)).thenReturn(0) | ||
val result = processor.process(referral) | ||
assertThat(result.status).isEqualTo(Status.PRE_ICA) | ||
verify(referralRepository).save(referral) | ||
} | ||
|
||
@Test | ||
fun `referral status is set to POST_ICA if first substantive appointment is delivered`() { | ||
whenever(deliverySessionRepository.countNumberOfAttendedSessions(referral.id)).thenReturn(1) | ||
val result = processor.process(referral) | ||
assertThat(result.status).isEqualTo(Status.POST_ICA) | ||
verify(referralRepository).save(referral) | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
...ofsentence/LoadEndOfSentenceReaderTest.kt → ...oneoff/loadstatus/LoadStatusReaderTest.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
Oops, something went wrong.