Skip to content

Commit

Permalink
Flytt ProsesseringFlyt til egen fil
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasvinjevoll committed Oct 7, 2024
1 parent da1be17 commit bcf8c96
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,53 +54,3 @@ class ProsesserStegService(
}
}
}

class ProsesseringFlyt private constructor(
private val rekkefølge: List<Steg>,
private val stegTilUtfall: HashMap<Steg, ProsesseringStatus>,
private val utfallTilSteg: HashMap<ProsesseringStatus, Steg>,
) {

fun fraStatus(prosesseringStatus: ProsesseringStatus?): List<Steg> {
if (prosesseringStatus == null) {
return rekkefølge
}
val stegForUtfall = utfallTilSteg[prosesseringStatus]
?: throw IllegalStateException("Uforventet oppslag av udefinert steg for status $prosesseringStatus")
return rekkefølge.dropWhile { it != stegForUtfall }.drop(1)
}

fun utfall(steg: Steg): ProsesseringStatus {
return stegTilUtfall[steg]
?: throw IllegalStateException("Uforventet oppslag av udefinert utfall for steg $steg")
}

class Builder {
private val rekkefølge = mutableListOf<Steg>()
private val stegTilUtfall = mutableMapOf<Steg, ProsesseringStatus>()
private val utfallTilSteg = mutableMapOf<ProsesseringStatus, Steg>()

fun med(steg: Steg, utfall: ProsesseringStatus): Builder {
if (rekkefølge.contains(steg)) {
throw IllegalStateException("Steg $steg er allerede lagt til: $rekkefølge")
}
rekkefølge.add(steg)
stegTilUtfall.put(steg, utfall)
utfallTilSteg.put(utfall, steg)

return this
}

fun build(): ProsesseringFlyt {
if (rekkefølge.isEmpty()) {
throw IllegalStateException("Ingen steg å prosessere.")
}

return ProsesseringFlyt(
rekkefølge = rekkefølge,
stegTilUtfall = HashMap(stegTilUtfall),
utfallTilSteg = HashMap(utfallTilSteg),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package no.nav.aap.brev.prosessering

import no.nav.aap.brev.domene.ProsesseringStatus
import no.nav.aap.brev.prosessering.steg.Steg

class ProsesseringFlyt private constructor(
private val rekkefølge: List<Steg>,
private val stegTilUtfall: HashMap<Steg, ProsesseringStatus>,
private val utfallTilSteg: HashMap<ProsesseringStatus, Steg>,
) {

fun fraStatus(prosesseringStatus: ProsesseringStatus?): List<Steg> {
if (prosesseringStatus == null) {
return rekkefølge
}
val stegForUtfall = utfallTilSteg[prosesseringStatus]
?: throw IllegalStateException("Uforventet oppslag av udefinert steg for status $prosesseringStatus")
return rekkefølge.dropWhile { it != stegForUtfall }.drop(1)
}

fun utfall(steg: Steg): ProsesseringStatus {
return stegTilUtfall[steg]
?: throw IllegalStateException("Uforventet oppslag av udefinert utfall for steg $steg")
}

class Builder {
private val rekkefølge = mutableListOf<Steg>()
private val stegTilUtfall = mutableMapOf<Steg, ProsesseringStatus>()
private val utfallTilSteg = mutableMapOf<ProsesseringStatus, Steg>()

fun med(steg: Steg, utfall: ProsesseringStatus): Builder {
if (rekkefølge.contains(steg)) {
throw IllegalStateException("Steg $steg er allerede lagt til: $rekkefølge")
}
rekkefølge.add(steg)
stegTilUtfall.put(steg, utfall)
utfallTilSteg.put(utfall, steg)

return this
}

fun build(): ProsesseringFlyt {
if (rekkefølge.isEmpty()) {
throw IllegalStateException("Ingen steg å prosessere.")
}

return ProsesseringFlyt(
rekkefølge = rekkefølge,
stegTilUtfall = HashMap(stegTilUtfall),
utfallTilSteg = HashMap(utfallTilSteg),
)
}
}
}

0 comments on commit bcf8c96

Please sign in to comment.