Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6295 Håndtere Kosovo som statsborgerskap ved sending av SED #703

Merged
merged 7 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -50,10 +51,12 @@ public class EuxConsumer implements RestConsumer {
private static final String SED_HANDLINGER = "/buc/{rinaSaksnummer}/sed/{sedId}/handlinger";
private static final String BUC_HANDLINGER = "/buc/{rinaSaksnummer}/muligeaksjoner";
private static final String RINA_LENKE_PATH = "/url/buc/{rinaSaksnummer}";
private final Environment environment;

public EuxConsumer(RestTemplate restTemplate, ObjectMapper objectMapper) {
public EuxConsumer(RestTemplate restTemplate, ObjectMapper objectMapper, Environment environment) {
this.euxRestTemplate = restTemplate;
this.objectMapper = objectMapper;
this.environment = environment;
}

public BUC hentBUC(String rinaSaksnummer) {
Expand Down Expand Up @@ -239,6 +242,15 @@ private <T> T exchange(String uri, HttpMethod method, HttpEntity<?> entity, Para
} catch (HttpClientErrorException.NotFound e) {
throw new NotFoundException("404 fra eux: " + hentFeilmeldingForEux(e), e);
} catch (RestClientException e) {
try {
String appEnvironment = environment.getProperty("APP_ENVIRONMENT");
if (appEnvironment != null && appEnvironment.equals("dev")) {
String value = objectMapper.writeValueAsString(entity.getBody());
log.info("Feil ved kall mot eux: {} sed:\n{}", e.getMessage(), value);
}
} catch (JsonProcessingException jsonProcessingException) {
log.error("Unable to serialize entity to JSON", jsonProcessingException);
fredrik-oh marked this conversation as resolved.
Show resolved Hide resolved
}
throw new IntegrationException("Feil i integrasjon mot eux: " + hentFeilmeldingForEux(e), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestInterceptor;
Expand All @@ -30,9 +31,9 @@ public EuxConsumerProducer(@Value("${melosys.integrations.euxapp-url}") String u
@Bean
@Primary
public EuxConsumer euxConsumer(RestTemplateBuilder builder, ClientConfigurationProperties clientConfigurationProperties,
OAuth2AccessTokenService oAuth2AccessTokenService, ObjectMapper objectMapper) {
OAuth2AccessTokenService oAuth2AccessTokenService, ObjectMapper objectMapper, Environment environment) {
ClientRequestInterceptor interceptor = new ClientRequestInterceptor(clientConfigurationProperties, oAuth2AccessTokenService, "eux-rina-api");
return new EuxConsumer(lagRestTemplate(builder, interceptor), objectMapper);
return new EuxConsumer(lagRestTemplate(builder, interceptor), objectMapper, environment);
}

private RestTemplate lagRestTemplate(RestTemplateBuilder restTemplateBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SedService(
sendAutomatisk: Boolean,
forsøkOppdaterEksisterende: Boolean
): BucOgSedOpprettetDto {
val gsakSaksnummer = hentGsakSaksnummer(sedDataDto)
val gsakSaksnummer = sedDataDto.gsakSaksnummer ?: throw MappingException("GsakId er påkrevd!")
log.info("Oppretter buc og sed, gsakSaksnummer: {}", gsakSaksnummer)
val mottakere = sedDataDto.mottakerIder
val sedType = bucType!!.hentFørsteLovligeSed()
Expand Down Expand Up @@ -177,6 +177,4 @@ class SedService(
log.info("gsakSaksnummer {} lagret med rinaId {}", gsakSaksnummer, opprettBucOgSedResponse.rinaSaksnummer)
return opprettBucOgSedResponse
}

private fun hentGsakSaksnummer(sedDataDto: SedDataDto): Long = sedDataDto.gsakSaksnummer ?: throw MappingException("GsakId er påkrevd!")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import java.util.*
* men er valgt på grunn av at de er i bruk i PDL og Rina. Disse gjenbruker vi i Melosys for å unngå å måtte lage egne.
*/
object LandkodeMapper {
private const val UKJENT_LANDKODE_ISO3 = "XUK"
private const val UKJENT_LANDKODE_ISO2 = "XU"
const val UKJENT_LANDKODE_ISO3 = "XUK"
const val UKJENT_LANDKODE_ISO2 = "XU"

const val KOSOVO_LANDKODE_ISO3 = "XXK" // Kosovo - XXK brukes i Nav kodeverk
const val KOSOVO_LANDKODE_ISO2 = "XK"

private const val STATSLØS_LANDKODE_ISO3 = "XXX"
private const val STATSLØS_LANDKODE_ISO2 = "XS"
Expand All @@ -21,7 +24,7 @@ object LandkodeMapper {
mapOf(
STATSLØS_LANDKODE_ISO3 to STATSLØS_LANDKODE_ISO2,
UKJENT_LANDKODE_ISO3 to UKJENT_LANDKODE_ISO2,
"XXK" to "XK", // Kosovo - XXK brukes i Nav kodeverk
KOSOVO_LANDKODE_ISO3 to KOSOVO_LANDKODE_ISO2,
)

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import no.nav.melosys.eessi.models.sed.nav.Periode;
import no.nav.melosys.eessi.models.sed.nav.*;
import no.nav.melosys.eessi.service.sed.helpers.LandkodeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import static no.nav.melosys.eessi.models.sed.Konstanter.*;
Expand All @@ -27,6 +29,8 @@
* å plukke ut nødvendig informasjon for en angitt SED.
*/
public interface SedMapper {
Logger log = LoggerFactory.getLogger(SedMapper.class);

default SED mapTilSed(SedDataDto sedData, Boolean erCDM4_3) {
var sed = new SED();
sed.setNav(prefillNav(sedData, erCDM4_3));
Expand Down Expand Up @@ -100,14 +104,20 @@ default Person hentPerson(SedDataDto sedData) {
}

default List<Statsborgerskap> hentStatsborgerskap(SedDataDto sedDataDto) {
Collection<String> statsborgerskap = sedDataDto.getBruker().getStatsborgerskap();
final List<Statsborgerskap> statsborgerskapList = statsborgerskap.stream()
Collection<String> statsborgerskapStringListe = sedDataDto.getBruker().getStatsborgerskap();
final List<Statsborgerskap> statsborgerskapList = statsborgerskapStringListe.stream()
.filter(landkodeIso3 -> LandkodeMapper.finnLandkodeIso2(landkodeIso3).isPresent())
.map(this::lagStatsborgerskap)
.toList();
for (Statsborgerskap statsborgerskap : statsborgerskapList) {
if (statsborgerskap.getLand() != null && statsborgerskap.getLand().equals(LandkodeMapper.KOSOVO_LANDKODE_ISO2)) {
statsborgerskap.setLand(LandkodeMapper.UKJENT_LANDKODE_ISO2);
log.info("Endrer statsborgerskap fra Kosovo til Ukjent. gsakSaksnummer: {}", sedDataDto.getGsakSaksnummer());
}
}
if (statsborgerskapList.isEmpty()) {
throw new MappingException("Statsborgerskap mangler eller er ugyldig. statsborgerskap fra sedData:" +
String.join(", ", statsborgerskap));
String.join(", ", statsborgerskapStringListe));
}
return statsborgerskapList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void setup() {
RestTemplate restTemplate = lagRestTemplate("", new RestTemplateBuilder(), interceptor);


euxConsumer = new EuxConsumer(restTemplate, objectMapper);
euxConsumer = new EuxConsumer(restTemplate, objectMapper, null);
server = MockRestServiceServer.createServer(restTemplate);
when(oAuth2AccessTokenService.getAccessToken(any())).thenReturn(OAuth2AccessTokenResponse.builder().accessToken("accesstoken").build());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package no.nav.melosys.eessi.service.sed

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.getunleash.FakeUnleash
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.mockk.CapturingSlot
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import no.nav.melosys.eessi.controller.dto.SedDataDto
import no.nav.melosys.eessi.models.BucType
import no.nav.melosys.eessi.models.FagsakRinasakKobling
import no.nav.melosys.eessi.models.SedType
Expand All @@ -18,12 +25,16 @@ import no.nav.melosys.eessi.models.buc.BUC
import no.nav.melosys.eessi.models.buc.Document
import no.nav.melosys.eessi.models.exception.IntegrationException
import no.nav.melosys.eessi.models.exception.MappingException
import no.nav.melosys.eessi.models.sed.SED
import no.nav.melosys.eessi.service.eux.EuxService
import no.nav.melosys.eessi.service.eux.OpprettBucOgSedResponse
import no.nav.melosys.eessi.service.saksrelasjon.SaksrelasjonService
import no.nav.melosys.eessi.service.sed.helpers.LandkodeMapper
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*

@ExtendWith(MockKExtension::class)
Expand Down Expand Up @@ -61,6 +72,30 @@ class SedServiceTest {
sedDto.rinaSaksnummer shouldBe RINA_ID
}

@Test
fun `opprettBucOgSed - Kosovo statsborgerskap skal mappes til ukjent`() {
val sedCapturingSlot = CapturingSlot<SED>()
every { euxService.opprettBucOgSed(any(), any(), capture(sedCapturingSlot), any()) } returns OpprettBucOgSedResponse(RINA_ID, "123")
every { euxService.hentRinaUrl(any()) } returns "URL"
every { saksrelasjonService.lagreKobling(any(), any(), any()) } returns mockk<FagsakRinasakKobling>()
every { euxService.sendSed(any(), any(), any()) } returns Unit

sendSedService.opprettBucOgSed(
sedDataDto = sedDataDto("mock/sedA009-Kosovo.json"),
vedlegg = setOf(SedVedlegg("tittei", "pdf".toByteArray())),
bucType = BucType.LA_BUC_01,
sendAutomatisk = true,
forsøkOppdaterEksisterende = false
)

sedCapturingSlot.captured.nav
.shouldNotBeNull()
.bruker.shouldNotBeNull()
.person.shouldNotBeNull()
.statsborgerskap.shouldHaveSize(1).single().shouldNotBeNull()
.land shouldBe LandkodeMapper.UKJENT_LANDKODE_ISO2
}

@Test
fun `opprettBucOgSed - send Sed kaster exception, forvent slett Buc og Sakrelasjon`() {
val sedData = SedDataStub.getStub()
Expand Down Expand Up @@ -195,4 +230,15 @@ class SedServiceTest {
verify { euxService.genererPdfFraSed(any()) }
pdf shouldBe mockPdf
}

private fun sedDataDto(jsonFile: String): SedDataDto =
jacksonObjectMapper().apply {
registerModule(JavaTimeModule())
}.readValue<SedDataDto>(
Files.readString(
Paths.get(
requireNotNull(SedDataStub::class.java.classLoader.getResource(jsonFile)).toURI()
)
)
)
}
99 changes: 99 additions & 0 deletions melosys-eessi-app/src/test/resources/mock/sedA009-Kosovo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"bruker" : {
"fornavn" : "TREKANTET",
"etternavn" : "ARM",
"foedseldato" : "1967-01-26",
"kjoenn" : "K",
"statsborgerskap" : [ "XXK" ],
"fnr" : "12345678901",
"harSensitiveOpplysninger" : false
},
"kontaktadresse" : null,
"oppholdsadresse" : null,
"familieMedlem" : [ ],
"søknadsperiode" : {
"fom" : "2024-10-05",
"tom" : "2024-10-06"
},
"avklartBostedsland" : "NO",
"vedtakDto" : {
"datoForrigeVedtak" : null,
"erFørstegangsvedtak" : true
},
"invalideringSedDto" : null,
"tidligereLovvalgsperioder" : [ ],
"gsakSaksnummer" : 140309382,
"mottakerIder" : [ "DK:0997" ],
"ytterligereInformasjon" : "test",
"svarAnmodningUnntak" : null,
"utpekingAvvis" : null,
"sedType" : "N/A",
"utenlandskIdent" : [ ],
"bostedsadresse" : {
"poststed" : "NOTODDEN",
"postnr" : "3675",
"land" : "NOR",
"gateadresse" : "Anundskåsveien 43 A",
"tilleggsnavn" : null,
"region" : null,
"adressetype" : "BOSTEDSADRESSE"
},
"arbeidsgivendeVirksomheter" : [ {
"navn" : "BESK KAFFE",
"adresse" : {
"poststed" : "ELVERUM",
"postnr" : "2408",
"land" : "NO",
"gateadresse" : "STENSLANDSFJELL 94",
"tilleggsnavn" : null,
"region" : null,
"adressetype" : null
},
"orgnr" : "963743254",
"type" : null
} ],
"selvstendigeVirksomheter" : [ ],
"arbeidssteder" : [ {
"navn" : "No fixed address",
"adresse" : {
"poststed" : "No fixed address",
"postnr" : null,
"land" : "DK",
"gateadresse" : null,
"tilleggsnavn" : null,
"region" : null,
"adressetype" : null
},
"fysisk" : false,
"hjemmebase" : null
} ],
"arbeidsland" : [ {
"land" : "DK",
"arbeidssted" : [ {
"navn" : "No fixed address",
"adresse" : {
"poststed" : "No fixed address",
"postnr" : null,
"land" : "DK",
"gateadresse" : null,
"tilleggsnavn" : null,
"region" : null,
"adressetype" : null
},
"fysisk" : false,
"hjemmebase" : null
} ]
} ],
"harFastArbeidssted" : false,
"lovvalgsperioder" : [ {
"lovvalgsland" : "NO",
"unntakFraLovvalgsland" : null,
"bestemmelse" : "ART_12_1",
"tilleggsBestemmelse" : null,
"fom" : "2024-10-05",
"tom" : "2024-10-06",
"unntaksBegrunnelse" : null,
"unntakFraBestemmelse" : null
} ],
"gjeldenderegler" : null
}
Loading