-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #771 from navikt/testprodusent/endrePåminnelseOppgave
Testprodusent/endre påminnelse oppgave
- Loading branch information
Showing
31 changed files
with
3,256 additions
and
14 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
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
3 changes: 0 additions & 3 deletions
3
...ain/kotlin/no/nav/arbeidsgiver/notifikasjon/infrastruktur/kafka/CoroutineKafkaConsumer.kt
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
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
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
102 changes: 102 additions & 0 deletions
102
...c/main/kotlin/no/nav/arbeidsgiver/notifikasjon/produsent/api/MutationOppgavePåminnelse.kt
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,102 @@ | ||
package no.nav.arbeidsgiver.notifikasjon.produsent.api | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import com.fasterxml.jackson.annotation.JsonTypeName | ||
import graphql.schema.idl.RuntimeWiring | ||
import no.nav.arbeidsgiver.notifikasjon.hendelse.HendelseModel | ||
import no.nav.arbeidsgiver.notifikasjon.infrastruktur.graphql.* | ||
import no.nav.arbeidsgiver.notifikasjon.produsent.ProdusentModel | ||
import no.nav.arbeidsgiver.notifikasjon.produsent.ProdusentRepository | ||
import java.time.OffsetDateTime | ||
import java.util.* | ||
|
||
internal class MutationOppgavePåminnelse( | ||
private val hendelseDispatcher: HendelseDispatcher, | ||
private val produsentRepository: ProdusentRepository, | ||
) { | ||
|
||
fun wire(runtime: RuntimeWiring.Builder) { | ||
runtime.resolveSubtypes<OppgaveEndrePaaminnelseResultat>() | ||
|
||
runtime.wire("Mutation") { | ||
coDataFetcher("oppgaveEndrePaaminnelse") { env -> | ||
oppgaveEndrePaaminnelse( | ||
context = env.notifikasjonContext(), | ||
idempotenceKey = env.getTypedArgumentOrNull<String>("idempotencyKey"), | ||
notifikasjon = hentNotifikasjon( | ||
produsentRepository, | ||
id = env.getTypedArgument<UUID>("id") | ||
) { error -> return@coDataFetcher error }, | ||
paaminnelse = env.getTypedArgumentOrNull<PaaminnelseInput>("paaminnelse"), | ||
) | ||
} | ||
coDataFetcher("oppgaveEndrePaaminnelseByEksternId") { env -> | ||
oppgaveEndrePaaminnelse( | ||
context = env.notifikasjonContext(), | ||
idempotenceKey = env.getTypedArgumentOrNull<String>("idempotencyKey"), | ||
notifikasjon = hentNotifikasjon( | ||
produsentRepository, | ||
eksternId = env.getTypedArgument<String>("eksternId"), | ||
merkelapp = env.getTypedArgument<String>("merkelapp") | ||
) { error -> return@coDataFetcher error }, | ||
paaminnelse = env.getTypedArgumentOrNull<PaaminnelseInput>("paaminnelse"), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "__typename") | ||
sealed interface OppgaveEndrePaaminnelseResultat | ||
|
||
@JsonTypeName("OppgaveEndrePaaminnelseVellykket") | ||
data class OppgaveEndrePaaminnelseVellykket( | ||
val id: UUID | ||
) : OppgaveEndrePaaminnelseResultat | ||
|
||
private suspend fun oppgaveEndrePaaminnelse( | ||
context: ProdusentAPI.Context, | ||
idempotenceKey: String?, | ||
notifikasjon: ProdusentModel.Notifikasjon, | ||
paaminnelse: PaaminnelseInput?, | ||
) : OppgaveEndrePaaminnelseResultat { | ||
if (notifikasjon !is ProdusentModel.Oppgave) { | ||
return Error.NotifikasjonFinnesIkke("Notifikasjonen (id ${notifikasjon.id}) er ikke en oppgave") | ||
} | ||
|
||
val produsent = hentProdusent(context) { error -> return error } | ||
|
||
tilgangsstyrMerkelapp(produsent, notifikasjon.merkelapp) { error -> return error } | ||
|
||
idempotenceKey?.let { | ||
if (produsentRepository.notifikasjonOppdateringFinnes(notifikasjon.id, it)) { | ||
return OppgaveEndrePaaminnelseVellykket(notifikasjon.id) | ||
} | ||
} | ||
|
||
try { | ||
hendelseDispatcher.send( | ||
HendelseModel.OppgavePåminnelseEndret( | ||
hendelseId = UUID.randomUUID(), | ||
notifikasjonId = notifikasjon.id, | ||
merkelapp = notifikasjon.merkelapp, | ||
virksomhetsnummer = notifikasjon.virksomhetsnummer, | ||
produsentId = produsent.id, | ||
kildeAppNavn = context.appName, | ||
påminnelse = paaminnelse?.tilDomene( | ||
opprettetTidspunkt = OffsetDateTime.now(), | ||
frist = notifikasjon.frist, | ||
startTidspunkt = null, | ||
virksomhetsnummer = notifikasjon.virksomhetsnummer, | ||
), | ||
frist = notifikasjon.frist, | ||
oppgaveOpprettetTidspunkt = notifikasjon.opprettetTidspunkt.toInstant(), | ||
idempotenceKey = idempotenceKey | ||
) | ||
) | ||
} catch (e: UgyldigPåminnelseTidspunktException) { | ||
return Error.UgyldigPåminnelseTidspunkt(e.message!!) | ||
} | ||
|
||
return OppgaveEndrePaaminnelseVellykket(notifikasjon.id) | ||
} | ||
} |
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
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
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
Oops, something went wrong.