Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated to return nomisNumber rather than prisonNumber #516

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDate

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(using = InductionScheduleDeserializer::class)
data class InductionSchedule(
@Schema(
description = "An ISO-8601 date representing when the Induction should be completed by.",
Expand All @@ -22,8 +27,28 @@ data class InductionSchedule(
)
val scheduleCalculationRule: String? = null,
@Schema(
description = "The prison number or NOMS number of the person.",
description = "The Nomis number of the person.",
example = "A1234BC",
)
val prisonNumber: String? = null,
val nomisNumber: String? = null,
)

class InductionScheduleDeserializer : JsonDeserializer<InductionSchedule>() {
override fun deserialize(
parser: JsonParser,
ctxt: DeserializationContext,
): InductionSchedule {
val node = parser.codec.readTree<com.fasterxml.jackson.databind.JsonNode>(parser)
val nomisNumber = node["prisonNumber"]?.asText()
val deadlineDate = node["deadlineDate"]?.asText()?.let { LocalDate.parse(it) }
val scheduleStatus = node["scheduleStatus"]?.asText()
val scheduleCalculationRule = node["scheduleCalculationRule"]?.asText()

return InductionSchedule(
deadlineDate = deadlineDate,
scheduleStatus = scheduleStatus,
scheduleCalculationRule = scheduleCalculationRule,
nomisNumber = nomisNumber,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PLPIntegrationTest : IntegrationTestBase() {
"deadlineDate":"2019-08-24",
"scheduleStatus":"SCHEDULED",
"scheduleCalculationRule": "NEW_PRISON_ADMISSION",
"prisonNumber": "A1234BC"}}
"nomisNumber": "A1234BC"}}
""",
),
)
Expand Down
Loading