-
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.
La inn støtte for å oppdage id merges
- Loading branch information
Showing
12 changed files
with
219 additions
and
30 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
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
22 changes: 5 additions & 17 deletions
22
apps/kafka-key-generator/src/main/kotlin/no/nav/paw/kafkakeygenerator/api/v2/InfoResponse.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 |
---|---|---|
@@ -1,21 +1,9 @@ | ||
package no.nav.paw.kafkakeygenerator.api.v2 | ||
|
||
data class InfoResponse( | ||
val lagretData: LokalIdData?, | ||
val pdlData: PdlData | ||
) | ||
|
||
data class LokalIdData( | ||
val arbeidsoekerId: Long, | ||
val recordKey: Long | ||
) | ||
import no.nav.paw.kafkakeygenerator.mergedetector.vo.MergeDetected | ||
import no.nav.paw.kafkakeygenerator.vo.Info | ||
|
||
data class PdlData( | ||
val error: String?, | ||
val id: List<PdlId>? | ||
) | ||
|
||
data class PdlId( | ||
val gruppe: String, | ||
val id: String | ||
data class InfoResponse( | ||
val info: Info, | ||
val mergeDetected: MergeDetected? | ||
) |
14 changes: 14 additions & 0 deletions
14
...ey-generator/src/main/kotlin/no/nav/paw/kafkakeygenerator/mergedetector/FailureBuilder.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.paw.kafkakeygenerator.mergedetector | ||
|
||
import no.nav.paw.kafkakeygenerator.Failure | ||
import no.nav.paw.kafkakeygenerator.FailureCode | ||
|
||
fun failure(code: FailureCode) : Failure = | ||
Failure( | ||
system = when (code) { | ||
FailureCode.PDL_NOT_FOUND -> "pdl" | ||
FailureCode.DB_NOT_FOUND -> "database" | ||
else -> "other" | ||
}, | ||
code = code | ||
) |
20 changes: 20 additions & 0 deletions
20
...fka-key-generator/src/main/kotlin/no/nav/paw/kafkakeygenerator/mergedetector/FindMerge.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,20 @@ | ||
package no.nav.paw.kafkakeygenerator.mergedetector | ||
|
||
import no.nav.paw.kafkakeygenerator.mergedetector.vo.LagretData | ||
import no.nav.paw.kafkakeygenerator.mergedetector.vo.MergeDetected | ||
import no.nav.paw.kafkakeygenerator.mergedetector.vo.MergeDetectorResult | ||
import no.nav.paw.kafkakeygenerator.mergedetector.vo.NoMergeDetected | ||
|
||
fun findMerge(lagretData: LagretData): MergeDetectorResult { | ||
val etterArbeidssoekerId = lagretData.lagretData | ||
.toList() | ||
.mapNotNull { (id, arbeidssoekerId) -> arbeidssoekerId?.let { it to id } } | ||
.groupBy { it.first } | ||
.toMap() | ||
.mapValues { (_, value) -> value.map { it.second } } | ||
return if (etterArbeidssoekerId.size > 1) { | ||
MergeDetected(lagretData.identitetsnummer, etterArbeidssoekerId) | ||
} else { | ||
NoMergeDetected(lagretData.identitetsnummer) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ey-generator/src/main/kotlin/no/nav/paw/kafkakeygenerator/mergedetector/HentLagretData.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,43 @@ | ||
package no.nav.paw.kafkakeygenerator.mergedetector | ||
|
||
import io.opentelemetry.instrumentation.annotations.WithSpan | ||
import kotlinx.coroutines.yield | ||
import no.nav.paw.kafkakeygenerator.* | ||
import no.nav.paw.kafkakeygenerator.FailureCode.DB_NOT_FOUND | ||
import no.nav.paw.kafkakeygenerator.FailureCode.PDL_NOT_FOUND | ||
import no.nav.paw.kafkakeygenerator.vo.Info | ||
import no.nav.paw.kafkakeygenerator.vo.PdlId | ||
import no.nav.paw.kafkakeygenerator.mergedetector.vo.LagretData | ||
import no.nav.paw.kafkakeygenerator.vo.ArbeidssoekerId | ||
import no.nav.paw.kafkakeygenerator.vo.Identitetsnummer | ||
import kotlin.coroutines.Continuation | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
import kotlin.coroutines.createCoroutine | ||
|
||
@WithSpan | ||
fun hentLagretData( | ||
hentArbeidssoekerId: (Identitetsnummer) -> Either<Failure, ArbeidssoekerId>, | ||
info: Info | ||
): Either<Failure, LagretData> { | ||
if (info.lagretData == null) return left(failure(DB_NOT_FOUND)) // Er ikke noe lagret kan vi ikke ha en merge | ||
val pdlData = info.pdlData.id | ||
if (pdlData.isNullOrEmpty()) return left(failure(PDL_NOT_FOUND)) // Er ikke noe pdl data kan vi ikke ha en merge | ||
return pdlData | ||
.asSequence() | ||
.filter { it.gruppe == "FOLKEREGISTERIDENT" } | ||
.map(PdlId::id) | ||
.map(::Identitetsnummer) | ||
.map { identitetsnummer -> | ||
hentArbeidssoekerId(identitetsnummer) | ||
.recover(DB_NOT_FOUND) { right(null) } | ||
.map { identitetsnummer to it } | ||
} | ||
.toList() | ||
.flatten() | ||
.map { it.toMap() } | ||
.map { LagretData( | ||
identitetsnummer = Identitetsnummer(info.identitetsnummer), | ||
lagretData = it | ||
) } | ||
} |
9 changes: 9 additions & 0 deletions
9
...key-generator/src/main/kotlin/no/nav/paw/kafkakeygenerator/mergedetector/vo/LagretData.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,9 @@ | ||
package no.nav.paw.kafkakeygenerator.mergedetector.vo | ||
|
||
import no.nav.paw.kafkakeygenerator.vo.ArbeidssoekerId | ||
import no.nav.paw.kafkakeygenerator.vo.Identitetsnummer | ||
|
||
data class LagretData( | ||
val identitetsnummer: Identitetsnummer, | ||
val lagretData: Map<Identitetsnummer, ArbeidssoekerId?> | ||
) |
17 changes: 17 additions & 0 deletions
17
...-generator/src/main/kotlin/no/nav/paw/kafkakeygenerator/mergedetector/vo/MergeDetected.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,17 @@ | ||
package no.nav.paw.kafkakeygenerator.mergedetector.vo | ||
|
||
import no.nav.paw.kafkakeygenerator.vo.ArbeidssoekerId | ||
import no.nav.paw.kafkakeygenerator.vo.Identitetsnummer | ||
|
||
interface MergeDetectorResult { | ||
val id: Identitetsnummer | ||
} | ||
|
||
data class NoMergeDetected( | ||
override val id: Identitetsnummer | ||
) : MergeDetectorResult | ||
|
||
data class MergeDetected( | ||
override val id: Identitetsnummer, | ||
val map: Map<ArbeidssoekerId, List<Identitetsnummer>> | ||
) : MergeDetectorResult |
22 changes: 22 additions & 0 deletions
22
apps/kafka-key-generator/src/main/kotlin/no/nav/paw/kafkakeygenerator/vo/Info.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,22 @@ | ||
package no.nav.paw.kafkakeygenerator.vo | ||
|
||
data class Info( | ||
val identitetsnummer: String, | ||
val lagretData: LokalIdData?, | ||
val pdlData: PdlData | ||
) | ||
|
||
data class LokalIdData( | ||
val arbeidsoekerId: Long, | ||
val recordKey: Long | ||
) | ||
|
||
data class PdlData( | ||
val error: String?, | ||
val id: List<PdlId>? | ||
) | ||
|
||
data class PdlId( | ||
val gruppe: String, | ||
val id: String | ||
) |
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