-
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.
- Loading branch information
1 parent
2ca06f6
commit 30b7b33
Showing
19 changed files
with
255 additions
and
5 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
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
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
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/no/nav/syfo/personstatus/application/meroppfolging/IMeroppfolgingClient.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,11 @@ | ||
package no.nav.syfo.personstatus.application.meroppfolging | ||
|
||
import no.nav.syfo.personstatus.domain.PersonIdent | ||
|
||
interface IMeroppfolgingClient { | ||
suspend fun getSenOppfolgingKandidater( | ||
callId: String, | ||
token: String, | ||
personidenter: List<PersonIdent>, | ||
): SenOppfolgingKandidaterResponseDTO? | ||
} |
29 changes: 29 additions & 0 deletions
29
...ain/kotlin/no/nav/syfo/personstatus/application/meroppfolging/SenOppfolgingKandidatDTO.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,29 @@ | ||
package no.nav.syfo.personstatus.application.meroppfolging | ||
|
||
import java.time.LocalDateTime | ||
import java.util.* | ||
|
||
data class SenOppfolgingKandidaterRequestDTO( | ||
val personidenter: List<String> | ||
) | ||
|
||
data class SenOppfolgingKandidaterResponseDTO( | ||
val kandidater: Map<String, SenOppfolgingKandidatDTO> | ||
) | ||
|
||
data class SenOppfolgingKandidatDTO( | ||
val uuid: UUID, | ||
val personident: String, | ||
val varselAt: LocalDateTime?, | ||
val svar: SvarResponseDTO?, | ||
) | ||
|
||
data class SvarResponseDTO( | ||
val svarAt: LocalDateTime, | ||
val onskerOppfolging: OnskerOppfolging, | ||
) | ||
|
||
enum class OnskerOppfolging { | ||
JA, | ||
NEI, | ||
} |
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
104 changes: 104 additions & 0 deletions
104
...tlin/no/nav/syfo/personstatus/infrastructure/clients/meroppfolging/MerOppfolgingClient.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,104 @@ | ||
package no.nav.syfo.personstatus.infrastructure.clients.meroppfolging | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.call.* | ||
import io.ktor.client.plugins.* | ||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.http.* | ||
import io.micrometer.core.instrument.Counter | ||
import net.logstash.logback.argument.StructuredArguments | ||
import no.nav.syfo.personstatus.application.meroppfolging.IMeroppfolgingClient | ||
import no.nav.syfo.personstatus.application.meroppfolging.SenOppfolgingKandidaterRequestDTO | ||
import no.nav.syfo.personstatus.application.meroppfolging.SenOppfolgingKandidaterResponseDTO | ||
import no.nav.syfo.personstatus.domain.PersonIdent | ||
import no.nav.syfo.personstatus.infrastructure.METRICS_NS | ||
import no.nav.syfo.personstatus.infrastructure.METRICS_REGISTRY | ||
import no.nav.syfo.personstatus.infrastructure.clients.ClientEnvironment | ||
import no.nav.syfo.personstatus.infrastructure.clients.azuread.AzureAdClient | ||
import no.nav.syfo.personstatus.infrastructure.clients.httpClientDefault | ||
import no.nav.syfo.util.NAV_CALL_ID_HEADER | ||
import no.nav.syfo.util.bearerHeader | ||
import no.nav.syfo.util.callIdArgument | ||
import org.slf4j.LoggerFactory | ||
|
||
class MerOppfolgingClient( | ||
private val azureAdClient: AzureAdClient, | ||
private val clientEnvironment: ClientEnvironment, | ||
private val httpClient: HttpClient = httpClientDefault(), | ||
) : IMeroppfolgingClient { | ||
|
||
override suspend fun getSenOppfolgingKandidater( | ||
callId: String, | ||
token: String, | ||
personidenter: List<PersonIdent> | ||
): SenOppfolgingKandidaterResponseDTO? { | ||
val oboToken = azureAdClient.getOnBehalfOfToken( | ||
scopeClientId = clientEnvironment.clientId, | ||
token, | ||
)?.accessToken ?: throw RuntimeException("Failed to get OBO-token for sen oppfolging kandidater") | ||
val requestDTO = SenOppfolgingKandidaterRequestDTO(personidenter.map { it.value }) | ||
|
||
return try { | ||
val response = httpClient.post("${clientEnvironment.baseUrl}$MEROPPFOLGING_SENOPPFOLGING_KANDIDATER_API_PATH") { | ||
header(HttpHeaders.Authorization, bearerHeader(oboToken)) | ||
header(NAV_CALL_ID_HEADER, callId) | ||
accept(ContentType.Application.Json) | ||
contentType(ContentType.Application.Json) | ||
setBody(requestDTO) | ||
} | ||
when (response.status) { | ||
HttpStatusCode.OK -> { | ||
COUNT_CALL_MEROPPFOLGING_SUCCESS.increment() | ||
response.body<SenOppfolgingKandidaterResponseDTO>() | ||
} | ||
HttpStatusCode.NotFound -> { | ||
log.error("Resource not found") | ||
COUNT_CALL_MEROPPFOLGING_FAIL.increment() | ||
null | ||
} | ||
else -> { | ||
log.error("Unhandled status code: ${response.status}") | ||
COUNT_CALL_MEROPPFOLGING_FAIL.increment() | ||
null | ||
} | ||
} | ||
} catch (e: ClientRequestException) { | ||
handleUnexpectedResponseException(e.response, callId) | ||
throw e | ||
} catch (e: ServerResponseException) { | ||
handleUnexpectedResponseException(e.response, callId) | ||
throw e | ||
} | ||
} | ||
|
||
private fun handleUnexpectedResponseException( | ||
response: HttpResponse, | ||
callId: String, | ||
) { | ||
log.error( | ||
"Error while requesting from ismeroppfolging with {}, {}", | ||
StructuredArguments.keyValue("statusCode", response.status.value.toString()), | ||
callIdArgument(callId) | ||
) | ||
COUNT_CALL_MEROPPFOLGING_FAIL.increment() | ||
} | ||
|
||
companion object { | ||
const val MEROPPFOLGING_SENOPPFOLGING_KANDIDATER_API_PATH = "/api/internad/v1/senoppfolging/get-kandidater" | ||
private val log = LoggerFactory.getLogger(this::class.java) | ||
|
||
private const val CALL_MEROPPFOLGING_BASE = "${METRICS_NS}_call_ismeroppfolging" | ||
private const val CALL_MEROPPFOLGING_SUCCESS = "${CALL_MEROPPFOLGING_BASE}_success_count" | ||
private const val CALL_MEROPPFOLGING_FAIL = "${CALL_MEROPPFOLGING_BASE}_fail_count" | ||
|
||
val COUNT_CALL_MEROPPFOLGING_SUCCESS: Counter = Counter | ||
.builder(CALL_MEROPPFOLGING_SUCCESS) | ||
.description("Counts the number of successful calls to ismeroppfolging") | ||
.register(METRICS_REGISTRY) | ||
val COUNT_CALL_MEROPPFOLGING_FAIL: Counter = Counter | ||
.builder(CALL_MEROPPFOLGING_FAIL) | ||
.description("Counts the number of failed calls to ismeroppfolging") | ||
.register(METRICS_REGISTRY) | ||
} | ||
} |
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.