Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
r Endrer signaturen på metodene for å hente flere
Browse files Browse the repository at this point in the history
  • Loading branch information
Jørgen Tu Sveli committed Sep 3, 2021
1 parent b25021d commit b9b08be
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProfileringRepositoryImpl(private val db: NamedParameterJdbcTemplate) : Pr
" FETCH NEXT 3 ROWS ONLY",
mapOf("id" to brukerregistreringId), mapper)!!

override fun hentProfileringerForIder(brukerregistreringIder: List<Long>): List<Profilering> =
override fun hentProfileringerForIder(brukerregistreringIder: List<Long>): Map<Long, Profilering> =
db.query(
"SELECT * FROM $BRUKER_PROFILERING WHERE $BRUKER_REGISTRERING_ID in (:id) order by $BRUKER_REGISTRERING_ID asc",
mapOf("id" to brukerregistreringIder), manyMapper)!!
Expand All @@ -55,15 +55,15 @@ class ProfileringRepositoryImpl(private val db: NamedParameterJdbcTemplate) : Pr
const val ARB_6_AV_SISTE_12_MND = "ARB_6_AV_SISTE_12_MND"
const val RESULTAT_PROFILERING = "RESULTAT_PROFILERING"

private val manyMapper: (ResultSet) -> List<Profilering> = { rs: ResultSet ->
val result = mutableMapOf<Int, Profilering>()
private val manyMapper: (ResultSet) -> Map<Long, Profilering> = { rs: ResultSet ->
val result = mutableMapOf<Long, Profilering>()

while (rs.next()) {
val profilering = result.getOrPut(rs.getInt(BRUKER_REGISTRERING_ID)) { Profilering() }
val profilering = result.getOrPut(rs.getLong(BRUKER_REGISTRERING_ID)) { Profilering() }

lesRadTilProfilering(profilering, rs)
}
result.values.toList()
result
}

private val mapper: (ResultSet) -> Profilering = { rs ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import no.nav.fo.veilarbregistrering.besvarelse.*
import no.nav.fo.veilarbregistrering.bruker.AktorId
import no.nav.fo.veilarbregistrering.bruker.Bruker
import no.nav.fo.veilarbregistrering.bruker.Foedselsnummer
import no.nav.fo.veilarbregistrering.db.registrering.BrukerRegistreringRepositoryImpl.Companion.registreringMapper
import no.nav.fo.veilarbregistrering.db.registrering.RegistreringTilstandRepositoryImpl.Companion.REGISTRERING_TILSTAND
import no.nav.fo.veilarbregistrering.registrering.bruker.BrukerRegistreringRepository
import no.nav.fo.veilarbregistrering.registrering.bruker.OrdinaerBrukerRegistrering
Expand All @@ -15,6 +16,7 @@ import no.nav.fo.veilarbregistrering.registrering.formidling.Status
import org.springframework.jdbc.core.RowMapper
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
import java.io.IOException
import java.sql.ResultSet
import java.sql.SQLException
import java.sql.Timestamp
import java.time.LocalDateTime.now
Expand Down Expand Up @@ -60,10 +62,10 @@ class BrukerRegistreringRepositoryImpl(private val db: NamedParameterJdbcTemplat
return db.queryForObject(sql, mapOf("id" to brukerregistreringId), registreringMapper)!!
}

override fun hentBrukerregistreringerForIder(brukerRegistreringIder: List<Long>): List<OrdinaerBrukerRegistrering> {
override fun hentBrukerregistreringerForIder(brukerRegistreringIder: List<Long>): Map<Long, Pair<AktorId, OrdinaerBrukerRegistrering>> {
val sql = "SELECT * FROM $BRUKER_REGISTRERING WHERE $BRUKER_REGISTRERING_ID in (:ider)"

return db.query(sql, mapOf("ider" to brukerRegistreringIder), registreringMapper)
return db.query(sql, mapOf("ider" to brukerRegistreringIder), registreringManyMapper)!!
}

override fun finnOrdinaerBrukerregistreringForAktorIdOgTilstand(
Expand Down Expand Up @@ -140,6 +142,15 @@ class BrukerRegistreringRepositoryImpl(private val db: NamedParameterJdbcTemplat
ANDRE_UTFORDRINGER,
JOBBHISTORIKK
)
private val registreringManyMapper: (ResultSet) -> Map<Long, Pair<AktorId, OrdinaerBrukerRegistrering>> = { rs: ResultSet ->
val result = mutableMapOf<Long, Pair<AktorId, OrdinaerBrukerRegistrering>>()

while (rs.next()) {
result[rs.getLong(BRUKER_REGISTRERING_ID)] = AktorId.of(rs.getString(AKTOR_ID)!!) to registreringMapper.mapRow(rs, rs.row)!!
}
result
}

private val registreringMapper = RowMapper<OrdinaerBrukerRegistrering> { rs, _ ->
try {
OrdinaerBrukerRegistrering()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package no.nav.fo.veilarbregistrering.profilering
interface ProfileringRepository {
fun lagreProfilering(brukerregistreringId: Long, profilering: Profilering)
fun hentProfileringForId(brukerregistreringId: Long): Profilering
fun hentProfileringerForIder(brukerregistreringIder: List<Long>): List<Profilering>
fun hentProfileringerForIder(brukerregistreringIder: List<Long>): Map<Long, Profilering>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface BrukerRegistreringRepository {
fun hentBrukerregistreringForId(brukerregistreringId: Long): OrdinaerBrukerRegistrering
fun finnOrdinaerBrukerregistreringForAktorIdOgTilstand(aktorId: AktorId, tilstander: List<Status>): List<OrdinaerBrukerRegistrering>
fun hentBrukerTilknyttet(brukerRegistreringId: Long): Bruker
fun hentBrukerregistreringerForIder(brukerRegistreringIder: List<Long>): List<OrdinaerBrukerRegistrering>
fun hentBrukerregistreringerForIder(brukerRegistreringIder: List<Long>): Map<Long, Pair<AktorId, OrdinaerBrukerRegistrering>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,47 @@ class PubliseringAvEventsService(

/*@Transactional
fun publiserEventsForFlereRegistreringer() {
val nesteRegTilstander = registreringTilstandRepository
.finnXNesteRegistreringTilstanderMed(0, Status.OVERFORT_ARENA)
val nesteRegistreringTilstander = registreringTilstandRepository
.finnFlereRegistreringTilstanderMed(1, Status.OVERFORT_ARENA)
val nesteReg = brukerRegistreringRepository.hentBrukerregistreringerForIder(nesteRegTilstander.map{ it.brukerRegistreringId })
LOG.info("{} registreringer klare for publisering", nesteRegistreringTilstander.size)
val nesteProfileringer = nesteRegistreringer
.map { (aktorId, regTilstand) -> aktorId to profileringRepository.hentProfileringForId(regTilstand.brukerRegistreringId) }
.toMap()
val nesteRegistreringer = brukerRegistreringRepository.hentBrukerregistreringerForIder(
nesteRegistreringTilstander.map { it.brukerRegistreringId }
)
val nesteProfileringer = profileringRepository.hentProfileringerForIder(
nesteRegistreringTilstander.map { it.brukerRegistreringId }
)
registreringTilstandRepository.oppdaterFlereTilstander(Status.PUBLISERT_KAFKA, nesteRegistreringer.values.map { it.id })
registreringTilstandRepository.oppdaterFlereTilstander(
Status.PUBLISERT_KAFKA,
nesteRegistreringTilstander.map { it.id })
nesteRegistreringer.map { (aktorId, registreringTilstand) ->
arbeidssokerRegistrertProducerAiven.publiserArbeidssokerRegistrert(ArbeidssokerRegistrertInternalEvent(
val resultatFraRegistrertProducer = nesteRegistreringer.map { (brukerRegistreringId, aktorOgReg) ->
val (aktorId, ordinaerBrukerRegistrering) = aktorOgReg
brukerRegistreringId to ArbeidssokerRegistrertInternalEvent(
aktorId,
ordinaerBrukerRegistrering.besvarelse,
ordinaerBrukerRegistrering.opprettetDato
))
)
}.associate { (id, event) ->
id to arbeidssokerRegistrertProducerAiven.publiserArbeidssokerRegistrert(event)
}
nesteProfileringer
.filter { (id, _) -> resultatFraRegistrertProducer[id] ?: false }
.forEach { (brukerRegistreringId, profilering) ->
val (aktorId, ordinaerBrukerRegistrering) = nesteRegistreringer[brukerRegistreringId]
?: throw IllegalStateException()
arbeidssokerProfilertProducerAiven.publiserProfilering(
aktorId,
profilering.innsatsgruppe,
ordinaerBrukerRegistrering.opprettetDato
)
}
}*/

private fun rapporterRegistreringStatusAntallForPublisering() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ class ProfileringRepositoryDbIntegrationTest(

val profileringFraDb = profileringRepository.hentProfileringerForIder(listOf(9))
assertThat(profileringFraDb.size).isEqualTo(1)
assertThat(profileringFraDb[0].toString()).isEqualTo(profilering.toString())
assertThat(profileringFraDb[9].toString()).isEqualTo(profilering.toString())
}
}

0 comments on commit b9b08be

Please sign in to comment.