Skip to content

Commit

Permalink
SPøkelse med fom qparameter (#1208)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolarsen authored Oct 27, 2022
1 parent 159b85b commit 4de143d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import javax.ws.rs.core.UriBuilder;

Expand Down Expand Up @@ -64,7 +65,7 @@ public List<Grunnlag> hentGrunnlagFailSoft(String fnr, LocalDate fom, LocalDate
}

private static String konverter(LocalDate dato) {
var brukDato = dato == null ? LocalDate.now() : dato;
var brukDato = Optional.ofNullable(dato).orElseGet(LocalDate::now);
return brukDato.format(DateTimeFormatter.ISO_LOCAL_DATE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package no.nav.vedtak.felles.integrasjon.spokelse;

import java.time.Duration;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import javax.ws.rs.core.UriBuilder;

Expand Down Expand Up @@ -39,11 +42,20 @@ public abstract class AbstractSpøkelseKlient implements Spøkelse {

@Override
public List<SykepengeVedtak> hentGrunnlag(String fnr) {
return hentGrunnlag(fnr, null);
}

@Override
public List<SykepengeVedtak> hentGrunnlag(String fnr, LocalDate fom) {
return hentGrunnlag(fnr, fom, Duration.ofSeconds(30));
}

@Override
public List<SykepengeVedtak> hentGrunnlag(String fnr, LocalDate fom, Duration timeout) {
try {
var path = UriBuilder.fromUri(restConfig.endpoint())
.queryParam("fodselsnummer", fnr)
.build();
var request = RestRequest.newGET(path, restConfig).timeout(Duration.ofSeconds(40));
var pathBuilder = UriBuilder.fromUri(restConfig.endpoint()).queryParam("fodselsnummer", fnr);
Optional.ofNullable(fom).ifPresent(f -> pathBuilder.queryParam("fom", f.format(DateTimeFormatter.ISO_LOCAL_DATE)));
var request = RestRequest.newGET(pathBuilder.build(), restConfig).timeout(timeout);
var grunnlag = restKlient.send(request, SykepengeVedtak[].class);
return Arrays.asList(grunnlag);
} catch (Exception e) {
Expand All @@ -53,8 +65,13 @@ public List<SykepengeVedtak> hentGrunnlag(String fnr) {

@Override
public List<SykepengeVedtak> hentGrunnlagFailSoft(String fnr) {
return hentGrunnlagFailSoft(fnr, null);
}

@Override
public List<SykepengeVedtak> hentGrunnlagFailSoft(String fnr, LocalDate fom) {
try {
return hentGrunnlag(fnr);
return hentGrunnlag(fnr, fom);
} catch (Exception e) {
LOG.info("SPokelse felles: feil ved oppslag mot {}, returnerer ingen grunnlag", restConfig.endpoint(), e);
return List.of();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package no.nav.vedtak.felles.integrasjon.spokelse;

import java.time.Duration;
import java.time.LocalDate;
import java.util.List;

public interface Spøkelse {

List<SykepengeVedtak> hentGrunnlag(String fnr);

List<SykepengeVedtak> hentGrunnlag(String fnr, LocalDate fom);

List<SykepengeVedtak> hentGrunnlag(String fnr, LocalDate fom, Duration timeout);

// Logger evt feil som info og gir tom list
List<SykepengeVedtak> hentGrunnlagFailSoft(String fnr);

// Logger evt feil som info og gir tom list
List<SykepengeVedtak> hentGrunnlagFailSoft(String fnr, LocalDate fom);
}

0 comments on commit 4de143d

Please sign in to comment.