Skip to content

Commit

Permalink
Add syfosmregler consumer for sykemelding validation #deploy-test-syk…
Browse files Browse the repository at this point in the history
…emelding-api

Introduced a new consumer, `SyfosmreglerConsumer`, to enable validation of sykemeldings using the sykemelding proxy service. This addition includes necessary DTOs and configurations, allowing the system to validate submitted sykemeldings and return validation results. Additionally, the `SykemeldingService` and `SykemeldingController` have been updated to incorporate the validation functionality.
  • Loading branch information
krharum committed Nov 29, 2024
1 parent ea26d4c commit e5e85d7
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 5 deletions.
2 changes: 2 additions & 0 deletions apps/sykemelding-api/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ spec:
- application: testnav-oversikt-frontend
- application: testnav-synt-sykemelding-api-dev
outbound:
rules:
- application: testnav-sykemelding-proxy
external:
- host: mqls04.preprod.local
ports:
Expand Down
2 changes: 2 additions & 0 deletions apps/sykemelding-api/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ spec:
- application: testnav-oversikt-frontend
- application: testnav-synt-sykemelding-api
outbound:
rules:
- application: testnav-sykemelding-proxy
external:
- host: mqls04.preprod.local
ports:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package no.nav.registre.testnorge.sykemelding.config;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import no.nav.testnav.libs.securitycore.domain.ServerProperties;

import static lombok.AccessLevel.PACKAGE;

@Configuration
@ConfigurationProperties(prefix = "consumers")
@NoArgsConstructor(access = PACKAGE)
@Getter
@Setter(PACKAGE)
public class Consumers {

private ServerProperties sykemeldingProxy;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Slf4j
@Component
@Service
public class SyfoConsumer {

private final JmsTemplate jmsTemplate;
private final String queueName;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package no.nav.registre.testnorge.sykemelding.consumer;

import no.nav.registre.testnorge.sykemelding.config.Consumers;
import no.nav.registre.testnorge.sykemelding.consumer.command.SyfosmreglerPostValidateCommand;
import no.nav.registre.testnorge.sykemelding.dto.ReceivedSykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.ValidationResultDTO;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Service
public class SyfosmreglerConsumer {

private final ServerProperties properties;
private final TokenExchange tokenExchange;
private final WebClient webClient;

public SyfosmreglerConsumer(Consumers consumers, WebClient.Builder webClientBuilder, TokenExchange tokenExchange) {

this.properties = consumers.getSykemeldingProxy();
this.tokenExchange = tokenExchange;
this.webClient = webClientBuilder
.baseUrl(properties.getUrl())
.build();
}

public Mono<ValidationResultDTO> validate(ReceivedSykemeldingDTO sykemelding) {

return tokenExchange.exchange(properties)
.flatMap(token -> new SyfosmreglerPostValidateCommand(webClient, sykemelding, token.getTokenValue()).call());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package no.nav.registre.testnorge.sykemelding.consumer.command;

import lombok.RequiredArgsConstructor;
import no.nav.registre.testnorge.sykemelding.dto.ReceivedSykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.ValidationResultDTO;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.concurrent.Callable;

@RequiredArgsConstructor
public class SyfosmreglerPostValidateCommand implements Callable<Mono<ValidationResultDTO>> {

private static final String SYFOSMREGLER_VALIDATE_URL = "/v1/rules/validate";

private final WebClient webClient;
private final ReceivedSykemeldingDTO receivedSykemelding;
private final String accessToken;

@Override
public Mono<ValidationResultDTO> call() {

return webClient.post()
.uri(uriBuilder -> uriBuilder.path(SYFOSMREGLER_VALIDATE_URL).build())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
.bodyValue(receivedSykemelding)
.retrieve()
.bodyToMono(ValidationResultDTO.class);
}
}
Loading

0 comments on commit e5e85d7

Please sign in to comment.