Skip to content

Commit

Permalink
Merge branch 'main' into forsendelse_slett_forsendelser
Browse files Browse the repository at this point in the history
  • Loading branch information
s148719 committed Oct 19, 2023
2 parents a322693 + f1c88d6 commit 5267e9c
Show file tree
Hide file tree
Showing 97 changed files with 2,235 additions and 1,425 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run tests for dependabot PRs
on:
workflow_dispatch:
pull_request:
types: [ ready_for_review, opened, synchronize ]
branches:
- 'dependabot/**'

env:
GITHUB_USERNAME: x-access-token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
run-tests:
runs-on: ubuntu-latest
name: Run tests
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 test
8 changes: 5 additions & 3 deletions .github/workflows/deploy_feature.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Deploy feature
on:
workflow_dispatch:
push:
branches:
- '**'
Expand Down Expand Up @@ -29,7 +30,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -B -e --settings .m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand Down Expand Up @@ -58,11 +59,12 @@ jobs:
${{ runner.os }}-maven-
- run: mvn -B -e --settings .m2/maven-settings.xml clean install


deploy-feature:
runs-on: ubuntu-latest
name: Deploy feature
needs: build

needs:
- build
steps:
- uses: actions/checkout@v4
with:
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Deploy to dev
on:
workflow_dispatch:
pull_request:
types: [ ready_for_review, opened, synchronize ]
branches:
- '**'
- '!dependabot/**'

env:
GITHUB_USERNAME: x-access-token
Expand All @@ -27,7 +31,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -B -e --settings .m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand All @@ -38,10 +42,11 @@ jobs:
image: ${{ steps.docker-push.outputs.image }}
tag: ${{ steps.docker-push.outputs.tag }}

run-tests:
deploy-dev:
runs-on: ubuntu-latest
name: Run tests
needs: build
name: Deploy dev
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target/
.settings
.springBeans
.sts4-cache
*nais-secrets*

### IntelliJ IDEA ###
.idea
Expand All @@ -30,4 +31,4 @@ build/

### VS Code ###
.vscode/
*nais-secrets*

