Skip to content

Commit

Permalink
Propagate begrunnelse to affected statuses when using stop-functionality
Browse files Browse the repository at this point in the history
- Add begrunnelse to oppgave, godskriv and brev when stopping.
  • Loading branch information
jacob-meidell committed Dec 18, 2024
1 parent ffbac88 commit 2cd6deb
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ sealed class Brev {
return copy(statushistorikk = statushistorikk + status.retry(melding))
}

fun stoppet(): Persistent {
return copy(statushistorikk = statushistorikk + status.stoppet())
fun stoppet(begrunnelse: String?): Persistent {
return copy(statushistorikk = statushistorikk + status.stoppet(begrunnelse))
}

fun restart(): Persistent {
Expand All @@ -71,7 +71,7 @@ sealed class Brev {
throw IllegalArgumentException("Kan ikke gå fra status:${this::class.java} til Retry")
}

open fun stoppet(): Status {
open fun stoppet(begrunnelse: String?): Status {
throw IllegalArgumentException("Kan ikke gå fra status:${this::class.java} til Stoppet")
}

Expand All @@ -92,8 +92,8 @@ sealed class Brev {
return Retry(melding = melding)
}

override fun stoppet(): Status {
return Stoppet()
override fun stoppet(begrunnelse: String?): Status {
return Stoppet(begrunnelse = begrunnelse)
}

override fun restart() : Status {
Expand All @@ -114,6 +114,7 @@ sealed class Brev {
@JsonTypeName("Stoppet")
data class Stoppet(
val tidspunkt: Instant = Instant.now(),
val begrunnelse: String? = null,
) : Status() {
override fun restart() : Status {
return Klar()
Expand Down Expand Up @@ -153,8 +154,8 @@ sealed class Brev {
}
}

override fun stoppet(): Status {
return Stoppet()
override fun stoppet(begrunnelse: String?): Status {
return Stoppet(begrunnelse = begrunnelse)
}

override fun restart() : Status {
Expand All @@ -166,8 +167,8 @@ sealed class Brev {
data class Feilet(
val tidspunkt: Instant = Instant.now(),
) : Status() {
override fun stoppet(): Status {
return Stoppet()
override fun stoppet(begrunnelse: String?): Status {
return Stoppet(begrunnelse = begrunnelse)
}

override fun restart() : Status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,29 @@ class BrevService(
}
}

fun stoppForMelding(meldingsId: UUID) {
fun stoppForMelding(meldingsId: UUID, begrunnelse: String?) {
brevRepository.findForMelding(meldingsId).forEach { brev ->
when (brev.status) {
is Brev.Status.Ferdig -> Unit
is Brev.Status.Stoppet -> Unit
else -> {
log.info("Stopper brev: ${brev.id}")
brev.stoppet().let {
brev.stoppet(begrunnelse).let {
brevRepository.updateStatus(it)
}
}
}
}
}

fun stopp(id: UUID): UUID? {
fun stopp(id: UUID, begrunnelse: String?): UUID? {
return brevRepository.tryFind(id)?.let { brev ->
when (brev.status) {
is Brev.Status.Ferdig -> brev.id
is Brev.Status.Stoppet -> brev.id
else -> {
log.info("Stopper brev: ${brev.id}")
brev.stoppet().let {
brev.stoppet(begrunnelse).let {
brevRepository.updateStatus(it)
it.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ sealed class GodskrivOpptjening {
return copy(statushistorikk = statushistorikk + status.retry(melding))
}

fun stoppet(): Persistent {
return copy(statushistorikk = statushistorikk + status.stoppet())
fun stoppet(begrunnelse: String?): Persistent {
return copy(statushistorikk = statushistorikk + status.stoppet(begrunnelse))
}

fun klar(): Persistent {
Expand Down Expand Up @@ -87,7 +87,7 @@ sealed class GodskrivOpptjening {
throw IllegalArgumentException("Kan ikke gå fra status:${this::class.java} til Retry")
}

open fun stoppet(): Status {
open fun stoppet(begrunnelse: String?): Status {
throw IllegalArgumentException("Kan ikke gå fra status:${this::class.java} til Stoppet")
}

Expand All @@ -107,23 +107,24 @@ sealed class GodskrivOpptjening {
return Retry(melding = melding)
}

override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}
}

@JsonTypeName("Ferdig")
data class Ferdig(
val tidspunkt: Instant = Instant.now(),
) : Status() {
override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}
}

@JsonTypeName("Stoppet")
data class Stoppet(
val tidspunkt: Instant = Instant.now()
val tidspunkt: Instant = Instant.now(),
val begrunnelse: String? = null,
) : Status() {
override fun klar(): Status {
return Klar()
Expand Down Expand Up @@ -166,17 +167,17 @@ sealed class GodskrivOpptjening {
}
}

override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}
}

@JsonTypeName("Feilet")
data class Feilet(
val tidspunkt: Instant = Instant.now(),
) : Status() {
override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}

override fun klar(): Status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ interface GodskrivOpptjeningService {
fun opprett(godskrivOpptjening: GodskrivOpptjening.Transient): GodskrivOpptjening.Persistent
fun håndter(godskrivOpptjening: GodskrivOpptjening.Persistent): GodskrivOpptjening.Persistent
fun retry(godskrivOpptjening: GodskrivOpptjening.Persistent, ex: Throwable)
fun stoppForMelding(meldingsId: UUID)
fun stopp(id: UUID): UUID?
fun stoppForMelding(meldingsId: UUID, begrunnelse: String?)
fun stopp(id: UUID, begrunnelse: String?): UUID?
fun restart(id: UUID): UUID?
fun hentOgLås(antall: Int): GodskrivOpptjeningRepo.Locked
fun frigiLås(låst: GodskrivOpptjeningRepo.Locked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ internal class GodskrivOpptjeningServiceImpl(
}


override fun stoppForMelding(meldingsId: UUID) {
override fun stoppForMelding(meldingsId: UUID, begrunnelse: String?) {
godskrivOpptjeningRepo.findForMelding(meldingsId).forEach { godkjenn ->
log.info("Stopper godkjenning: ${godkjenn.id}")
godkjenn.stoppet().let {
godkjenn.stoppet(begrunnelse).let {
godskrivOpptjeningRepo.updateStatus(it)
}
}
}

override fun stopp(id: UUID): UUID? {
override fun stopp(id: UUID, begrunnelse: String?): UUID? {
log.info("Stopper godkjenning: $id")
return godskrivOpptjeningRepo.tryFind(id)?.stoppet()?.let {
return godskrivOpptjeningRepo.tryFind(id)?.stoppet(begrunnelse)?.let {
godskrivOpptjeningRepo.updateStatus(it)
id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ sealed class Oppgave {
return copy(statushistorikk = statushistorikk + status.ferdig(oppgaveId))
}

fun stoppet(): Persistent {
return copy(statushistorikk = statushistorikk + status.stoppet())
fun stoppet(begrunnelse: String?): Persistent {
return copy(statushistorikk = statushistorikk + status.stoppet(begrunnelse))
}

fun retry(melding: String): Persistent {
Expand Down Expand Up @@ -117,7 +117,7 @@ sealed class Oppgave {
throw IllegalArgumentException("Kan ikke gå fra status:${this::class.java} til Retry")
}

open fun stoppet(): Status {
open fun stoppet(begrunnelse: String?): Status {
throw IllegalArgumentException("Kan ikke gå fra status:${this::class.java} til Retry")
}

Expand All @@ -142,8 +142,8 @@ sealed class Oppgave {
return Retry(melding = melding)
}

override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}

override fun klar(): Status {
Expand All @@ -161,8 +161,8 @@ sealed class Oppgave {
val tidspunkt: Instant = Instant.now(),
val oppgaveId: String,
) : Status() {
override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}

override fun kansellert(begrunnelse: String, kanselleringsResultat: KanselleringsResultat): Status {
Expand Down Expand Up @@ -215,8 +215,8 @@ sealed class Oppgave {
}
}

override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}

override fun klar(): Status {
Expand All @@ -234,8 +234,8 @@ sealed class Oppgave {
data class Feilet(
val tidspunkt: Instant = Instant.now(),
) : Status() {
override fun stoppet(): Stoppet {
return Stoppet()
override fun stoppet(begrunnelse: String?): Stoppet {
return Stoppet(begrunnelse = begrunnelse)
}

override fun klar(): Status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.uti
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.utils.NewTransactionTemplate
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import java.sql.SQLException
import java.util.UUID

Expand Down Expand Up @@ -138,10 +135,10 @@ class OppgaveService(
}
}

fun stoppForMelding(meldingsId: UUID) {
fun stoppForMelding(meldingsId: UUID, begrunnelse: String?) {
oppgaveRepo.findForMelding(meldingsId).forEach { oppgave ->
log.info("Stopper oppgave: ${oppgave.id}")
oppgave.stoppet().let { oppgaveRepo.updateStatus(it) }
oppgave.stoppet(begrunnelse = begrunnelse).let { oppgaveRepo.updateStatus(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,24 @@ internal class PersongrunnlagMeldingServiceImpl(

private fun stoppMeldingIntern(id: UUID, begrunnelse: String?): UUID {
log.info("Stopper melding: $id")
persongrunnlagRepo.find(id).stoppet(begrunnelse).let {
persongrunnlagRepo.find(id).stoppet(begrunnelse = begrunnelse).let {
persongrunnlagRepo.updateStatus(it)
}
oppgaveService.stoppForMelding(meldingsId = id)
brevService.stoppForMelding(meldingsId = id)
behandlingRepo.stoppBehandlingerForMelding(meldingsId = id)
godskrivOpptjeningService.stoppForMelding(meldingsId = id)
oppgaveService.stoppForMelding(
meldingsId = id,
begrunnelse = begrunnelse
)
brevService.stoppForMelding(
meldingsId = id,
begrunnelse = begrunnelse
)
behandlingRepo.stoppBehandlingerForMelding(
meldingsId = id
)
godskrivOpptjeningService.stoppForMelding(
meldingsId = id,
begrunnelse = begrunnelse,
)
return id
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class AdminWebApi(
val responsStrenger =
brev.map { id ->
try {
val retId = brevService.stopp(id)
val retId = brevService.stopp(id, begrunnelse)
if (retId == null) {
"$id: Fant ikke brevet"
} else {
Expand Down Expand Up @@ -251,7 +251,7 @@ class AdminWebApi(
val responsStrenger =
uuider.map { id ->
try {
val retId = godskrivOpptjeningService.stopp(id)
val retId = godskrivOpptjeningService.stopp(id, begrunnelse)
if (retId == null) {
"$id: Fant ikke godskrivingen"
} else {
Expand Down
Loading

0 comments on commit 2cd6deb

Please sign in to comment.