-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Henter ut arbeidsgivere fra legacySøknad.
- Loading branch information
Showing
16 changed files
with
213 additions
and
48 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
26 changes: 26 additions & 0 deletions
26
...in/no/nav/sifinnsynapi/legacy/legacyinnsynapi/NotSupportedArbeidsgiverMeldingException.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,26 @@ | ||
package no.nav.sifinnsynapi.legacy.legacyinnsynapi | ||
|
||
import no.nav.sifinnsynapi.util.ServletUtils | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ProblemDetail | ||
import org.springframework.web.ErrorResponseException | ||
import java.net.URI | ||
import java.net.URLDecoder | ||
import java.nio.charset.Charset | ||
|
||
class NotSupportedArbeidsgiverMeldingException(søknadId: String, søknadstype: LegacySøknadstype) : | ||
ErrorResponseException(HttpStatus.BAD_REQUEST, asProblemDetail(søknadId, søknadstype), null) { | ||
private companion object { | ||
private fun asProblemDetail(søknadId: String, søknadstype: LegacySøknadstype): ProblemDetail { | ||
val problemDetail = ProblemDetail.forStatus(HttpStatus.BAD_REQUEST) | ||
problemDetail.title = "Arbeidsgivermelding ikke støttet" | ||
problemDetail.detail = | ||
"Søknad med søknadId = $søknadId og søknadstype = $søknadstype støtter ikke arbeidsgivermelding." | ||
problemDetail.type = URI("/problem-details/arbeidsgivermelding-ikke-støttet") | ||
ServletUtils.currentHttpRequest()?.let { | ||
problemDetail.instance = URI(URLDecoder.decode(it.requestURL.toString(), Charset.defaultCharset())) | ||
} | ||
return problemDetail | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ynapi/legacy/legacyinnsynapi/PleiepengesøknadMedOrganisasjonsnummerIkkeFunnetException.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,27 @@ | ||
package no.nav.sifinnsynapi.legacy.legacyinnsynapi | ||
|
||
import no.nav.sifinnsynapi.util.ServletUtils | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ProblemDetail | ||
import org.springframework.web.ErrorResponseException | ||
import java.net.URI | ||
import java.net.URLDecoder | ||
import java.nio.charset.Charset | ||
|
||
class PleiepengesøknadMedOrganisasjonsnummerIkkeFunnetException(søknadId: String, organisasjonsnummer: String) : | ||
ErrorResponseException(HttpStatus.NOT_FOUND, asProblemDetail(søknadId, organisasjonsnummer), null) { | ||
private companion object { | ||
private fun asProblemDetail(søknadId: String, organisasjonsnummer: String): ProblemDetail { | ||
val problemDetail = ProblemDetail.forStatus(HttpStatus.NOT_FOUND) | ||
problemDetail.title = "Arbeidsgiver ikke funnet" | ||
problemDetail.detail = | ||
"Søknad med søknadId = $søknadId og organisasjonsnummer = $organisasjonsnummer ble ikke funnet." | ||
problemDetail.type = URI("/problem-details/arbeidsgiver-ikke-funnet") | ||
ServletUtils.currentHttpRequest()?.let { | ||
problemDetail.instance = URI(URLDecoder.decode(it.requestURL.toString(), Charset.defaultCharset())) | ||
} | ||
|
||
return problemDetail | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/kotlin/no/nav/sifinnsynapi/legacy/legacyinnsynapi/utils/PSBJsonUtils.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,54 @@ | ||
package no.nav.sifinnsynapi.legacy.legacyinnsynapi.utils | ||
|
||
import no.nav.sifinnsynapi.legacy.legacyinnsynapi.PleiepengesøknadMedOrganisasjonsnummerIkkeFunnetException | ||
import no.nav.sifinnsynapi.oppslag.Organisasjon | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
|
||
object PSBJsonUtils { | ||
const val ARBEIDSGIVERE = "arbeidsgivere" | ||
const val ORGANISASJONER = "organisasjoner" | ||
const val ORGANISASJONSNUMMER = "organisasjonsnummer" | ||
|
||
fun JSONObject.finnOrganisasjon(søknadId: String, organisasjonsnummer: String): JSONObject { | ||
val organisasjoner = when (val arbeidsgivereObjekt = get(ARBEIDSGIVERE)) { | ||
is JSONObject -> arbeidsgivereObjekt.getJSONArray(ORGANISASJONER) | ||
is JSONArray -> arbeidsgivereObjekt | ||
else -> throw Error("Ugyldig type for feltet $ARBEIDSGIVERE. Forventet enten JSONObject eller JSONArray, men fikk ${arbeidsgivereObjekt.javaClass}") | ||
} | ||
|
||
var organisasjon: JSONObject? = null | ||
|
||
for (i in 0 until organisasjoner.length()) { | ||
val org = organisasjoner.getJSONObject(i) | ||
if (org.getString(ORGANISASJONSNUMMER) == organisasjonsnummer) { | ||
organisasjon = org | ||
} | ||
} | ||
|
||
if (organisasjon == null) throw PleiepengesøknadMedOrganisasjonsnummerIkkeFunnetException( | ||
søknadId, | ||
organisasjonsnummer | ||
) | ||
return organisasjon | ||
} | ||
|
||
fun JSONObject.arbeidsgivere(): MutableList<Organisasjon> { | ||
val organisasjonerJsonArray = when (val arbeidsgivereObjekt = get(ARBEIDSGIVERE)) { | ||
is JSONObject -> arbeidsgivereObjekt.getJSONArray(ORGANISASJONER) | ||
is JSONArray -> arbeidsgivereObjekt | ||
else -> throw Error("Ugyldig type for feltet $ARBEIDSGIVERE. Forventet enten JSONObject eller JSONArray, men fikk ${arbeidsgivereObjekt.javaClass}") | ||
} | ||
|
||
val organisasjoner = mutableListOf<Organisasjon>() | ||
|
||
for (i in 0 until organisasjonerJsonArray.length()) { | ||
val org = organisasjonerJsonArray.getJSONObject(i) | ||
val organisasjonsnummer = org.getString(ORGANISASJONSNUMMER) | ||
val organisasjonsnavn = org.optString("navn", null) | ||
organisasjoner.add(Organisasjon(organisasjonsnummer, organisasjonsnavn)) | ||
} | ||
|
||
return organisasjoner | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package no.nav.sifinnsynapi.util | ||
|
||
import jakarta.servlet.http.HttpServletRequest | ||
import org.springframework.web.context.request.RequestContextHolder | ||
import org.springframework.web.context.request.ServletRequestAttributes | ||
|
||
object ServletUtils { | ||
|
||
fun currentHttpRequest(): HttpServletRequest? { | ||
val requestAttributes = RequestContextHolder.getRequestAttributes() | ||
return if (requestAttributes is ServletRequestAttributes) { | ||
requestAttributes.request | ||
} else null | ||
} | ||
} |
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
Oops, something went wrong.