Skip to content

Commit

Permalink
Legge til journalforendeEnhet for å se om den kan brukes til å rute k…
Browse files Browse the repository at this point in the history
…lage/anke ref DAG-896
  • Loading branch information
geiralund committed Dec 16, 2024
1 parent 3410412 commit 9daca40
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import org.postgresql.util.PGobject
import java.time.LocalDateTime
import javax.sql.DataSource

internal class InnsendingPostgresRepository(private val datasource: DataSource = PostgresDataSourceBuilder.dataSource) :
InnsendingRepository {
internal class InnsendingPostgresRepository(
private val datasource: DataSource = PostgresDataSourceBuilder.dataSource,
) : InnsendingRepository {
// language=PostgreSQL
private val hentDataSql =
"""
Expand All @@ -38,6 +39,7 @@ internal class InnsendingPostgresRepository(private val datasource: DataSource =
journalpost.brukertype as "brukerType",
journalpost.behandlingstema as "behandlingstema",
journalpost.registrertdato as "registrertdato",
journalpost.journalforendeEnhet as "journalforendeEnhet",
arenasak.fagsakid as "fagsakId",
arenasak.oppgaveId as "oppgaveId",
soknad.data as "søknadsData",
Expand All @@ -62,88 +64,90 @@ internal class InnsendingPostgresRepository(private val datasource: DataSource =

override fun hent(journalpostId: String): Innsending? =
using(sessionOf(datasource)) { session ->
session.run(
queryOf(
hentDataSql,
mapOf("jpId" to journalpostId.toLong()),
).map { row ->
InnsendingData(
id = row.long("internId"),
journalpostId = row.long("journalpostId").toString(),
tilstand = TilstandData(TilstandData.InnsendingTilstandTypeData.valueOf(row.string("tilstand"))),
journalpostData =
row.localDateTimeOrNull("registrertDato")?.let {
InnsendingData.JournalpostData(
journalpostId = row.long("journalpostId").toString(),
bruker =
row.stringOrNull("brukerType")?.let { type ->
BrukerData(BrukerTypeData.valueOf(type), row.string("brukerId"))
},
journalpostStatus = row.string("status"),
behandlingstema = row.stringOrNull("behandlingstema"),
registertDato = it,
dokumenter = listOf(),
)
},
personData =
row.stringOrNull("ident")?.let {
InnsendingData.PersonData(
navn = row.string("navn"),
aktørId = row.string("aktørId"),
fødselsnummer = row.string("ident"),
norskTilknytning = row.boolean("norsktilknytning"),
diskresjonskode = row.boolean("diskresjonskode"),
egenAnsatt = row.boolean("egenansatt"),
)
},
arenaSakData =
row.stringOrNull("fagsakId")?.let {
InnsendingData.ArenaSakData(
oppgaveId = row.string("oppgaveId"),
fagsakId = it,
)
},
søknadsData =
row.binaryStreamOrNull("søknadsData")?.use {
JsonMapper.jacksonJsonAdapter.readTree(it)
},
aktivitetslogg =
row.binaryStream("aktivitetslogg").use {
JsonMapper.jacksonJsonAdapter.readValue(
it,
InnsendingData.AktivitetsloggData::class.java,
session
.run(
queryOf(
hentDataSql,
mapOf("jpId" to journalpostId.toLong()),
).map { row ->
InnsendingData(
id = row.long("internId"),
journalpostId = row.long("journalpostId").toString(),
tilstand = TilstandData(TilstandData.InnsendingTilstandTypeData.valueOf(row.string("tilstand"))),
journalpostData =
row.localDateTimeOrNull("registrertDato")?.let {
InnsendingData.JournalpostData(
journalpostId = row.long("journalpostId").toString(),
bruker =
row.stringOrNull("brukerType")?.let { type ->
BrukerData(BrukerTypeData.valueOf(type), row.string("brukerId"))
},
journalpostStatus = row.string("status"),
behandlingstema = row.stringOrNull("behandlingstema"),
journalførendeEnhet = row.stringOrNull("journalforendeEnhet"),
registertDato = it,
dokumenter = listOf(),
)
},
personData =
row.stringOrNull("ident")?.let {
InnsendingData.PersonData(
navn = row.string("navn"),
aktørId = row.string("aktørId"),
fødselsnummer = row.string("ident"),
norskTilknytning = row.boolean("norsktilknytning"),
diskresjonskode = row.boolean("diskresjonskode"),
egenAnsatt = row.boolean("egenansatt"),
)
},
arenaSakData =
row.stringOrNull("fagsakId")?.let {
InnsendingData.ArenaSakData(
oppgaveId = row.string("oppgaveId"),
fagsakId = it,
)
},
søknadsData =
row.binaryStreamOrNull("søknadsData")?.use {
JsonMapper.jacksonJsonAdapter.readTree(it)
},
aktivitetslogg =
row.binaryStream("aktivitetslogg").use {
JsonMapper.jacksonJsonAdapter.readValue(
it,
InnsendingData.AktivitetsloggData::class.java,
)
},
)
}.asSingle,
)?.let {
val dokumenter =
session.run(
queryOf(
//language=PostgreSQL
"""
SELECT
brevkode,
tittel,
dokumentinfoid,
hovedDokument
FROM journalpost_dokumenter_v1 WHERE id = :internId
""".trimIndent(),
mapOf(
"internId" to it.id,
),
).map { row ->
InnsendingData.JournalpostData.DokumentInfoData(
brevkode = row.string("brevkode"),
tittel = row.string("tittel"),
dokumentInfoId = row.string("dokumentInfoId"),
hovedDokument = row.boolean("hovedDokument"),
)
},
)
}.asSingle,
)?.let {
val dokumenter =
session.run(
queryOf(
//language=PostgreSQL
"""
SELECT
brevkode,
tittel,
dokumentinfoid,
hovedDokument
FROM journalpost_dokumenter_v1 WHERE id = :internId
""".trimIndent(),
mapOf(
"internId" to it.id,
),
).map { row ->
InnsendingData.JournalpostData.DokumentInfoData(
brevkode = row.string("brevkode"),
tittel = row.string("tittel"),
dokumentInfoId = row.string("dokumentInfoId"),
hovedDokument = row.boolean("hovedDokument"),
)
}.asList,
)
}.asList,
)

it.copy(journalpostData = it.journalpostData?.copy(dokumenter = dokumenter)).createInnsending()
}
it.copy(journalpostData = it.journalpostData?.copy(dokumenter = dokumenter)).createInnsending()
}
}

override fun lagre(innsending: Innsending): Int {
Expand Down Expand Up @@ -199,8 +203,7 @@ internal class InnsendingPostgresRepository(private val datasource: DataSource =
class NyInnsendingQueryVisiotor(
private val innsending: Innsending,
private val transactionalSession: TransactionalSession,
) :
InnsendingVisitor {
) : InnsendingVisitor {
var internId: Long = 0

init {
Expand All @@ -223,7 +226,10 @@ internal class InnsendingPostgresRepository(private val datasource: DataSource =
}
}

class InnsendingQueryVisitor(innsending: Innsending, private val internId: Long) : InnsendingVisitor {
class InnsendingQueryVisitor(
innsending: Innsending,
private val internId: Long,
) : InnsendingVisitor {
val lagreQueries: MutableList<Query> = mutableListOf()

init {
Expand Down Expand Up @@ -251,15 +257,16 @@ internal class InnsendingPostgresRepository(private val datasource: DataSource =
journalpostStatus: String,
bruker: Journalpost.Bruker?,
behandlingstema: String?,
journalførendeEnhet: String?,
registrertDato: LocalDateTime,
dokumenter: List<Journalpost.DokumentInfo>,
) {
lagreQueries.add(
queryOf(
//language=PostgreSQL
"""
INSERT INTO journalpost_v1(id,status, brukerId,brukerType,behandlingstema,registrertDato)
VALUES(:id, :status,:brukerId, :brukerType, :behandlingstema,:registrertDato)
INSERT INTO journalpost_v1(id,status, brukerId,brukerType,behandlingstema,journalforendeEnhet,registrertDato)
VALUES(:id, :status,:brukerId, :brukerType, :behandlingstema,:journalforendeEnhet,:registrertDato)
ON CONFLICT(id) DO NOTHING
""".trimIndent(),
mapOf(
Expand All @@ -268,6 +275,7 @@ internal class InnsendingPostgresRepository(private val datasource: DataSource =
"brukerId" to bruker?.id,
"brukerType" to bruker?.type?.name,
"behandlingstema" to behandlingstema,
"journalforendeEnhet" to journalførendeEnhet,
"registrertDato" to registrertDato,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class JoarkMottak(
private val logg = KotlinLogging.logger {}

private val forbudteMottaksKanaler =
setOf<String>(
setOf(
"EESSI",
"NAV_NO_CHAT",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ internal class JournalpostMottak(
?.asText()
.let { LocalDateTime.parse(it) } ?: LocalDateTime.now(),
behandlingstema = it["behandlingstema"].textValue(),
journalførendeEnhet = it["journalfoerendeEnhet"]?.asText(),
).also {
logg.info {
"""Mottok ny journalpost.
|Antall dokumenter=${it.dokumenter().size},
|brevkode=${it.hovedDokument().brevkode},
|registrertDato=${it.datoRegistrert()},
|journalførendeEnhet=${it.journalførendeEnhet()},
|behandlingstema=${packet[løsning]["behandlingstema"].textValue()}
""".trimMargin()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE journalpost_v1
ADD COLUMN journalforendeEnhet TEXT NULL;
1 change: 1 addition & 0 deletions mediator/src/test/kotlin/no/nav/dagpenger/TestHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ val innsendingData =
behandlingstema = "DAG",
registertDato = registrertdato,
dokumenter = dokumenter,
journalførendeEnhet = "ENHET",
),
personData =
InnsendingData.PersonData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import org.junit.jupiter.api.Test
import java.time.LocalDateTime

internal class InnsendingPostgresRepositoryTest {
class TestVisitor(innsending: Innsending) : InnsendingVisitor {
class TestVisitor(
innsending: Innsending,
) : InnsendingVisitor {
val forventetDokumenter = mutableListOf<Journalpost.DokumentInfo>()

init {
Expand All @@ -34,6 +36,7 @@ internal class InnsendingPostgresRepositoryTest {
journalpostStatus: String,
bruker: Journalpost.Bruker?,
behandlingstema: String?,
journalførendeEnhet: String?,
registrertDato: LocalDateTime,
dokumenter: List<Journalpost.DokumentInfo>,
) {
Expand Down Expand Up @@ -82,13 +85,14 @@ internal class InnsendingPostgresRepositoryTest {
)
}
val innsending2 =
innsendingData.copy(
aktivitetslogg = InnsendingData.AktivitetsloggData(nyLogg.toList()),
tilstand =
InnsendingData.TilstandData(
InnsendingData.TilstandData.InnsendingTilstandTypeData.AvventerFerdigstillJournalpostType,
),
).createInnsending()
innsendingData
.copy(
aktivitetslogg = InnsendingData.AktivitetsloggData(nyLogg.toList()),
tilstand =
InnsendingData.TilstandData(
InnsendingData.TilstandData.InnsendingTilstandTypeData.AvventerFerdigstillJournalpostType,
),
).createInnsending()
withMigratedDb {
with(InnsendingPostgresRepository(PostgresDataSourceBuilder.dataSource)) {
lagre(innsending).also {
Expand Down Expand Up @@ -153,13 +157,14 @@ internal class InnsendingPostgresRepositoryTest {
val innsending = innsendingData.createInnsending()

val innsending2 =
innsendingData.copy(
journalpostId = "287689",
personData =
innsendingData.personData!!.copy(
fødselsnummer = dnr,
),
).createInnsending()
innsendingData
.copy(
journalpostId = "287689",
personData =
innsendingData.personData!!.copy(
fødselsnummer = dnr,
),
).createInnsending()
withMigratedDb {
with(InnsendingPostgresRepository(PostgresDataSourceBuilder.dataSource)) {
lagre(innsending).also {
Expand All @@ -181,13 +186,14 @@ internal class InnsendingPostgresRepositoryTest {
@Test
fun `Lagring der arena sak er null`() {
val innsending =
innsendingData.copy(
arenaSakData =
InnsendingData.ArenaSakData(
oppgaveId = "2234",
fagsakId = null,
),
).createInnsending()
innsendingData
.copy(
arenaSakData =
InnsendingData.ArenaSakData(
oppgaveId = "2234",
fagsakId = null,
),
).createInnsending()
withMigratedDb {
with(InnsendingPostgresRepository(PostgresDataSourceBuilder.dataSource)) {
lagre(innsending).also {
Expand Down Expand Up @@ -221,9 +227,10 @@ internal class InnsendingPostgresRepositoryTest {
val faktiskeRader =
using(sessionOf(PostgresDataSourceBuilder.dataSource)) { session ->
session.run(
queryOf("select count(1) from $tabell").map { row ->
row.int(1)
}.asSingle,
queryOf("select count(1) from $tabell")
.map { row ->
row.int(1)
}.asSingle,
)
}
assertEquals(antallRader, faktiskeRader, "Feil antall rader for tabell: $tabell")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class SkjemaTest {
@Test
fun `riktig anntall migreringer`() {
withCleanDb {
assertEquals(15, PostgresDataSourceBuilder.runMigration())
assertEquals(16, PostgresDataSourceBuilder.runMigration())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface JournalpostVisitor {
journalpostStatus: String,
bruker: Journalpost.Bruker?,
behandlingstema: String?,
journalførendeEnhet: String?,
registrertDato: LocalDateTime,
dokumenter: List<Journalpost.DokumentInfo>,
) {
Expand Down
Loading

0 comments on commit 9daca40

Please sign in to comment.