-
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.
Add syfosmregler consumer for sykemelding validation #deploy-test-syk…
…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
Showing
11 changed files
with
483 additions
and
5 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
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
22 changes: 22 additions & 0 deletions
22
...sykemelding-api/src/main/java/no/nav/registre/testnorge/sykemelding/config/Consumers.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,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; | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
...pi/src/main/java/no/nav/registre/testnorge/sykemelding/consumer/SyfosmreglerConsumer.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,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()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../nav/registre/testnorge/sykemelding/consumer/command/SyfosmreglerPostValidateCommand.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,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); | ||
} | ||
} |
Oops, something went wrong.