-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1204 from navikt/oppgave-client
Oppgave client
- Loading branch information
Showing
13 changed files
with
305 additions
and
9 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
15 changes: 15 additions & 0 deletions
15
...tlin/no/nav/klage/oppgave/clients/oppgaveapi/OffsetDateTimeToLocalDateTimeDeserializer.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.klage.oppgave.clients.oppgaveapi | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
class OffsetDateTimeToLocalDateTimeDeserializer : StdDeserializer<LocalDateTime>(LocalDateTime::class.java) { | ||
|
||
override fun deserialize(jsonParser: JsonParser, ctxt: DeserializationContext?): LocalDateTime { | ||
return LocalDateTime.parse(jsonParser.readValueAs(String::class.java), DateTimeFormatter.ISO_OFFSET_DATE_TIME) | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/kotlin/no/nav/klage/oppgave/clients/oppgaveapi/OppgaveApiClient.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,69 @@ | ||
package no.nav.klage.oppgave.clients.oppgaveapi | ||
|
||
import no.nav.klage.oppgave.util.TokenUtil | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.web.reactive.function.client.WebClient | ||
import io.opentelemetry.api.trace.Span | ||
import no.nav.klage.oppgave.util.getLogger | ||
import no.nav.klage.oppgave.util.getSecureLogger | ||
|
||
import org.springframework.http.HttpHeaders | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.reactive.function.client.WebClientResponseException | ||
|
||
import org.springframework.web.reactive.function.client.bodyToMono | ||
|
||
@Component | ||
class OppgaveApiClient( | ||
private val oppgaveApiWebClient: WebClient, | ||
private val tokenUtil: TokenUtil, | ||
@Value("\${spring.application.name}") private val applicationName: String, | ||
){ | ||
|
||
companion object { | ||
@Suppress("JAVA_CLASS_ON_COMPANION") | ||
private val logger = getLogger(javaClass.enclosingClass) | ||
private val securelogger = getSecureLogger() | ||
} | ||
|
||
fun getOppgave(oppgaveId: Long): OppgaveApiRecord { | ||
return logTimingAndWebClientResponseException(OppgaveApiClient::getOppgave.name) { | ||
oppgaveApiWebClient.get() | ||
.uri { uriBuilder -> | ||
uriBuilder.pathSegment("oppgaver", "{id}").build(oppgaveId) | ||
} | ||
.header( | ||
HttpHeaders.AUTHORIZATION, | ||
"Bearer ${tokenUtil.getSaksbehandlerAccessTokenWithOppgaveApiScope()}" | ||
) | ||
.header("X-Correlation-ID", Span.current().spanContext.traceId) | ||
.header("Nav-Consumer-Id", applicationName) | ||
.retrieve() | ||
.bodyToMono<OppgaveApiRecord>() | ||
.block() ?: throw OppgaveClientException("Oppgave could not be fetched") | ||
} | ||
} | ||
|
||
private fun <T> logTimingAndWebClientResponseException(methodName: String, function: () -> T): T { | ||
val start: Long = System.currentTimeMillis() | ||
try { | ||
return function.invoke() | ||
} catch (ex: WebClientResponseException) { | ||
logger.warn("Caught WebClientResponseException, see securelogs for details") | ||
securelogger.error( | ||
"Got a {} error calling Oppgave {} {} with message {}", | ||
ex.statusCode, | ||
ex.request?.method ?: "-", | ||
ex.request?.uri ?: "-", | ||
ex.responseBodyAsString | ||
) | ||
throw OppgaveClientException("Caught WebClientResponseException", ex) | ||
} catch (rtex: RuntimeException) { | ||
logger.warn("Caught RuntimeException", rtex) | ||
throw OppgaveClientException("Caught runtimeexception", rtex) | ||
} finally { | ||
val end: Long = System.currentTimeMillis() | ||
logger.info("Method {} took {} millis", methodName, (end - start)) | ||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
src/main/kotlin/no/nav/klage/oppgave/clients/oppgaveapi/OppgaveApiRecord.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,128 @@ | ||
package no.nav.klage.oppgave.clients.oppgaveapi | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class OppgaveApiRecord( | ||
val id: Long, | ||
val versjon: Int, | ||
val journalpostId: String?, | ||
val saksreferanse: String?, | ||
val mappeId: Long?, | ||
val status: Status?, | ||
val tildeltEnhetsnr: String?, | ||
val opprettetAvEnhetsnr: String?, | ||
val endretAvEnhetsnr: String?, | ||
val tema: String, | ||
val temagruppe: String?, | ||
val behandlingstema: String?, | ||
val oppgavetype: String?, | ||
val behandlingstype: String?, | ||
val prioritet: Prioritet?, | ||
val tilordnetRessurs: String?, | ||
val beskrivelse: String?, | ||
val fristFerdigstillelse: LocalDate?, | ||
val aktivDato: String?, | ||
val opprettetAv: String?, | ||
val endretAv: String?, | ||
@JsonDeserialize(using = OffsetDateTimeToLocalDateTimeDeserializer::class) | ||
val opprettetTidspunkt: LocalDateTime, | ||
@JsonDeserialize(using = OffsetDateTimeToLocalDateTimeDeserializer::class) | ||
val endretTidspunkt: LocalDateTime?, | ||
@JsonDeserialize(using = OffsetDateTimeToLocalDateTimeDeserializer::class) | ||
val ferdigstiltTidspunkt: LocalDateTime?, | ||
val behandlesAvApplikasjon: String?, | ||
val journalpostkilde: String?, | ||
val identer: List<Ident>?, | ||
val metadata: Map<String, String>?, | ||
val bnr: String?, | ||
val samhandlernr: String?, | ||
val aktoerId: String?, | ||
val orgnr: String?, | ||
) | ||
|
||
enum class Status(val statusId: Long) { | ||
|
||
OPPRETTET(1), | ||
AAPNET(2), | ||
UNDER_BEHANDLING(3), | ||
FERDIGSTILT(4), | ||
FEILREGISTRERT(5); | ||
|
||
companion object { | ||
|
||
fun of(statusId: Long): Status { | ||
return entries.firstOrNull { it.statusId == statusId } | ||
?: throw IllegalArgumentException("No status with $statusId exists") | ||
} | ||
|
||
fun kategoriForStatus(status: Status): Statuskategori { | ||
return when (status) { | ||
AAPNET, OPPRETTET, UNDER_BEHANDLING -> Statuskategori.AAPEN | ||
FEILREGISTRERT, FERDIGSTILT -> Statuskategori.AVSLUTTET | ||
} | ||
} | ||
} | ||
|
||
fun kategoriForStatus(): Statuskategori { | ||
return kategoriForStatus(this) | ||
} | ||
} | ||
|
||
enum class Prioritet { | ||
HOY, | ||
NORM, | ||
LAV | ||
} | ||
|
||
data class Ident( | ||
val id: Long?, | ||
val identType: IdentType, | ||
val verdi: String, | ||
val folkeregisterident: String?, | ||
val registrertDato: LocalDate? | ||
) | ||
|
||
enum class IdentType { | ||
AKTOERID, ORGNR, SAMHANDLERNR, BNR | ||
} | ||
|
||
enum class Statuskategori { | ||
AAPEN, | ||
AVSLUTTET; | ||
|
||
fun statuserForKategori(kategori: Statuskategori): List<Status> { | ||
return when (kategori) { | ||
AAPEN -> aapen() | ||
AVSLUTTET -> avsluttet() | ||
} | ||
} | ||
|
||
fun avsluttet(): List<Status> { | ||
return listOf(Status.FERDIGSTILT, Status.FEILREGISTRERT) | ||
} | ||
|
||
fun aapen(): List<Status> { | ||
return listOf(Status.OPPRETTET, Status.AAPNET, Status.UNDER_BEHANDLING) | ||
} | ||
} | ||
|
||
data class OppgaveResponse( | ||
val antallTreffTotalt: Int, | ||
val oppgaver: List<OppgaveApiRecord> | ||
) | ||
|
||
class OppgaveClientException : Exception { | ||
constructor(message: String?) : super(message) | ||
|
||
constructor(message: String?, cause: Throwable?) : super(message, cause) | ||
} | ||
|
||
data class FerdigstillOppgaveRequest( | ||
val oppgaveId: Long, | ||
val versjon: Int, | ||
val status: Status = Status.FERDIGSTILT, | ||
) |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/no/nav/klage/oppgave/config/OppgaveApiClientConfiguration.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,27 @@ | ||
package no.nav.klage.oppgave.config | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.MediaType | ||
import org.springframework.http.client.reactive.ReactorClientHttpConnector | ||
import org.springframework.web.reactive.function.client.WebClient | ||
import reactor.netty.http.client.HttpClient.newConnection | ||
|
||
@Configuration | ||
class OppgaveApiClientConfiguration(private val webClientBuilder: WebClient.Builder) { | ||
@Value("\${OPPGAVE_API_BASE_URL}") | ||
private lateinit var oppgaveBaseURL: String | ||
|
||
@Bean | ||
fun oppgaveApiWebClient(): WebClient { | ||
return webClientBuilder | ||
.baseUrl(oppgaveBaseURL) | ||
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) | ||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.clientConnector(ReactorClientHttpConnector(newConnection())) | ||
.build() | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/no/nav/klage/oppgave/service/OppgaveApiService.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,24 @@ | ||
package no.nav.klage.oppgave.service | ||
|
||
import no.nav.klage.oppgave.clients.oppgaveapi.OppgaveApiClient | ||
import no.nav.klage.oppgave.util.getLogger | ||
import no.nav.klage.oppgave.util.getSecureLogger | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class OppgaveApiService( | ||
private val oppgaveApiClient: OppgaveApiClient | ||
) { | ||
|
||
companion object { | ||
@Suppress("JAVA_CLASS_ON_COMPANION") | ||
private val logger = getLogger(javaClass.enclosingClass) | ||
private val securelogger = getSecureLogger() | ||
} | ||
|
||
fun getOppgaveEntryView(oppgaveId: Long): String? { | ||
val oppgave = oppgaveApiClient.getOppgave(oppgaveId = oppgaveId) | ||
return oppgave.beskrivelse | ||
} | ||
|
||
} |
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.