-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1302 from navikt/patch_error
Correct outcome for completed behandling. Updates local db, resends m…
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/db/migration/V178__dvh_fix_wrong_outcome.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,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
70
src/main/kotlin/db/migration/V179__pesys_fix_wrong_outcome.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,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() | ||
} | ||
} | ||
} | ||
} | ||
} |
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,3 @@ | ||
UPDATE klage.behandling | ||
SET utfall_id = '6' | ||
WHERE id = '765491dc-1b31-4008-b711-fd3a69217996'; |