Skip to content

Commit

Permalink
API endringer i registreringsdata
Browse files Browse the repository at this point in the history
  • Loading branch information
JulieHillRoa committed Aug 16, 2023
1 parent edfc648 commit 4460ff7
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 3 deletions.
4 changes: 4 additions & 0 deletions nais-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ spec:
value: api://dev-gcp.okonomi.sokos-kontoregister-person/.default
- name: KONTOREGISTER_PERSON_V1_URL
value: https://sokos-kontoregister-person.intern.dev.nav.no
- name: AIA_BACKEND_URL
value: https://www.intern.dev.nav.no/aia-backend
- name: AIA_BACKEND_SCOPE
value: api://dev-gcp.paw.paw-arbeidssoker-besvarelse/.default
envFrom:
- configmap: pto-config
- configmap: loginservice-idporten
4 changes: 4 additions & 0 deletions nais-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ spec:
value: api://prod-gcp.okonomi.sokos-kontoregister-person/.default
- name: KONTOREGISTER_PERSON_V1_URL
value: https://sokos-kontoregister-person.intern.nav.no
- name: AIA_BACKEND_URL
value: https://www.nav.no/aia-backend
- name: AIA_BACKEND_SCOPE
value: api://prod-gcp.paw.paw-arbeidssoker-besvarelse/.default
envFrom:
- configmap: pto-config
- configmap: loginservice-idporten
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package no.nav.veilarbperson.client.aiabackend

import no.nav.common.health.HealthCheck
import okhttp3.Response

