Skip to content

Commit

Permalink
Slett forsendelser hvis behandlingstatus er feilregistrert (#36)
Browse files Browse the repository at this point in the history
* Slett forsendelser hvis behandlingstatus er feilregistrert
---------

Co-authored-by: s148719 <[email protected]>
  • Loading branch information
ugur93 and s148719 authored Oct 19, 2023
1 parent f1c88d6 commit 089366b
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 227 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/deploy_feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ jobs:
image: ${{ steps.docker-push.outputs.image }}
tag: ${{ steps.docker-push.outputs.tag }}

run-tests:
runs-on: ubuntu-latest
name: Run tests
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -B -e --settings .m2/maven-settings.xml clean install


deploy-feature:
runs-on: ubuntu-latest
name: Deploy feature
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:

jobs:
build:
if: github.event.pull_request.draft == false
if: github.event.pull_request.draft == false && ${{ github.actor != 'dependabot[bot]' }}
permissions:
contents: "read"
id-token: "write"
Expand Down Expand Up @@ -47,6 +47,24 @@ jobs:
name: Deploy dev
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -B -e --settings .m2/maven-settings.xml clean install

deploy-main:
runs-on: ubuntu-latest
name: Deploy main
needs: build
steps:
- uses: actions/checkout@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/

mvnw
mvnw.cmd

### STS ###
.apt_generated
.classpath
Expand Down
2 changes: 2 additions & 0 deletions initEnv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kubectx dev-gcp
kubectl exec --tty deployment/bidrag-behandling printenv | grep -E 'AZURE_APP_CLIENT_ID|AZURE_APP_CLIENT_SECRET|TOKEN_X|AZURE_OPENID_CONFIG_TOKEN_ENDPOINT|AZURE_APP_TENANT_ID|AZURE_APP_WELL_KNOWN_URL|_URL|SCOPE' > src/test/resources/application-lokal-nais-secrets.properties
67 changes: 66 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
<mockk.version>4.0.2</mockk.version>
<kotlin-logging-jvm.version>3.0.5</kotlin-logging-jvm.version>
<flyway.version>9.22.3</flyway.version>
<jackson.version>2.15.3</jackson.version>
<testcontainers.version>1.19.1</testcontainers.version>
<tomcat-embed-core.version>10.1.15</tomcat-embed-core.version>
</properties>

<repositories>
Expand All @@ -38,6 +40,16 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
Expand All @@ -53,6 +65,21 @@
<artifactId>spring-kafka</artifactId>
<version>3.0.12</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat-embed-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>${tomcat-embed-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>${tomcat-embed-core.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -159,7 +186,7 @@
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.15.3</version>
<version>${jackson.version}</version>
</dependency>


Expand Down Expand Up @@ -430,4 +457,42 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>OSX</id>
<activation>
<os>
<name>Mac OS X</name>
</os>
</activation>
<properties>
<profile.default.on>false</profile.default.on>
</properties>
<repositories>
<repository>
<id>nexus-internal-release</id>
<url>https://repo.adeo.no/repository/maven-release</url>
</repository>
<repository>
<id>nexus-internal-mirror</id>
<url>https://repo.adeo.no/repository/maven-public</url>
</repository>
</repositories>
</profile>
<profile>
<id>default</id>
<activation>
<property>
<name>profile.default.on</name>
<value>true</value>
</property>
</activation>
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/navikt/bidrag-commons</url>
</repository>
</repositories>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ForskuddBeregning {
private fun prepareBostatus(
husstandsBarnPerioder: List<HusstandsBarnPeriodeModel>,
soknadsBarnIdent: String,
soknadBarn: Rolle
soknadBarn: Rolle,
): List<Grunnlag> =
husstandsBarnPerioder
.filter { soknadsBarnIdent == it.ident }
Expand Down Expand Up @@ -218,14 +218,14 @@ class ForskuddBeregning {
beregnDatoFra = b.virkningsDato,
beregnDatoTil = b.datoTom,
grunnlagListe = prepareSoknadsBarn(soknadsBarn, fDato) +
prepareBarnIHusstand(b) +
prepareBostatus(b.husstandsBarnPerioder, soknadsBarn.ident, soknadsBarn) +
prepareInntekterForBeregning(
b.inntekter,
b.barnetillegg,
b.utvidetbarnetrygd,
) +
prepareSivilstand(b.sivilstand),
prepareBarnIHusstand(b) +
prepareBostatus(b.husstandsBarnPerioder, soknadsBarn.ident, soknadsBarn) +
prepareInntekterForBeregning(
b.inntekter,
b.barnetillegg,
b.utvidetbarnetrygd,
) +
prepareSivilstand(b.sivilstand),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ class BidragPersonConsumer(
fun hentPerson(ident: String): HentPersonResponse {
return postForNonNullEntity(hentPersonUri, HentPersonRequest(ident))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BehandlingBeregnForskuddController(
private val behandlingService: BehandlingService,
private val bidragBeregnForskuddConsumer: BidragBeregnForskuddConsumer,
private val forskuddBeregning: ForskuddBeregning,
private val bidragPersonConsumer: BidragPersonConsumer
private val bidragPersonConsumer: BidragPersonConsumer,
) {
private fun isPeriodOneWithinPeriodTwo(
datoFom1: LocalDate?,
Expand Down Expand Up @@ -56,7 +56,9 @@ class BehandlingBeregnForskuddController(
.mapOrAccumulate {
val fDato = if (it.fodtDato == null) {
bidragPersonConsumer.hentPerson(it.ident).fødselsdato
} else it.fodtDato.toLocalDate().toNoString()
} else {
it.fodtDato.toLocalDate().toNoString()
}

val payload = forskuddBeregning.toPayload(behandlingModel, it, fDato)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class ForsendelseController(private val forsendelseService: ForsendelseService)
@RequestBody(required = true)
request: InitalizeForsendelseRequest,
): List<String> {
return forsendelseService.opprettForsendelse(request)
return forsendelseService.slettEllerOpprettForsendelse(request)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package no.nav.bidrag.behandling.dto
data class HentPersonResponse(
val ident: String,
valdselsdato: String,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import no.nav.bidrag.domain.enums.EngangsbelopType
import no.nav.bidrag.domain.enums.StonadType
import no.nav.bidrag.domain.enums.VedtakType

data class DokumentDto(
val tittel: String? = null,
val dokumentmalId: String? = null,
val bestillDokument: Boolean? = null,
val språk: String? = null,
val arkivsystem: String? = null,
)

data class BehandlingInfoDto(
val vedtakId: Long? = null,
val behandlingId: Long? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ import no.nav.bidrag.domain.ident.PersonIdent

data class InitalizeForsendelseRequest(
@field:NotBlank(message = "Saksnummer kan ikke være blank")
@field:Size(max = 7, message = "Saks nummer kan ikke være lengre enn 7 tegn")
@field:Size(max = 7, message = "Saksnummer kan ikke være lengre enn 7 tegn")
val saksnummer: String,
val behandlingInfo: BehandlingInfoDto,
val enhet: String,
val tema: String? = null,
val roller: List<ForsendelseRolleDto>,
val behandlingStatus: BehandlingStatus? = null,
)

data class ForsendelseRolleDto(
valdselsnummer: PersonIdent?,
val type: Rolletype,
)

// TODO: Flytt dette hvis det blir også brukt i Behandling domain objektet
enum class BehandlingStatus {
OPPRETTET,
ENDRET,
FEILREGISTRERT,
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ class VedtakHendelseListener(
opprettForsendelse(vedtak, behandling)
}

private fun opprettForsendelse(
vedtak: VedtakHendelse,
behandling: Behandling,
) {
forsendelseService.opprettForsendelse(
private fun opprettForsendelse(vedtak: VedtakHendelse, behandling: Behandling) {
forsendelseService.slettEllerOpprettForsendelse(
InitalizeForsendelseRequest(
saksnummer = vedtak.saksnummer,
enhet = vedtak.enhetId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BehandlingService(
}

private fun opprettForsendelseForBehandling(behandling: Behandling) {
forsendelseService.opprettForsendelse(
forsendelseService.slettEllerOpprettForsendelse(
InitalizeForsendelseRequest(
saksnummer = behandling.saksnummer,
enhet = behandling.behandlerEnhet,
Expand Down Expand Up @@ -163,10 +163,8 @@ class BehandlingService(
)

@Transactional
fun oppdaterVedtakId(
behandlingId: Long,
vedtakId: Long,
) = behandlingRepository.oppdaterVedtakId(behandlingId, vedtakId)
fun oppdaterVedtakId(behandlingId: Long, vedtakId: Long) =
behandlingRepository.oppdaterVedtakId(behandlingId, vedtakId)

@Transactional
fun syncRoller(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import no.nav.bidrag.behandling.consumer.BidragTilgangskontrollConsumer
import no.nav.bidrag.behandling.consumer.ForsendelseStatusTo
import no.nav.bidrag.behandling.consumer.ForsendelseTypeTo
import no.nav.bidrag.behandling.dto.forsendelse.BehandlingInfoDto
import no.nav.bidrag.behandling.dto.forsendelse.BehandlingStatus
import no.nav.bidrag.behandling.dto.forsendelse.ForsendelseRolleDto
import no.nav.bidrag.behandling.dto.forsendelse.InitalizeForsendelseRequest
import no.nav.bidrag.behandling.dto.forsendelse.MottakerDto
Expand All @@ -28,7 +29,22 @@ class ForsendelseService(
private val ikkeOpprettVarslingForForskuddMedType =
listOf(VedtakType.FASTSETTELSE, VedtakType.ENDRING)

fun opprettForsendelse(request: InitalizeForsendelseRequest): List<String> {
fun slettEllerOpprettForsendelse(request: InitalizeForsendelseRequest): List<String> {
if (request.behandlingStatus == BehandlingStatus.FEILREGISTRERT) {
return slettForsendelse(request)
}

return opprettForsendelse(request)
}

private fun slettForsendelse(request: InitalizeForsendelseRequest): List<String> {
return slettVarselbrevUnderOpprettelse(
request.saksnummer,
request.behandlingInfo.soknadId,
).map { it.toString() }
}

private fun opprettForsendelse(request: InitalizeForsendelseRequest): List<String> {
val opprettRequestTemplate = OpprettForsendelseForespørsel(
behandlingInfo = request.behandlingInfo
.copy(
Expand Down Expand Up @@ -69,15 +85,16 @@ class ForsendelseService(
return opprettetForsendelser
}

fun slettVarselbrevUnderOpprettelse(saksnummer: String, soknadId: Long) {
private fun slettVarselbrevUnderOpprettelse(saksnummer: String, soknadId: Long): List<Long> {
val forsendelser = bidragForsendelseConsumer.hentForsendelserISak(saksnummer)
forsendelser
return forsendelser
.filter { it.forsendelseType == ForsendelseTypeTo.UTGÅENDE }
.filter { it.status == ForsendelseStatusTo.UNDER_OPPRETTELSE && it.behandlingInfo?.soknadId?.isNotEmpty() == true }
.filter { it.behandlingInfo?.soknadId == soknadId.toString() && !it.behandlingInfo.erFattet }
.forEach {
.map {
bidragForsendelseConsumer.slettForsendelse(it.forsendelseId)
log.info { "Slettet forsendelse ${it.forsendelseId} for varselbrev som var under opprettelse" }
it.forsendelseId
}
}

Expand Down
Loading

0 comments on commit 089366b

Please sign in to comment.