From 13ba7dc212efd920ae9c9268f3ea952d308b7250 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Tue, 8 Oct 2024 10:18:07 +0200 Subject: [PATCH 1/9] Add repository methods for counting and finding Idents Introduced new methods in `IdentRepository` to count and find `Ident` entities based on various parameters including `Rekvireringsstatus`, `Identtype`, `Syntetisk`, `Kjoenn`, and date range. Updated `DatabaseService` to utilize these new repository methods, enhancing the service's querying capabilities. --- .../identpool/repository/IdentRepository.java | 36 ++++++++++++++++++ .../identpool/service/DatabaseService.java | 38 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/repository/IdentRepository.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/repository/IdentRepository.java index e1019be2f7a..49a6beddeea 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/repository/IdentRepository.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/repository/IdentRepository.java @@ -55,4 +55,40 @@ Page findAll(@Param("rekvireringsstatus") Rekvireringsstatus rekvirerings @Param("identtype") Identtype identtype, @Param("kjoenn") Kjoenn kjoenn, @Param("foedtFoer") LocalDate foedtFoer, @Param("foedtEtter") LocalDate foedtEtter, @Param("syntetisk") boolean syntetisk, Pageable pageable); + + @Query + int countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( + Rekvireringsstatus rekvireringsstatus, + Identtype identtype, + Boolean syntetisk, + LocalDate foedtEtter, + LocalDate foedtFoer); + + @Query + int countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( + Rekvireringsstatus rekvireringsstatus, + Identtype identtype, + Boolean syntetisk, + Kjoenn kjoenn, + LocalDate foedtEtter, + LocalDate foedtFoer); + + @Query + Page findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( + Rekvireringsstatus rekvireringsstatus, + Identtype identtype, + Boolean syntetisk, + LocalDate foedtEtter, + LocalDate foedtFoer, + Pageable pageable); + + @Query + Page findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( + Rekvireringsstatus rekvireringsstatus, + Identtype identtype, + Boolean syntetisk, + Kjoenn kjoenn, + LocalDate foedtEtter, + LocalDate foedtFoer, + Pageable pageable); } diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java index 9113e859dee..ab9579e7172 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java @@ -8,6 +8,7 @@ import no.nav.testnav.identpool.repository.IdentRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.security.SecureRandom; @@ -15,8 +16,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; +import static java.util.Objects.nonNull; import static org.apache.commons.lang3.BooleanUtils.isTrue; @Service @@ -63,4 +66,39 @@ private Page findPage(HentIdenterRequest request, Rekvireringsstatus rekv rekvireringsstatus, request.getIdenttype(), request.getKjoenn(), request.getFoedtFoer(), request.getFoedtEtter(), isTrue(request.getSyntetisk()), PageRequest.of(page, request.getAntall())); } + + private int getAntall(HentIdenterRequest request, + Rekvireringsstatus rekvireringsstatus) { + + return nonNull(request.getKjoenn()) ? + + identRepository.countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( + rekvireringsstatus, request.getIdenttype(), + isTrue(request.getSyntetisk()), request.getKjoenn(), + request.getFoedtEtter(), request.getFoedtFoer()) : + + identRepository.countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( + rekvireringsstatus, request.getIdenttype(), + isTrue(request.getSyntetisk()), + request.getFoedtEtter(), request.getFoedtFoer()); + } + + private Page findPage(HentIdenterRequest request, + Rekvireringsstatus rekvireringsstatus, + Pageable page) { + + return nonNull(request.getKjoenn()) ? + + identRepository.findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( + rekvireringsstatus, request.getIdenttype(), + isTrue(request.getSyntetisk()), request.getKjoenn(), + request.getFoedtEtter(), request.getFoedtFoer(), page + ) : + + identRepository.findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( + rekvireringsstatus, request.getIdenttype(), + isTrue(request.getSyntetisk()), + request.getFoedtEtter(), request.getFoedtFoer(), page + ); + } } From ac3a91452b82d8f6ee57bd4d0afe006d7b88c2d1 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Wed, 9 Oct 2024 10:22:41 +0200 Subject: [PATCH 2/9] Refactor Ident fetching logic and add H2 support #deploy-testnav-ident-pool Revised methods for fetching and counting Idents in `DatabaseService` to improve query efficiency. Enabled H2 database console for local development and included sample data for testing. Adjusted security configurations to accommodate new endpoints and data sources. --- .../identpool/config/SecurityConfig.java | 24 ++++--- .../identpool/service/DatabaseService.java | 68 +++++++------------ .../service/IdentGeneratorService.java | 25 ++++--- .../identpool/service/PoolService.java | 5 +- .../src/main/resources/application-local.yml | 34 ++++------ .../src/main/resources/application-prod.yaml | 7 +- .../src/main/resources/application.yaml | 5 -- .../resources/db/dev/h2-default-config.sql | 34 ++++++++++ 8 files changed, 106 insertions(+), 96 deletions(-) create mode 100644 apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/SecurityConfig.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/SecurityConfig.java index b4f02ff8b89..3b917270a0c 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/SecurityConfig.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/SecurityConfig.java @@ -6,6 +6,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; @@ -19,15 +20,20 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti httpSecurity.sessionManagement(sessionConfig -> sessionConfig.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authorizeConfig -> authorizeConfig.requestMatchers( - "/internal/**", - "/webjars/**", - "/swagger-resources/**", - "/v3/api-docs/**", - "/swagger-ui/**", - "/swagger", - "/error", - "/swagger-ui.html" - ).permitAll().requestMatchers("/api/**").fullyAuthenticated()) + "/internal/**", + "/webjars/**", + "/swagger-resources/**", + "/v3/api-docs/**", + "/swagger-ui/**", + "/swagger", + "/error", + "/swagger-ui.html", + "/h2/**", + "/member/**") + .permitAll() + .requestMatchers("/api/**") + .fullyAuthenticated()) + .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) .oauth2ResourceServer(oauth2RSConfig -> oauth2RSConfig.jwt(Customizer.withDefaults())); return httpSecurity.build(); diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java index ab9579e7172..1c75f38baee 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/DatabaseService.java @@ -12,11 +12,8 @@ import org.springframework.stereotype.Service; import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; -import java.util.List; -import java.util.Objects; +import java.util.Random; import java.util.Set; import static java.util.Objects.nonNull; @@ -26,77 +23,58 @@ @RequiredArgsConstructor public class DatabaseService { + private static final Random RANDOM = new SecureRandom(); + private final IdentRepository identRepository; private final MapperFacade mapperFacade; public Set hentLedigeIdenterFraDatabase(HentIdenterRequest request) { - Set identEntities = new HashSet<>(); - - HentIdenterRequest availableIdentsRequest = mapperFacade.map(request, HentIdenterRequest.class); - - var firstPage = findPage(availableIdentsRequest, Rekvireringsstatus.LEDIG, 0); - var pageCache = new HashMap>(); - pageCache.put(0, firstPage); - - int totalPages = firstPage.getTotalPages(); - if (totalPages > 0) { - List usedIdents = new ArrayList<>(); - SecureRandom rand = new SecureRandom(); - for (var i = 0; i < request.getAntall(); i++) { - var randomPageNumber = rand.nextInt(totalPages); - pageCache.computeIfAbsent(randomPageNumber, k -> - findPage(availableIdentsRequest, Rekvireringsstatus.LEDIG, randomPageNumber)); - - List content = pageCache.get(randomPageNumber).getContent(); - for (Ident ident : content) { - if (!usedIdents.contains(ident.getPersonidentifikator())) { - usedIdents.add(ident.getPersonidentifikator()); - identEntities.add(ident); - break; - } - } - } + + var availableIdentsRequest = mapperFacade.map(request, HentIdenterRequest.class); + + var antall = getAntall(availableIdentsRequest); + + if (antall == 0) { + return new HashSet<>(); } - return identEntities; - } - private Page findPage(HentIdenterRequest request, Rekvireringsstatus rekvireringsstatus, int page) { + if (antall > request.getAntall()) { + var resultat = getPage(request, PageRequest.of(RANDOM.nextInt(antall/request.getAntall()), request.getAntall())); + return new HashSet<>(resultat.getContent()); + } - return identRepository.findAll( - rekvireringsstatus, request.getIdenttype(), request.getKjoenn(), request.getFoedtFoer(), - request.getFoedtEtter(), isTrue(request.getSyntetisk()), PageRequest.of(page, request.getAntall())); + return new HashSet<>( + getPage(request, PageRequest.of(0, request.getAntall())) + .getContent()); } - private int getAntall(HentIdenterRequest request, - Rekvireringsstatus rekvireringsstatus) { + private int getAntall(HentIdenterRequest request) { return nonNull(request.getKjoenn()) ? identRepository.countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( - rekvireringsstatus, request.getIdenttype(), + Rekvireringsstatus.LEDIG, request.getIdenttype(), isTrue(request.getSyntetisk()), request.getKjoenn(), request.getFoedtEtter(), request.getFoedtFoer()) : identRepository.countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( - rekvireringsstatus, request.getIdenttype(), + Rekvireringsstatus.LEDIG, request.getIdenttype(), isTrue(request.getSyntetisk()), request.getFoedtEtter(), request.getFoedtFoer()); } - private Page findPage(HentIdenterRequest request, - Rekvireringsstatus rekvireringsstatus, - Pageable page) { + private Page getPage(HentIdenterRequest request, Pageable page) { return nonNull(request.getKjoenn()) ? identRepository.findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( - rekvireringsstatus, request.getIdenttype(), + Rekvireringsstatus.LEDIG, request.getIdenttype(), isTrue(request.getSyntetisk()), request.getKjoenn(), request.getFoedtEtter(), request.getFoedtFoer(), page ) : identRepository.findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( - rekvireringsstatus, request.getIdenttype(), + Rekvireringsstatus.LEDIG, request.getIdenttype(), isTrue(request.getSyntetisk()), request.getFoedtEtter(), request.getFoedtFoer(), page ); diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/IdentGeneratorService.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/IdentGeneratorService.java index d17c7a5ae2d..3de97f20546 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/IdentGeneratorService.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/IdentGeneratorService.java @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Set; import java.util.function.BiFunction; import java.util.function.Function; @@ -31,7 +32,7 @@ public class IdentGeneratorService { private static final int SYNTETISK = 4; - private static final SecureRandom random = new SecureRandom(); + private static final Random random = new SecureRandom(); private static String addSyntetiskIdentifier(String format) { return String.format("%s%1d%s", format.substring(0, 2), Integer.parseInt(format.substring(2, 3)) + SYNTETISK, format.substring(3)); @@ -67,15 +68,14 @@ public Set genererIdenter(HentIdenterRequest request, Set idente request.setFoedtFoer(request.getFoedtEtter().plusDays(1)); } - var identer = identerIIdentPool; - var antall = request.getAntall() + identer.size(); + var antall = request.getAntall() + identerIIdentPool.size(); var iteratorRange = (request.getKjoenn() == null) ? 1 : 2; var numberOfDates = toIntExact(ChronoUnit.DAYS.between(request.getFoedtEtter(), request.getFoedtFoer())); Function numberFormat = numberFormatter.getOrDefault(request.getIdenttype(), IdentGeneratorUtil::randomFormat); - while (identer.size() < antall) { + while (identerIIdentPool.size() < antall) { var birthdate = request.getFoedtEtter().plusDays(random.nextInt(numberOfDates)); var format = numberFormat.apply(birthdate); if (isTrue(request.getSyntetisk())) { @@ -83,29 +83,32 @@ public Set genererIdenter(HentIdenterRequest request, Set idente } var yearRange = getYearRange(birthdate); - var originalSize = identer.size(); + var originalSize = identerIIdentPool.size(); var genderNumber = getGenderNumber(yearRange, request.getKjoenn()); var startIndex = getStartIndex(yearRange.get(0), request.getKjoenn()); for (int i = startIndex; identerIIdentPool.size() == originalSize && i < genderNumber; i += iteratorRange) { String fnr = generateFnr(String.format(format, i)); if (fnr != null) { - identer.add(fnr); + identerIIdentPool.add(fnr); } } - for (int i = genderNumber; identer.size() == originalSize && i < yearRange.get(1); i += iteratorRange) { - String fnr = generateFnr(String.format(format, i)); + for (int i = genderNumber; identerIIdentPool.size() == originalSize && i < yearRange.get(1); i += iteratorRange) { + var fnr = generateFnr(String.format(format, i)); if (fnr != null) { - identer.add(fnr); + identerIIdentPool.add(fnr); } } if (identerIIdentPool.size() == originalSize) { - throw new IllegalArgumentException("Kan ikke finne ønsket antall fødselsnummer med angitte kriterier"); + break; } } - return identer; + if (identerIIdentPool.isEmpty()) { + throw new IllegalArgumentException("Finner ingen fødselsnummer med angitte kriterier"); + } + return identerIIdentPool; } private void validateDates(LocalDate foedtEtter, LocalDate foedtFoer) { diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java index 12468574b74..3e3bcb94828 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java @@ -3,7 +3,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import no.nav.testnav.identpool.domain.Ident; -import no.nav.testnav.identpool.domain.Identtype; import no.nav.testnav.identpool.domain.Rekvireringsstatus; import no.nav.testnav.identpool.dto.TpsStatusDTO; import no.nav.testnav.identpool.exception.ForFaaLedigeIdenterException; @@ -14,7 +13,6 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import static java.lang.String.format; import static java.time.format.DateTimeFormatter.ISO_DATE; @@ -69,7 +67,8 @@ public synchronized List allocateIdenter(HentIdenterRequest request) { if (missingIdentCount > 0) { - var tpsStatusDTOS = identerAvailService.generateAndCheckIdenter(request, ATTEMPT_OBTAIN); + var tpsStatusDTOS = identerAvailService.generateAndCheckIdenter(request, + isTrue(request.getSyntetisk()) ? ATTEMPT_OBTAIN * 6 : ATTEMPT_OBTAIN); List identerFraTps = tpsStatusDTOS.stream() .map(this::buildIdent) diff --git a/apps/testnav-ident-pool/src/main/resources/application-local.yml b/apps/testnav-ident-pool/src/main/resources/application-local.yml index dab53564868..69e57990421 100644 --- a/apps/testnav-ident-pool/src/main/resources/application-local.yml +++ b/apps/testnav-ident-pool/src/main/resources/application-local.yml @@ -1,27 +1,17 @@ spring: - cloud: - vault: - connection-timeout: 15000 - fail-fast: true - host: vault.adeo.no - port: 443 - read-timeout: 30000 + h2: + console: + enabled: true + path: /h2 datasource: - hikari: - maximum-pool-size: 3 - minimum-idle: 1 - url: jdbc:postgresql://localhost:5432/ident-pool-test - username: postgres - flyway: - baseline-on-migrate: true - enabled: true # Disabled by default as you should probably think twice before running Flyway-migrations - locations: classpath:/db/migration - jpa: - properties: - hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect - default-schema: public - showSql: true + url: jdbc:h2:mem:testdb + username: sa + password: + driverClassName: org.h2.Driver + sql: + init: + mode: always + data-locations: classpath:/db/dev/h2-default-config.sql consumers: tps: diff --git a/apps/testnav-ident-pool/src/main/resources/application-prod.yaml b/apps/testnav-ident-pool/src/main/resources/application-prod.yaml index 1e3bd334c34..6ca2a2eedec 100644 --- a/apps/testnav-ident-pool/src/main/resources/application-prod.yaml +++ b/apps/testnav-ident-pool/src/main/resources/application-prod.yaml @@ -1,8 +1,13 @@ spring: + oauth2: + tokenx: + issuer-uri: ${TOKEN_X_ISSUER} + jwk-set-uri: ${TOKEN_X_JWKS_URI} + accepted-audience: ${TOKEN_X_CLIENT_ID} datasource: url: jdbc:postgresql://${NAIS_DATABASE_TESTNAV_IDENTPOOL_TESTNAV_IDENTPOOL_HOST}:${NAIS_DATABASE_TESTNAV_IDENTPOOL_TESTNAV_IDENTPOOL_PORT}/${NAIS_DATABASE_TESTNAV_IDENTPOOL_TESTNAV_IDENTPOOL_DATABASE}?user=${NAIS_DATABASE_TESTNAV_IDENTPOOL_TESTNAV_IDENTPOOL_USERNAME}&password=${NAIS_DATABASE_TESTNAV_IDENTPOOL_TESTNAV_IDENTPOOL_PASSWORD} driverClassName: org.postgresql.Driver hikari: maximum-pool-size: 3 - minimum-idle: 1 \ No newline at end of file + minimum-idle: 1 diff --git a/apps/testnav-ident-pool/src/main/resources/application.yaml b/apps/testnav-ident-pool/src/main/resources/application.yaml index f411431ba17..1aa6e5379e4 100644 --- a/apps/testnav-ident-pool/src/main/resources/application.yaml +++ b/apps/testnav-ident-pool/src/main/resources/application.yaml @@ -45,11 +45,6 @@ spring: issuer-uri: https://login.microsoftonline.com/62366534-1ec3-4962-8869-9b5535279d0b/v2.0 #The client_id of this application accepted-audience: ${azure.app.client.id}, api://${azure.app.client.id} - tokenx: - issuer-uri: ${TOKEN_X_ISSUER} - jwk-set-uri: ${TOKEN_X_JWKS_URI} - accepted-audience: ${TOKEN_X_CLIENT_ID} - springdoc: swagger-ui: diff --git a/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql b/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql new file mode 100644 index 00000000000..818c31b1025 --- /dev/null +++ b/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql @@ -0,0 +1,34 @@ + +insert into personidentifikator values(1,'FNR','13048226064','I_BRUK',false,'1982-04-13','KVINNE','TPS',false); +insert into personidentifikator values(2,'FNR','03058225613','I_BRUK',false,'1982-05-03','KVINNE','TPS',false); +insert into personidentifikator values(3,'FNR','25078225966','I_BRUK',false,'1982-07-25','MANN','TPS',false); +insert into personidentifikator values(4,'FNR','16118225841','I_BRUK',false,'1982-11-16','KVINNE','TPS',false); +insert into personidentifikator values(5,'FNR','30128225516','I_BRUK',false,'1982-12-30','MANN','TPS',false); +insert into personidentifikator values(6,'FNR','03128225772','I_BRUK',false,'1982-12-03','MANN','TPS',false); +insert into personidentifikator values(7,'FNR','22098225777','I_BRUK',false,'1982-09-22','MANN','TPS',false); +insert into personidentifikator values(8,'FNR','26028225864','I_BRUK',false,'1982-02-26','KVINNE','TPS',false); +insert into personidentifikator values(9,'FNR','09048225990','I_BRUK',false,'1982-04-09','MANN','TPS',false); +insert into personidentifikator values(10,'FNR','14496205422','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(11,'FNR','14496208650','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(12,'FNR','14496201087','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(13,'FNR','14496209444','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(14,'FNR','14496205260','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(15,'FNR','14496209282','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(16,'FNR','14496200889','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(17,'FNR','14496201834','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(18,'FNR','14496202628','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(19,'FNR','14496206801','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(20,'FNR','14496201672','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(21,'FNR','14496204205','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(22,'FNR','14496203411','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(23,'FNR','14496202466','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(24,'FNR','14496205856','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(25,'FNR','14496204043','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(26,'FNR','14496208227','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(27,'FNR','14496206488','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(28,'FNR','14496203098','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(29,'FNR','14496205694','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(30,'FNR','14496207433','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(31,'FNR','14496209010','LEDIG',false,'1962-09-14','KVINNE',null,true); + +commit; \ No newline at end of file From 029baed8dc3cb3dbb7b1ff7abf120dc0a5c0ee78 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Wed, 9 Oct 2024 11:01:40 +0200 Subject: [PATCH 3/9] Update tests to handle potential insufficient identifiers #deploy-testnav-ident-pool Modified the tests to ensure that identifier generation does not throw an exception when the desired amount of identifiers cannot be generated. Instead, the tests now assert that the resulting set size is less than the requested amount. --- .../service/IdentGeneratorServiceTest.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/testnav-ident-pool/src/test/java/no/nav/testnav/identpool/service/IdentGeneratorServiceTest.java b/apps/testnav-ident-pool/src/test/java/no/nav/testnav/identpool/service/IdentGeneratorServiceTest.java index 6cdf0ae0a3f..6a192cef89b 100644 --- a/apps/testnav-ident-pool/src/test/java/no/nav/testnav/identpool/service/IdentGeneratorServiceTest.java +++ b/apps/testnav-ident-pool/src/test/java/no/nav/testnav/identpool/service/IdentGeneratorServiceTest.java @@ -32,7 +32,7 @@ class IdentGeneratorServiceTest { private static final int START_1900 = 0; private static final int GENERATE_SIZE = 100; - private final LocalDate LOCAL_DATE = LocalDate.now(); + private final LocalDate timeNow = LocalDate.now(); private final IdentGeneratorService identGeneratorService = new IdentGeneratorService(); @@ -41,7 +41,7 @@ class IdentGeneratorServiceTest { void shouldThrowToDateAfterFromDate() { var request = createRequest(Identtype.FNR, Kjoenn.MANN) - .foedtFoer(LOCAL_DATE.minusDays(2)) + .foedtFoer(timeNow.minusDays(2)) .build(); Set result = new HashSet<>(); @@ -51,24 +51,24 @@ void shouldThrowToDateAfterFromDate() { } @Test - @DisplayName("Skal feile når ønsket antall ikke kan genereres") - void shouldThrowToFewIdents() { + @DisplayName("Skal ikke feile når ønsket antall ikke kan genereres") + void shouldNotThrowTooFewIdents() { + var requestedAmount = 500; var request = createRequest(Identtype.FNR, Kjoenn.MANN) - .antall(500) + .antall(requestedAmount) .build(); - Set result = new HashSet<>(); + var result = identGeneratorService.genererIdenter(request, new HashSet<>()); - assertThrows(IllegalArgumentException.class, - () -> identGeneratorService.genererIdenter(request, result)); + assertThat(result.size(), is(lessThan(requestedAmount))); } @Test @DisplayName("Skal ikke generere identer i sortert rekkefølge") void fnrGenererDescendingTest() { // This test will stop working 1. Jan 2040 :( - LocalDate localDate = LocalDate.now(); + var localDate = LocalDate.now(); Map> pinMap = identGeneratorService.genererIdenterMap(localDate, localDate.plusDays(1), Identtype.FNR, false); assertThat(pinMap.size(), is(equalTo(1))); @@ -82,9 +82,9 @@ void fnrGenererKjonnKriterier() { Set kvinner = generateIdents(Identtype.FNR, Kjoenn.KVINNE); assertThat(menn.size(), is(equalTo(GENERATE_SIZE))); - menn.forEach(fnr -> assertFnrValues(fnr, Kjoenn.MANN, LOCAL_DATE)); + menn.forEach(fnr -> assertFnrValues(fnr, Kjoenn.MANN, timeNow)); assertThat(kvinner.size(), is(equalTo(GENERATE_SIZE))); - kvinner.forEach(fnr -> assertFnrValues(fnr, Kjoenn.KVINNE, LOCAL_DATE)); + kvinner.forEach(fnr -> assertFnrValues(fnr, Kjoenn.KVINNE, timeNow)); } @Test @@ -94,9 +94,9 @@ void dnrGenererKjonnKriterier() { Set kvinner = generateIdents(Identtype.DNR, Kjoenn.KVINNE); assertThat(menn.size(), is(equalTo(GENERATE_SIZE))); - menn.forEach(dnr -> assertDnrValues(dnr, Kjoenn.MANN, LOCAL_DATE)); + menn.forEach(dnr -> assertDnrValues(dnr, Kjoenn.MANN, timeNow)); assertThat(kvinner.size(), is(equalTo(GENERATE_SIZE))); - kvinner.forEach(dnr -> assertDnrValues(dnr, Kjoenn.KVINNE, LOCAL_DATE)); + kvinner.forEach(dnr -> assertDnrValues(dnr, Kjoenn.KVINNE, timeNow)); } @Test @@ -106,22 +106,22 @@ void bostGenererKjonnKriterier() { Set kvinner = generateIdents(Identtype.BOST, Kjoenn.KVINNE); assertThat(menn.size(), is(equalTo(GENERATE_SIZE))); - menn.forEach(bnr -> assertBnrValues(bnr, Kjoenn.MANN, LOCAL_DATE)); + menn.forEach(bnr -> assertBnrValues(bnr, Kjoenn.MANN, timeNow)); assertThat(kvinner.size(), is(equalTo(GENERATE_SIZE))); - kvinner.forEach(bnr -> assertBnrValues(bnr, Kjoenn.KVINNE, LOCAL_DATE)); + kvinner.forEach(bnr -> assertBnrValues(bnr, Kjoenn.KVINNE, timeNow)); } private Set generateIdents(Identtype identtype, Kjoenn kjoenn) { return identGeneratorService.genererIdenter( - createRequest(identtype, kjoenn).build(), new HashSet()); + createRequest(identtype, kjoenn).build(), new HashSet<>()); } private HentIdenterRequest.HentIdenterRequestBuilder createRequest(Identtype identtype, Kjoenn kjoenn) { return HentIdenterRequest.builder() .identtype(identtype) .antall(GENERATE_SIZE) - .foedtEtter(LOCAL_DATE) - .foedtFoer(LOCAL_DATE) + .foedtEtter(timeNow) + .foedtFoer(timeNow) .kjoenn(kjoenn); } From 24002d6e92a7c7100943f049da6aa9e7e0b3c0d7 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Wed, 9 Oct 2024 12:23:58 +0200 Subject: [PATCH 4/9] Configure HikariCP datasource properties #deploy-testnav-ident-pool Added HikariCP datasource configuration with minimum idle connections set to 10 and maximum pool size set to 100 to improve database connection management. This change is intended to optimize performance and resource utilization. --- apps/testnav-ident-pool/src/main/resources/application.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/testnav-ident-pool/src/main/resources/application.yaml b/apps/testnav-ident-pool/src/main/resources/application.yaml index 1aa6e5379e4..027f8d20270 100644 --- a/apps/testnav-ident-pool/src/main/resources/application.yaml +++ b/apps/testnav-ident-pool/src/main/resources/application.yaml @@ -38,6 +38,10 @@ spring: default-schema: public dialect: org.hibernate.dialect.PostgreSQLDialect showSql: true + datasource: + hikari: + minimum-idle: 10 + maximum-pool-size: 100 security: oauth2: resourceserver: From 44ded2e8bff874a53f7ddd9c4e9ea298d543b89a Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Wed, 9 Oct 2024 12:40:07 +0200 Subject: [PATCH 5/9] Create index for syntetisk in personidentifikator #deploy-testnav-ident-pool This commit adds a new SQL migration script (V1.3.1__IndeksSyntetisk.sql) that creates an index for the 'syntetisk' column in the 'personidentifikator' table. This change is aimed at improving query performance involving the 'syntetisk' column. --- .../main/resources/db/migration/V1.3.1__IndeksSyntetisk.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 apps/testnav-ident-pool/src/main/resources/db/migration/V1.3.1__IndeksSyntetisk.sql diff --git a/apps/testnav-ident-pool/src/main/resources/db/migration/V1.3.1__IndeksSyntetisk.sql b/apps/testnav-ident-pool/src/main/resources/db/migration/V1.3.1__IndeksSyntetisk.sql new file mode 100644 index 00000000000..663b0e8b703 --- /dev/null +++ b/apps/testnav-ident-pool/src/main/resources/db/migration/V1.3.1__IndeksSyntetisk.sql @@ -0,0 +1,6 @@ +--------------------------------- +-- C R E A T E I N D E X E S -- +--------------------------------- + +create index idx_syntetisk_personidendifikator + on personidentifikator(syntetisk); \ No newline at end of file From c304c12ad443adff9e5907768116b394d38bd029 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Wed, 9 Oct 2024 15:36:51 +0200 Subject: [PATCH 6/9] Update PostgreSQL version in config to 16 #deploy-testnav-ident-pool Changed the PostgreSQL version from 15 to 16 in the configuration file. This update ensures compatibility with the latest features and improvements provided by PostgreSQL 16. --- apps/testnav-ident-pool/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/testnav-ident-pool/config.yml b/apps/testnav-ident-pool/config.yml index a029e5d1348..6f16dd191fc 100644 --- a/apps/testnav-ident-pool/config.yml +++ b/apps/testnav-ident-pool/config.yml @@ -68,7 +68,7 @@ spec: cluster: dev-gcp gcp: sqlInstances: - - type: POSTGRES_15 + - type: POSTGRES_16 tier: db-custom-2-7680 name: testnav-identpool databases: From 827e689d691a4cee35459f99e91c1dabf6d5564f Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Wed, 9 Oct 2024 16:13:16 +0200 Subject: [PATCH 7/9] Increase CPU request limit from 200m to 600m in config.yml #deploy-testnav-ident-pool Adjusting the CPU request limit ensures that the application has sufficient resources to handle increased load. This change aims to prevent potential performance issues under higher demand. --- apps/testnav-ident-pool/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/testnav-ident-pool/config.yml b/apps/testnav-ident-pool/config.yml index 6f16dd191fc..5751ddbecf3 100644 --- a/apps/testnav-ident-pool/config.yml +++ b/apps/testnav-ident-pool/config.yml @@ -52,7 +52,7 @@ spec: limits: memory: 4096Mi requests: - cpu: 200m + cpu: 600m memory: 2048Mi accessPolicy: inbound: From 669e83a25af27685e27b640c482ff995affaa045 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Mon, 14 Oct 2024 08:52:35 +0200 Subject: [PATCH 8/9] Add new records and tweak logging in PoolService #deploy-testnav-ident-pool Inserted additional `personidentifikator` entries to the H2 database initialization script and adjusted the sequence restart point. Enhanced logging in `PoolService` to include the count of generated identifiers and increased the number of attempts for synthetic identifier generation. --- .../identpool/service/PoolService.java | 8 +- .../resources/db/dev/h2-default-config.sql | 73 +++++++++++-------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java index 3e3bcb94828..b641733d602 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java @@ -67,10 +67,12 @@ public synchronized List allocateIdenter(HentIdenterRequest request) { if (missingIdentCount > 0) { - var tpsStatusDTOS = identerAvailService.generateAndCheckIdenter(request, - isTrue(request.getSyntetisk()) ? ATTEMPT_OBTAIN * 6 : ATTEMPT_OBTAIN); + var statusDTOS = identerAvailService.generateAndCheckIdenter(request, + isTrue(request.getSyntetisk()) ? ATTEMPT_OBTAIN * 12 : ATTEMPT_OBTAIN); - List identerFraTps = tpsStatusDTOS.stream() + log.info("Generert {} identer ved mining", statusDTOS.size()); + + List identerFraTps = statusDTOS.stream() .map(this::buildIdent) .toList(); identRepository.saveAll(identerFraTps); diff --git a/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql b/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql index 818c31b1025..7351d87c2cb 100644 --- a/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql +++ b/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql @@ -1,34 +1,43 @@ +insert into personidentifikator values(1,'FNR','30451075868','I_BRUK',false,'2010-05-30','KVINNE','PDLF',true); +insert into personidentifikator values(2,'FNR','04449908207','I_BRUK',false,'1999-04-04','KVINNE','PDLF',true); +insert into personidentifikator values(3,'FNR','06511781491','I_BRUK',false,'2017-11-06','KVINNE','PDLF',true); +insert into personidentifikator values(4,'FNR','12436512110','I_BRUK',false,'1965-03-12','MANN','PDLF',true); +insert into personidentifikator values(5,'FNR','02527908240','I_BRUK',false,'1979-12-02','KVINNE','PDLF',true); +insert into personidentifikator values(6,'FNR','07512352957','I_BRUK',false,'2023-11-07','MANN','PDLF',true); +insert into personidentifikator values(7,'FNR','28491551978','I_BRUK',false,'2015-09-28','MANN','PDLF',true); +insert into personidentifikator values(8,'FNR','21510899285','I_BRUK',false,'2008-11-21','KVINNE','PDLF',true); +insert into personidentifikator values(9,'FNR','14439441004','I_BRUK',false,'1994-03-14','KVINNE','PDLF',true); +insert into personidentifikator values(10,'FNR','28451886098','I_BRUK',false,'2018-05-28','KVINNE','PDLF',true); +insert into personidentifikator values(11,'FNR','12438916677','I_BRUK',false,'1989-03-12','KVINNE','PDLF',true); +insert into personidentifikator values(12,'FNR','08499622687','I_BRUK',false,'1996-09-08','KVINNE','PDLF',true); +insert into personidentifikator values(13,'FNR','12429230339','I_BRUK',false,'1992-02-12','MANN','PDLF',true); +insert into personidentifikator values(14,'FNR','12479433478','I_BRUK',false,'1994-07-12','KVINNE','PDLF',true); +insert into personidentifikator values(15,'FNR','23496643054','I_BRUK',false,'1966-09-23','KVINNE','PDLF',true); +insert into personidentifikator values(16,'FNR','23441374054','I_BRUK',false,'2013-04-23','KVINNE','PDLF',true); +insert into personidentifikator values(17,'FNR','04431360662','I_BRUK',false,'2013-03-04','KVINNE','PDLF',true); +insert into personidentifikator values(18,'FNR','14496205422','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(19,'FNR','14496208650','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(20,'FNR','14496201087','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(21,'FNR','14496209444','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(22,'FNR','14496205260','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(23,'FNR','14496209282','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(24,'FNR','14496200889','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(25,'FNR','14496201834','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(26,'FNR','14496202628','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(27,'FNR','14496206801','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(28,'FNR','14496201672','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(29,'FNR','14496204205','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(30,'FNR','14496203411','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(31,'FNR','14496202466','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(32,'FNR','14496205856','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(33,'FNR','14496204043','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(34,'FNR','14496208227','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(35,'FNR','14496206488','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(36,'FNR','14496203098','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(37,'FNR','14496205694','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(38,'FNR','14496207433','LEDIG',false,'1962-09-14','KVINNE',null,true); +insert into personidentifikator values(39,'FNR','14496209010','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(1,'FNR','13048226064','I_BRUK',false,'1982-04-13','KVINNE','TPS',false); -insert into personidentifikator values(2,'FNR','03058225613','I_BRUK',false,'1982-05-03','KVINNE','TPS',false); -insert into personidentifikator values(3,'FNR','25078225966','I_BRUK',false,'1982-07-25','MANN','TPS',false); -insert into personidentifikator values(4,'FNR','16118225841','I_BRUK',false,'1982-11-16','KVINNE','TPS',false); -insert into personidentifikator values(5,'FNR','30128225516','I_BRUK',false,'1982-12-30','MANN','TPS',false); -insert into personidentifikator values(6,'FNR','03128225772','I_BRUK',false,'1982-12-03','MANN','TPS',false); -insert into personidentifikator values(7,'FNR','22098225777','I_BRUK',false,'1982-09-22','MANN','TPS',false); -insert into personidentifikator values(8,'FNR','26028225864','I_BRUK',false,'1982-02-26','KVINNE','TPS',false); -insert into personidentifikator values(9,'FNR','09048225990','I_BRUK',false,'1982-04-09','MANN','TPS',false); -insert into personidentifikator values(10,'FNR','14496205422','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(11,'FNR','14496208650','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(12,'FNR','14496201087','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(13,'FNR','14496209444','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(14,'FNR','14496205260','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(15,'FNR','14496209282','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(16,'FNR','14496200889','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(17,'FNR','14496201834','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(18,'FNR','14496202628','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(19,'FNR','14496206801','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(20,'FNR','14496201672','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(21,'FNR','14496204205','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(22,'FNR','14496203411','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(23,'FNR','14496202466','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(24,'FNR','14496205856','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(25,'FNR','14496204043','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(26,'FNR','14496208227','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(27,'FNR','14496206488','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(28,'FNR','14496203098','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(29,'FNR','14496205694','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(30,'FNR','14496207433','LEDIG',false,'1962-09-14','KVINNE',null,true); -insert into personidentifikator values(31,'FNR','14496209010','LEDIG',false,'1962-09-14','KVINNE',null,true); +commit; -commit; \ No newline at end of file +ALTER SEQUENCE personidentifikator_seq RESTART WITH 40; \ No newline at end of file From 31f40367f70815b675b727922a04643d7ed993d6 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Mon, 14 Oct 2024 08:57:05 +0200 Subject: [PATCH 9/9] Refactor variable names in PoolService Changed variable names to improve code readability and consistency in the `allocateIdenter` method. Replaced `List` with `var` keyword for type inference. These changes should help streamline future modifications and maintenance. --- .../no/nav/testnav/identpool/service/PoolService.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java index b641733d602..7ddce546a8d 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/service/PoolService.java @@ -10,9 +10,7 @@ import no.nav.testnav.identpool.repository.IdentRepository; import org.springframework.stereotype.Service; -import java.util.Iterator; import java.util.List; -import java.util.Set; import static java.lang.String.format; import static java.time.format.DateTimeFormatter.ISO_DATE; @@ -62,7 +60,7 @@ private static void logRequest(HentIdenterRequest request) { public synchronized List allocateIdenter(HentIdenterRequest request) { - Set identEntities = databaseService.hentLedigeIdenterFraDatabase(request); + var identEntities = databaseService.hentLedigeIdenterFraDatabase(request); int missingIdentCount = request.getAntall() - identEntities.size(); if (missingIdentCount > 0) { @@ -72,12 +70,12 @@ public synchronized List allocateIdenter(HentIdenterRequest request) { log.info("Generert {} identer ved mining", statusDTOS.size()); - List identerFraTps = statusDTOS.stream() + var identerFraMining = statusDTOS.stream() .map(this::buildIdent) .toList(); - identRepository.saveAll(identerFraTps); + identRepository.saveAll(identerFraMining); - Iterator ledigeIdents = identerFraTps.stream() + var ledigeIdents = identerFraMining.stream() .filter(Ident::isLedig) .toList().iterator();