interface AiaBackendClient : HealthCheck {
fun hentEndringIRegistreringsdata(endringIRegistreringsdataRequestDTO: EndringIRegistreringsdataRequestDTO) : Response
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package no.nav.veilarbperson.client.aiabackend

import lombok.SneakyThrows
import no.nav.common.health.HealthCheckResult
import no.nav.common.health.HealthCheckUtils
import no.nav.common.rest.client.RestClient
import no.nav.common.rest.client.RestUtils
import no.nav.common.utils.UrlUtils.joinPaths
import org.springframework.http.HttpHeaders.ACCEPT
import org.springframework.http.MediaType.APPLICATION_JSON_VALUE
import no.nav.veilarbperson.utils.toJson
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import org.springframework.http.HttpHeaders
import java.util.function.Supplier

class AiaBackendClientImpl(private val aiaBackendUrl: String, private val userTokenSupplier: Supplier<String>) : AiaBackendClient {
private val client: OkHttpClient = RestClient.baseClient()

@SneakyThrows
override fun hentEndringIRegistreringsdata(endringIRegistreringsdataRequestDTO: EndringIRegistreringsdataRequestDTO) : Response {
val request = Request.Builder()
.url(joinPaths(aiaBackendUrl, "/veileder/besvarelse"))
.header(HttpHeaders.AUTHORIZATION, userTokenSupplier.get())
.header(ACCEPT, APPLICATION_JSON_VALUE)
.post(endringIRegistreringsdataRequestDTO.toJson().toRequestBody(RestUtils.MEDIA_TYPE_JSON))
.build()

return client.newCall(request).execute()
}

override fun checkHealth(): HealthCheckResult {
return HealthCheckUtils.pingUrl(joinPaths(aiaBackendUrl, "/internal/isReady"), client)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package no.nav.veilarbperson.client.aiabackend

data class EndringIRegistreringsdataRequestDTO(
val foedselsnummer: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import no.nav.common.rest.client.RestUtils
import no.nav.common.types.identer.Fnr
import no.nav.common.utils.AuthUtils
import no.nav.common.utils.UrlUtils
import no.nav.veilarbperson.utils.deserializeJsonOrThrow
import no.nav.veilarbperson.utils.toJson
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import no.nav.poao_tilgang.client.PoaoTilgangClient;
import no.nav.poao_tilgang.client.PoaoTilgangHttpClient;
import no.nav.poao_tilgang.client.PolicyInput;
import no.nav.veilarbperson.client.regoppslag.JsonUtils;
import no.nav.veilarbperson.utils.JsonUtils;
import no.nav.veilarbperson.client.regoppslag.RegoppslagClient;
import no.nav.veilarbperson.client.regoppslag.RegoppslagClientImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/no/nav/veilarbperson/config/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import no.nav.common.token_client.client.MachineToMachineTokenClient;
import no.nav.common.utils.Credentials;
import no.nav.common.utils.NaisUtils;
import no.nav.veilarbperson.client.aiabackend.AiaBackendClient;
import no.nav.veilarbperson.client.aiabackend.AiaBackendClientImpl;
import no.nav.veilarbperson.client.difi.DifiAccessTokenProviderImpl;
import no.nav.veilarbperson.client.difi.DifiClient;
import no.nav.veilarbperson.client.difi.DifiClientImpl;
Expand Down Expand Up @@ -64,6 +66,13 @@ public VeilarboppfolgingClient veilarboppfolgingClient(EnvironmentProperties pro
() -> authService.getAadOboTokenForTjeneste(properties.getVeilarboppfolgingScope()));
}

@Bean
public AiaBackendClient aiaBackendClient(EnvironmentProperties environmentProperties, AuthService authService) {
return new AiaBackendClientImpl(
environmentProperties.getAiaBackendUrl(),
() -> authService.getAadOboTokenForTjeneste(environmentProperties.getAiaBackendScope()));
}

@Bean
public DigdirClient digdirClient(EnvironmentProperties properties, MachineToMachineTokenClient tokenClient) {
return new DigdirClientImpl(properties.getKrrUrl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public class EnvironmentProperties {
private String veilarbregistreringUrl;
private String kontoregisterScope;
private String kontoregisterUrl;
private String aiaBackendUrl;
private String aiaBackendScope;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public ResponseEntity<String> registrering(@RequestParam(value = "fnr") Fnr fnr)
return registreringService.hentRegistrering(fnr);
}

@GetMapping("/registrering/endringer")
public ResponseEntity<String> endringIRegistreringdata(@RequestParam(value = "fnr") Fnr fnr) {
authService.stoppHvisEksternBruker();
authService.sjekkLesetilgang(fnr);
return registreringService.hentEndringIRegistreringsdata(fnr);
}

// TODO: Det er hårete å måtte skille på ekstern og intern
// Lag istedenfor en egen controller for interne operasjoner og en annen for eksterne
private Fnr hentIdentForEksternEllerIntern(Fnr queryParamFnr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import no.nav.common.types.identer.Fnr;
import no.nav.veilarbperson.client.aiabackend.AiaBackendClient;
import no.nav.veilarbperson.client.aiabackend.EndringIRegistreringsdataRequestDTO;
import no.nav.veilarbperson.client.veilarbregistrering.VeilarbregistreringClient;
import okhttp3.Response;
import okhttp3.ResponseBody;
Expand All @@ -14,6 +16,7 @@
public class RegistreringService {

private final VeilarbregistreringClient client;
private final AiaBackendClient aiaBackendClient;

@SneakyThrows
public ResponseEntity<String> hentRegistrering(Fnr fnr) {
Expand All @@ -31,4 +34,21 @@ public ResponseEntity<String> hentRegistrering(Fnr fnr) {
.body(bodyString);
}
}

@SneakyThrows
public ResponseEntity<String> hentEndringIRegistreringsdata(Fnr fnr) {
try (Response response = aiaBackendClient.hentEndringIRegistreringsdata(new EndringIRegistreringsdataRequestDTO(fnr.get()));
ResponseBody responseBody = response.body()) {

String bodyString = null;

if (responseBody != null) {
bodyString = responseBody.string();
}

return ResponseEntity
.status(response.code())
.body(bodyString);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.veilarbperson.client.regoppslag
package no.nav.veilarbperson.utils

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import com.fasterxml.jackson.module.kotlin.KotlinModule
import no.nav.common.rest.client.RestUtils
import okhttp3.Response
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ app.env.veilarbregistreringScope=${VEILARBREGISTRERING_SCOPE}
app.env.veilarbregistreringUrl=${VEILARBREGISTRERING_URL}
app.env.kontoregisterScope=${KONTOREGISTER_PERSON_V1_SCOPE}
app.env.kontoregisterUrl=${KONTOREGISTER_PERSON_V1_URL}
app.env.aiaBackendUrl=${AIA_BACKEND_URL}
app.env.aiaBackendScope=${AIA_BACKEND_SCOPE}

# From config map "loginservice-idporten"
app.env.loginserviceIdportenAudience=${LOGINSERVICE_IDPORTEN_AUDIENCE}
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/no/nav/veilarbperson/config/ClientTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import no.nav.common.types.identer.AktorId;
import no.nav.common.types.identer.EksternBrukerId;
import no.nav.common.types.identer.Fnr;
import no.nav.veilarbperson.client.aiabackend.AiaBackendClient;
import no.nav.veilarbperson.client.aiabackend.EndringIRegistreringsdataRequestDTO;
import no.nav.veilarbperson.client.difi.DifiClient;
import no.nav.veilarbperson.client.difi.HarLoggetInnRespons;
import no.nav.veilarbperson.client.digdir.DigdirClient;
Expand All @@ -30,6 +32,7 @@
import no.nav.veilarbperson.client.veilarbregistrering.VeilarbregistreringClient;
import no.nav.veilarbperson.client.veilarbregistrering.VeilarbregistreringClientImpl;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;
import org.springframework.cloud.contract.wiremock.WireMockConfiguration;
import org.springframework.cloud.contract.wiremock.WireMockConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -201,6 +204,22 @@ public HealthCheckResult checkHealth() {
};
}

@Bean
public AiaBackendClient aiaBackendClient() {
return new AiaBackendClient() {
@NotNull
@Override
public Response hentEndringIRegistreringsdata(@NotNull EndringIRegistreringsdataRequestDTO endringIRegistreringsdataRequestDTO) {
return null;
}

@Override
public HealthCheckResult checkHealth() {
return HealthCheckResult.healthy();
}
};
}

@Bean
public PdlClient pdlClient() {
return new PdlClient() {
Expand Down

0 comments on commit 4460ff7

Please sign in to comment.