-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Opprette omregningskjøring for automatisk behandling * rettet test som feilet * rettet etter tilbakemeldinger * rettet etter tilbakemeldinger * rettet etter tilbakemeldinger * rette byggefeil * la til tester * rettet tilbakemeldinger * rettet tilbakemeldinger
- Loading branch information
1 parent
b4ae1d9
commit 3261132
Showing
14 changed files
with
325 additions
and
57 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
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
20 changes: 20 additions & 0 deletions
20
...ng/src/main/kotlin/inntektsjustering/selvbetjening/InntektsjusteringSelvbetjeningRoute.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,20 @@ | ||
package no.nav.etterlatte.inntektsjustering.selvbetjening | ||
|
||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.call | ||
import io.ktor.server.request.receive | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.post | ||
import io.ktor.server.routing.route | ||
import no.nav.etterlatte.libs.common.inntektsjustering.InntektsjusteringRequest | ||
|
||
internal fun Route.inntektsjusteringSelvbetjeningRoute(service: InntektsjusteringSelvbetjeningService) { | ||
route("/inntektsjustering") { | ||
post("behandle") { | ||
val request = call.receive<InntektsjusteringRequest>() | ||
service.behandleInntektsjustering(request) | ||
call.respond(HttpStatusCode.OK) | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
.../src/main/kotlin/inntektsjustering/selvbetjening/InntektsjusteringSelvbetjeningService.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,117 @@ | ||
package no.nav.etterlatte.inntektsjustering.selvbetjening | ||
|
||
import no.nav.etterlatte.funksjonsbrytere.FeatureToggle | ||
import no.nav.etterlatte.funksjonsbrytere.FeatureToggleService | ||
import no.nav.etterlatte.kafka.JsonMessage | ||
import no.nav.etterlatte.kafka.KafkaProdusent | ||
import no.nav.etterlatte.libs.common.behandling.Revurderingaarsak | ||
import no.nav.etterlatte.libs.common.inntektsjustering.InntektsjusteringRequest | ||
import no.nav.etterlatte.libs.common.logging.getCorrelationId | ||
import no.nav.etterlatte.libs.common.oppgave.OppgaveKilde | ||
import no.nav.etterlatte.libs.common.oppgave.OppgaveType | ||
import no.nav.etterlatte.libs.common.rapidsandrivers.CORRELATION_ID_KEY | ||
import no.nav.etterlatte.libs.common.rapidsandrivers.TEKNISK_TID_KEY | ||
import no.nav.etterlatte.libs.common.sak.SakId | ||
import no.nav.etterlatte.libs.common.tidspunkt.Tidspunkt | ||
import no.nav.etterlatte.oppgave.OppgaveService | ||
import no.nav.etterlatte.rapidsandrivers.OmregningData | ||
import no.nav.etterlatte.rapidsandrivers.OmregningDataPacket | ||
import no.nav.etterlatte.rapidsandrivers.OmregningHendelseType | ||
import org.slf4j.LoggerFactory | ||
import java.time.YearMonth | ||
|
||
class InntektsjusteringSelvbetjeningService( | ||
private val oppgaveService: OppgaveService, | ||
private val rapid: KafkaProdusent<String, String>, | ||
private val featureToggleService: FeatureToggleService, | ||
) { | ||
private val logger = LoggerFactory.getLogger(this::class.java) | ||
|
||
fun behandleInntektsjustering(request: InntektsjusteringRequest) { | ||
logger.info("Starter behandling av innmeldt inntektsjustering for sak ${request.sak.sakId}") | ||
|
||
if (skalGjoeresAutomatisk()) { | ||
startAutomatiskBehandling( | ||
request, | ||
SakId(request.sak.sakId), | ||
) | ||
} else { | ||
startManuellBehandling(request) | ||
} | ||
} | ||
|
||
private fun startAutomatiskBehandling( | ||
request: InntektsjusteringRequest, | ||
sakId: SakId, | ||
) { | ||
logger.info("Behandles automatisk: starter omregning for sak ${request.sak.sakId}") | ||
publiserKlarForOmregning( | ||
sakId, | ||
InntektsjusteringRequest.utledLoependeFom(), | ||
InntektsjusteringRequest.utledKjoering(request.inntektsjusteringId), | ||
) | ||
} | ||
|
||
private fun startManuellBehandling(request: InntektsjusteringRequest) { | ||
logger.info("Behandles manuelt: oppretter oppgave for mottatt inntektsjustering for sak ${request.sak.sakId}") | ||
oppgaveService.opprettOppgave( | ||
sakId = SakId(request.sak.sakId), | ||
kilde = OppgaveKilde.BRUKERDIALOG, | ||
type = OppgaveType.MOTTATT_INNTEKTSJUSTERING, | ||
merknad = "Mottatt inntektsjustering", | ||
referanse = request.journalpostId, | ||
) | ||
} | ||
|
||
private fun publiserKlarForOmregning( | ||
sakId: SakId, | ||
loependeFom: YearMonth, | ||
kjoering: String, | ||
) { | ||
val correlationId = getCorrelationId() | ||
rapid | ||
.publiser( | ||
"inntektsjustering-$sakId", | ||
JsonMessage | ||
.newMessage( | ||
OmregningHendelseType.KLAR_FOR_OMREGNING.lagEventnameForType(), | ||
mapOf( | ||
CORRELATION_ID_KEY to correlationId, | ||
TEKNISK_TID_KEY to Tidspunkt.now(), | ||
OmregningDataPacket.KEY to | ||
OmregningData( | ||
kjoering = kjoering, | ||
sakId = sakId, | ||
revurderingaarsak = Revurderingaarsak.INNTEKTSENDRING, | ||
fradato = loependeFom.atDay(1), | ||
).toPacket(), | ||
), | ||
).toJson(), | ||
).also { (partition, offset) -> | ||
logger.info( | ||
"Publiserte klar for omregningshendelse for $sakId på partition " + | ||
"$partition, offset $offset, correlationid: $correlationId", | ||
) | ||
} | ||
} | ||
|
||
private fun skalGjoeresAutomatisk(): Boolean { | ||
val featureToggle = | ||
featureToggleService.isEnabled( | ||
InntektsjusterinFeatureToggle.AUTOMATISK_BEHANDLE, | ||
false, | ||
) | ||
|
||
// TODO: sjekke om riktig tilstand for automatisk behandling | ||
return featureToggle | ||
} | ||
|
||
enum class InntektsjusterinFeatureToggle( | ||
private val key: String, | ||
) : FeatureToggle { | ||
AUTOMATISK_BEHANDLE("inntektsjustering-automatisk-behandle"), | ||
; | ||
|
||
override fun key() = key | ||
} | ||
} |
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.