Skip to content

Commit

Permalink
Fikset feil i merge detector
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsmsa committed Oct 29, 2024
1 parent 1138866 commit 6287b2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class MergeDetector(
private val kafkaKeys: KafkaKeys
) {
private val logger = LoggerFactory.getLogger("MergeDetector")
private val hentEllerNull: (Identitetsnummer) -> ArbeidssoekerId? = { id ->
kafkaKeys.hent(id)
.fold(
{ null},
{ it }
)
}

suspend fun findMerges(batchSize: Int): Either<Failure, Long> {
require(batchSize > 0) { "Batch size must be greater than 0" }
Expand Down Expand Up @@ -47,9 +54,9 @@ class MergeDetector(
val storedData = kafkaKeys.hent(currentPos, maxSize)
val detected = storedData
.suspendingFlatMap {
pdlIdentitesTjeneste.hentIdenter(it.keys.toList()).map { res -> it to res }
pdlIdentitesTjeneste.hentIdenter(it.keys.toList())
}
.map { (local, pdl) -> detectMerges(local, pdl) }
.map { pdl -> detectMerges(hentEllerNull, pdl) }
.map(Sequence<MergeDetected>::count)
.map(Int::toLong)
.map(results.right::plus)
Expand All @@ -63,15 +70,15 @@ class MergeDetector(
}

fun detectMerges(
local: Map<Identitetsnummer, ArbeidssoekerId>,
local: (Identitetsnummer) -> ArbeidssoekerId?,
pdl: Map<String, List<IdentInformasjon>>
): Sequence<MergeDetected> {
return pdl.asSequence()
.mapNotNull { (searchedId, resultIds) ->
val arbIds = resultIds
.map { Identitetsnummer(it.ident) }
.mapNotNull { pdlId ->
local[pdlId]?.let { pdlId to it }
local(pdlId)?.let { pdlId to it }
}
if (arbIds.map { (_, arbId) -> arbId }.distinct().size > 1) {
MergeDetected(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import org.junit.jupiter.api.Assertions.*
class MergeDetectorKtTest : FreeSpec({

"Når 2 identiteter er samme person i PDL, men har forskjellige arbeidssøkerId skal det slå ut som 'merge detected" {
val local = mapOf(
val localMap = mapOf(
Identitetsnummer("1") to ArbeidssoekerId(11),
Identitetsnummer("2") to ArbeidssoekerId(12)
)
fun local(id: Identitetsnummer): ArbeidssoekerId? = localMap[id]
val pdl = mapOf(
"1" to listOf(
IdentInformasjon(
Expand All @@ -35,18 +36,19 @@ class MergeDetectorKtTest : FreeSpec({
)
)
detectMerges(
local = local,
local = ::local,
pdl = pdl
) should { merges ->
merges.toList().size shouldBe 1
}
}

"Når 2 identiteter er samme person i PDL, og har arbeidssøkerId skal det ikke slå ut som 'merge detected" {
val local = mapOf(
val localMap = mapOf(
Identitetsnummer("1") to ArbeidssoekerId(11),
Identitetsnummer("2") to ArbeidssoekerId(11)
)
fun local(id: Identitetsnummer): ArbeidssoekerId? = localMap[id]
val pdl = mapOf(
"1" to listOf(
IdentInformasjon(
Expand All @@ -62,7 +64,7 @@ class MergeDetectorKtTest : FreeSpec({
)
)
detectMerges(
local = local,
local = ::local,
pdl = pdl
).shouldBeEmpty()
}
Expand Down

0 comments on commit 6287b2c

Please sign in to comment.