-
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
* EY-4815 Arbeidstabell med tester * Ta med jobbtype fra definert enum som kan utvides på samme måte som i tidshendelser * Logg jobbtype ved opprett * bump sql * Bump igjen
- Loading branch information
1 parent
6fbd909
commit 4ad9732
Showing
5 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
apps/etterlatte-behandling/src/main/kotlin/behandling/jobs/brevjobber/Arbeidsjobb.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,39 @@ | ||
package no.nav.etterlatte.behandling.jobs.brevjobber | ||
|
||
import no.nav.etterlatte.libs.common.sak.SakId | ||
import no.nav.etterlatte.libs.common.tidspunkt.Tidspunkt | ||
import java.util.UUID | ||
|
||
data class Arbeidsjobb( | ||
val id: UUID, | ||
val sakId: SakId, | ||
val type: JobbType, | ||
val status: ArbeidStatus, | ||
val resultat: String? = null, | ||
val merknad: String? = null, | ||
val opprettet: Tidspunkt, | ||
val sistEndret: Tidspunkt, | ||
) | ||
|
||
fun lagNyArbeidsJobb( | ||
sakId: SakId, | ||
type: JobbType, | ||
merknad: String?, | ||
): Arbeidsjobb = | ||
Arbeidsjobb( | ||
id = UUID.randomUUID(), | ||
sakId = sakId, | ||
type = type, | ||
status = ArbeidStatus.NY, | ||
merknad = merknad, | ||
opprettet = Tidspunkt.now(), | ||
sistEndret = Tidspunkt.now(), | ||
) | ||
|
||
enum class ArbeidStatus { | ||
NY, | ||
PAAGAAENDE, | ||
STANSET, | ||
FERDIG, | ||
FEILET, | ||
} |
68 changes: 68 additions & 0 deletions
68
apps/etterlatte-behandling/src/main/kotlin/behandling/jobs/brevjobber/ArbeidstabellDao.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,68 @@ | ||
package no.nav.etterlatte.behandling.jobs.brevjobber | ||
|
||
import no.nav.etterlatte.common.ConnectionAutoclosing | ||
import no.nav.etterlatte.libs.common.sak.SakId | ||
import no.nav.etterlatte.libs.common.tidspunkt.getTidspunkt | ||
import no.nav.etterlatte.libs.common.tidspunkt.setTidspunkt | ||
import no.nav.etterlatte.libs.database.toList | ||
import org.slf4j.LoggerFactory | ||
import java.sql.ResultSet | ||
import java.util.UUID | ||
|
||
class ArbeidstabellDao( | ||
private val connectionAutoclosing: ConnectionAutoclosing, | ||
) { | ||
private val logger = LoggerFactory.getLogger(this::class.java) | ||
|
||
fun opprettJobb(jobb: Arbeidsjobb) { | ||
connectionAutoclosing.hentConnection { | ||
with(it) { | ||
val statement = | ||
prepareStatement( | ||
""" | ||
INSERT INTO arbeidstabell(id, sak_id, status, merknad, resultat, opprettet, endret, jobbtype) | ||
VALUES(?::UUID, ?, ?, ?, ?, ?, ?, ?) | ||
""".trimIndent(), | ||
) | ||
statement.setObject(1, jobb.id) | ||
statement.setLong(2, jobb.sakId.sakId) | ||
statement.setString(3, jobb.status.name) | ||
statement.setObject(4, jobb.merknad) | ||
statement.setObject(5, jobb.resultat) | ||
statement.setTidspunkt(6, jobb.opprettet) | ||
statement.setTidspunkt(7, jobb.sistEndret) | ||
statement.setString(8, jobb.type.name) | ||
statement.executeUpdate() | ||
logger.info("Opprettet en jobb av type ${jobb.type.name} for sak ${jobb.sakId} med status ${jobb.status}") | ||
} | ||
} | ||
} | ||
|
||
fun hentKlareJobber(): List<Arbeidsjobb> = | ||
connectionAutoclosing.hentConnection { | ||
with(it) { | ||
val statement = | ||
prepareStatement( | ||
""" | ||
SELECT * from arbeidstabell where status = ? | ||
""".trimIndent(), | ||
) | ||
statement.setString(1, ArbeidStatus.NY.name) | ||
statement.executeQuery().toList { | ||
asJobb() | ||
} | ||
} | ||
} | ||
|
||
private fun ResultSet.asJobb() = | ||
Arbeidsjobb( | ||
id = getObject("id") as UUID, | ||
sakId = SakId(getLong("sak_id")), | ||
type = JobbType.valueOf(getString("jobbtype")), | ||
status = ArbeidStatus.valueOf(getString("status")), | ||
resultat = getString("resultat"), | ||
merknad = getString("merknad"), | ||
opprettet = getTidspunkt("opprettet"), | ||
sistEndret = getTidspunkt("endret"), | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
apps/etterlatte-behandling/src/main/kotlin/behandling/jobs/brevjobber/Jobbtyper.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,15 @@ | ||
package no.nav.etterlatte.behandling.jobs.brevjobber | ||
|
||
import no.nav.etterlatte.libs.common.behandling.SakType | ||
|
||
enum class JobbType( | ||
val beskrivelse: String, | ||
val kategori: JobbKategori, | ||
val sakType: SakType?, | ||
) { | ||
TREKKPLIKT_2025("Trekkplikt 2025, du taper penger på dette", JobbKategori.TREKKPLIKT, SakType.OMSTILLINGSSTOENAD), | ||
} | ||
|
||
enum class JobbKategori { | ||
TREKKPLIKT, | ||
} |
12 changes: 12 additions & 0 deletions
12
apps/etterlatte-behandling/src/main/resources/db/migration/V197__create_arbeidstabell.sql
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,12 @@ | ||
create table arbeidstabell ( | ||
id UUID PRIMARY KEY, | ||
sak_id BIGINT NOT NULL | ||
CONSTRAINT behandling_sak_id_fk | ||
REFERENCES sak (id), | ||
status TEXT, | ||
jobbtype TEXT, | ||
merknad TEXT, | ||
resultat JSONB, | ||
opprettet TIMESTAMP WITH TIME ZONE DEFAULT (now() AT TIME ZONE 'UTC') NOT NULL, | ||
endret TIMESTAMP WITH TIME ZONE DEFAULT (now() AT TIME ZONE 'UTC') NOT NULL | ||
) |
58 changes: 58 additions & 0 deletions
58
.../etterlatte-behandling/src/test/kotlin/behandling/jobs/brevjobber/ArbeidstabellDaoTest.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,58 @@ | ||
package no.nav.etterlatte.behandling.jobs.brevjobber | ||
|
||
import io.kotest.matchers.shouldBe | ||
import io.mockk.mockk | ||
import no.nav.etterlatte.ConnectionAutoclosingTest | ||
import no.nav.etterlatte.DatabaseExtension | ||
import no.nav.etterlatte.common.Enheter | ||
import no.nav.etterlatte.libs.common.behandling.SakType | ||
import no.nav.etterlatte.sak.SakSkrivDao | ||
import no.nav.etterlatte.sak.SakendringerDao | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import javax.sql.DataSource | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@ExtendWith(DatabaseExtension::class) | ||
internal class ArbeidstabellDaoTest( | ||
val dataSource: DataSource, | ||
) { | ||
private lateinit var arbeidstabellDao: ArbeidstabellDao | ||
private lateinit var sakRepo: SakSkrivDao | ||
|
||
@BeforeAll | ||
fun beforeAll() { | ||
arbeidstabellDao = ArbeidstabellDao(ConnectionAutoclosingTest(dataSource = dataSource)) | ||
sakRepo = SakSkrivDao(SakendringerDao(ConnectionAutoclosingTest(dataSource)) { mockk() }) | ||
} | ||
|
||
@AfterEach | ||
fun afterEach() { | ||
dataSource.connection.use { | ||
it.prepareStatement("TRUNCATE arbeidstabell CASCADE;").execute() | ||
} | ||
} | ||
|
||
@Test | ||
fun `Kan opprette jobber og hente jobber`() { | ||
val sak = sakRepo.opprettSak("123", SakType.BARNEPENSJON, Enheter.defaultEnhet.enhetNr) | ||
val sakId = sak.id | ||
|
||
val testjobb = lagNyArbeidsJobb(sakId, merknad = "testmerknad", type = JobbType.TREKKPLIKT_2025) | ||
arbeidstabellDao.opprettJobb(testjobb) | ||
|
||
val nyeJobber = arbeidstabellDao.hentKlareJobber() | ||
|
||
nyeJobber.size shouldBe 1 | ||
nyeJobber.first() shouldBe testjobb | ||
|
||
val enSakMedFlerejobber = lagNyArbeidsJobb(sakId, merknad = "jobbtoforsak", type = JobbType.TREKKPLIKT_2025) | ||
arbeidstabellDao.opprettJobb(enSakMedFlerejobber) | ||
|
||
val sakMedToJobber = arbeidstabellDao.hentKlareJobber() | ||
sakMedToJobber.size shouldBe 2 | ||
} | ||
} |