Skip to content

Commit

Permalink
Fjern rivers for lagring av sak- og oppgave-ID (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjerga authored Oct 24, 2024
1 parent bc2c8a8 commit 7078ce9
Show file tree
Hide file tree
Showing 39 changed files with 53 additions and 920 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.helsearbeidsgiver.inntektsmelding.api.inntektselvbestemt
package no.nav.helsearbeidsgiver.inntektsmelding.api.tilgangselvbestemt

import io.kotest.matchers.shouldBe
import io.ktor.client.statement.bodyAsText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import no.nav.helsearbeidsgiver.inntektsmelding.db.river.LagreImRiver
import no.nav.helsearbeidsgiver.inntektsmelding.db.river.LagreImSkjemaRiver
import no.nav.helsearbeidsgiver.inntektsmelding.db.river.LagreJournalpostIdRiver
import no.nav.helsearbeidsgiver.inntektsmelding.db.river.LagreSelvbestemtImRiver
import no.nav.helsearbeidsgiver.inntektsmelding.db.river.PersisterOppgaveLoeser
import no.nav.helsearbeidsgiver.inntektsmelding.db.river.PersisterSakLoeser
import no.nav.helsearbeidsgiver.utils.log.logger

private val logger = "helsearbeidsgiver-im-db".logger()
Expand Down Expand Up @@ -47,29 +45,23 @@ fun RapidsConnection.createDbRivers(
logger.info("Starter ${LagreForespoerselRiver::class.simpleName}...")
LagreForespoerselRiver(forespoerselRepo).connect(this)

logger.info("Starter ${LagreImSkjemaRiver::class.simpleName}...")
LagreImSkjemaRiver(imRepo).connect(this)

logger.info("Starter ${HentLagretImRiver::class.simpleName}...")
HentLagretImRiver(imRepo).connect(this)

logger.info("Starter ${HentSelvbestemtImRiver::class.simpleName}...")
HentSelvbestemtImRiver(selvbestemtImRepo).connect(this)

logger.info("Starter ${LagreImSkjemaRiver::class.simpleName}...")
LagreImSkjemaRiver(imRepo).connect(this)

logger.info("Starter ${LagreImRiver::class.simpleName}...")
LagreImRiver(imRepo).connect(this)

logger.info("Starter ${LagreEksternImRiver::class.simpleName}...")
LagreEksternImRiver(imRepo).connect(this)

logger.info("Starter ${LagreJournalpostIdRiver::class.simpleName}...")
LagreJournalpostIdRiver(imRepo, selvbestemtImRepo).connect(this)

logger.info("Starter ${PersisterSakLoeser::class.simpleName}...")
PersisterSakLoeser(this, forespoerselRepo)

logger.info("Starter ${PersisterOppgaveLoeser::class.simpleName}...")
PersisterOppgaveLoeser(this, forespoerselRepo)

logger.info("Starter ${HentSelvbestemtImRiver::class.simpleName}...")
HentSelvbestemtImRiver(selvbestemtImRepo).connect(this)
logger.info("Starter ${LagreEksternImRiver::class.simpleName}...")
LagreEksternImRiver(imRepo).connect(this)

logger.info("Starter ${LagreSelvbestemtImRiver::class.simpleName}...")
LagreSelvbestemtImRiver(selvbestemtImRepo).connect(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,87 +1,23 @@
package no.nav.helsearbeidsgiver.inntektsmelding.db

import no.nav.helsearbeidsgiver.felles.db.exposed.firstOrNull
import no.nav.helsearbeidsgiver.felles.metrics.Metrics
import no.nav.helsearbeidsgiver.inntektsmelding.db.tabell.ForespoerselEntitet
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import java.time.LocalDateTime
import java.util.UUID

class ForespoerselRepository(
private val db: Database,
) {
fun oppdaterOppgaveId(
forespoerselId: String,
oppgaveId: String,
) {
Metrics.dbForespoersel.recordTime(::oppdaterOppgaveId) {
transaction(db) {
ForespoerselEntitet.update(
where = {
(ForespoerselEntitet.forespoerselId eq forespoerselId) and
ForespoerselEntitet.oppgaveId.isNull()
},
) {
it[ForespoerselEntitet.oppgaveId] = oppgaveId
}
}
}
}

fun oppdaterSakId(
forespoerselId: String,
sakId: String,
) {
Metrics.dbForespoersel.recordTime(::oppdaterSakId) {
transaction(db) {
ForespoerselEntitet.update(
where = {
(ForespoerselEntitet.forespoerselId eq forespoerselId) and
ForespoerselEntitet.sakId.isNull()
},
) {
it[ForespoerselEntitet.sakId] = sakId
}
}
}
}

fun hentOppgaveId(forespoerselId: UUID): String? =
Metrics.dbForespoersel.recordTime(::hentOppgaveId) {
transaction(db) {
ForespoerselEntitet
.selectAll()
.where { ForespoerselEntitet.forespoerselId eq forespoerselId.toString() }
.firstOrNull(ForespoerselEntitet.oppgaveId)
}
}

fun hentSakId(forespoerselId: UUID): String? =
Metrics.dbForespoersel.recordTime(::hentSakId) {
transaction(db) {
ForespoerselEntitet
.selectAll()
.where { ForespoerselEntitet.forespoerselId eq forespoerselId.toString() }
.firstOrNull(ForespoerselEntitet.sakId)
}
}

fun lagreForespoersel(
forespoerselId: String,
organisasjonsnummer: String,
) {
Metrics.dbForespoersel.recordTime(::lagreForespoersel) {
transaction(db) {
ForespoerselEntitet.insert {
it[this.forespoerselId] = forespoerselId
it[orgnr] = organisasjonsnummer
it[opprettet] = LocalDateTime.now()
}
transaction(db) {
ForespoerselEntitet.insert {
it[this.forespoerselId] = forespoerselId
it[orgnr] = organisasjonsnummer
it[opprettet] = LocalDateTime.now()
}
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ import org.jetbrains.exposed.sql.javatime.datetime
object ForespoerselEntitet : Table("forespoersel") {
val forespoerselId = varchar(name = "forespoersel_id", length = 40)
val orgnr = text("orgnr")
val sakId = varchar("sak_id", 36).nullable()
val oppgaveId = varchar("oppgave_id", 36).nullable()
val opprettet = datetime("opprettet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object InntektsmeldingEntitet : Table("inntektsmelding") {
long("id").autoIncrement(
idSeqName = "inntektsmelding_id_seq",
)
val forespoerselId = varchar(name = "forespoersel_id", length = 40) references ForespoerselEntitet.forespoerselId
val forespoerselId = varchar(name = "forespoersel_id", length = 40)
val dokument =
jsonb<Inntektsmelding>(
name = "dokument",
Expand Down
Loading

0 comments on commit 7078ce9

Please sign in to comment.