7 changes: 6 additions & 1 deletion .nais/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: bidrag-behandling-feature
ingresses:
- https://bidrag-behandling-feature.intern.dev.nav.no
env:
BIDRAG_PERSON_URL: https://bidrag-person-feature.dev-fss-pub.nais.io/bidrag-person
BIDRAG_PERSON_SCOPE: dev-fss.bidrag.bidrag-person-feature
BIDRAG_BEREGN_FORSKUDD_URL: http://bidrag-beregn-forskudd-rest-feature
BIDRAG_BEREGN_FORSKUDD_SCOPE: dev-gcp.bidrag.bidrag-beregn-forskudd-rest-feature
BIDRAG_GRUNNLAG_URL: http://bidrag-grunnlag-feature
Expand All @@ -11,6 +13,7 @@ env:
BIDRAG_TILGANGSKONTROLL_URL: http://bidrag-tilgangskontroll-feature
BIDRAG_TILGANGGSKONTROLL_SCOPE: dev-gcp.bidrag.bidrag-tilgangskontroll-feature
TOPIC_VEDTAK: bidrag.vedtak-feature
JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
kafka:
pool: nav-dev
azure_access_inbound:
Expand All @@ -34,4 +37,6 @@ outbound-access-apps:
- bidrag-beregn-forskudd-rest-feature
- bidrag-grunnlag-feature
- bidrag-dokument-forsendelse-feature
- bidrag-tilgangskontroll-feature
- bidrag-tilgangskontroll-feature
outbound-access-hosts:
- bidrag-person-feature.dev-fss-pub.nais.io
7 changes: 6 additions & 1 deletion .nais/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: bidrag-behandling
ingresses:
- https://bidrag-behandling.intern.dev.nav.no
env:
BIDRAG_PERSON_URL: https://bidrag-person.dev-fss-pub.nais.io/bidrag-person
BIDRAG_PERSON_SCOPE: dev-fss.bidrag.bidrag-person
BIDRAG_BEREGN_FORSKUDD_URL: http://bidrag-beregn-forskudd-rest
BIDRAG_BEREGN_FORSKUDD_SCOPE: dev-gcp.bidrag.bidrag-beregn-forskudd-rest
BIDRAG_GRUNNLAG_URL: http://bidrag-grunnlag
Expand All @@ -11,6 +13,7 @@ env:
BIDRAG_TILGANGSKONTROLL_URL: http://bidrag-tilgangskontroll
BIDRAG_TILGANGGSKONTROLL_SCOPE: dev-gcp.bidrag.bidrag-tilgangskontroll
TOPIC_VEDTAK: bidrag.vedtak-syntetisk
JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
kafka:
pool: nav-dev
azure_access_inbound:
Expand All @@ -34,4 +37,6 @@ outbound-access-apps:
- bidrag-beregn-forskudd-rest
- bidrag-grunnlag
- bidrag-dokument-forsendelse
- bidrag-tilgangskontroll
- bidrag-tilgangskontroll
outbound-access-hosts:
- bidrag-person.dev-fss-pub.nais.io
6 changes: 5 additions & 1 deletion .nais/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: bidrag-behandling
ingresses:
- https://bidrag-behandling.intern.nav.no
env:
BIDRAG_PERSON_URL: https://bidrag-person.prod-fss-pub.nais.io/bidrag-person
BIDRAG_PERSON_SCOPE: prod-fss.bidrag.bidrag-person
BIDRAG_BEREGN_FORSKUDD_URL: http://bidrag-beregn-forskudd-rest
BIDRAG_BEREGN_FORSKUDD_SCOPE: prod-gcp.bidrag.bidrag-beregn-forskudd-rest
BIDRAG_GRUNNLAG_URL: http://bidrag-grunnlag
Expand Down Expand Up @@ -34,4 +36,6 @@ outbound-access-apps:
- bidrag-beregn-forskudd-rest
- bidrag-grunnlag
- bidrag-dokument-forsendelse
- bidrag-tilgangskontroll
- bidrag-tilgangskontroll
outbound-access-hosts:
- bidrag-person.prod-fss-pub.nais.io
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ Legg til Github secret `NAIS_DEPLOY_APIKEY` hvor secret hentes fra [Api key](htt

## Kjøre applikasjonen lokalt

#### Dockermiljø
Et lokalt Dockermiljø må være tilgjengelig for lokal kjøring. Forebredelsessteg for lokal kjøring på Mac OS med Colima Docker:

> colima start \
> docker-compose build \
> docker-compose up
#### Starte applikasjon lokalt

Profil: local (angis i program arguments)

Start opp applikasjonen ved å kjøre [BidragTemplateLocal.kt](src/test/kotlin/no/nav/bidrag/behandling/BidragSpringAppLocal.kt).

Dette starter applikasjonen med profil `local` og henter miljøvariabler for Q1 miljøet fra filen [application-local.yaml](src/test/resources/application-local.yaml).

Her mangler det noen miljøvariabler som ikke bør committes til Git (Miljøvariabler for passord/secret osv).<br/>
Expand All @@ -23,14 +35,10 @@ Disse kan hentes ved å kjøre kan hentes ved å kjøre
kubectl exec --tty deployment/bidrag-behandling-feature -- printenv | grep -e AZURE_APP_CLIENT_ID -e AZURE_APP_CLIENT_SECRET
```

### Live reload
Med `spring-boot-devtools` har Spring støtte for live-reload av applikasjon. Dette betyr i praksis at Spring vil automatisk restarte applikasjonen når en fil endres. Du vil derfor slippe å restarte applikasjonen hver gang du gjør endringer. Dette er forklart i [dokumentasjonen](https://docs.spring.io/spring-boot/docs/1.5.16.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart).
For at dette skal fungere må det gjøres noe endringer i Intellij instillingene slik at Intellij automatisk re-bygger filene som er endret:
#### Kjøre lokalt mot sky

* Gå til `Preference -> Compiler -> check "Build project automatically"`
* Gå til `Preference -> Advanced settings -> check "Allow auto-make to start even if developed application is currently running"`
Profil: local-nais (angis i program arguments)

#### Kjøre lokalt mot sky
For å kunne kjøre lokalt mot sky må du gjøre følgende

Åpne terminal på root mappen til `bidrag-behandling`
Expand All @@ -51,4 +59,12 @@ Deretter kjør følgende kommando for å importere secrets. Viktig at filen som
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
```

Deretter kan tokenet brukes til å logge inn på swagger-ui http://localhost:8080/swagger-ui.html
Deretter kan tokenet brukes til å logge inn på swagger-ui http://localhost:8990/swagger-ui.html

### Live reload
Med `spring-boot-devtools` har Spring støtte for live-reload av applikasjon. Dette betyr i praksis at Spring vil automatisk restarte applikasjonen når en fil endres. Du vil derfor slippe å restarte applikasjonen hver gang du gjør endringer. Dette er forklart i [dokumentasjonen](https://docs.spring.io/spring-boot/docs/1.5.16.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart).
For at dette skal fungere må det gjøres noe endringer i Intellij instillingene slik at Intellij automatisk re-bygger filene som er endret:

* Gå til `Preference -> Compiler -> check "Build project automatically"`
* Gå til `Preference -> Advanced settings -> check "Allow auto-make to start even if developed application is currently running"`
*
6 changes: 6 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ services:
POSTGRES_DB: bidrag-behandling
volumes:
- db:/var/lib/postgresql/data
zookeeper:
container_name: zookeeper
image: confluentinc/cp-zookeeper:7.1.2
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: confluentinc/cp-kafka:6.2.1
depends_on:
Expand Down
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>no.nav</groupId>
Expand All @@ -18,15 +18,15 @@
<bidrag-commons.version>20230510130746_8b93e85</bidrag-commons.version>
<bidrag-domain.version>20230824131636_7aef062</bidrag-domain.version>
<logback-encoder.version>7.4</logback-encoder.version>
<token-support.version>3.1.5</token-support.version>
<token-support.version>3.1.7</token-support.version>
<springdoc.version>2.2.0</springdoc.version>
<springframework-cloud.version>4.0.4</springframework-cloud.version>
<bidrag-commons-test.version>LATEST</bidrag-commons-test.version>
<kotest.version>5.6.2</kotest.version>
<kotest.version>5.7.2</kotest.version>
<mockk.version>4.0.2</mockk.version>
<kotlin-logging-jvm.version>3.0.5</kotlin-logging-jvm.version>
<flyway.version>9.22.0</flyway.version>
<testcontainers.version>1.19.0</testcontainers.version>
<flyway.version>9.22.3</flyway.version>
<testcontainers.version>1.19.1</testcontainers.version>
</properties>

<repositories>
Expand All @@ -46,12 +46,12 @@
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.10.3</version>
<version>1.1.10.5</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>3.0.11</version>
<version>3.0.12</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -130,7 +130,7 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<version>2.2.220</version>
<version>2.2.224</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
Expand Down Expand Up @@ -159,7 +159,7 @@
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.15.2</version>
<version>2.15.3</version>
</dependency>


Expand Down Expand Up @@ -198,7 +198,7 @@
<dependency>
<groupId>no.nav.bidrag</groupId>
<artifactId>bidrag-transport</artifactId>
<version>20230821134807_d0642b9</version>
<version>20230918144946_1e1bc33</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -423,7 +423,7 @@
<dependency>
<groupId>com.pinterest</groupId>
<artifactId>ktlint</artifactId>
<version>0.48.2</version>
<version>0.50.0</version>
</dependency>
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
Expand Down
10 changes: 8 additions & 2 deletions src/main/kotlin/no/nav/bidrag/behandling/Exceptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package no.nav.bidrag.behandling
import org.springframework.http.HttpStatus
import org.springframework.web.client.HttpClientErrorException

fun `404`(behandlingId: Long): Nothing =
fun behandlingNotFoundException(behandlingId: Long): Nothing =
throw HttpClientErrorException(HttpStatus.NOT_FOUND, "Fant ikke behandling med id $behandlingId")

class KunneIkkeLeseMeldingFraHendelse(melding: String?, throwable: Throwable) : RuntimeException(melding, throwable)
fun fantIkkeSak(saksnummer: String): Nothing = throw HttpClientErrorException(HttpStatus.BAD_REQUEST, "Sak med saksnummer $saksnummer finnes ikke")

fun fantIkkeSak(saksnummer: String): Nothing =
throw HttpClientErrorException(
HttpStatus.BAD_REQUEST,
"Sak med saksnummer $saksnummer finnes ikke",
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class DefaultRestControllerAdvice {
}

@ResponseBody
@ExceptionHandler(value = [MethodArgumentNotValidException::class, IllegalArgumentException::class, MethodArgumentTypeMismatchException::class, ConversionFailedException::class, HttpMessageNotReadableException::class])
@ExceptionHandler(
value = [MethodArgumentNotValidException::class, IllegalArgumentException::class, MethodArgumentTypeMismatchException::class, ConversionFailedException::class, HttpMessageNotReadableException::class],
)
fun handleInvalidValueExceptions(exception: Exception): ResponseEntity<*> {
val cause = exception.cause
val valideringsFeil =
Expand Down Expand Up @@ -91,10 +93,11 @@ class DefaultRestControllerAdvice {

private fun createMissingKotlinParameterViolation(ex: MissingKotlinParameterException): String {
val errorFieldRegex = Regex("\\.([^.]*)\\[\\\"(.*)\"\\]\$")
val paths = ex.path.map { errorFieldRegex.find(it.description)!! }.map {
val (objectName, field) = it.destructured
"$objectName.$field"
}
return "${paths.joinToString("->")} kan ikke være null"
val paths =
ex.path.map { errorFieldRegex.find(it.description)!! }.map {
val (objectName, field) = it.destructured
"$objectName.$field"
}
return "${paths.joinToString("->")} må fylles ut"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ private val log = KotlinLogging.logger {}
@Component
@Aspect
class HendelseCorrelationAspect(private val objectMapper: ObjectMapper) {

@Before(value = "execution(* no.nav.bidrag.behandling.kafka.VedtakHendelseListener.prossesserVedtakHendelse(..)) && args(hendelse)")
fun leggSporingFraVedtakHendelseTilMDC(joinPoint: JoinPoint, hendelse: ConsumerRecord<String, String>) {
fun leggSporingFraVedtakHendelseTilMDC(
joinPoint: JoinPoint,
hendelse: ConsumerRecord<String, String>,
) {
hentSporingFraHendelse(hendelse)?.let {
val correlationId = CorrelationId.existing(it)
MDC.put(CORRELATION_ID_HEADER, correlationId.get())
Expand Down
Loading

0 comments on commit 5267e9c

Please sign in to comment.