Skip to content

Commit

Permalink
Merge pull request #4766 from navikt/fix/arrangor-melding-deserialise…
Browse files Browse the repository at this point in the history
…ring

Fix serialisering av Amt Arrangor Melding
  • Loading branch information
fredrikpe authored Dec 9, 2024
2 parents 2bd42e6 + 7f4c381 commit c527af6
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.mulighetsrommet.domain.dto.amt

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import no.nav.mulighetsrommet.domain.serializers.LocalDateSerializer
import no.nav.mulighetsrommet.domain.serializers.LocalDateTimeSerializer
Expand All @@ -14,159 +15,180 @@ sealed interface Melding {
val deltakerId: UUID
val opprettetAvArrangorAnsattId: UUID
val opprettet: LocalDateTime
}

@Serializable
data class EndringFraArrangor(
@Serializable(with = UUIDSerializer::class)
override val id: UUID,
@Serializable(with = UUIDSerializer::class)
override val deltakerId: UUID,
@Serializable(with = UUIDSerializer::class)
override val opprettetAvArrangorAnsattId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
override val opprettet: LocalDateTime,
val endring: Endring,
) : Melding {
@Serializable
sealed interface Endring {
@SerialName("EndringFraArrangor")
data class EndringFraArrangor(
@Serializable(with = UUIDSerializer::class)
override val id: UUID,
@Serializable(with = UUIDSerializer::class)
override val deltakerId: UUID,
@Serializable(with = UUIDSerializer::class)
override val opprettetAvArrangorAnsattId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
override val opprettet: LocalDateTime,
val endring: Endring,
) : Melding {
@Serializable
data class LeggTilOppstartsdato(
@Serializable(with = LocalDateSerializer::class)
val startdato: LocalDate,
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate?,
) : Endring
sealed interface Endring {
@Serializable
@SerialName("LeggTilOppstartsdato")
data class LeggTilOppstartsdato(
@Serializable(with = LocalDateSerializer::class)
val startdato: LocalDate,
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate?,
) : Endring
}
}
}

@Serializable
data class Forslag(
@Serializable(with = UUIDSerializer::class)
override val id: UUID,
@Serializable(with = UUIDSerializer::class)
override val deltakerId: UUID,
@Serializable(with = UUIDSerializer::class)
override val opprettetAvArrangorAnsattId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
override val opprettet: LocalDateTime,
val begrunnelse: String?,
val endring: Endring,
val status: Status,
) : Melding {
@Serializable
sealed interface Status {
@SerialName("Forslag")
data class Forslag(
@Serializable(with = UUIDSerializer::class)
override val id: UUID,
@Serializable(with = UUIDSerializer::class)
override val deltakerId: UUID,
@Serializable(with = UUIDSerializer::class)
override val opprettetAvArrangorAnsattId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
override val opprettet: LocalDateTime,
val begrunnelse: String?,
val endring: Endring,
val status: Status,
) : Melding {
@Serializable
data class Godkjent(
val godkjentAv: NavAnsatt,
@Serializable(with = LocalDateTimeSerializer::class)
val godkjent: LocalDateTime,
) : Status
sealed interface Status {
@Serializable
@SerialName("Godkjent")
data class Godkjent(
val godkjentAv: NavAnsatt,
@Serializable(with = LocalDateTimeSerializer::class)
val godkjent: LocalDateTime,
) : Status

@Serializable
@SerialName("Avvist")
data class Avvist(
val avvistAv: NavAnsatt,
@Serializable(with = LocalDateTimeSerializer::class)
val avvist: LocalDateTime,
val begrunnelseFraNav: String,
) : Status

@Serializable
@SerialName("Tilbakekalt")
data class Tilbakekalt(
@Serializable(with = UUIDSerializer::class)
val tilbakekaltAvArrangorAnsattId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
val tilbakekalt: LocalDateTime,
) : Status

@Serializable
@SerialName("Erstattet")
data class Erstattet(
@Serializable(with = UUIDSerializer::class)
val erstattetMedForslagId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
val erstattet: LocalDateTime,
) : Status

@Serializable
@SerialName("VenterPaSvar")
data object VenterPaSvar : Status
}

@Serializable
data class Avvist(
val avvistAv: NavAnsatt,
@Serializable(with = LocalDateTimeSerializer::class)
val avvist: LocalDateTime,
val begrunnelseFraNav: String,
) : Status
sealed interface Endring {
@Serializable
@SerialName("ForlengDeltakelse")
data class ForlengDeltakelse(
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate,
) : Endring

@Serializable
@SerialName("AvsluttDeltakelse")
data class AvsluttDeltakelse(
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate?,
val aarsak: EndringAarsak,
val harDeltatt: Boolean?,
) : Endring

@Serializable
@SerialName("IkkeAktuell")
data class IkkeAktuell(
val aarsak: EndringAarsak,
) : Endring

@Serializable
@SerialName("Deltakelsesmengde")
data class Deltakelsesmengde(
val deltakelsesprosent: Int,
val dagerPerUke: Int?,
@Serializable(with = LocalDateSerializer::class)
val gyldigFra: LocalDate?,
) : Endring

@Serializable
@SerialName("Startdato")
data class Startdato(
@Serializable(with = LocalDateSerializer::class)
val startdato: LocalDate,
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate?,
) : Endring

@Serializable
@SerialName("Sluttdato")
data class Sluttdato(
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate,
) : Endring

@Serializable
@SerialName("Sluttarsak")
data class Sluttarsak(
val aarsak: EndringAarsak,
) : Endring
}

@Serializable
data class Tilbakekalt(
data class NavAnsatt(
@Serializable(with = UUIDSerializer::class)
val tilbakekaltAvArrangorAnsattId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
val tilbakekalt: LocalDateTime,
) : Status

@Serializable
data class Erstattet(
val id: UUID,
@Serializable(with = UUIDSerializer::class)
val erstattetMedForslagId: UUID,
@Serializable(with = LocalDateTimeSerializer::class)
val erstattet: LocalDateTime,
) : Status

@Serializable
data object VenterPaSvar : Status
}

@Serializable
sealed interface Endring {
@Serializable
data class ForlengDeltakelse(
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate,
) : Endring

@Serializable
data class AvsluttDeltakelse(
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate?,
val aarsak: EndringAarsak,
val harDeltatt: Boolean?,
) : Endring

@Serializable
data class IkkeAktuell(
val aarsak: EndringAarsak,
) : Endring

@Serializable
data class Deltakelsesmengde(
val deltakelsesprosent: Int,
val dagerPerUke: Int?,
@Serializable(with = LocalDateSerializer::class)
val gyldigFra: LocalDate?,
) : Endring

@Serializable
data class Startdato(
@Serializable(with = LocalDateSerializer::class)
val startdato: LocalDate,
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate?,
) : Endring

@Serializable
data class Sluttdato(
@Serializable(with = LocalDateSerializer::class)
val sluttdato: LocalDate,
) : Endring

@Serializable
data class Sluttarsak(
val aarsak: EndringAarsak,
) : Endring
val enhetId: UUID,
)
}

@Serializable
data class NavAnsatt(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
@Serializable(with = UUIDSerializer::class)
val enhetId: UUID,
)
}

@Serializable
sealed interface EndringAarsak {
@Serializable
@SerialName("Syk")
data object Syk : EndringAarsak

@Serializable
@SerialName("FattJobb")
data object FattJobb : EndringAarsak

@Serializable
@SerialName("TrengerAnnenStotte")
data object TrengerAnnenStotte : EndringAarsak

@Serializable
@SerialName("Utdanning")
data object Utdanning : EndringAarsak

@Serializable
@SerialName("IkkeMott")
data object IkkeMott : EndringAarsak

@Serializable
@SerialName("Annet")
data class Annet(
val beskrivelse: String,
) : EndringAarsak
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import no.nav.mulighetsrommet.domain.dto.Kid
import no.nav.mulighetsrommet.domain.dto.Kontonummer
import no.nav.mulighetsrommet.domain.dto.NorskIdent
import no.nav.mulighetsrommet.domain.dto.Organisasjonsnummer
import no.nav.mulighetsrommet.domain.dto.amt.Forslag
import no.nav.mulighetsrommet.domain.dto.amt.Melding
import no.nav.mulighetsrommet.domain.serializers.UUIDSerializer
import no.nav.mulighetsrommet.ktor.exception.StatusException
import org.koin.ktor.ext.inject
Expand Down Expand Up @@ -220,27 +220,27 @@ fun DeltakerForslag.relevantForDeltakelse(
val forsteStartDato = deltakelser.perioder.minOf { it.start }

return when (this.endring) {
is Forslag.Endring.AvsluttDeltakelse -> {
is Melding.Forslag.Endring.AvsluttDeltakelse -> {
val sluttDato = this.endring.sluttdato

this.endring.harDeltatt == false || (sluttDato != null && sluttDato.isBefore(sisteSluttDato))
}
is Forslag.Endring.Deltakelsesmengde -> {
is Melding.Forslag.Endring.Deltakelsesmengde -> {
this.endring.gyldigFra?.isBefore(sisteSluttDato) ?: true
}
is Forslag.Endring.ForlengDeltakelse -> {
is Melding.Forslag.Endring.ForlengDeltakelse -> {
this.endring.sluttdato.isAfter(sisteSluttDato) && this.endring.sluttdato.isBefore(periode.slutt)
}
is Forslag.Endring.IkkeAktuell -> {
is Melding.Forslag.Endring.IkkeAktuell -> {
true
}
is Forslag.Endring.Sluttarsak -> {
is Melding.Forslag.Endring.Sluttarsak -> {
false
}
is Forslag.Endring.Sluttdato -> {
is Melding.Forslag.Endring.Sluttdato -> {
this.endring.sluttdato.isBefore(sisteSluttDato)
}
is Forslag.Endring.Startdato -> {
is Melding.Forslag.Endring.Startdato -> {
this.endring.startdato.isAfter(forsteStartDato)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotliquery.Row
import kotliquery.Session
import kotliquery.queryOf
import no.nav.mulighetsrommet.database.Database
import no.nav.mulighetsrommet.domain.dto.amt.Forslag
import no.nav.mulighetsrommet.domain.dto.amt.Melding
import no.nav.mulighetsrommet.domain.serializers.UUIDSerializer
import org.intellij.lang.annotations.Language
import java.util.*
Expand Down Expand Up @@ -77,7 +77,7 @@ class DeltakerForslagRepository(private val db: Database) {

private fun Row.toForslagDbo(): DeltakerForslag {
val endring = string("endring")
.let { Json.decodeFromString<Forslag.Endring>(it) }
.let { Json.decodeFromString<Melding.Forslag.Endring>(it) }

return DeltakerForslag(
id = uuid("id"),
Expand All @@ -94,7 +94,7 @@ data class DeltakerForslag(
val id: UUID,
@Serializable(with = UUIDSerializer::class)
val deltakerId: UUID,
val endring: Forslag.Endring,
val endring: Melding.Forslag.Endring,
val status: Status,
) {
enum class Status {
Expand Down
Loading

0 comments on commit c527af6

Please sign in to comment.