Skip to content

Commit

Permalink
Lagt til midlertidlig JOURNALPOST_ID key (#769)
Browse files Browse the repository at this point in the history
* Lagt til midlertidlig JOURNALPOST_ID key

Co-authored-by: Mikael Bjerga <[email protected]>

* Fikset failing test

Co-authored-by: Mikael Bjerga <[email protected]>

* trigger full deploy

---------

Co-authored-by: Mikael Bjerga <[email protected]>
  • Loading branch information
Jesper-Hustad and bjerga authored Nov 12, 2024
1 parent 7930cea commit 15fb217
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class LagreJournalpostIdRiverTest :
Key.INNTEKTSMELDING to innkommendeMelding.inntektsmelding.toJson(Inntektsmelding.serializer()),
Key.BESTEMMENDE_FRAVAERSDAG to Mock.bestemmendeFravaersdag.toJson(),
Key.JOURNALPOST_ID to innkommendeMelding.journalpostId.toJson(),
Key.JOURNALPOST_ID_V2 to innkommendeMelding.journalpostId.toJson(),
)

verifySequence {
Expand Down Expand Up @@ -105,6 +106,7 @@ class LagreJournalpostIdRiverTest :
Key.UUID to innkommendeMelding.transaksjonId.toJson(),
Key.INNTEKTSMELDING to innkommendeMelding.inntektsmelding.toJson(Inntektsmelding.serializer()),
Key.JOURNALPOST_ID to innkommendeMelding.journalpostId.toJson(),
Key.JOURNALPOST_ID_V2 to innkommendeMelding.journalpostId.toJson(),
)

verifySequence {
Expand Down Expand Up @@ -245,6 +247,7 @@ private object Mock {
Key.EVENT_NAME to eventName.toJson(),
Key.UUID to transaksjonId.toJson(),
Key.JOURNALPOST_ID to journalpostId.toJson(),
Key.JOURNALPOST_ID_V2 to journalpostId.toJson(),
Key.INNTEKTSMELDING to inntektsmelding.toJson(Inntektsmelding.serializer()),
Key.BESTEMMENDE_FRAVAERSDAG to bestemmendeFravaersdag.toJson(),
Key.INNSENDING_ID to INNSENDING_ID.toJson(Long.serializer()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class DistribusjonRiverTest :
Key.EVENT_NAME to EventName.INNTEKTSMELDING_DISTRIBUERT.toJson(),
Key.UUID to innkommendeMelding.transaksjonId.toJson(),
Key.JOURNALPOST_ID to innkommendeMelding.journalpostId.toJson(),
Key.JOURNALPOST_ID_V2 to innkommendeMelding.journalpostId.toJson(),
Key.INNTEKTSMELDING to innkommendeMelding.inntektsmelding.toJson(Inntektsmelding.serializer()),
Key.BESTEMMENDE_FRAVAERSDAG to innkommendeMelding.bestemmendeFravaersdag?.toJson(),
).mapValuesNotNull { it }
Expand Down Expand Up @@ -109,6 +110,7 @@ class DistribusjonRiverTest :
Key.EVENT_NAME to EventName.INNTEKTSMELDING_DISTRIBUERT.toJson(),
Key.UUID to innkommendeMelding.transaksjonId.toJson(),
Key.JOURNALPOST_ID to innkommendeMelding.journalpostId.toJson(),
Key.JOURNALPOST_ID_V2 to innkommendeMelding.journalpostId.toJson(),
Key.INNTEKTSMELDING to selvbestemtInntektsmelding.toJson(Inntektsmelding.serializer()),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum class Key(
// ulik formattering
FORESPOERSEL_ID("forespoerselId"),
JOURNALPOST_ID("journalpostId"),
JOURNALPOST_ID_V2("journalpost_id"),
ORGNRUNDERENHET("orgnrUnderenhet"),
SPINN_INNTEKTSMELDING_ID("spinnInntektsmeldingId"),
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonNull
import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.utils.collection.mapValuesNotNull
import no.nav.helsearbeidsgiver.utils.json.parseJson
import no.nav.helsearbeidsgiver.utils.json.toJson

fun MessageContext.publish(vararg messageFields: Pair<Key, JsonElement>): JsonElement = publish(messageFields.toMap())

fun MessageContext.publish(messageFields: Map<Key, JsonElement>): JsonElement =
messageFields
.mapAddTemporaryJournalpostKey()
.mapKeys { (key, _) -> key.toString() }
.filterValues { it !is JsonNull }
.toJson()
Expand All @@ -29,3 +31,12 @@ fun MessageContext.publish(messageFields: Map<Key, JsonElement>): JsonElement =
}.toJson()
.also(::publish)
.parseJson()

private fun Map<Key, JsonElement>.mapAddTemporaryJournalpostKey(): Map<Key, JsonElement> {
// forsikre at this inneholder journalpost
if (!this.containsKey(Key.JOURNALPOST_ID)) {
return this
}

return this.plus(Key.JOURNALPOST_ID_V2 to this[Key.JOURNALPOST_ID]).mapValuesNotNull { it }
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class JournalfoerImRiverTest :
Key.EVENT_NAME to EventName.INNTEKTSMELDING_JOURNALFOERT.toJson(),
Key.UUID to innkommendeMelding.transaksjonId.toJson(),
Key.JOURNALPOST_ID to journalpostId.toJson(),
Key.JOURNALPOST_ID_V2 to journalpostId.toJson(),
Key.INNTEKTSMELDING to Mock.inntektsmelding.toJson(Inntektsmelding.serializer()),
Key.BESTEMMENDE_FRAVAERSDAG to Mock.bestemmendeFravaersdag.toJson(),
Key.INNSENDING_ID to innsendingId.toJson(Long.serializer()),
Expand Down Expand Up @@ -124,6 +125,7 @@ class JournalfoerImRiverTest :
Key.EVENT_NAME to EventName.INNTEKTSMELDING_JOURNALFOERT.toJson(),
Key.UUID to innkommendeMelding.transaksjonId.toJson(),
Key.JOURNALPOST_ID to journalpostId.toJson(),
Key.JOURNALPOST_ID_V2 to journalpostId.toJson(),
Key.INNTEKTSMELDING to Mock.inntektsmelding.toJson(Inntektsmelding.serializer()),
)

Expand Down

0 comments on commit 15fb217

Please sign in to comment.