-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POFIM-12: Initial commit på opprettelse av oppgaver. (#6)
- Loading branch information
Showing
14 changed files
with
1,890 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
...ava/no/nav/familie/inntektsmelding/arbeidsgivernotifikasjon/ArbeidsgiverNotifikasjon.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,11 @@ | ||
package no.nav.familie.inntektsmelding.arbeidsgivernotifikasjon; | ||
|
||
import java.net.URI; | ||
import java.time.LocalDateTime; | ||
|
||
public interface ArbeidsgiverNotifikasjon { | ||
|
||
String opprettNyOppgave(String eksternId, String tekst, URI lenke, Merkelapp merkelapp, String virksomhetsnummer, LocalDateTime tidspunkt); | ||
|
||
String lukkOppgave(String id, LocalDateTime utfoertTidspunkt); | ||
} |
24 changes: 24 additions & 0 deletions
24
...amilie/inntektsmelding/arbeidsgivernotifikasjon/ArbeidsgiverNotifikasjonErrorHandler.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,24 @@ | ||
package no.nav.familie.inntektsmelding.arbeidsgivernotifikasjon; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLError; | ||
|
||
import no.nav.vedtak.exception.TekniskException; | ||
|
||
class ArbeidsgiverNotifikasjonErrorHandler { | ||
|
||
ArbeidsgiverNotifikasjonErrorHandler() { | ||
} | ||
|
||
public static <T> T handleError(List<GraphQLError> errors, URI uri, String kode) { | ||
throw new TekniskException(kode, String.format("Feil %s mot %s", errors.stream().map(GraphQLError::getMessage).collect(joining(",")), uri)); | ||
} | ||
|
||
public static void handleValidationError(String typename, String feilmelding, String aksjon) { | ||
throw new TekniskException("F-FAGER", String.format("Funksjonel feil ved %s: %s:%s", aksjon, typename, feilmelding)); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../nav/familie/inntektsmelding/arbeidsgivernotifikasjon/ArbeidsgiverNotifikasjonKlient.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,68 @@ | ||
package no.nav.familie.inntektsmelding.arbeidsgivernotifikasjon; | ||
|
||
import static no.nav.familie.inntektsmelding.arbeidsgivernotifikasjon.ArbeidsgiverNotifikasjonErrorHandler.handleError; | ||
import static no.nav.familie.inntektsmelding.arbeidsgivernotifikasjon.ArbeidsgiverNotifikasjonErrorHandler.handleValidationError; | ||
|
||
import java.net.http.HttpRequest; | ||
|
||
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequest; | ||
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult; | ||
|
||
import no.nav.vedtak.felles.integrasjon.rest.RestClient; | ||
import no.nav.vedtak.felles.integrasjon.rest.RestClientConfig; | ||
import no.nav.vedtak.felles.integrasjon.rest.RestConfig; | ||
import no.nav.vedtak.felles.integrasjon.rest.RestRequest; | ||
import no.nav.vedtak.felles.integrasjon.rest.TokenFlow; | ||
|
||
@RestClientConfig(tokenConfig = TokenFlow.AZUREAD_CC, endpointProperty = "arbeidsgiver.notifikasjon.url", endpointDefault = "https://ag-notifikasjon-produsent-api.intern.nav.no", scopesProperty = "arbeidsgiver.notifikasjon.scopes", scopesDefault = "api://prod-gcp.fager.notifikasjon-produsent-api/.default") | ||
class ArbeidsgiverNotifikasjonKlient { | ||
|
||
private static final String ERROR_RESPONSE = "F-102030"; | ||
|
||
private final RestClient restKlient; | ||
private final RestConfig restConfig; | ||
|
||
public ArbeidsgiverNotifikasjonKlient(RestClient restKlient) { | ||
this.restKlient = restKlient; | ||
this.restConfig = RestConfig.forClient(this.getClass()); | ||
} | ||
|
||
public String opprettNyOppgave(NyOppgaveMutationRequest request, NyOppgaveResultatResponseProjection projection) { | ||
var resultat = query(new GraphQLRequest(request, projection), NyOppgaveMutationResponse.class).nyOppgave(); | ||
if (resultat instanceof NyOppgaveVellykket vellykket) { | ||
return vellykket.getId(); | ||
} else { | ||
loggFeilmelding((Error) resultat, "opprettelse av ny oppgave"); | ||
} | ||
throw new IllegalStateException("Utviklerfeil: Ulovlig tilstand."); | ||
} | ||
|
||
public String lukkOppgave(OppgaveUtfoertMutationRequest request, OppgaveUtfoertResultatResponseProjection projection) { | ||
var resultat = query(new GraphQLRequest(request, projection), OppgaveUtfoertMutationResponse.class).oppgaveUtfoert(); | ||
if (resultat instanceof OppgaveUtfoertVellykket vellykket) { | ||
return vellykket.getId(); | ||
} else { | ||
loggFeilmelding((Error) resultat, "lukking av oppgave"); | ||
} | ||
throw new IllegalStateException("Utviklerfeil: Ulovlig tilstand."); | ||
} | ||
|
||
private <T extends GraphQLResult<?>> T query(GraphQLRequest req, Class<T> clazz) { | ||
var method = new RestRequest.Method(RestRequest.WebMethod.POST, HttpRequest.BodyPublishers.ofString(req.toHttpJsonBody())); | ||
var restRequest = RestRequest.newRequest(method, restConfig.endpoint(), restConfig); | ||
var res = restKlient.send(restRequest, clazz); | ||
if (res.hasErrors()) { | ||
return handleError(res.getErrors(), restConfig.endpoint(), ERROR_RESPONSE); | ||
} | ||
return res; | ||
} | ||
|
||
private static void loggFeilmelding(Error feil, String action) { | ||
handleValidationError("Funksjonellfeil", feil.getFeilmelding(), action); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + " [endpoint=" + restConfig.endpoint() + "]"; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...av/familie/inntektsmelding/arbeidsgivernotifikasjon/ArbeidsgiverNotifikasjonTjeneste.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,56 @@ | ||
package no.nav.familie.inntektsmelding.arbeidsgivernotifikasjon; | ||
|
||
import java.net.URI; | ||
import java.time.LocalDateTime; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
class ArbeidsgiverNotifikasjonTjeneste implements ArbeidsgiverNotifikasjon { | ||
|
||
static final String SERVICE_CODE = "4936"; | ||
static final String SERVICE_EDITION_CODE = "1"; | ||
|
||
private ArbeidsgiverNotifikasjonKlient klient; | ||
|
||
@Inject | ||
public ArbeidsgiverNotifikasjonTjeneste(ArbeidsgiverNotifikasjonKlient klient) { | ||
this.klient = klient; | ||
} | ||
|
||
@Override | ||
public String opprettNyOppgave(String eksternId, String tekst, URI lenke, Merkelapp merkelapp, String virksomhetsnummer, LocalDateTime tidspunkt) { | ||
|
||
var request = new NyOppgaveMutationRequest(); | ||
var input = new NyOppgaveInput(); | ||
input.setMottaker(new MottakerInput(new AltinnMottakerInput(SERVICE_CODE, SERVICE_EDITION_CODE), null)); | ||
input.setNotifikasjon(new NotifikasjonInput(lenke.toString(), merkelapp.getBeskrivelse(), tekst)); | ||
input.setMetadata(new MetadataInput(eksternId, null, null, tidspunkt.toString(), virksomhetsnummer)); | ||
request.setNyOppgave(input); | ||
|
||
var projection = new NyOppgaveResultatResponseProjection().typename() | ||
.onNyOppgaveVellykket(new NyOppgaveVellykketResponseProjection().id()) | ||
.onUgyldigMerkelapp(new UgyldigMerkelappResponseProjection().feilmelding()) | ||
.onUgyldigMottaker(new UgyldigMottakerResponseProjection().feilmelding()) | ||
.onDuplikatEksternIdOgMerkelapp(new DuplikatEksternIdOgMerkelappResponseProjection().feilmelding()) | ||
.onUkjentProdusent(new UkjentProdusentResponseProjection().feilmelding()) | ||
.onUgyldigPaaminnelseTidspunkt(new UgyldigPaaminnelseTidspunktResponseProjection().feilmelding()) | ||
.onUkjentRolle(new UkjentRolleResponseProjection().feilmelding()); | ||
|
||
return klient.opprettNyOppgave(request, projection); | ||
} | ||
|
||
@Override | ||
public String lukkOppgave(String id, LocalDateTime tidspunkt) { | ||
|
||
var request = new OppgaveUtfoertMutationRequest(); | ||
request.setId(id); | ||
request.setUtfoertTidspunkt(tidspunkt.toString()); | ||
|
||
var projection = new OppgaveUtfoertResultatResponseProjection().typename() | ||
.onOppgaveUtfoertVellykket(new OppgaveUtfoertVellykketResponseProjection().id()) | ||
.onUgyldigMerkelapp(new UgyldigMerkelappResponseProjection().feilmelding()) | ||
.onUkjentProdusent(new UkjentProdusentResponseProjection().feilmelding()) | ||
.onNotifikasjonFinnesIkke(new NotifikasjonFinnesIkkeResponseProjection().feilmelding()); | ||
return klient.lukkOppgave(request, projection); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/no/nav/familie/inntektsmelding/arbeidsgivernotifikasjon/Merkelapp.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,23 @@ | ||
package no.nav.familie.inntektsmelding.arbeidsgivernotifikasjon; | ||
|
||
public enum Merkelapp { | ||
INNTEKTSMELDING_FP("Inntektsmelding foreldrepenger"), | ||
INNTEKTSMELDING_SVP("Inntektsmelding svangerskapspenger"), | ||
INNTEKTSMELDING_PSB("Inntektsmelding pleiepenger sykt barn"), | ||
INNTEKTSMELDING_OMP("Inntektsmelding omsorgspenger"), | ||
INNTEKTSMELDING_PILS("Inntektsmelding pleiepenger i livets sluttfase"), | ||
INNTEKTSMELDING_OPP("Inntektsmelding opplæringspenger") | ||
; | ||
|
||
private String beskrivelse; | ||
|
||
Merkelapp(String beskrivelse) { | ||
this.beskrivelse = beskrivelse; | ||
} | ||
|
||
public String getBeskrivelse() { | ||
return beskrivelse; | ||
} | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pdl.base.url=https://pdl-api.dev-fss-pub.nais.io/graphql | ||
pdl.scopes=api://dev-fss.pdl.pdl-api/.default | ||
|
||
arbeidsgiver.notifikasjon.url=https://ag-notifikasjon-produsent-api.intern.dev.nav.no/ | ||
arbeidsgiver.notifikasjon.scopes=api://dev-gcp.fager.notifikasjon-produsent-api/.default |
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,2 @@ | ||
arbeidsgiver.notifikasjon.url=https://ag-notifikasjon-produsent-api.intern.nav.no/ | ||
arbeidsgiver.notifikasjon.scopes=api://prod-gcp.fager.notifikasjon-produsent-api/.default |
Oops, something went wrong.