-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Korrigerer mappingen for behandlingsresultat saksbehandlingsstatistikk * Rydder i gamle utfall som kan ha blitt feil / misvisende * Rydder opp mellom tester * Fikser linje som ble fjernet ved en glipp * Fjerner ekstra t
- Loading branch information
Showing
16 changed files
with
448 additions
and
68 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
43 changes: 43 additions & 0 deletions
43
apps/etterlatte-statistikk/src/main/kotlin/statistikk/clients/VedtakKlient.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.etterlatte.statistikk.clients | ||
|
||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.github.michaelbull.result.mapBoth | ||
import com.typesafe.config.Config | ||
import io.ktor.client.HttpClient | ||
import kotlinx.coroutines.runBlocking | ||
import no.nav.etterlatte.libs.common.objectMapper | ||
import no.nav.etterlatte.libs.common.vedtak.VedtakDto | ||
import no.nav.etterlatte.libs.ktor.ktor.ktorobo.AzureAdClient | ||
import no.nav.etterlatte.libs.ktor.ktor.ktorobo.DownstreamResourceClient | ||
import no.nav.etterlatte.libs.ktor.ktor.ktorobo.Resource | ||
import no.nav.etterlatte.libs.ktor.token.Systembruker | ||
import java.util.UUID | ||
|
||
class VedtakKlient( | ||
config: Config, | ||
httpClient: HttpClient, | ||
) { | ||
private val azureAdClient = AzureAdClient(config) | ||
private val downstreamResourceClient = DownstreamResourceClient(azureAdClient, httpClient) | ||
|
||
private val clientId = config.getString("vedtak.client.id") | ||
private val resourceUrl = config.getString("vedtak.resource.url") | ||
|
||
fun hentVedtak( | ||
behandlingId: UUID, | ||
systembruker: Systembruker, | ||
): VedtakDto = | ||
runBlocking { | ||
downstreamResourceClient | ||
.get( | ||
Resource( | ||
clientId = clientId, | ||
url = "$resourceUrl/api/vedtak/$behandlingId", | ||
), | ||
systembruker, | ||
).mapBoth( | ||
success = { resource -> resource.response.let { objectMapper.readValue(it.toString()) } }, | ||
failure = { errorResponse -> throw errorResponse }, | ||
) | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
apps/etterlatte-statistikk/src/main/kotlin/statistikk/database/RyddVedtakResultatDao.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,72 @@ | ||
package no.nav.etterlatte.statistikk.database | ||
|
||
import no.nav.etterlatte.libs.common.behandling.BehandlingType | ||
import no.nav.etterlatte.libs.database.toList | ||
import no.nav.etterlatte.statistikk.domain.BehandlingResultat | ||
import java.util.UUID | ||
import javax.sql.DataSource | ||
|
||
class RyddVedtakResultatDao( | ||
private val datasource: DataSource, | ||
) { | ||
fun hentRaderMedPotensiellFeil(): List<RadMedKanskjeFeilResultat> { | ||
datasource.connection.use { connection -> | ||
val statement = | ||
connection.prepareStatement( | ||
""" | ||
select id, behandling_id, behandling_type, fikset from sak_rader_med_potensielt_feil_resultat | ||
where fikset = false order by behandling_id limit 100 | ||
""".trimIndent(), | ||
) | ||
|
||
return statement.executeQuery().toList { | ||
RadMedKanskjeFeilResultat( | ||
id = getLong("id"), | ||
behandlingId = getObject("behandling_id") as UUID, | ||
behandlingType = enumValueOf(getString("behandling_type")), | ||
fikset = getBoolean("fikset"), | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun oppdaterResultat( | ||
rad: RadMedKanskjeFeilResultat, | ||
resultat: BehandlingResultat, | ||
) { | ||
datasource.connection.use { connection -> | ||
connection.autoCommit = false | ||
val stmntOppdaterSak = | ||
connection.prepareStatement( | ||
""" | ||
update sak set behandling_resultat = ? where id = ? and behandling_id = ? | ||
""".trimIndent(), | ||
) | ||
|
||
stmntOppdaterSak.setString(1, resultat.name) | ||
stmntOppdaterSak.setLong(2, rad.id) | ||
stmntOppdaterSak.setObject(3, rad.behandlingId) | ||
stmntOppdaterSak.executeUpdate() | ||
|
||
val stmntOppdaterRydderad = | ||
connection.prepareStatement( | ||
""" | ||
update sak_rader_med_potensielt_feil_resultat set fikset = true where id = ? and behandling_id = ? | ||
""".trimIndent(), | ||
) | ||
|
||
stmntOppdaterRydderad.setLong(1, rad.id) | ||
stmntOppdaterRydderad.setObject(2, rad.behandlingId) | ||
stmntOppdaterRydderad.executeUpdate() | ||
|
||
connection.commit() | ||
} | ||
} | ||
} | ||
|
||
data class RadMedKanskjeFeilResultat( | ||
val id: Long, | ||
val behandlingId: UUID, | ||
val behandlingType: BehandlingType, | ||
val fikset: Boolean, | ||
) |
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
97 changes: 97 additions & 0 deletions
97
apps/etterlatte-statistikk/src/main/kotlin/statistikk/jobs/RyddVedtakResultatJob.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,97 @@ | ||
package no.nav.etterlatte.statistikk.jobs | ||
|
||
import no.nav.etterlatte.jobs.LoggerInfo | ||
import no.nav.etterlatte.jobs.fixedRateCancellableTimer | ||
import no.nav.etterlatte.libs.common.TimerJob | ||
import no.nav.etterlatte.libs.common.behandling.BehandlingStatus | ||
import no.nav.etterlatte.libs.common.feilhaandtering.InternfeilException | ||
import no.nav.etterlatte.libs.common.vedtak.VedtakKafkaHendelseHendelseType | ||
import no.nav.etterlatte.libs.jobs.LeaderElection | ||
import no.nav.etterlatte.libs.ktor.token.HardkodaSystembruker | ||
import no.nav.etterlatte.statistikk.clients.VedtakKlient | ||
import no.nav.etterlatte.statistikk.database.RyddVedtakResultatDao | ||
import no.nav.etterlatte.statistikk.service.behandlingResultatFraVedtak | ||
import org.slf4j.LoggerFactory | ||
import java.time.Duration | ||
import java.time.temporal.ChronoUnit | ||
import java.util.Timer | ||
|
||
class RyddVedtakResultatJob( | ||
private val dao: RyddVedtakResultatDao, | ||
private val vedtakKlient: VedtakKlient, | ||
private val leaderElection: LeaderElection, | ||
) : TimerJob { | ||
private val logger = LoggerFactory.getLogger(this::class.java) | ||
private val jobbNavn = this::class.simpleName | ||
private val periode = Duration.of(5, ChronoUnit.MINUTES) | ||
private val initialDelay = Duration.of(2, ChronoUnit.MINUTES).toMillis() | ||
|
||
override fun schedule(): Timer { | ||
logger.info("$jobbNavn er satt til å kjøre med periode $periode etter $initialDelay ms") | ||
|
||
return fixedRateCancellableTimer( | ||
name = jobbNavn, | ||
period = periode.toMillis(), | ||
initialDelay = initialDelay, | ||
loggerInfo = LoggerInfo(logger = logger, loggTilSikkerLogg = false), | ||
) { | ||
OppdaterResultatSakRad( | ||
leaderElection = leaderElection, | ||
dao = dao, | ||
klient = vedtakKlient, | ||
).run() | ||
} | ||
} | ||
|
||
class OppdaterResultatSakRad( | ||
val leaderElection: LeaderElection, | ||
val dao: RyddVedtakResultatDao, | ||
val klient: VedtakKlient, | ||
) { | ||
private val logger = LoggerFactory.getLogger(this::class.java) | ||
|
||
fun run() { | ||
if (!leaderElection.isLeader()) { | ||
logger.info("Er ikke leader, kjører ikke oppdater sak resultat jobb") | ||
return | ||
} | ||
|
||
try { | ||
val saker = dao.hentRaderMedPotensiellFeil().groupBy { it.behandlingId } | ||
saker.entries.forEach { (behandlingId, rader) -> | ||
val vedtak = | ||
try { | ||
klient.hentVedtak(behandlingId, HardkodaSystembruker.statistikk) | ||
} catch (e: Exception) { | ||
logger.warn( | ||
"Feilet i henting / oppdatering av behandling resultat " + | ||
"for vedtak til behandling med id = $behandlingId", | ||
) | ||
return@forEach | ||
} | ||
val resultat = | ||
behandlingResultatFraVedtak( | ||
vedtak, | ||
VedtakKafkaHendelseHendelseType.ATTESTERT, | ||
behandligStatus = BehandlingStatus.ATTESTERT, | ||
) ?: throw InternfeilException( | ||
"Fikk ikke utledet resultat fra vedtak til " + | ||
"behandling med id = $behandlingId", | ||
) | ||
rader.forEach { | ||
try { | ||
dao.oppdaterResultat(it, resultat) | ||
} catch (e: Exception) { | ||
logger.warn( | ||
"Kunne ikke oppdatere resulatet for sak rad med id = ${it.id} for " + | ||
"behandling med id = $behandlingId", | ||
) | ||
} | ||
} | ||
} | ||
} catch (e: Exception) { | ||
logger.warn("Feilet i uthenting av rader med potensiell feil", e) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.