-
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.
* bedre caching * jersey variants * path * path * cleanup * feature complete?
- Loading branch information
1 parent
d67574d
commit 556d26b
Showing
31 changed files
with
1,048 additions
and
147 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
63 changes: 34 additions & 29 deletions
63
...nav/vedtak/felles/integrasjon/arbeidsfordeling/rest/ArbeidsfordelingJerseyRestKlient.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 |
---|---|---|
@@ -1,57 +1,62 @@ | ||
package no.nav.vedtak.felles.integrasjon.arbeidsfordeling.rest; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import no.nav.vedtak.feil.Feil; | ||
import no.nav.vedtak.feil.FeilFactory; | ||
import no.nav.vedtak.feil.LogLevel; | ||
import no.nav.vedtak.feil.deklarasjon.DeklarerteFeil; | ||
import no.nav.vedtak.feil.deklarasjon.IntegrasjonFeil; | ||
import no.nav.vedtak.felles.integrasjon.rest.jersey.AbstractJerseyRestClient; | ||
import no.nav.vedtak.felles.integrasjon.rest.jersey.OIDCTokenRequestFilter; | ||
import java.util.Optional; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.GenericType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import no.nav.vedtak.exception.IntegrasjonException; | ||
import no.nav.vedtak.felles.integrasjon.rest.jersey.AbstractJerseyOidcRestClient; | ||
import no.nav.vedtak.konfig.KonfigVerdi; | ||
|
||
public class ArbeidsfordelingJerseyRestKlient extends AbstractJerseyRestClient { | ||
public class ArbeidsfordelingJerseyRestKlient extends AbstractJerseyOidcRestClient { | ||
|
||
private static final String DEFAULT_URI = "https://app.adeo.no/norg2/api/v1/arbeidsfordeling/enheter"; | ||
private static final String BEST_MATCH = "/bestmatch"; | ||
|
||
private final URI alleEnheterUri; | ||
private final URI besteEnhetUri; | ||
private final URI uri; | ||
|
||
public ArbeidsfordelingJerseyRestKlient( | ||
@KonfigVerdi(value = "arbeidsfordeling.rs.url", defaultVerdi = DEFAULT_URI) URI uri) { | ||
super(OIDCTokenRequestFilter.class); | ||
this.alleEnheterUri = uri; | ||
this.besteEnhetUri = URI.create(uri + BEST_MATCH); | ||
this.uri = uri; | ||
} | ||
|
||
public List<ArbeidsfordelingResponse> hentAlleAktiveEnheter(ArbeidsfordelingRequest request) { | ||
return hentEnheterFor(request, alleEnheterUri); | ||
return hentEnheterFor(request, null); | ||
} | ||
|
||
public List<ArbeidsfordelingResponse> finnEnhet(ArbeidsfordelingRequest request) { | ||
return hentEnheterFor(request, besteEnhetUri); | ||
return hentEnheterFor(request, BEST_MATCH); | ||
} | ||
|
||
private List<ArbeidsfordelingResponse> hentEnheterFor(ArbeidsfordelingRequest request, URI uri) { | ||
private List<ArbeidsfordelingResponse> hentEnheterFor(ArbeidsfordelingRequest request, String path) { | ||
try { | ||
return Arrays.stream(post(uri, request, ArbeidsfordelingResponse[].class)) | ||
.filter(response -> "AKTIV".equalsIgnoreCase(response.getStatus())) | ||
.collect(Collectors.toList()); | ||
return target(path) | ||
.request() | ||
.accept(APPLICATION_JSON_TYPE) | ||
.get(Response.class) | ||
.readEntity(new GenericType<List<ArbeidsfordelingResponse>>() { | ||
}).stream() | ||
.filter(r -> "AKTIV".equalsIgnoreCase(r.getStatus())) | ||
.collect(toList()); | ||
} catch (WebApplicationException e) { | ||
throw new IntegrasjonException("F-016913", e, uri, e.getResponse().getStatus(), e.getResponse().getEntity()); | ||
} catch (Exception e) { | ||
throw ArbeidsfordelingRestKlientFeil.FACTORY.feilfratjeneste(alleEnheterUri.toString(), e.getMessage(), e).toException(); | ||
throw new IntegrasjonException(e, uri); | ||
} | ||
} | ||
|
||
interface ArbeidsfordelingRestKlientFeil extends DeklarerteFeil { | ||
ArbeidsfordelingRestKlientFeil FACTORY = FeilFactory.create(ArbeidsfordelingRestKlientFeil.class); | ||
|
||
@IntegrasjonFeil(feilkode = "F-016913", feilmelding = "NORG2 arbeidsfordeling feil ved oppslag mot %s", logLevel = LogLevel.WARN) | ||
Feil feilfratjeneste(String var1, String msg, Throwable t); | ||
private WebTarget target(String path) { | ||
var target = client.target(uri); | ||
return Optional.ofNullable(path) | ||
.map(p -> target.path(p)) | ||
.orElse(target); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...main/java/no/nav/vedtak/felles/integrasjon/organisasjon/OrganisasjonJerseyRestKlient.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,47 @@ | ||
package no.nav.vedtak.felles.integrasjon.organisasjon; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; | ||
|
||
import java.net.URI; | ||
|
||
import javax.inject.Inject; | ||
|
||
import no.nav.vedtak.felles.integrasjon.rest.jersey.AbstractJerseyOidcRestClient; | ||
import no.nav.vedtak.konfig.KonfigVerdi; | ||
|
||
//@ApplicationScoped | ||
public class OrganisasjonJerseyRestKlient extends AbstractJerseyOidcRestClient { | ||
|
||
private static final String ENDPOINT_KEY = "organisasjon.rs.url"; | ||
private static final String DEFAULT_URI = "https://modapp.adeo.no/ereg/api/v1/organisasjon"; | ||
|
||
private URI endpoint; | ||
|
||
public OrganisasjonJerseyRestKlient() { | ||
} | ||
|
||
@Inject | ||
public OrganisasjonJerseyRestKlient(@KonfigVerdi(value = ENDPOINT_KEY, defaultVerdi = DEFAULT_URI) URI endpoint) { | ||
this.endpoint = endpoint; | ||
} | ||
|
||
public OrganisasjonEReg hentOrganisasjon(String orgnummer) { | ||
return get(orgnummer, OrganisasjonEReg.class); | ||
} | ||
|
||
public OrganisasjonAdresse hentOrganisasjonAdresse(String orgnummer) { | ||
return get(orgnummer, OrganisasjonAdresse.class); | ||
} | ||
|
||
private <T> T get(String orgnummer, Class<T> clazz) { | ||
return client.target(endpoint) | ||
.path(orgnummer) | ||
.request(APPLICATION_JSON_TYPE) | ||
.get(clazz); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + " [endpoint=" + endpoint + "]"; | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...ava/no/nav/vedtak/felles/integrasjon/infotrygd/saker/v1/InfotrygdSakerJerseyConsumer.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,37 @@ | ||
package no.nav.vedtak.felles.integrasjon.infotrygd.saker.v1; | ||
|
||
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; | ||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
||
import java.net.URI; | ||
import java.time.LocalDate; | ||
|
||
import no.nav.vedtak.felles.integrasjon.infotrygd.saker.v1.respons.Saker; | ||
import no.nav.vedtak.felles.integrasjon.rest.jersey.AbstractJerseyOidcRestClient; | ||
|
||
public abstract class InfotrygdSakerJerseyConsumer extends AbstractJerseyOidcRestClient { | ||
|
||
private final URI uri; | ||
|
||
public InfotrygdSakerJerseyConsumer(URI uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public Saker getSaker(String fnr, LocalDate fom) throws Exception { | ||
return client.target(uri) | ||
.queryParam("fnr", fnr) // TODO bli kvitt fnr i URL | ||
.queryParam("fom", fom(fom)) | ||
.request(APPLICATION_JSON) | ||
.get(Saker.class); | ||
} | ||
|
||
private static String fom(LocalDate fom) { | ||
return ISO_LOCAL_DATE.format(fom); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "[uri=" + uri + ", uri=" + uri + "]"; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...t/src/main/java/no/nav/vedtak/felles/integrasjon/medl2/MedlemsunntakJerseyRestKlient.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,69 @@ | ||
package no.nav.vedtak.felles.integrasjon.medl2; | ||
|
||
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; | ||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; | ||
import static no.nav.vedtak.log.mdc.MDCOperations.getCallId; | ||
|
||
import java.net.URI; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.core.GenericType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import no.nav.vedtak.felles.integrasjon.rest.jersey.AbstractJerseyOidcRestClient; | ||
import no.nav.vedtak.konfig.KonfigVerdi; | ||
|
||
/* | ||
* Dokumentasjon https://confluence.adeo.no/display/FEL/MEDL2 | ||
* Swagger https://app-q1.adeo.no/medl2/swagger-ui.html | ||
*/ | ||
|
||
//@ApplicationScoped | ||
public class MedlemsunntakJerseyRestKlient extends AbstractJerseyOidcRestClient { | ||
|
||
private static final String ENDPOINT_KEY = "medl2.rs.url"; | ||
private static final String DEFAULT_URI = "https://app.adeo.no/medl2/api/v1/medlemskapsunntak"; | ||
|
||
public static final String HEADER_NAV_CALL_ID = "Nav-Call-Id"; | ||
public static final String HEADER_NAV_PERSONIDENT = "Nav-Personident"; | ||
public static final String PARAM_FRA_OG_MED = "fraOgMed"; | ||
public static final String PARAM_TIL_OG_MED = "tilOgMed"; | ||
public static final String PARAM_STATUSER = "statuser"; | ||
public static final String PARAM_INKLUDER_SPORINGSINFO = "inkluderSporingsinfo"; | ||
|
||
// Fra kodeverk PeriodestatusMedl | ||
public static final String KODE_PERIODESTATUS_GYLD = "GYLD"; | ||
public static final String KODE_PERIODESTATUS_UAVK = "UAVK"; | ||
|
||
private URI endpoint; | ||
|
||
public MedlemsunntakJerseyRestKlient() { | ||
} | ||
|
||
@Inject | ||
public MedlemsunntakJerseyRestKlient(@KonfigVerdi(value = ENDPOINT_KEY, defaultVerdi = DEFAULT_URI) URI endpoint) { | ||
this.endpoint = endpoint; | ||
} | ||
|
||
public List<Medlemskapsunntak> finnMedlemsunntak(String aktørId, LocalDate fom, LocalDate tom) throws Exception { | ||
return client.target(endpoint) | ||
.queryParam(PARAM_INKLUDER_SPORINGSINFO, "true") | ||
.queryParam(PARAM_FRA_OG_MED, d2s(fom)) | ||
.queryParam(PARAM_TIL_OG_MED, d2s(tom)) | ||
.queryParam(PARAM_STATUSER, KODE_PERIODESTATUS_GYLD) | ||
.queryParam(PARAM_STATUSER, KODE_PERIODESTATUS_UAVK) | ||
.request() | ||
.accept(APPLICATION_JSON_TYPE) | ||
.header(HEADER_NAV_CALL_ID, getCallId()) | ||
.header(HEADER_NAV_PERSONIDENT, aktørId) | ||
.get(Response.class) | ||
.readEntity(new GenericType<List<Medlemskapsunntak>>() { | ||
}); | ||
} | ||
|
||
private static String d2s(LocalDate dato) { | ||
return ISO_LOCAL_DATE.format(dato); | ||
} | ||
} |
Oops, something went wrong.