Skip to content

Commit

Permalink
Merge pull request #1302 from navikt/patch_error
Browse files Browse the repository at this point in the history
Correct outcome for completed behandling. Updates local db, resends m…
  • Loading branch information
oyvind-wedoe authored Jan 8, 2025
2 parents 12e24ef + 8622a49 commit d30bcca
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/main/kotlin/db/migration/V178__dvh_fix_wrong_outcome.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package db.migration

import no.nav.klage.oppgave.domain.kafka.StatistikkTilDVH
import no.nav.klage.oppgave.util.ourJacksonObjectMapper
import org.flywaydb.core.api.migration.BaseJavaMigration
import org.flywaydb.core.api.migration.Context
import java.time.LocalDateTime
import java.util.*

class V178__dvh_fix_wrong_outcome : BaseJavaMigration() {
override fun migrate(context: Context) {
val preparedStatement = context.connection.prepareStatement(
"""
update klage.kafka_event
set json_payload = ?, status_id = ?
where id = ?
""".trimIndent()
)

context.connection.createStatement().use { select ->
select.executeQuery(
"""
select ke.id, ke.json_payload
from klage.kafka_event ke
where ke.id = 'ec9074c3-f4df-4f2a-9374-9641fd4548e3'
"""
)
.use { rows ->
while (rows.next()) {
val kafkaEventId = rows.getObject(1, UUID::class.java)
val jsonPayload = rows.getString(2)

val statistikkTilDVH =
ourJacksonObjectMapper().readValue(jsonPayload, StatistikkTilDVH::class.java)

val modifiedVersion = statistikkTilDVH.copy(resultat = "STADFESTELSE", tekniskTid = LocalDateTime.now())

preparedStatement.setString(1, ourJacksonObjectMapper().writeValueAsString(modifiedVersion))
preparedStatement.setObject(2,"IKKE_SENDT")
preparedStatement.setObject(3, kafkaEventId)

preparedStatement.executeUpdate()
}

}
}
}
}
70 changes: 70 additions & 0 deletions src/main/kotlin/db/migration/V179__pesys_fix_wrong_outcome.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package db.migration

import no.nav.klage.oppgave.domain.kafka.BehandlingEvent
import no.nav.klage.oppgave.domain.kafka.ExternalUtfall
import no.nav.klage.oppgave.util.ourJacksonObjectMapper
import org.flywaydb.core.api.migration.BaseJavaMigration
import org.flywaydb.core.api.migration.Context
import java.time.LocalDateTime
import java.util.*

class V179__pesys_fix_wrong_outcome : BaseJavaMigration() {
override fun migrate(context: Context) {
val preparedStatement = context.connection.prepareStatement(
"""
INSERT INTO klage.kafka_event (id, behandling_id, kilde, kilde_referanse, json_payload, status_id, error_message, type, created)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
""".trimIndent()
)

context.connection.createStatement().use { select ->
select.executeQuery(
"""
select ke.behandling_id, ke.kilde, ke.kilde_referanse, ke.json_payload, ke.type
from klage.kafka_event ke
where ke.id = '54f5191c-a0ab-492b-a9a4-3c8fcad96c17'
"""
)
.use { rows ->
while (rows.next()) {
val behandlingId = rows.getObject(1, UUID::class.java)
val kilde = rows.getString(2)
val kildeReferanse = rows.getString(3)
val jsonPayload = rows.getString(4)
val type = rows.getString(5)

val behandlingEvent =
ourJacksonObjectMapper().readValue(jsonPayload, BehandlingEvent::class.java)

val behandlingEventDetaljerAnkebehandlingAvsluttet =
behandlingEvent.detaljer.ankebehandlingAvsluttet!!
val oldAvsluttet = behandlingEventDetaljerAnkebehandlingAvsluttet.avsluttet

val newBehandlingEventDetaljerAnkebehandlingAvsluttet =
behandlingEventDetaljerAnkebehandlingAvsluttet.copy(
avsluttet = oldAvsluttet.plusMinutes(5),
utfall = ExternalUtfall.STADFESTELSE
)

val newBehandlingEvent =
behandlingEvent.copy(
eventId = UUID.randomUUID(),
detaljer = behandlingEvent.detaljer.copy(ankebehandlingAvsluttet = newBehandlingEventDetaljerAnkebehandlingAvsluttet)
)

preparedStatement.setObject(1, UUID.randomUUID())
preparedStatement.setObject(2, behandlingId)
preparedStatement.setObject(3, kilde)
preparedStatement.setObject(4, kildeReferanse)
preparedStatement.setString(5, ourJacksonObjectMapper().writeValueAsString(newBehandlingEvent))
preparedStatement.setObject(6,"IKKE_SENDT")
preparedStatement.setObject(7, null)
preparedStatement.setObject(8, type)
preparedStatement.setObject(9, LocalDateTime.now())

preparedStatement.executeUpdate()
}
}
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/db/migration/V177__patch_outcome.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE klage.behandling
SET utfall_id = '6'
WHERE id = '765491dc-1b31-4008-b711-fd3a69217996';

0 comments on commit d30bcca

Please sign in to comment.