-
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.
Browse files
Browse the repository at this point in the history
This reverts commit 38e399a.
- Loading branch information
Showing
35 changed files
with
1,876 additions
and
31 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
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApi.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,58 @@ | ||
package no.nav.syfo.api.maxdate | ||
|
||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.ApplicationCall | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.get | ||
import net.logstash.logback.argument.StructuredArguments | ||
import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer | ||
import no.nav.syfo.domain.PersonIdent | ||
import no.nav.syfo.service.SykepengerMaxDateService | ||
import no.nav.syfo.utils.* | ||
import org.slf4j.LoggerFactory | ||
import java.io.Serializable | ||
import java.time.LocalDate | ||
|
||
fun Route.registerSykepengerMaxDateAzureApi( | ||
sykepengerMaxDateService: SykepengerMaxDateService, | ||
veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer, | ||
) { | ||
val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateAzureApi") | ||
get("/api/azure/v1/sykepenger/maxdate") { | ||
val personIdent = call.personIdent() | ||
val token = call.bearerToken() | ||
val callId = call.getCallId() | ||
|
||
if (veilederTilgangskontrollConsumer.hasAccess(personIdent, token, callId)) { | ||
try { | ||
val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(personIdent.value) | ||
log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}") | ||
call.respond(SykepengerMaxDateAzureResponse(sykepengerMaxDate?.forelopig_beregnet_slutt)) | ||
} catch (e: Exception) { | ||
log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}") | ||
call.respond( | ||
HttpStatusCode.InternalServerError, | ||
"Encountered exception during fetching max date from database: ${e.message}", | ||
) | ||
} | ||
} else { | ||
val message = "Cannot fetch max date: Veileder has no access to person" | ||
log.warn("$message, {}", callIdArgument(callId)) | ||
call.respond(HttpStatusCode.Forbidden, message) | ||
} | ||
} | ||
} | ||
|
||
data class SykepengerMaxDateAzureResponse( | ||
val maxDate: LocalDate?, | ||
) : Serializable | ||
|
||
private fun ApplicationCall.personIdent(): PersonIdent = this.getPersonIdent() | ||
?: throw IllegalArgumentException("Failed to get maxDate: No $NAV_PERSONIDENT_HEADER supplied in request header") | ||
|
||
private fun ApplicationCall.bearerToken(): String = this.getBearerToken() | ||
?: throw IllegalArgumentException("Failed to get maxDate: No Authorization header supplied") | ||
|
||
private fun callIdArgument(callId: String) = StructuredArguments.keyValue("callId", callId)!! |
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApiV2.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,61 @@ | ||
package no.nav.syfo.api.maxdate | ||
|
||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.ApplicationCall | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.get | ||
import net.logstash.logback.argument.StructuredArguments | ||
import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer | ||
import no.nav.syfo.db.domain.PMaksDato | ||
import no.nav.syfo.domain.PersonIdent | ||
import no.nav.syfo.service.SykepengerMaxDateService | ||
import no.nav.syfo.utils.NAV_PERSONIDENT_HEADER | ||
import no.nav.syfo.utils.getBearerToken | ||
import no.nav.syfo.utils.getCallId | ||
import no.nav.syfo.utils.getPersonIdent | ||
import org.slf4j.LoggerFactory | ||
import java.io.Serializable | ||
|
||
fun Route.registerSykepengerMaxDateAzureApiV2( | ||
sykepengerMaxDateService: SykepengerMaxDateService, | ||
veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer, | ||
) { | ||
val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateAzureApiV2") | ||
get("/api/azure/v2/sykepenger/maxdate") { | ||
val personIdent = call.personIdent() | ||
val token = call.bearerToken() | ||
val callId = call.getCallId() | ||
|
||
if (veilederTilgangskontrollConsumer.hasAccess(personIdent, token, callId)) { | ||
try { | ||
val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(personIdent.value) | ||
log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}") | ||
call.respond(SykepengerMaxDateAzureV2Response(sykepengerMaxDate)) | ||
} catch (e: Exception) { | ||
log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}") | ||
call.respond( | ||
HttpStatusCode.InternalServerError, | ||
"Encountered exception during fetching max date from database: ${e.message}", | ||
) | ||
} | ||
} else { | ||
val message = "Cannot fetch max date: Veileder has no access to person" | ||
log.warn("$message, {}", callIdArgument(callId)) | ||
call.respond(HttpStatusCode.Forbidden, message) | ||
} | ||
} | ||
} | ||
|
||
data class SykepengerMaxDateAzureV2Response( | ||
val maxDate: PMaksDato?, | ||
) : Serializable | ||
|
||
private fun ApplicationCall.personIdent(): PersonIdent = this.getPersonIdent() | ||
?: throw IllegalArgumentException("Failed to get maxDate: No $NAV_PERSONIDENT_HEADER supplied in request header") | ||
|
||
private fun ApplicationCall.bearerToken(): String = this.getBearerToken() | ||
?: throw IllegalArgumentException("Failed to get maxDate: No Authorization header supplied") | ||
|
||
private fun callIdArgument(callId: String) = StructuredArguments.keyValue("callId", callId)!! |
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateRest.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,62 @@ | ||
package no.nav.syfo.api.maxdate | ||
|
||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.call | ||
import io.ktor.server.auth.authentication | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.get | ||
import no.nav.syfo.auth.BrukerPrincipal | ||
import no.nav.syfo.service.SykepengerMaxDateService | ||
import no.nav.syfo.utils.formatDateForLetter | ||
import org.slf4j.LoggerFactory | ||
import java.io.Serializable | ||
|
||
fun Route.registerSykepengerMaxDateRestApi( | ||
sykepengerMaxDateService: SykepengerMaxDateService, | ||
) { | ||
val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateRest") | ||
get("/api/v1/sykepenger/maxdate") { | ||
val principal: BrukerPrincipal = call.authentication.principal()!! | ||
val sykmeldtFnr = principal.fnr | ||
val isoFormat = call.request.queryParameters["isoformat"]?.toBoolean() ?: false | ||
|
||
try { | ||
val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(sykmeldtFnr) | ||
val maxDate = sykepengerMaxDate?.let { | ||
if (isoFormat) { | ||
it.forelopig_beregnet_slutt.toString() | ||
} else { | ||
formatDateForLetter(it.forelopig_beregnet_slutt) | ||
} | ||
} | ||
val utbetaltTom = sykepengerMaxDate?.let { | ||
if (isoFormat) { | ||
it.utbetalt_tom.toString() | ||
} else { | ||
formatDateForLetter(it.utbetalt_tom) | ||
} | ||
} | ||
log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}") | ||
call.respond( | ||
SykepengerMaxDateResponse( | ||
maxDate = maxDate, | ||
utbetaltTom = utbetaltTom, | ||
gjenstaendeSykedager = sykepengerMaxDate?.gjenstaende_sykedager | ||
) | ||
) | ||
} catch (e: Exception) { | ||
log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}") | ||
call.respond( | ||
HttpStatusCode.InternalServerError, | ||
"Encountered exception during fetching max date from database: ${e.message}", | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class SykepengerMaxDateResponse( | ||
val maxDate: String?, | ||
val utbetaltTom: String?, | ||
val gjenstaendeSykedager: String? | ||
) : Serializable |
Oops, something went wrong.