-
Notifications
You must be signed in to change notification settings - Fork 2
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 #3255 from navikt/feature/flytt-kontaktpersoner-ho…
…vedenhet Flytt kontaktpersoner hos arrangør til å henge på hovedenhet
- Loading branch information
Showing
17 changed files
with
328 additions
and
395 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
55 changes: 52 additions & 3 deletions
55
...api/src/main/kotlin/no/nav/mulighetsrommet/api/clients/arenaadapter/ArenaAdapterClient.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 |
---|---|---|
@@ -1,11 +1,60 @@ | ||
package no.nav.mulighetsrommet.api.clients.arenaadapter | ||
|
||
import io.ktor.client.call.* | ||
import io.ktor.client.engine.* | ||
import io.ktor.client.engine.cio.* | ||
import io.ktor.client.plugins.* | ||
import io.ktor.client.plugins.cache.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import no.nav.mulighetsrommet.domain.dto.ArenaTiltaksgjennomforingDto | ||
import no.nav.mulighetsrommet.domain.dto.ExchangeArenaIdForIdResponse | ||
import no.nav.mulighetsrommet.ktor.clients.httpJsonClient | ||
import org.slf4j.LoggerFactory | ||
import java.util.* | ||
|
||
interface ArenaAdapterClient { | ||
suspend fun exchangeTiltaksgjennomforingsArenaIdForId(arenaId: String): ExchangeArenaIdForIdResponse? | ||
private val log = LoggerFactory.getLogger(ArenaAdapterClient::class.java) | ||
|
||
suspend fun hentArenadata(id: UUID): ArenaTiltaksgjennomforingDto? | ||
class ArenaAdapterClient( | ||
private val baseUrl: String, | ||
private val machineToMachineTokenClient: () -> String, | ||
clientEngine: HttpClientEngine = CIO.create(), | ||
) { | ||
val client = httpJsonClient(clientEngine).config { | ||
install(HttpCache) | ||
} | ||
|
||
suspend fun exchangeTiltaksgjennomforingsArenaIdForId(arenaId: String): ExchangeArenaIdForIdResponse? { | ||
val response = client.get("$baseUrl/api/exchange/$arenaId") { | ||
bearerAuth( | ||
machineToMachineTokenClient.invoke(), | ||
) | ||
} | ||
|
||
return when (response.status) { | ||
HttpStatusCode.OK -> response.body() | ||
HttpStatusCode.NotFound -> { | ||
log.info("Tiltaksgjennomføring finnes ikke: $arenaId") | ||
null | ||
} | ||
else -> throw ResponseException(response, "Unexpected response from arena-adapter") | ||
} | ||
} | ||
|
||
suspend fun hentArenadata(id: UUID): ArenaTiltaksgjennomforingDto? { | ||
val response = client.get("$baseUrl/api/arenadata/$id") { | ||
bearerAuth( | ||
machineToMachineTokenClient.invoke(), | ||
) | ||
} | ||
|
||
return when (response.status) { | ||
HttpStatusCode.OK -> response.body() | ||
HttpStatusCode.NotFound -> { | ||
log.info("Tiltaksgjennomføring finnes ikke: $id") | ||
null | ||
} | ||
else -> throw ResponseException(response, "Unexpected response from arena-adapter") | ||
} | ||
} | ||
} |
60 changes: 0 additions & 60 deletions
60
...src/main/kotlin/no/nav/mulighetsrommet/api/clients/arenaadapter/ArenaAdapterClientImpl.kt
This file was deleted.
Oops, something went wrong.
46 changes: 44 additions & 2 deletions
46
...mmet-api/src/main/kotlin/no/nav/mulighetsrommet/api/clients/dialog/VeilarbdialogClient.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 |
---|---|---|
@@ -1,8 +1,50 @@ | ||
package no.nav.mulighetsrommet.api.clients.dialog | ||
|
||
import io.ktor.client.call.* | ||
import io.ktor.client.engine.* | ||
import io.ktor.client.engine.cio.* | ||
import io.ktor.client.plugins.cache.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import no.nav.mulighetsrommet.api.services.DialogRequest | ||
import no.nav.mulighetsrommet.api.services.DialogResponse | ||
import no.nav.mulighetsrommet.ktor.clients.httpJsonClient | ||
import no.nav.mulighetsrommet.securelog.SecureLog | ||
import org.slf4j.LoggerFactory | ||
|
||
interface VeilarbdialogClient { | ||
suspend fun sendMeldingTilDialogen(fnr: String, accessToken: String, requestBody: DialogRequest): DialogResponse? | ||
class VeilarbdialogClient( | ||
private val baseUrl: String, | ||
private val tokenProvider: (accessToken: String) -> String, | ||
clientEngine: HttpClientEngine = CIO.create(), | ||
) { | ||
private val log = LoggerFactory.getLogger(javaClass) | ||
|
||
private val client = httpJsonClient(clientEngine).config { | ||
install(HttpCache) | ||
} | ||
|
||
suspend fun sendMeldingTilDialogen( | ||
fnr: String, | ||
accessToken: String, | ||
requestBody: DialogRequest, | ||
): DialogResponse? { | ||
return try { | ||
val response = client.post("$baseUrl/dialog?fnr=$fnr") { | ||
bearerAuth(tokenProvider.invoke(accessToken)) | ||
header(HttpHeaders.ContentType, ContentType.Application.Json) | ||
setBody(requestBody) | ||
} | ||
|
||
if (response.status == HttpStatusCode.Conflict) { | ||
log.info("Kan ikke sende melding til dialogen, bruker oppfyller ikke kravene for digital kommunikasjon") | ||
return null | ||
} | ||
|
||
return response.body<DialogResponse>() | ||
} catch (exe: Exception) { | ||
SecureLog.logger.error("Klarte ikke sende melding til dialogen til bruker med fnr: $fnr", exe) | ||
log.error("Klarte ikke sende melding til dialogen. Se detaljer i secureLog.") | ||
null | ||
} | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
...-api/src/main/kotlin/no/nav/mulighetsrommet/api/clients/dialog/VeilarbdialogClientImpl.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.