-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Lagre åpen inntektsmelding * Fjern unødvendige exceptions * Rett navnefeil i metric * Slett ubrukt testkode
- Loading branch information
Showing
24 changed files
with
484 additions
and
226 deletions.
There are no files selected for viewing
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
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
62 changes: 62 additions & 0 deletions
62
db/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/AapenImRepo.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,62 @@ | ||
package no.nav.helsearbeidsgiver.inntektsmelding.db | ||
|
||
import no.nav.helsearbeidsgiver.domene.inntektsmelding.v1.Inntektsmelding | ||
import no.nav.helsearbeidsgiver.felles.metrics.Metrics | ||
import no.nav.helsearbeidsgiver.felles.metrics.recordTime | ||
import no.nav.helsearbeidsgiver.inntektsmelding.db.config.firstOrNull | ||
import no.nav.helsearbeidsgiver.inntektsmelding.db.tabell.AapenInntektsmeldingEntitet | ||
import org.jetbrains.exposed.sql.Database | ||
import org.jetbrains.exposed.sql.Query | ||
import org.jetbrains.exposed.sql.SortOrder | ||
import org.jetbrains.exposed.sql.and | ||
import org.jetbrains.exposed.sql.insert | ||
import org.jetbrains.exposed.sql.select | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import org.jetbrains.exposed.sql.update | ||
import java.util.UUID | ||
|
||
// TODO test | ||
class AapenImRepo(private val db: Database) { | ||
|
||
fun hentNyesteIm(aapenId: UUID): Inntektsmelding? = | ||
Metrics.dbAapenIm.recordTime(::hentNyesteIm.name) { | ||
transaction(db) { | ||
hentNyesteImQuery(aapenId) | ||
.firstOrNull(AapenInntektsmeldingEntitet.inntektsmelding) | ||
} | ||
} | ||
|
||
fun lagreIm(aapenId: UUID, im: Inntektsmelding) { | ||
Metrics.dbAapenIm.recordTime(::lagreIm.name) { | ||
transaction(db) { | ||
AapenInntektsmeldingEntitet.insert { | ||
it[this.aapenId] = aapenId | ||
it[inntektsmelding] = im | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun oppdaterJournalpostId(aapenId: UUID, journalpostId: String) { | ||
Metrics.dbAapenIm.recordTime(::oppdaterJournalpostId.name) { | ||
transaction(db) { | ||
AapenInntektsmeldingEntitet.update( | ||
where = { | ||
(AapenInntektsmeldingEntitet.id eqSubQuery hentNyesteImQuery(aapenId).adjustSlice { slice(AapenInntektsmeldingEntitet.id) }) and | ||
AapenInntektsmeldingEntitet.journalpostId.isNull() | ||
} | ||
) { | ||
it[this.journalpostId] = journalpostId | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun hentNyesteImQuery(aapenId: UUID): Query = | ||
AapenInntektsmeldingEntitet | ||
.select { | ||
AapenInntektsmeldingEntitet.aapenId eq aapenId | ||
} | ||
.orderBy(AapenInntektsmeldingEntitet.opprettet, SortOrder.DESC) | ||
.limit(1) |
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
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
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
Oops, something went wrong.