Skip to content

Commit

Permalink
Bruker saksbehandler-token i kommunikasjon med SAF når det skjer i sy…
Browse files Browse the repository at this point in the history
…nkron kontekst.

Gjort noen funksjonsnavn tydeligere, hvorvidt det er saksbehandler eller systembruker-kontekst.
  • Loading branch information
oyvind-wedoe committed Jun 22, 2021
1 parent e5c02bd commit 7cf2bf6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class KlagebehandlingVedtakController(
val klagebehandling = klagebehandlingService.getKlagebehandling(klagebehandlingId.toUUIDOrException())
val vedtak = vedtakService.getVedtak(klagebehandling, vedtakId.toUUIDOrException())
if (vedtak.journalpostId == null) throw JournalpostNotFoundException("Vedtak med id $vedtakId er ikke journalført")
val arkivertDokumentWithTitle = dokumentService.getArkivertDokumentWithTitle(vedtak.journalpostId!!)
val arkivertDokumentWithTitle = dokumentService.getArkivertDokumentWithTitleAsSaksbehandler(vedtak.journalpostId!!)

val responseHeaders = HttpHeaders()
responseHeaders.contentType = arkivertDokumentWithTitle.contentType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class KlagebehandlingMapper(

fun getVedleggView(vedtakJournalpostId: String?, opplastet: LocalDateTime?): VedleggView? {
return if (vedtakJournalpostId != null && opplastet != null) {
val arkivertDokumentWithTitle = dokumentService.getArkivertDokumentWithTitle(vedtakJournalpostId)
val arkivertDokumentWithTitle = dokumentService.getArkivertDokumentWithTitleAsSaksbehandler(vedtakJournalpostId)
mapArkivertDokumentWithTitleToVedleggView(arkivertDokumentWithTitle, opplastet)
} else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SafGraphQlClient(
}

@Retryable
fun getJournalpost(journalpostId: String): Journalpost? {
fun getJournalpostAsSaksbehandler(journalpostId: String): Journalpost? {
return runWithTimingAndLogging {
val token = tokenUtil.getSaksbehandlerAccessTokenWithSafScope()
getJournalpostWithToken(journalpostId, token)
Expand Down
36 changes: 31 additions & 5 deletions src/main/kotlin/no/nav/klage/oppgave/service/DokumentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DokumentService(

fun fetchJournalposterConnectedToKlagebehandling(klagebehandling: Klagebehandling): DokumenterResponse {
val dokumentReferanser = klagebehandling.saksdokumenter
.mapNotNull { safGraphQlClient.getJournalpost(it.journalpostId) }
.mapNotNull { safGraphQlClient.getJournalpostAsSaksbehandler(it.journalpostId) }
.map { dokumentMapper.mapJournalpostToDokumentReferanse(it, klagebehandling) }
return DokumenterResponse(
dokumenter = dokumentReferanser,
Expand All @@ -68,7 +68,7 @@ class DokumentService(

fun validateJournalpostExists(journalpostId: String) {
try {
safGraphQlClient.getJournalpost(journalpostId)
safGraphQlClient.getJournalpostAsSaksbehandler(journalpostId)
} catch (e: Exception) {
logger.warn("Unable to find journalpost $journalpostId", e)
null
Expand All @@ -94,6 +94,16 @@ class DokumentService(
}
}

fun fetchDokumentInfoIdForJournalpostAsSaksbehandler(journalpostId: String): List<String> {
return try {
val journalpost = safGraphQlClient.getJournalpostAsSaksbehandler(journalpostId)
journalpost?.dokumenter?.filter { harArkivVariantformat(it) }?.map { it.dokumentInfoId } ?: emptyList()
} catch (e: Exception) {
logger.warn("Unable to find journalpost $journalpostId", e)
emptyList()
}
}

fun getArkivertDokument(journalpostId: String, dokumentInfoId: String): ArkivertDokument {
return safRestClient.getDokument(dokumentInfoId, journalpostId)
}
Expand All @@ -103,6 +113,11 @@ class DokumentService(
return getArkivertDokument(journalpostId, dokumentInfoId.first())
}

fun getMainDokumentAsSaksbehandler(journalpostId: String): ArkivertDokument {
val dokumentInfoId = fetchDokumentInfoIdForJournalpostAsSaksbehandler(journalpostId)
return getArkivertDokument(journalpostId, dokumentInfoId.first())
}

fun getMainDokumentTitle(journalpostId: String): String {
return try {
val journalpost = safGraphQlClient.getJournalpostAsSystembruker(journalpostId)
Expand All @@ -114,9 +129,20 @@ class DokumentService(
}
}

fun getArkivertDokumentWithTitle(journalpostId: String): ArkivertDokumentWithTitle {
val title = getMainDokumentTitle(journalpostId)
val dokument = getMainDokument(journalpostId)
fun getMainDokumentTitleAsSaksbehandler(journalpostId: String): String {
return try {
val journalpost = safGraphQlClient.getJournalpostAsSaksbehandler(journalpostId)
val dokumentVariant = journalpost?.dokumenter?.filter { harArkivVariantformat(it) }
return dokumentVariant?.first()?.dokumentvarianter?.first()?.filnavn!!
} catch (e: Exception) {
logger.warn("Unable to find journalpost $journalpostId", e)
"Unknown"
}
}

fun getArkivertDokumentWithTitleAsSaksbehandler(journalpostId: String): ArkivertDokumentWithTitle {
val title = getMainDokumentTitleAsSaksbehandler(journalpostId)
val dokument = getMainDokumentAsSaksbehandler(journalpostId)
return ArkivertDokumentWithTitle(
title,
dokument.bytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class VedtakService(
journalfoerendeEnhet: String
): Klagebehandling {
return try {
val journalpost = safClient.getJournalpost(vedtak.journalpostId!!)
val journalpost = safClient.getJournalpostAsSaksbehandler(vedtak.journalpostId!!)
?: throw JournalpostNotFoundException("Journalpost med id ${vedtak.journalpostId} finnes ikke")
if (journalpost.journalstatus != FERDIGSTILT) {
joarkClient.finalizeJournalpost(vedtak.journalpostId!!, journalfoerendeEnhet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class KlagebehandlingDistribusjonService(
@Transactional(propagation = Propagation.NEVER)
fun distribuerKlagebehandling(klagebehandlingId: UUID) {
try {
var klagebehandling = klagebehandlingService.getKlagebehandling(klagebehandlingId)
var klagebehandling = klagebehandlingService.getKlagebehandlingForUpdateBySystembruker(klagebehandlingId, null)
klagebehandling.vedtak
.filter { vedtak -> vedtak.erIkkeFerdigDistribuert() }
.forEach { vedtak ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal class SafJournalpostTest {
tracerMock
)

return safClient.getJournalpost("whatever")
return safClient.getJournalpostAsSaksbehandler("whatever")
}

@Language("json")
Expand Down

0 comments on commit 7cf2bf6

Please sign in to comment.