Skip to content

Commit

Permalink
Proper validation of prosessfullmektig in mottak.
Browse files Browse the repository at this point in the history
Validate address in fullmektig update.

Co-authored-by: Andreas Jonsson <[email protected]>
  • Loading branch information
oyvind-wedoe and flexable777 committed Jan 20, 2025
1 parent adab4ef commit ef6805e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.klage.dokument.api.view

import com.fasterxml.jackson.databind.JsonNode
import no.nav.klage.dokument.exceptions.AddressValidationException
import java.time.LocalDate
import java.util.*

Expand Down Expand Up @@ -70,4 +71,14 @@ data class AddressInput(
val adresselinje3: String?,
val landkode: String,
val postnummer: String?,
)
) {
fun validateAddress() {
if (landkode == "NO") {
if (postnummer == null) {
throw AddressValidationException("Trenger postnummer for norske adresser.")
}
} else if (adresselinje1 == null) {
throw AddressValidationException("Trenger adresselinje1 for utenlandske adresser.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import no.nav.klage.dokument.api.view.DocumentValidationResponse

class DokumentValidationException(msg: String) : RuntimeException(msg)

class AddressValidationException(msg: String) : RuntimeException(msg)

class SmartDocumentValidationException(msg: String, val errors: List<DocumentValidationResponse>) : RuntimeException(msg)

class SvarbrevPreviewException(msg: String) : RuntimeException(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.micrometer.core.instrument.MeterRegistry
import jakarta.servlet.http.HttpServletRequest
import no.nav.klage.dokument.api.mapper.DokumentMapper
import no.nav.klage.dokument.api.view.*
import no.nav.klage.dokument.api.view.JournalfoertDokumentReference
import no.nav.klage.dokument.api.view.Mottaker
import no.nav.klage.dokument.domain.PDFDocument
import no.nav.klage.dokument.domain.dokumenterunderarbeid.*
Expand Down Expand Up @@ -833,15 +832,7 @@ class DokumentUnderArbeidService(
throw DokumentValidationException("Ugyldig landkode: ${mottaker.overriddenAddress.landkode}")
}

if (mottaker.overriddenAddress.landkode == "NO") {
if (mottaker.overriddenAddress.postnummer == null) {
throw DokumentValidationException("Trenger postnummer for norske adresser.")
}
} else {
if (mottaker.overriddenAddress.adresselinje1 == null) {
throw DokumentValidationException("Trenger adresselinje1 for utenlandske adresser.")
}
}
mottaker.overriddenAddress.validateAddress()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import no.nav.klage.kodeverk.Type
import no.nav.klage.kodeverk.hjemmel.Hjemmel
import no.nav.klage.kodeverk.ytelse.Ytelse
import no.nav.klage.oppgave.domain.klage.*
import no.nav.klage.oppgave.exceptions.OversendtKlageNotValidException
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*
Expand Down Expand Up @@ -204,7 +205,17 @@ data class OversendtAdresse(
description = "ISO 3166-1 alpha-2 kode. F.eks. NO for Norge."
)
val land: String,
)
) {
fun validateAddress() {
if (land == "NO") {
if (postnummer == null) {
throw OversendtKlageNotValidException("Trenger postnummer for norske adresser.")
}
} else if (adresselinje1 == null) {
throw OversendtKlageNotValidException("Trenger adresselinje1 for utenlandske adresser.")
}
}
}

data class OversendtPart(
@Schema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ class ProblemHandlingControllerAdvice : ResponseEntityExceptionHandler() {
): ProblemDetail =
create(HttpStatus.BAD_REQUEST, ex)

@ExceptionHandler
fun handleAddressValidationException(
ex: AddressValidationException,
request: NativeWebRequest
): ProblemDetail =
create(HttpStatus.BAD_REQUEST, ex)

@ExceptionHandler
fun handleDocumentDoesNotExistException(
ex: DocumentDoesNotExistException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,15 @@ class BehandlingService(
if ((input.address != null && input.name == null) || (input.address == null && input.name != null) ) {
throw IllegalOperation("Both address or name must be set")
}

if (input.address != null) {
input.address.validateAddress()
}
}

val behandling = getBehandlingForUpdate(
behandlingId
)

val partId: PartId? = if (input?.identifikator == null) {
null
} else {
Expand All @@ -1317,7 +1320,7 @@ class BehandlingService(
val poststed = if (it.landkode == "NO") {
if (it.postnummer != null) {
kodeverkService.getPoststed(it.postnummer)
} else null
} else throw IllegalOperation("Postnummer must be set for Norwegian address")
} else null
Adresse(
adresselinje1 = it.adresselinje1,
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/no/nav/klage/oppgave/service/MottakService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,27 @@ class MottakService(
validateOptionalDateTimeNotInFuture(sakMottattKaTidspunkt, ::sakMottattKaTidspunkt.name)
validateKildeReferanse(kildeReferanse)
validateEnhet(forrigeBehandlendeEnhet)
prosessfullmektig?.let { validateProsessfullmektig(it) }
}

private fun validateProsessfullmektig(prosessfullmektig: OversendtProsessfullmektig) {
if (prosessfullmektig.id == null && prosessfullmektig.navn == null && prosessfullmektig.adresse == null) {
throw OversendtKlageNotValidException("Enten id eller navn og adresse må være satt.")
}

if (prosessfullmektig.id != null && (prosessfullmektig.adresse != null || prosessfullmektig.navn != null)) {
throw OversendtKlageNotValidException("Adresse og navn kan bare settes når id ikke er satt.")
}

if ((prosessfullmektig.adresse != null && prosessfullmektig.navn == null) || (prosessfullmektig.adresse == null && prosessfullmektig.navn != null)) {
throw OversendtKlageNotValidException("Både adresse og navn må være satt.")
}

if (prosessfullmektig.id != null) {
validatePartId(prosessfullmektig.id.toPartId())
} else {
prosessfullmektig.adresse!!.validateAddress()
}
}

fun CreateKlageBasedOnKabinInput.validate() {
Expand Down

0 comments on commit ef6805e

Please sign in to comment.