Skip to content

Commit

Permalink
feilhåndtering
Browse files Browse the repository at this point in the history
  • Loading branch information
vegardlu committed Aug 2, 2024
1 parent b55fb06 commit f8f0631
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 65 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,18 @@ jobs:
VARS: .nais/q2.yaml
PRINT_PAYLOAD: true

prod:
name: 'Deploy to prod'
runs-on: ubuntu-latest
needs: [build, deploy-q1, deploy-q2]
steps:
- uses: actions/checkout@v4
- name: 'Calling nais deploy action for prod'
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: prod-gcp
RESOURCE: .nais/nais.yaml
VAR: image=${{ needs.build.outputs.docker-image }}
VARS: .nais/prod.yaml
PRINT_PAYLOAD: true
# Endret feilhåndtering, avventer litt produksjon
# prod:
# name: 'Deploy to prod'
# runs-on: ubuntu-latest
# needs: [build, deploy-q1, deploy-q2]
# steps:
# - uses: actions/checkout@v4
# - name: 'Calling nais deploy action for prod'
# uses: nais/deploy/actions/deploy@v2
# env:
# CLUSTER: prod-gcp
# RESOURCE: .nais/nais.yaml
# VAR: image=${{ needs.build.outputs.docker-image }}
# VARS: .nais/prod.yaml
# PRINT_PAYLOAD: true
8 changes: 0 additions & 8 deletions eux-journal-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.eux.journal.integration.client.eux.navrinasak

import no.nav.eux.journal.integration.config.get
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate
import org.springframework.web.client.toEntity
Expand All @@ -14,14 +13,10 @@ class EuxNavRinasakClient(
val euxNavRinasakRestTemplate: RestTemplate
) {

fun finn(rinasakId: Int): EuxNavRinasak {
val entity: ResponseEntity<EuxNavRinasak> = euxNavRinasakRestTemplate
.get()
.uri("${euxNavRinasakUrl}/api/v1/rinasaker/${rinasakId}")
.retrieve()
.toEntity()
if (!entity.statusCode.is2xxSuccessful)
throw RuntimeException("Fant ikke rinasak $rinasakId på: $euxNavRinasakUrl")
return entity.body!!
}
fun finn(rinasakId: Int): EuxNavRinasak = euxNavRinasakRestTemplate
.get()
.uri("${euxNavRinasakUrl}/api/v1/rinasaker/${rinasakId}")
.retrieve()
.toEntity<EuxNavRinasak>()
.body!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate
import org.springframework.web.client.toEntity
import org.springframework.web.client.body

@Component
class SafClient(
Expand All @@ -14,44 +14,54 @@ class SafClient(
val safRestTemplate: RestTemplate
) {

fun safSakerRoot(fnr: String): SafSakerRoot =
fun safSakerRoot(fnr: String): List<SafSak> =
safRestTemplate
.post()
.uri("$safUrl/graphql")
.body(sakerQuery(fnr))
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.retrieve()
.toEntity<SafSakerRoot>()
.body!!
.body<SafRoot<SafSakerData>>()
.safData()
.saker

fun safJournalpost(journalpostId: String): SafJournalpostRoot =
fun safJournalpost(journalpostId: String): SafJournalpost =
safRestTemplate
.post()
.uri("$safUrl/graphql")
.body(journalpostQuery(journalpostId))
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.retrieve()
.toEntity<SafJournalpostRoot>()
.body!!
.body<SafRoot<SafJournalpostData>>()
.safData()
.journalpost

fun firstTilknyttetJournalpostOrNull(dokumentInfoId: String): SafJournalpost? =
tilknyttedeJournalposterRoot(dokumentInfoId)
.data
.tilknyttedeJournalposter
.firstOrNull()

fun tilknyttedeJournalposterRoot(dokumentInfoId: String): SafTilknyttedeJournalposterRoot =
fun tilknyttedeJournalposterRoot(dokumentInfoId: String): List<SafJournalpost> =
safRestTemplate
.post()
.uri("$safUrl/graphql")
.body(tilknyttedeJournalposterQuery(dokumentInfoId))
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.retrieve()
.toEntity<SafTilknyttedeJournalposterRoot>()
.body!!
.body<SafRoot<SafTilknyttedeJournalposterData>>()
.safData()
.tilknyttedeJournalposter

fun <T> SafRoot<T>?.safData(): T =
when (this!!.data) {
null -> throw SafErrorException(
"Feil fra SAF: ${errors?.joinToString { it.message }}",
errors ?: emptyList()
)
else -> data!!
}
}

fun journalpostQuery(journalpostId: String) = GraphQlQuery(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package no.nav.eux.journal.integration.client.saf

data class SafJournalpostRoot(val data: SafJournalpostData)
data class SafRoot<T>(
val data: T?,
val errors: List<SafError>?,
)
data class SafJournalpostData(val journalpost: SafJournalpost)
data class SafSakerRoot(val data: SafSakerData)
data class SafSakerData(val saker: List<SafSak>)
data class SafTilknyttedeJournalposterRoot(val data: SafTilknyttedeJournalposterData)
data class SafTilknyttedeJournalposterData(val tilknyttedeJournalposter: List<SafJournalpost>)
data class SafDokumentoversiktBrukerData(val dokumentoversiktBruker: SafDokumentoversiktBruker)
data class SafDokumentoversiktBruker(val journalposter: List<SafJournalpost>)

data class SafError (
val message: String,
)

class SafErrorException(
message: String,
val errors: List<SafError>
) : RuntimeException(message)
8 changes: 0 additions & 8 deletions eux-journal-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
8 changes: 0 additions & 8 deletions eux-journal-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions eux-journal-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-XX:+EnableDynamicAgentLoading</argLine>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package no.nav.eux.journal.advice

import no.nav.eux.journal.integration.client.saf.SafErrorException
import org.springframework.http.HttpStatus.BAD_REQUEST
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.context.request.WebRequest
import java.time.LocalDateTime
import java.time.LocalDateTime.now

@RestControllerAdvice
class SafErrorExceptionAdvice {

@ExceptionHandler(value = [SafErrorException::class])
fun handleMethodArgumentValidationExceptions(
exception: SafErrorException,
webRequest: WebRequest
) = ResponseEntity
.status(BAD_REQUEST)
.body(exception.safError)

val SafErrorException.safError
get() = SafError(errors = errors.map { it.message })

data class SafError(
val timestamp: LocalDateTime = now(),
val errors: List<String>
)
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>no.nav.eux</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.13</version>
<version>1.0.16</version>
</parent>

<properties>
Expand Down

0 comments on commit f8f0631

Please sign in to comment.