-
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.
- Loading branch information
Showing
8 changed files
with
152 additions
and
141 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
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
14 changes: 14 additions & 0 deletions
14
...in/kotlin/no/nav/su/se/bakover/service/journalføring/JournalføringOgDistribueringsFeil.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,14 @@ | ||
package no.nav.su.se.bakover.service.journalføring | ||
|
||
import dokument.domain.brev.KunneIkkeBestilleBrevForDokument | ||
import dokument.domain.brev.KunneIkkeJournalføreDokument | ||
|
||
sealed interface JournalføringOgDistribueringsFeil { | ||
@JvmInline | ||
value class Distribuering( | ||
val originalFeil: KunneIkkeBestilleBrevForDokument, | ||
) : JournalføringOgDistribueringsFeil | ||
|
||
@JvmInline | ||
value class Journalføring(val originalFeil: KunneIkkeJournalføreDokument) : JournalføringOgDistribueringsFeil | ||
} |
130 changes: 130 additions & 0 deletions
130
...otlin/no/nav/su/se/bakover/service/journalføring/JournalføringOgDistribueringsResultat.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,130 @@ | ||
package no.nav.su.se.bakover.service.journalføring | ||
|
||
import arrow.core.Either | ||
import dokument.domain.Dokumentdistribusjon | ||
import dokument.domain.brev.BrevbestillingId | ||
import dokument.domain.brev.KunneIkkeBestilleBrevForDokument | ||
import dokument.domain.brev.KunneIkkeJournalføreDokument | ||
import no.nav.su.se.bakover.common.journal.JournalpostId | ||
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty | ||
import org.slf4j.Logger | ||
import vilkår.skatt.domain.Skattedokument | ||
import java.util.UUID | ||
|
||
sealed interface JournalføringOgDistribueringsResultat { | ||
val id: UUID | ||
val journalpostId: JournalpostId? | ||
val brevbestillingsId: BrevbestillingId? | ||
|
||
data class Ok( | ||
override val id: UUID, | ||
override val journalpostId: JournalpostId?, | ||
override val brevbestillingsId: BrevbestillingId?, | ||
) : JournalføringOgDistribueringsResultat | ||
|
||
data class Feil( | ||
override val id: UUID, | ||
override val journalpostId: JournalpostId?, | ||
val originalFeil: JournalføringOgDistribueringsFeil, | ||
) : JournalføringOgDistribueringsResultat { | ||
override val brevbestillingsId: BrevbestillingId? = null | ||
} | ||
|
||
companion object { | ||
/** | ||
* dokumentdistribusjonen må for i feil-caser | ||
*/ | ||
@JvmName("dokumentDistribusjonTilResultat") | ||
fun Either<KunneIkkeBestilleBrevForDokument, Dokumentdistribusjon>.tilResultat( | ||
dokument: Dokumentdistribusjon, | ||
log: Logger, | ||
): JournalføringOgDistribueringsResultat { | ||
return this.fold( | ||
ifLeft = { | ||
log.error( | ||
"Kunne ikke distribuere dokument ${dokument.id}: $it", | ||
RuntimeException("Genererer en stacktrace for enklere debugging."), | ||
) | ||
Feil( | ||
dokument.id, | ||
dokument.journalføringOgBrevdistribusjon.journalpostId(), | ||
JournalføringOgDistribueringsFeil.Distribuering(it), | ||
) | ||
}, | ||
ifRight = { | ||
Ok( | ||
it.id, | ||
it.journalføringOgBrevdistribusjon.journalpostId(), | ||
it.journalføringOgBrevdistribusjon.brevbestillingsId(), | ||
) | ||
}, | ||
) | ||
} | ||
|
||
/** | ||
* dokumentdistribusjonen må for i feil-caser | ||
*/ | ||
fun Either<KunneIkkeJournalføreDokument, Dokumentdistribusjon>.tilResultat( | ||
dokument: Dokumentdistribusjon, | ||
log: Logger, | ||
): JournalføringOgDistribueringsResultat { | ||
return this.fold( | ||
ifLeft = { | ||
log.error( | ||
"Kunne ikke journalføre dokument ${dokument.id}: $it", | ||
RuntimeException("Genererer en stacktrace for enklere debugging."), | ||
) | ||
Feil( | ||
dokument.id, | ||
dokument.journalføringOgBrevdistribusjon.journalpostId(), | ||
JournalføringOgDistribueringsFeil.Journalføring(it), | ||
) | ||
}, | ||
ifRight = { | ||
Ok( | ||
it.id, | ||
it.journalføringOgBrevdistribusjon.journalpostId(), | ||
it.journalføringOgBrevdistribusjon.brevbestillingsId(), | ||
) | ||
}, | ||
) | ||
} | ||
|
||
@JvmName("skattedokumentTilReesultat") | ||
fun Either<KunneIkkeJournalføreDokument, Skattedokument.Journalført>.tilResultat( | ||
skattedokument: Skattedokument.Generert, | ||
log: Logger, | ||
): JournalføringOgDistribueringsResultat { | ||
return this.fold( | ||
ifLeft = { | ||
log.error( | ||
"Kunne ikke journalføre skattedokument ${skattedokument.id}: $it", | ||
RuntimeException("Genererer en stacktrace for enklere debugging."), | ||
) | ||
Feil( | ||
skattedokument.id, | ||
skattedokument.journalpostid, | ||
JournalføringOgDistribueringsFeil.Journalføring(it), | ||
) | ||
}, | ||
ifRight = { Ok(it.id, it.journalpostid, null) }, | ||
) | ||
} | ||
} | ||
} | ||
fun List<JournalføringOgDistribueringsResultat>.logResultat(logContext: String, log: Logger) { | ||
this.ifNotEmpty { | ||
val ok = this.ok() | ||
val feil = this.feil() | ||
if (feil.isEmpty()) { | ||
log.info("$logContext $ok") | ||
} else { | ||
log.error("$logContext feilet: $feil. Disse gikk ok: $ok") | ||
} | ||
} | ||
} | ||
fun List<JournalføringOgDistribueringsResultat>.ok(): List<UUID> = | ||
this.filterIsInstance<JournalføringOgDistribueringsResultat.Ok>().map { it.id } | ||
|
||
fun List<JournalføringOgDistribueringsResultat>.feil() = | ||
this.filterIsInstance<JournalføringOgDistribueringsResultat.Feil>().map { it.id } |
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
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