diff --git a/apps/testnav-ident-pool/config.yml b/apps/testnav-ident-pool/config.yml index a029e5d1348..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: @@ -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: 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/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..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 @@ -8,59 +8,75 @@ 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; -import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; -import java.util.List; +import java.util.Random; import java.util.Set; +import static java.util.Objects.nonNull; import static org.apache.commons.lang3.BooleanUtils.isTrue; @Service @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; + + if (antall > request.getAntall()) { + var resultat = getPage(request, PageRequest.of(RANDOM.nextInt(antall/request.getAntall()), request.getAntall())); + return new HashSet<>(resultat.getContent()); + } + + return new HashSet<>( + getPage(request, PageRequest.of(0, request.getAntall())) + .getContent()); } - private Page findPage(HentIdenterRequest request, Rekvireringsstatus rekvireringsstatus, int page) { + private int getAntall(HentIdenterRequest request) { + + return nonNull(request.getKjoenn()) ? + + identRepository.countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( + Rekvireringsstatus.LEDIG, request.getIdenttype(), + isTrue(request.getSyntetisk()), request.getKjoenn(), + request.getFoedtEtter(), request.getFoedtFoer()) : + + identRepository.countAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( + Rekvireringsstatus.LEDIG, request.getIdenttype(), + isTrue(request.getSyntetisk()), + request.getFoedtEtter(), request.getFoedtFoer()); + } + + private Page getPage(HentIdenterRequest request, Pageable page) { + + return nonNull(request.getKjoenn()) ? + + identRepository.findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndKjoennAndFoedselsdatoBetween( + Rekvireringsstatus.LEDIG, request.getIdenttype(), + isTrue(request.getSyntetisk()), request.getKjoenn(), + request.getFoedtEtter(), request.getFoedtFoer(), page + ) : - return identRepository.findAll( - rekvireringsstatus, request.getIdenttype(), request.getKjoenn(), request.getFoedtFoer(), - request.getFoedtEtter(), isTrue(request.getSyntetisk()), PageRequest.of(page, request.getAntall())); + identRepository.findAllByRekvireringsstatusAndIdenttypeAndSyntetiskAndFoedselsdatoBetween( + 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..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 @@ -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; @@ -11,10 +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 java.util.stream.Collectors; import static java.lang.String.format; import static java.time.format.DateTimeFormatter.ISO_DATE; @@ -64,19 +60,22 @@ 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) { - var tpsStatusDTOS = identerAvailService.generateAndCheckIdenter(request, 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()); + + 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(); 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..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: @@ -45,11 +49,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..7351d87c2cb --- /dev/null +++ b/apps/testnav-ident-pool/src/main/resources/db/dev/h2-default-config.sql @@ -0,0 +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); + +commit; + +ALTER SEQUENCE personidentifikator_seq RESTART WITH 40; \ No newline at end of file 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 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); }