-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
78 additions
and
1 deletion.
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
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
54 changes: 54 additions & 0 deletions
54
...n/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/notifikasjon/SlettSakLoeser.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,54 @@ | ||
package no.nav.helsearbeidsgiver.inntektsmelding.notifikasjon | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import no.nav.helse.rapids_rivers.RapidsConnection | ||
import no.nav.helse.rapids_rivers.River | ||
import no.nav.helsearbeidsgiver.arbeidsgivernotifikasjon.ArbeidsgiverNotifikasjonKlient | ||
import no.nav.helsearbeidsgiver.arbeidsgivernotifikasjon.HardDeleteSakException | ||
import no.nav.helsearbeidsgiver.felles.BehovType | ||
import no.nav.helsearbeidsgiver.felles.Key | ||
import no.nav.helsearbeidsgiver.felles.rapidsrivers.Loeser | ||
import no.nav.helsearbeidsgiver.felles.rapidsrivers.model.Behov | ||
import no.nav.helsearbeidsgiver.utils.log.logger | ||
import no.nav.helsearbeidsgiver.utils.pipe.ifFalse | ||
import no.nav.helsearbeidsgiver.utils.pipe.ifTrue | ||
|
||
class SlettSakLoeser( | ||
rapidsConnection: RapidsConnection, | ||
private val arbeidsgiverNotifikasjonKlient: ArbeidsgiverNotifikasjonKlient | ||
) : Loeser(rapidsConnection) { | ||
|
||
private val logger = logger() | ||
|
||
override fun accept(): River.PacketValidation { | ||
return River.PacketValidation { | ||
it.demandValue(Key.BEHOV.str, BehovType.SLETT_SAK.name) | ||
it.requireKey(Key.SAK_ID.str) | ||
} | ||
} | ||
private fun slettSak( | ||
sakId: String | ||
): Boolean { | ||
return try { | ||
runBlocking { | ||
arbeidsgiverNotifikasjonKlient.hardDeleteSak(sakId) | ||
} | ||
true | ||
} catch (e: HardDeleteSakException) { | ||
sikkerLogger.error("Feil ved sletting av sak: $sakId", e) | ||
false | ||
} | ||
} | ||
|
||
override fun onBehov(behov: Behov) { | ||
val sakId = behov[Key.SAK_ID].asText() | ||
slettSak(sakId) | ||
.ifTrue { | ||
"Slettet sak: $sakId".also { | ||
logger.info(it) | ||
sikkerLogger.info(it) | ||
} | ||
} | ||
.ifFalse { logger.error("Feil ved sletting av sak: $sakId") } | ||
} | ||
} |