-
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.
Merge remote-tracking branch 'origin/main' into feature/EY-5030-behan…
…dling-som-brev-proxy # Conflicts: # apps/etterlatte-behandling/src/test/kotlin/integration/BehandlingIntegrationTest.kt
- Loading branch information
Showing
53 changed files
with
927 additions
and
244 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
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
74 changes: 74 additions & 0 deletions
74
apps/etterlatte-behandling/src/main/kotlin/behandling/etteroppgjoer/EtteroppgjoerDao.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,74 @@ | ||
package no.nav.etterlatte.behandling.etteroppgjoer | ||
|
||
import no.nav.etterlatte.common.ConnectionAutoclosing | ||
import no.nav.etterlatte.libs.common.Enhetsnummer | ||
import no.nav.etterlatte.libs.common.feilhaandtering.krev | ||
import no.nav.etterlatte.libs.common.sak.Sak | ||
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.setSakId | ||
import no.nav.etterlatte.libs.database.singleOrNull | ||
import java.sql.ResultSet | ||
import java.util.UUID | ||
|
||
class EtteroppgjoerDao( | ||
private val connectionAutoclosing: ConnectionAutoclosing, | ||
) { | ||
fun hentEtteroppgjoer(behandlingId: UUID): EtteroppgjoerBehandling? = | ||
connectionAutoclosing.hentConnection { | ||
with(it) { | ||
val statement = | ||
prepareStatement( | ||
""" | ||
SELECT t.id, t.sak_id, s.saktype, s.fnr, s.enhet, t.opprettet, t.status | ||
FROM etteroppgjoer_behandling t INNER JOIN sak s on t.sak_id = s.id | ||
WHERE t.id = ? | ||
""".trimIndent(), | ||
) | ||
statement.setObject(1, behandlingId) | ||
statement.executeQuery().singleOrNull { toEtteroppgjoer() } | ||
} | ||
} | ||
|
||
fun lagreEtteroppgjoer(etteroppgjoer: EtteroppgjoerBehandling) = | ||
connectionAutoclosing.hentConnection { | ||
with(it) { | ||
val statement = | ||
prepareStatement( | ||
""" | ||
INSERT INTO etteroppgjoer_behandling( | ||
id, status, sak_id, opprettet | ||
) | ||
VALUES (?, ?, ?, ?) | ||
ON CONFLICT (id) DO UPDATE SET | ||
status = excluded.status | ||
""".trimIndent(), | ||
) | ||
statement.setObject(1, etteroppgjoer.id) | ||
statement.setString(2, etteroppgjoer.status) | ||
statement.setSakId(3, etteroppgjoer.sak.id) | ||
statement.setTidspunkt(4, etteroppgjoer.opprettet) | ||
statement.executeUpdate().also { | ||
krev(it == 1) { | ||
"Kunne ikke lagre forbehandling etteroppgjør for sakid ${etteroppgjoer.sak.id}" | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun ResultSet.toEtteroppgjoer(): EtteroppgjoerBehandling = | ||
EtteroppgjoerBehandling( | ||
id = getString("id").let { UUID.fromString(it) }, | ||
sak = | ||
Sak( | ||
id = SakId(getLong("sak_id")), | ||
sakType = enumValueOf(getString("saktype")), | ||
ident = getString("fnr"), | ||
enhet = Enhetsnummer(getString("enhet")), | ||
), | ||
opprettet = getTidspunkt("opprettet"), | ||
status = getString("status"), | ||
aar = 2024, | ||
) | ||
} |
93 changes: 93 additions & 0 deletions
93
apps/etterlatte-behandling/src/main/kotlin/behandling/etteroppgjoer/EtteroppgjoerRoutes.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,93 @@ | ||
package no.nav.etterlatte.behandling.etteroppgjoer | ||
|
||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.get | ||
import io.ktor.server.routing.post | ||
import io.ktor.server.routing.route | ||
import no.nav.etterlatte.funksjonsbrytere.FeatureToggle | ||
import no.nav.etterlatte.funksjonsbrytere.FeatureToggleService | ||
import no.nav.etterlatte.libs.common.feilhaandtering.IkkeTillattException | ||
import no.nav.etterlatte.libs.common.sak.Sak | ||
import no.nav.etterlatte.libs.common.tidspunkt.Tidspunkt | ||
import no.nav.etterlatte.libs.ktor.route.ETTEROPPGJOER_CALL_PARAMETER | ||
import no.nav.etterlatte.libs.ktor.route.SAKID_CALL_PARAMETER | ||
import no.nav.etterlatte.libs.ktor.route.etteroppgjoerId | ||
import no.nav.etterlatte.libs.ktor.route.sakId | ||
import no.nav.etterlatte.tilgangsstyring.kunSkrivetilgang | ||
import java.util.UUID | ||
|
||
enum class EtteroppgjoerToggles( | ||
private val toggle: String, | ||
) : FeatureToggle { | ||
ETTEROPPGJOER("etteroppjoer"), | ||
; | ||
|
||
override fun key(): String = toggle | ||
} | ||
|
||
fun Route.etteroppgjoerRoutes( | ||
service: EtteroppgjoerService, | ||
featureToggleService: FeatureToggleService, | ||
) { | ||
route("/api/etteroppgjoer/{$ETTEROPPGJOER_CALL_PARAMETER}") { | ||
get { | ||
sjekkEtteroppgjoerEnabled(featureToggleService) | ||
kunSkrivetilgang { | ||
val etteroppgjoer = service.hentEtteroppgjoer(etteroppgjoerId) | ||
call.respond(etteroppgjoer) | ||
} | ||
} | ||
} | ||
|
||
route("/etteroppgjoer/{$SAKID_CALL_PARAMETER}") { | ||
post { | ||
sjekkEtteroppgjoerEnabled(featureToggleService) | ||
kunSkrivetilgang { | ||
service.opprettEtteroppgjoer(sakId) | ||
call.respond(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun sjekkEtteroppgjoerEnabled(featureToggleService: FeatureToggleService) { | ||
if (!featureToggleService.isEnabled(EtteroppgjoerToggles.ETTEROPPGJOER, false)) { | ||
throw IkkeTillattException("ETTEROPPGJOER_NOT_ENABLED", "Etteroppgjør er ikke skrudd på i miljøet.") | ||
} | ||
} | ||
|
||
data class Etteroppgjoer( | ||
val behandling: EtteroppgjoerBehandling, | ||
val opplysninger: EtteroppgjoerOpplysninger, | ||
) | ||
|
||
data class EtteroppgjoerBehandling( | ||
val id: UUID, | ||
// val referanse: String, TODO en referanse/id til en hendelse el. | ||
val status: String, // TODO enum | ||
val sak: Sak, | ||
val aar: Int, | ||
val opprettet: Tidspunkt, | ||
) | ||
|
||
data class EtteroppgjoerOpplysninger( | ||
val skatt: OpplysnignerSkatt, | ||
val ainntekt: AInntekt, | ||
// TODO.. | ||
) | ||
|
||
data class OpplysnignerSkatt( | ||
val aarsinntekt: Int, | ||
) | ||
|
||
data class AInntekt( | ||
val inntektsmaaneder: List<AInntektMaaned>, | ||
) | ||
|
||
data class AInntektMaaned( | ||
val maaned: String, | ||
val summertBeloep: Int, | ||
) |
85 changes: 85 additions & 0 deletions
85
apps/etterlatte-behandling/src/main/kotlin/behandling/etteroppgjoer/EtteroppgjoerService.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,85 @@ | ||
package no.nav.etterlatte.behandling.etteroppgjoer | ||
|
||
import io.ktor.server.plugins.NotFoundException | ||
import no.nav.etterlatte.inTransaction | ||
import no.nav.etterlatte.libs.common.feilhaandtering.IkkeFunnetException | ||
import no.nav.etterlatte.libs.common.oppgave.OppgaveKilde | ||
import no.nav.etterlatte.libs.common.oppgave.OppgaveType | ||
import no.nav.etterlatte.libs.common.sak.SakId | ||
import no.nav.etterlatte.libs.common.tidspunkt.Tidspunkt | ||
import no.nav.etterlatte.oppgave.OppgaveService | ||
import no.nav.etterlatte.sak.SakLesDao | ||
import java.util.UUID | ||
|
||
class EtteroppgjoerService( | ||
private val dao: EtteroppgjoerDao, | ||
private val sakDao: SakLesDao, | ||
private val oppgaveService: OppgaveService, | ||
) { | ||
fun hentEtteroppgjoer(behandlingId: UUID): Etteroppgjoer { | ||
val etteroppgjoerBehandling = | ||
inTransaction { | ||
dao.hentEtteroppgjoer(behandlingId) | ||
} ?: throw IkkeFunnetException( | ||
code = "MANGLER_FORBEHANDLING_ETTEROPPGJOER", | ||
detail = "Fant ikke forbehandling etteroppgjør $behandlingId", | ||
) | ||
|
||
// TODO egen tabell? I beregning? | ||
val opplysninger = | ||
EtteroppgjoerOpplysninger( | ||
skatt = | ||
OpplysnignerSkatt( | ||
aarsinntekt = 200000, | ||
), | ||
ainntekt = | ||
AInntekt( | ||
inntektsmaaneder = | ||
listOf( | ||
AInntektMaaned( | ||
maaned = "Januar", | ||
summertBeloep = 150000, | ||
), | ||
AInntektMaaned( | ||
maaned = "Januar", | ||
summertBeloep = 150000, | ||
), | ||
), | ||
), | ||
) | ||
|
||
return Etteroppgjoer( | ||
behandling = etteroppgjoerBehandling, | ||
opplysninger = opplysninger, | ||
) | ||
} | ||
|
||
fun opprettEtteroppgjoer(sakId: SakId) { | ||
inTransaction { | ||
val sak = sakDao.hentSak(sakId) ?: throw NotFoundException("Fant ikke sak med id=$sakId") | ||
|
||
// TODO skal opplysninger mottas eller hentes her? | ||
|
||
val nyBehandling = | ||
EtteroppgjoerBehandling( | ||
id = UUID.randomUUID(), | ||
status = "opprettet", | ||
sak = sak, | ||
aar = 2024, | ||
opprettet = Tidspunkt.now(), | ||
) | ||
|
||
dao.lagreEtteroppgjoer(nyBehandling) | ||
oppgaveService.opprettOppgave( | ||
referanse = nyBehandling.id.toString(), | ||
sakId = sakId, | ||
kilde = OppgaveKilde.BEHANDLING, | ||
type = OppgaveType.ETTEROPPGJOER, | ||
merknad = null, | ||
frist = null, | ||
saksbehandler = null, | ||
gruppeId = null, | ||
) | ||
} | ||
} | ||
} |
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.