Skip to content

Commit

Permalink
Merge pull request #238 from navikt/unit_type
Browse files Browse the repository at this point in the history
Unit type
  • Loading branch information
oyvind-wedoe authored Jul 23, 2024
2 parents 6476be2 + 91b4aef commit 4e27258
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/klage/kodeverk/Brevmottakertype.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ enum class Brevmottakertype(override val id: String, override val navn: String,

companion object {
fun of(id: String): Brevmottakertype {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Bremottakertype with id $id exists")
}

fun fromNavn(navn: String): Brevmottakertype {
return values().firstOrNull { it.navn == navn }
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No Bremottakertype with navn $navn exists")
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/no/nav/klage/kodeverk/DokumentType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ enum class DokumentType(

companion object {
fun of(id: String): DokumentType {
return DokumentType.values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No DokumentType with id $id exists")
}

fun fromNavn(navn: String): DokumentType {
return DokumentType.values().firstOrNull { it.navn == navn }
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No DokumentType with navn $navn exists")
}

fun fromBeskrivelse(beskrivelse: String): DokumentType {
return DokumentType.values().firstOrNull { it.beskrivelse == beskrivelse }
return entries.firstOrNull { it.beskrivelse == beskrivelse }
?: throw IllegalArgumentException("No DokumentType with beskrivelse $beskrivelse exists")
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/klage/kodeverk/Fagsystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ enum class Fagsystem(

companion object {
fun of(id: String): Fagsystem {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Fagsystem with id $id exists")
}

fun fromNavn(navn: String): Fagsystem {
return values().firstOrNull { it.navn == navn }
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No Fagsystem with navn $navn exists")
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/klage/kodeverk/MedunderskriverFlyt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ enum class MedunderskriverFlyt(override val id: String, override val navn: Strin

companion object {
fun of(id: String): MedunderskriverFlyt {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Medunderskriverflyt with id $id exists")
}

fun fromNavn(navn: String?): MedunderskriverFlyt {
return values().firstOrNull { it.navn == navn }
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No Medunderskriverflyt with navn $navn exists")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/klage/kodeverk/PartIdType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum class PartIdType(override val id: String, override val navn: String, overri

companion object {
fun of(id: String): PartIdType {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No PartIdType with id $id exists")
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/klage/kodeverk/ROLState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ enum class ROLState(override val id: String, override val navn: String, override

companion object {
fun of(id: String): ROLState {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No ROLState with id $id exists")
}

fun fromNavn(navn: String?): ROLState {
return values().firstOrNull { it.navn == navn }
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No ROLState with navn $navn exists")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/klage/kodeverk/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum class Source(override val id: String, override val navn: String, override v

companion object {
fun of(id: String): Source {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Source with id $id exists")
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/klage/kodeverk/Tema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ enum class Tema(override val id: String, override val navn: String, override val

companion object {
fun of(id: String): Tema {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Tema with id $id exists")
}

fun fromNavn(navn: String?): Tema {
return values().firstOrNull { it.navn == navn }
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No Tema with navn $navn exists")
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/kotlin/no/nav/klage/kodeverk/TimeUnitType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package no.nav.klage.kodeverk

import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter

enum class TimeUnitType(override val id: String, override val navn: String, override val beskrivelse: String) : Kode {

WEEKS("1", "WEEKS", "WEEKS"),
MONTHS("2", "MONTHS", "MONTHS"),
;

override fun toString(): String {
return "Type(id=$id, " +
"navn=$navn)"
}

companion object {
fun of(id: String): TimeUnitType {
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No TimeUnitType with id $id exists")
}

fun fromNavn(navn: String): TimeUnitType {
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No TimeUnitType with navn $navn exists")
}
}
}

@Converter
class TimeUnitTypeConverter : AttributeConverter<TimeUnitType, String?> {

override fun convertToDatabaseColumn(entity: TimeUnitType?): String? =
entity?.id

override fun convertToEntityAttribute(id: String?): TimeUnitType? =
id?.let { TimeUnitType.of(it) }
}
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/klage/kodeverk/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ enum class Type(override val id: String, override val navn: String, override val

companion object {
fun of(id: String): Type {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Type with id $id exists")
}

fun fromNavn(navn: String): Type {
return values().firstOrNull { it.navn == navn }
return entries.firstOrNull { it.navn == navn }
?: throw IllegalArgumentException("No Type with navn $navn exists")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/klage/kodeverk/Utfall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum class Utfall(override val id: String, override val navn: String, override v

companion object {
fun of(id: String): Utfall {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Utfall with id $id exists")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/klage/kodeverk/Ytelse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ enum class Ytelse(override val id: String, override val navn: String, override v

companion object {
fun of(id: String): Ytelse {
return values().firstOrNull { it.id == id }
return entries.firstOrNull { it.id == id }
?: throw IllegalArgumentException("No Ytelse with id $id exists")
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/kotlin/no/nav/klage/kodeverk/KodeverkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,25 @@ internal class KodeverkTest {
it.value.size > 1
}).isEmpty()
}

@Test
fun `TimeUnitType has no duplicate values`() {
assertThat(TimeUnitType.entries.groupBy {
it.id
}.filter {
it.value.size > 1
}).isEmpty()

assertThat(TimeUnitType.entries.groupBy {
it.navn
}.filter {
it.value.size > 1
}).isEmpty()

assertThat(TimeUnitType.entries.groupBy {
it.beskrivelse
}.filter {
it.value.size > 1
}).isEmpty()
}
}

0 comments on commit 4e27258

Please sign in to comment.