Skip to content

Commit

Permalink
EY-5030: Behandling som proxy for oppretting av vedtaksbrev. (#7060)
Browse files Browse the repository at this point in the history
* EY-5030: Behandling som proxy for oppretting av vedtaksbrev.

* EY-5030: Behandling som proxy for tilbakestilling og pdf-generering av vedtaksbrev.

* EY-5030: Fikser feil pga manglende transaksjon. Integrasjonstest

* EY-5030: Fikset litt på tilbakestilling. Flere tester.

* EY-5030: Proxy for ferdigstilling og henting av vedtaksbrev. Flytter inTransaction til route for å unngå nøsting.

* EY-5030: Sletter ubrukt kode.

* Merge remote-tracking branch 'origin/main' into feature/EY-5030-behandling-som-brev-proxy

# Conflicts:
#	apps/etterlatte-behandling/src/test/kotlin/integration/BehandlingIntegrationTest.kt

* EY-5030: Returnerer Pdf fra gammel route for generer PDF i brev-api istedenfor byte array.

* EY-5030: Merge-fix

* EY-5030: Fikser feilende test
  • Loading branch information
tvsignal authored Feb 27, 2025
1 parent 70b60bf commit c9d660c
Show file tree
Hide file tree
Showing 22 changed files with 887 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class KlageBrevService(
saksbehandler: Saksbehandler,
) {
runBlocking {
brevApiKlient.ferdigstillVedtaksbrev(klage.id, klage.sak.id, saksbehandler)
brevApiKlient.ferdigstillVedtaksbrev(klage.id, saksbehandler)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import com.typesafe.config.Config
import io.ktor.client.HttpClient
import no.nav.etterlatte.behandling.objectMapper
import no.nav.etterlatte.brev.BrevParametre
import no.nav.etterlatte.brev.BrevPayload
import no.nav.etterlatte.brev.Brevtype
import no.nav.etterlatte.brev.Pdf
import no.nav.etterlatte.brev.model.Brev
import no.nav.etterlatte.brev.model.BrevID
import no.nav.etterlatte.brev.model.BrevStatusResponse
Expand Down Expand Up @@ -64,7 +67,6 @@ interface BrevApiKlient {

suspend fun ferdigstillVedtaksbrev(
behandlingId: UUID,
sakId: SakId,
brukerTokenInfo: BrukerTokenInfo,
)

Expand Down Expand Up @@ -122,6 +124,20 @@ interface BrevApiKlient {
behandlingId: UUID,
brukerTokenInfo: BrukerTokenInfo,
): Brev?

suspend fun genererPdf(
brevID: BrevID,
behandlingId: UUID,
brukerTokenInfo: BrukerTokenInfo,
): Pdf

suspend fun tilbakestillVedtaksbrev(
brevID: BrevID,
behandlingId: UUID,
sakId: SakId,
brevtype: Brevtype,
brukerTokenInfo: BrukerTokenInfo,
): BrevPayload
}

class BrevApiKlientObo(
Expand Down Expand Up @@ -230,7 +246,6 @@ class BrevApiKlientObo(

override suspend fun ferdigstillVedtaksbrev(
behandlingId: UUID,
sakId: SakId,
brukerTokenInfo: BrukerTokenInfo,
) {
post(
Expand Down Expand Up @@ -345,6 +360,42 @@ class BrevApiKlientObo(
).mapError { error -> throw error }
}

override suspend fun genererPdf(
brevID: BrevID,
behandlingId: UUID,
brukerTokenInfo: BrukerTokenInfo,
): Pdf =
get(
url = "$resourceUrl/api/brev/behandling/$behandlingId/vedtak/pdf?brevId=$brevID",
onSuccess = { resource ->
resource.response?.let { deserialize(it.toJson()) }
?: throw InternfeilException("Feil ved generering av pdf vedtaksbrev")
},
brukerTokenInfo = brukerTokenInfo,
)

override suspend fun tilbakestillVedtaksbrev(
brevID: BrevID,
behandlingId: UUID,
sakId: SakId,
brevtype: Brevtype,
brukerTokenInfo: BrukerTokenInfo,
): BrevPayload =
put(
url = "$resourceUrl/api/brev/behandling/$behandlingId/payload/tilbakestill",
onSuccess = { resource ->
resource.response?.let { deserialize(it.toJson()) }
?: throw InternfeilException("Feil ved tilbakestilling av pdf vedtaksbrev")
},
putBody =
ResetPayloadRequest(
brevId = brevID,
sakId = sakId,
brevtype = brevtype,
),
brukerTokenInfo = brukerTokenInfo,
)

private suspend fun <T> post(
url: String,
postBody: Any = Unit,
Expand Down Expand Up @@ -374,6 +425,22 @@ class BrevApiKlientObo(
success = onSuccess,
failure = { throwableErrorMessage -> throw throwableErrorMessage },
)

private suspend fun <T> put(
url: String,
putBody: Any = Unit,
onSuccess: (Resource) -> T,
brukerTokenInfo: BrukerTokenInfo,
): T =
downstreamResourceClient
.put(
resource = Resource(clientId = clientId, url = url),
brukerTokenInfo = brukerTokenInfo,
putBody = putBody,
).mapBoth(
success = onSuccess,
failure = { errorResponse -> throw errorResponse },
)
}

data class KlageNotatRequest(
Expand All @@ -386,3 +453,9 @@ data class KlageNotatRequest(
data class OpprettJournalpostDto(
val journalpostId: String,
)

private data class ResetPayloadRequest(
val brevId: Long,
val sakId: SakId,
val brevtype: Brevtype,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import no.nav.etterlatte.libs.common.tilbakekreving.TilbakekrevingStatus
import no.nav.etterlatte.libs.database.single
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.sql.Connection
import java.sql.ResultSet
import java.util.UUID

Expand All @@ -18,45 +19,58 @@ class VedtaksbehandlingDao(
fun erBehandlingRedigerbar(behandlingId: UUID): Boolean =
connectionAutoclosing.hentConnection {
with(it) {
val statement =
prepareStatement(
"""
SELECT 'BEHANDLING', id, status FROM behandling WHERE id = ?
union SELECT 'TILBAKEKREVING', id, status FROM tilbakekreving WHERE id = ?
union SELECT 'KLAGE', id, status FROM klage WHERE id = ?
""".trimIndent(),
)
statement.setObject(1, behandlingId)
statement.setObject(2, behandlingId)
statement.setObject(3, behandlingId)

statement
.executeQuery()
.single { toVedtaksbehandling() }
hentVedtaksbehandling(behandlingId)
.erRedigerbar()
}
}

fun hentVedtaksbehandling(behandlingId: UUID): Vedtaksbehandling =
connectionAutoclosing.hentConnection {
with(it) {
hentVedtaksbehandling(behandlingId)
}
}

private fun Connection.hentVedtaksbehandling(behandlingId: UUID): Vedtaksbehandling {
val statement =
prepareStatement(
"""
SELECT 'BEHANDLING', id, status FROM behandling WHERE id = ?
union SELECT 'TILBAKEKREVING', id, status FROM tilbakekreving WHERE id = ?
union SELECT 'KLAGE', id, status FROM klage WHERE id = ?
""".trimIndent(),
)
statement.setObject(1, behandlingId)
statement.setObject(2, behandlingId)
statement.setObject(3, behandlingId)

val vedtaksbehandling =
statement
.executeQuery()
.single { toVedtaksbehandling() }
return vedtaksbehandling
}

private fun ResultSet.toVedtaksbehandling(): Vedtaksbehandling {
val type = BehandlingType.valueOf(getString(1))
val type = VedtaksbehandlingType.valueOf(getString(1))
val id = UUID.fromString(getString(2))
val status = getString(3)

return Vedtaksbehandling(id, type, status)
}
}

private data class Vedtaksbehandling(
data class Vedtaksbehandling(
val id: UUID,
val type: BehandlingType,
val type: VedtaksbehandlingType,
val status: String,
) {
fun erRedigerbar(): Boolean {
val redigerbar =
when (type) {
BehandlingType.BEHANDLING -> BehandlingStatus.valueOf(status).kanEndres()
BehandlingType.TILBAKEKREVING -> TilbakekrevingStatus.valueOf(status).kanEndres()
BehandlingType.KLAGE -> {
VedtaksbehandlingType.BEHANDLING -> BehandlingStatus.valueOf(status).kanEndres()
VedtaksbehandlingType.TILBAKEKREVING -> TilbakekrevingStatus.valueOf(status).kanEndres()
VedtaksbehandlingType.KLAGE -> {
val klageStatus = KlageStatus.valueOf(status)
// I konteksten av vedtak så er klager også mulig å endre når formkravene ikke er oppfylt,
// siden det er da man oppretter vedtak om avvist klage
Expand All @@ -71,7 +85,7 @@ private data class Vedtaksbehandling(
}
}

private enum class BehandlingType {
enum class VedtaksbehandlingType {
BEHANDLING,
TILBAKEKREVING,
KLAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ class VedtaksbehandlingService(
private val vedtaksbehandlingDao: VedtaksbehandlingDao,
) {
fun erBehandlingRedigerbar(behandlingId: UUID): Boolean = vedtaksbehandlingDao.erBehandlingRedigerbar(behandlingId)

fun hentVedtaksbehandling(behandlingId: UUID): Vedtaksbehandling = vedtaksbehandlingDao.hentVedtaksbehandling(behandlingId)
}
Loading

0 comments on commit c9d660c

Please sign in to comment.