Skip to content

Commit

Permalink
Fiks for Excel bankkonti #deploy-dolly-backend #deploy-test-dolly-bac… (
Browse files Browse the repository at this point in the history
#3271)

Bugfiks for Excel bankkonti
  • Loading branch information
krharum authored Sep 8, 2023
1 parent f77c3b8 commit 1aece65
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public static void main(String[] args) {

SpringApplication.run(DollyBackendApplicationStarter.class, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
import no.nav.testnav.libs.dto.kontoregisterservice.v1.OppdaterKontoRequestDTO;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;

import java.time.Duration;
import java.util.List;
Expand All @@ -44,6 +47,12 @@ public KontoregisterConsumer(
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.exchangeStrategies(getJacksonStrategy(objectMapper))
.clientConnector(new ReactorClientHttpConnector(
HttpClient.create(ConnectionProvider.builder("custom")
.maxConnections(10)
.pendingAcquireMaxCount(10000)
.pendingAcquireTimeout(Duration.ofMinutes(15))
.build())))
.build();
}

Expand Down Expand Up @@ -88,5 +97,4 @@ public String serviceUrl() {
public String consumerName() {
return "testnav-kontoregister-person-proxy";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@Service
public class PdlPersonConsumer implements ConsumerStatus {

private static final int BLOCK_SIZE = 50;
private static final int BLOCK_SIZE = 100;
private static final int MAX_RETRIES = 3;
private final TokenExchange tokenService;
private final ServerProperties serviceProperties;
Expand Down Expand Up @@ -79,6 +79,12 @@ public Flux<PdlPersonBolk> getPdlPersoner(List<String> identer) {
return getPdlPersoner(identer, new AtomicInteger(0));
}

@Timed(name = "providers", tags = {"operation", "pdl_getPersoner"})
public Flux<PdlPersonBolk> getPdlPersonerNoRetries(List<String> identer) {

return getPdlPersoner(identer, new AtomicInteger(MAX_RETRIES));
}

@Timed(name = "providers", tags = {"operation", "pdl_getPersoner"})
public Flux<PdlPersonBolk> getPdlPersoner(List<String> identer, AtomicInteger retry) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.io.IOException;

Expand All @@ -30,7 +27,7 @@ public class ExcelController {

@SneakyThrows
@GetMapping(value = "/gruppe/{gruppeId}")
public ResponseEntity<Resource> getExcelsheet(@PathVariable Long gruppeId){
public Mono<ResponseEntity<Resource>> getExcelsheet(@PathVariable Long gruppeId) {

var resource = excelService.getExcelWorkbook(gruppeId);

Expand All @@ -39,7 +36,7 @@ public ResponseEntity<Resource> getExcelsheet(@PathVariable Long gruppeId){

@SneakyThrows
@GetMapping(value = "/organisasjoner")
public ResponseEntity<Resource> getOrganisasjonExcelsheet(@RequestParam(required = false) String brukerId){
public ResponseEntity<Resource> getOrganisasjonExcelsheet(@RequestParam(required = false) String brukerId) {

var bruker = brukerService.fetchOrCreateBruker(StringUtils.isNotBlank(brukerId) ? brukerId : getUserId(getUserInfo));
var resource = excelService.getExcelOrganisasjonerWorkbook(bruker);
Expand All @@ -55,4 +52,20 @@ private ResponseEntity<Resource> wrapContents(Resource resource) throws IOExcept
.contentType(MediaType.parseMediaType("application/vnd.ms-excel"))
.body(resource);
}

private Mono<ResponseEntity<Resource>> wrapContents(Mono<Resource> resource) {

return resource
.handle((resource1, sink) -> {
try {
sink.next(ResponseEntity.ok()
.header("Content-Disposition", "attachment; filename=" + resource1.getFilename())
.contentLength(resource1.contentLength())
.contentType(MediaType.parseMediaType("application/vnd.ms-excel"))
.body(resource1));
} catch (IOException e) {
sink.error(new RuntimeException(e));
}
});
}
}
Loading

0 comments on commit 1aece65

Please sign in to comment.