Skip to content

Commit

Permalink
Refactor sykemelding classes and fix DTO typo #deploy-test-dolly-backend
Browse files Browse the repository at this point in the history
#deploy-test-sykemelding-api #deploy-test-synt-sykemelding-api

Refactored the Sykemelding classes to use a new response DTO and improved logging for better traceability. Also corrected the typo in SykemeldingResponseDTO across the codebase, ensuring consistent naming conventions. Updated application URLs in the configuration files.
  • Loading branch information
krharum committed Nov 28, 2024
1 parent b518705 commit 4f5d27b
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private void saveTransaksjonId(SykemeldingResponse sykemelding, Long bestillingI

log.info("Lagrer transaksjon for {} i q1 ", sykemelding.getIdent());

sykemelding.getSykemeldingRequest().setSykemeldingId(sykemelding.getMsgId());
transaksjonMappingService.save(TransaksjonMapping.builder()
.ident(sykemelding.getIdent())
.bestillingId(bestillingId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public Mono<SykemeldingResponse> postDetaljertSykemelding(DetaljertSykemeldingRe

return tokenService.exchange(serverProperties)
.flatMap(token -> new SykemeldingPostCommand(webClient, detaljertSykemeldingRequest,
token.getTokenValue()).call());
token.getTokenValue()).call())
.doOnNext(response -> log.info("Status fra sykemelding innsending: {}", response.getStatus()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package no.nav.dolly.bestilling.sykemelding.command;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.sykemelding.domain.DetaljertSykemeldingRequest;
import no.nav.dolly.bestilling.sykemelding.dto.SykemeldingResponse;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import no.nav.testnav.libs.securitycore.config.UserConstant;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;
Expand All @@ -16,6 +17,7 @@

import static no.nav.dolly.util.TokenXUtil.getUserJwt;

@Slf4j
@RequiredArgsConstructor
public class SykemeldingPostCommand implements Callable<Mono<SykemeldingResponse>> {

Expand All @@ -35,10 +37,10 @@ public Mono<SykemeldingResponse> call() {
.header(UserConstant.USER_HEADER_JWT, getUserJwt())
.bodyValue(request)
.retrieve()
.toBodilessEntity()
.timeout(Duration.ofMinutes(4))
.bodyToMono(SykemeldingResponseDTO.class)
.map(response -> SykemeldingResponse.builder()
.status(HttpStatus.valueOf(response.getStatusCode().value()))
.status(response.getStatus())
.msgId(response.getSykemeldingId())
.ident(request.getPasient().getIdent())
.sykemeldingRequest(SykemeldingResponse.SykemeldingRequest.builder()
.detaljertSykemeldingRequest(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import lombok.RequiredArgsConstructor;
import no.nav.dolly.bestilling.sykemelding.domain.SyntSykemeldingRequest;
import no.nav.dolly.bestilling.sykemelding.dto.SykemeldingResponse;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import no.nav.testnav.libs.securitycore.config.UserConstant;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;
Expand Down Expand Up @@ -34,10 +34,10 @@ public Mono<SykemeldingResponse> call() {
.header(UserConstant.USER_HEADER_JWT, getUserJwt())
.bodyValue(sykemeldingRequest)
.retrieve()
.toBodilessEntity()
.timeout(Duration.ofMinutes(4))
.bodyToMono(SykemeldingResponseDTO.class)
.map(response -> SykemeldingResponse.builder()
.status(HttpStatus.valueOf(response.getStatusCode().value()))
.status(response.getStatus())
.msgId(response.getSykemeldingId())
.ident(sykemeldingRequest.getIdent())
.sykemeldingRequest(SykemeldingResponse.SykemeldingRequest.builder()
.syntSykemeldingRequest(sykemeldingRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SykemeldingResponse {
private HttpStatus status;
private String avvik;
private SykemeldingRequest sykemeldingRequest;
private String msgId;
private String ident;

@Data
Expand All @@ -27,6 +28,7 @@ public class SykemeldingResponse {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class SykemeldingRequest {

private String sykemeldingId;
private SyntSykemeldingRequest syntSykemeldingRequest;
private DetaljertSykemeldingRequest detaljertSykemeldingRequest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import no.nav.testnav.libs.dto.kodeverkservice.v1.KodeverkDTO;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;
Expand Down Expand Up @@ -31,6 +32,10 @@ public Mono<KodeverkDTO> call() {
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.retrieve()
.bodyToMono(KodeverkDTO.class)
.map(kodeverk -> {
kodeverk.setStatus(HttpStatus.OK);
return kodeverk;
})
.doOnError(WebClientFilter::logErrorMessage)
.onErrorResume(error -> Mono.just(KodeverkDTO.builder()
.kodeverknavn(kodeverk)
Expand Down
3 changes: 2 additions & 1 deletion apps/dolly-backend/src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ consumers:
name: testnav-pdl-forvalter-dev
url: https://testnav-synt-sykemelding-api.intern.dev.nav.no
testnav-sykemelding-api:
url: http://testnav-sykemelding-api.intern.dev.nav.no
name: testnav-sykemelding-api-dev
url: https://testnav-sykemelding-api-dev.intern.dev.nav.no
testnav-miljoer-service:
url: https://testnav-miljoer-service.intern.dev.nav.no
testnav-arbeidsplassencv-proxy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import no.nav.registre.testnorge.sykemelding.domain.Sykemelding;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldningResponseDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.jms.core.JmsTemplate;
Expand All @@ -19,14 +19,14 @@ public SyfoConsumer(JmsTemplate jmsTemplate, @Value("${syfo.queue.name}") String
this.queueName = queueName;
}

public SykemeldningResponseDTO send(Sykemelding sykemelding) {
public SykemeldingResponseDTO send(Sykemelding sykemelding) {

var xml = sykemelding.toXml();
log.info("Legger sykemelding på kø med MsgId {}\n{}", sykemelding.getMsgId(), sykemelding);
jmsTemplate.send(queueName, session -> session.createTextMessage(xml));
log.trace(xml);

return SykemeldningResponseDTO.builder()
return SykemeldingResponseDTO.builder()
.sykemeldingId(sykemelding.getMsgId())
.status(HttpStatus.OK)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package no.nav.registre.testnorge.sykemelding.provider;

import lombok.RequiredArgsConstructor;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldningResponseDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import no.nav.registre.testnorge.sykemelding.domain.ApplicationInfo;
import no.nav.registre.testnorge.sykemelding.domain.Sykemelding;
import no.nav.registre.testnorge.sykemelding.service.SykemeldingService;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingDTO;
import no.nav.registre.testnorge.sykemelding.domain.ApplicationInfo;
import no.nav.registre.testnorge.sykemelding.domain.Sykemelding;
import no.nav.registre.testnorge.sykemelding.service.SykemeldingService;

@RestController
@RequestMapping("/api/v1/sykemeldinger")
@RequiredArgsConstructor
Expand All @@ -23,7 +20,7 @@ public class SykemeldingController {
private final ApplicationInfo applicationInfo;

@PostMapping
public SykemeldningResponseDTO create(@RequestBody SykemeldingDTO dto) {
public SykemeldingResponseDTO create(@RequestBody SykemeldingDTO dto) {

return service.send(new Sykemelding(dto, applicationInfo));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import lombok.RequiredArgsConstructor;
import no.nav.registre.testnorge.sykemelding.consumer.SyfoConsumer;
import no.nav.registre.testnorge.sykemelding.domain.Sykemelding;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldningResponseDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SykemeldingService {
private final SyfoConsumer syfoConsumer;

public SykemeldningResponseDTO send(Sykemelding sykemelding) {
public SykemeldingResponseDTO send(Sykemelding sykemelding) {

return syfoConsumer.send(sykemelding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import no.nav.testnav.apps.syntsykemeldingapi.config.Consumers;
import no.nav.testnav.apps.syntsykemeldingapi.consumer.command.PostSykemeldingCommand;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldningResponseDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Component;
Expand All @@ -30,7 +30,7 @@ public SykemeldingConsumer(
.build();
}

public SykemeldningResponseDTO opprettSykemelding(SykemeldingDTO sykemelding) {
public SykemeldingResponseDTO opprettSykemelding(SykemeldingDTO sykemelding) {

return tokenExchange.exchange(serverProperties)
.flatMap(accessToken ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldningResponseDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -17,23 +17,23 @@

@Slf4j
@RequiredArgsConstructor
public class PostSykemeldingCommand implements Callable<Mono<SykemeldningResponseDTO>> {
public class PostSykemeldingCommand implements Callable<Mono<SykemeldingResponseDTO>> {

private final WebClient webClient;
private final String token;
private final SykemeldingDTO sykemelding;

@SneakyThrows
@Override
public Mono<SykemeldningResponseDTO> call() {
public Mono<SykemeldingResponseDTO> call() {
return webClient.post()
.uri(builder ->
builder.path("/api/v1/sykemeldinger").build()
)
.header(AUTHORIZATION, "Bearer " + token)
.bodyValue(sykemelding)
.retrieve()
.bodyToMono(SykemeldningResponseDTO.class)
.bodyToMono(SykemeldingResponseDTO.class)
.doOnError(WebClientFilter::logErrorMessage)
.onErrorResume(throwable ->
Mono.error(new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Feil oppsto i innsending av sykemelding")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import no.nav.testnav.apps.syntsykemeldingapi.service.SykemeldingService;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldningResponseDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import no.nav.testnav.libs.dto.synt.sykemelding.v1.SyntSykemeldingDTO;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;

@RestController
@Slf4j
Expand All @@ -25,7 +18,7 @@ public class SyntSykemeldingController {
private final SykemeldingService sykemeldingService;

@PostMapping
public SykemeldningResponseDTO opprett(@RequestBody SyntSykemeldingDTO sykemelding) {
public SykemeldingResponseDTO opprett(@RequestBody SyntSykemeldingDTO sykemelding) {

return sykemeldingService.opprettSykemelding(sykemelding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import no.nav.testnav.apps.syntsykemeldingapi.consumer.SyntElsamConsumer;
import no.nav.testnav.apps.syntsykemeldingapi.domain.Person;
import no.nav.testnav.apps.syntsykemeldingapi.domain.Sykemelding;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldningResponseDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.SykemeldingResponseDTO;
import no.nav.testnav.libs.dto.synt.sykemelding.v1.SyntSykemeldingDTO;
import org.springframework.stereotype.Service;

import java.util.Objects;

import static java.util.Objects.nonNull;

@Slf4j
Expand All @@ -27,7 +25,7 @@ public class SykemeldingService {
private final ArbeidsforholdAdapter arbeidsforholdAdapter;
private final PdlProxyConsumer pdlProxyConsumer;

public SykemeldningResponseDTO opprettSykemelding(SyntSykemeldingDTO syntSykemelding) {
public SykemeldingResponseDTO opprettSykemelding(SyntSykemeldingDTO syntSykemelding) {

var pdlData = pdlProxyConsumer.getPdlPerson(syntSykemelding.getIdent());
var pasient = new Person(pdlData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SykemeldningResponseDTO {
public class SykemeldingResponseDTO {

private HttpStatus status;
private String sykemeldingId;
Expand Down

0 comments on commit 4f5d27b

Please sign in to comment.