Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AudunSorheim committed Jan 12, 2024
1 parent ec514a8 commit 86ab84d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main/kotlin/no/nav/syfo/narmesteleder/NarmesteLederClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.cache.annotation.Cacheable
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import org.springframework.web.client.RestClientResponseException
import org.springframework.web.client.RestTemplate
Expand All @@ -23,8 +25,6 @@ class NarmesteLederClient(
private val tokenDingsConsumer: TokenDingsConsumer,
private val contextHolder: TokenValidationContextHolder,
) {
private val ansatteNarmesteLederSelvbetjeningPath = "$baseUrl/api/selvbetjening/v1/narmestelederrelasjoner"

@Cacheable(value = ["aktive_ledere"], key = "#ansattFnr", condition = "#ansattFnr != null")
fun alleAktiveLedereForSykmeldt(
ansattFnr: String,
Expand All @@ -34,13 +34,14 @@ class NarmesteLederClient(
val exchangedToken = tokenDingsConsumer.exchangeToken(issuerToken, targetApp)

try {
val allRelations = getNarmesteLederRelasjoner(
url = ansatteNarmesteLederSelvbetjeningPath,
val response = getResponse(
fnr = ansattFnr,
accessToken = exchangedToken
)

return allRelations
val relasjoner = response.body ?: emptyArray()

return relasjoner
.filter { it.status == NarmesteLederRelasjonStatus.INNMELDT_AKTIV.name }
.filter { it.arbeidstakerPersonIdentNumber == ansattFnr }
.distinctBy { it.narmesteLederPersonIdentNumber }
Expand Down Expand Up @@ -83,17 +84,16 @@ class NarmesteLederClient(
return HttpEntity(headers)
}

private fun getNarmesteLederRelasjoner(
url: String,
private fun getResponse(
fnr: String,
accessToken: String
): Array<NarmesteLederRelasjonDTO> {
log.info("Getting relasjoner. URL: $url FNR: $fnr ACCESSTOKEN: $accessToken")
return RestTemplate().getForObject(
url,
Array<NarmesteLederRelasjonDTO>::class.java,
): ResponseEntity<Array<NarmesteLederRelasjonDTO>> {
return RestTemplate().exchange(
"$baseUrl/api/selvbetjening/v1/narmestelederrelasjoner",
HttpMethod.GET,
headers(fnr, accessToken),
) ?: emptyArray()
Array<NarmesteLederRelasjonDTO>::class.java,
)
}

companion object {
Expand Down

0 comments on commit 86ab84d

Please sign in to comment.