-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and optimize logging repository and services
#deploy-levende-arbeidsfoehold-ansettelse Refactor LoggRepository to use Mono for count and remove unnecessary vault dependencies. Added delay in ArbeidsforholdService to manage requests better and set restart policy in docker-compose. Introduced PageableHandlerMethodArgumentResolver for custom pageable handling and adjusted entity timestamp types.
- Loading branch information
Showing
13 changed files
with
127 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ttelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package no.nav.testnav.levendearbeidsforholdansettelse.config; | ||
|
||
import no.nav.testnav.levendearbeidsforholdansettelse.utility.PageableHandlerMethodArgumentResolver; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.reactive.config.WebFluxConfigurer; | ||
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebFluxConfigurer { | ||
|
||
@Override | ||
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { | ||
configurer.addCustomResolver(new PageableHandlerMethodArgumentResolver()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
...c/main/java/no/nav/testnav/levendearbeidsforholdansettelse/repository/LoggRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package no.nav.testnav.levendearbeidsforholdansettelse.repository; | ||
|
||
import no.nav.testnav.levendearbeidsforholdansettelse.entity.AnsettelseLogg; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.repository.reactive.ReactiveSortingRepository; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface LoggRepository extends ReactiveSortingRepository<AnsettelseLogg, Long> { | ||
|
||
Flux<Page<AnsettelseLogg>> findAllBy(Pageable pageable); | ||
Flux<AnsettelseLogg> findAllBy(Pageable pageable); | ||
|
||
Mono<Long> countAllBy(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...estnav/levendearbeidsforholdansettelse/utility/PageableHandlerMethodArgumentResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package no.nav.testnav.levendearbeidsforholdansettelse.utility; | ||
|
||
import org.springframework.core.MethodParameter; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.web.reactive.BindingContext; | ||
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.nonNull; | ||
|
||
public class PageableHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
private static final String DEFAULT_PAGE = "0"; | ||
private static final String DEFAULT_SIZE = "10"; | ||
private static final Integer MAX_SIZE = 50; | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return Pageable.class.equals(parameter.getParameterType()); | ||
} | ||
|
||
@Override | ||
public Mono<Object> resolveArgument(MethodParameter methodParameter, | ||
BindingContext bindingContext, | ||
ServerWebExchange serverWebExchange) { | ||
|
||
var pageValues = serverWebExchange.getRequest() | ||
.getQueryParams() | ||
.getOrDefault("page", List.of(DEFAULT_PAGE)); | ||
var sizeValues = serverWebExchange.getRequest() | ||
.getQueryParams() | ||
.getOrDefault("size", List.of(DEFAULT_SIZE)); | ||
|
||
var page = pageValues.getFirst(); | ||
|
||
var sortParam = serverWebExchange.getRequest() | ||
.getQueryParams().getFirst("sort"); | ||
|
||
var sort = Sort.unsorted(); | ||
|
||
if (nonNull(sortParam)) { | ||
var parts = sortParam.split(","); | ||
if (parts.length == 2) { | ||
var property = parts[0]; | ||
var direction = Sort.Direction.fromString(parts[1]); | ||
sort = Sort.by(direction, property); | ||
} | ||
} | ||
|
||
return Mono.just( | ||
PageRequest.of( | ||
Integer.parseInt(page), | ||
Math.min(Integer.parseInt(sizeValues.getFirst()), | ||
MAX_SIZE), sort | ||
) | ||
); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...de-arbeidsforhold-ansettelse/src/main/resources/db/migration/V1.2.0__ModifyPrimaryKey.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
----------------------------------- | ||
-- M O D I F Y I N D E C I E S -- | ||
----------------------------------- | ||
|
||
ALTER TABLE ansettelse_logg | ||
ALTER COLUMN id SET DEFAULT NEXTVAL('ansettelse_logg_id_seq'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters