-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ River og løsning for å hente fullmakt
Co-authored-by: Martin Solheim <[email protected]>
- Loading branch information
1 parent
67bc89e
commit 711553d
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...ialist-selve/src/main/kotlin/no/nav/helse/mediator/meldinger/løsninger/Fullmaktløsning.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,81 @@ | ||
package no.nav.helse.mediator.meldinger.løsninger | ||
|
||
import no.nav.helse.mediator.MeldingMediator | ||
import no.nav.helse.mediator.SpesialistRiver | ||
import no.nav.helse.modell.vergemal.VergemålDao | ||
import no.nav.helse.rapids_rivers.JsonMessage | ||
import no.nav.helse.rapids_rivers.MessageContext | ||
import no.nav.helse.rapids_rivers.River | ||
import no.nav.helse.rapids_rivers.asLocalDate | ||
import no.nav.helse.rapids_rivers.asLocalDateTime | ||
import org.slf4j.LoggerFactory | ||
import java.time.LocalDate | ||
import java.util.UUID | ||
|
||
internal class Fullmaktløsning( | ||
private val fødselsnummer: String, | ||
val harFullmakt: Boolean, | ||
) { | ||
private val log = LoggerFactory.getLogger(Fullmaktløsning::class.java) | ||
|
||
internal fun lagre(vergemålDao: VergemålDao) { | ||
log.info("Lagrer ennå ikke fullmakt") | ||
} | ||
|
||
internal class FullmaktRiver( | ||
private val meldingMediator: MeldingMediator, | ||
) : SpesialistRiver { | ||
private val sikkerLogg = LoggerFactory.getLogger("tjenestekall") | ||
|
||
override fun validations() = | ||
River.PacketValidation { | ||
it.demandValue("@event_name", "behov") | ||
it.demandValue("@final", true) | ||
it.demandAll("@behov", listOf("Fullmakt")) | ||
it.demandKey("contextId") | ||
it.demandKey("hendelseId") | ||
it.demandKey("fødselsnummer") | ||
it.requireKey("@id") | ||
it.require("@opprettet") { node -> node.asLocalDateTime() } | ||
it.requireArray("@løsning") { | ||
require("fullmakt") { | ||
interestedIn("gyldigFraOgMed", "gyldigTilOgMed") | ||
} | ||
} | ||
} | ||
|
||
override fun onPacket( | ||
packet: JsonMessage, | ||
context: MessageContext, | ||
) { | ||
sikkerLogg.info("Mottok melding Fullmakt:\n{}", packet.toJson()) | ||
val contextId = UUID.fromString(packet["contextId"].asText()) | ||
val hendelseId = UUID.fromString(packet["hendelseId"].asText()) | ||
val fødselsnummer = packet["fødselsnummer"].asText() | ||
|
||
val nå = LocalDate.now() | ||
val harFullmakt = packet["@løsning"].filter { fullmaktNode -> | ||
val fullmakt = fullmaktNode.path("fullmakt") | ||
fullmakt.size() > 0 && | ||
fullmakt["gyldigFraOgMed"].asLocalDate().isSameOrBefore(nå) && | ||
fullmakt["gyldigTilOgMed"].asLocalDate().isSameOrAfter(nå) | ||
}.isNotEmpty() | ||
|
||
val fullmaktløsning = Fullmaktløsning( | ||
fødselsnummer = fødselsnummer, | ||
harFullmakt = harFullmakt, | ||
) | ||
|
||
meldingMediator.løsning( | ||
hendelseId = hendelseId, | ||
contextId = contextId, | ||
behovId = UUID.fromString(packet["@id"].asText()), | ||
løsning = fullmaktløsning, | ||
context = context, | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun LocalDate.isSameOrBefore(other: LocalDate) = this.isEqual(other) || this.isBefore(other) | ||
fun LocalDate.isSameOrAfter(other: LocalDate) = this.isEqual(other) || this.isAfter(other) |
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
...list-selve/src/test/kotlin/no/nav/helse/mediator/meldinger/løsninger/FullmaktRiverTest.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.helse.mediator.meldinger.løsninger | ||
|
||
import io.mockk.mockk | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import no.nav.helse.medRivers | ||
import no.nav.helse.mediator.MeldingMediator | ||
import no.nav.helse.mediator.meldinger.Testmeldingfabrikk | ||
import no.nav.helse.rapids_rivers.testsupport.TestRapid | ||
import no.nav.helse.spesialist.test.lagFødselsnummer | ||
import org.junit.jupiter.api.Assertions.assertFalse | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import java.time.LocalDate.now | ||
|
||
class FullmaktRiverTest { | ||
private val mediator = mockk<MeldingMediator>(relaxed = true) | ||
private val testRapid = TestRapid().medRivers(Fullmaktløsning.FullmaktRiver(mediator)) | ||
|
||
@Test | ||
fun `motta melding med fullmakter`() { | ||
val fnr = lagFødselsnummer() | ||
val slot = slot<Fullmaktløsning>() | ||
testRapid.sendTestMessage(Testmeldingfabrikk.lagFullmaktløsningMedFullmakt( | ||
fnr, | ||
fom = now(), | ||
tom = now() | ||
)) | ||
verify(exactly = 1) { mediator.løsning(any(), any(), any(), capture(slot), any()) } | ||
assertTrue(slot.captured.harFullmakt) | ||
} | ||
|
||
@Test | ||
fun `motta melding med utdaterte fullmakter`() { | ||
val fnr = lagFødselsnummer() | ||
val slot = slot<Fullmaktløsning>() | ||
testRapid.sendTestMessage(Testmeldingfabrikk.lagFullmaktløsningMedFullmakt( | ||
fnr, | ||
fom = now().minusYears(2), | ||
tom = now().minusDays(1) | ||
)) | ||
verify(exactly = 1) { mediator.løsning(any(), any(), any(), capture(slot), any()) } | ||
assertFalse(slot.captured.harFullmakt) | ||
} | ||
|
||
@Test | ||
fun `motta melding uten fullmakter`() { | ||
val fnr = lagFødselsnummer() | ||
val slot = slot<Fullmaktløsning>() | ||
testRapid.sendTestMessage(Testmeldingfabrikk.lagFullmaktløsningUtenFullmakter(fnr)) | ||
verify(exactly = 1) { mediator.løsning(any(), any(), any(), capture(slot), any()) } | ||
assertFalse(slot.captured.harFullmakt) | ||
} | ||
} |