-
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.
Inntekt api for å hente faktor for kapitalinntekt (#292)
- Loading branch information
Showing
9 changed files
with
65 additions
and
42 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
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
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
40 changes: 40 additions & 0 deletions
40
bidrag-inntekt/src/main/kotlin/no/nav/bidrag/inntekt/util/PostMappingUtil.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,40 @@ | ||
package no.nav.bidrag.inntekt.util | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import no.nav.bidrag.domene.enums.diverse.PlussMinus | ||
import no.nav.bidrag.inntekt.service.MappingPoster | ||
import no.nav.bidrag.inntekt.service.Post | ||
import no.nav.bidrag.inntekt.service.PostKonfig | ||
import org.springframework.core.io.ClassPathResource | ||
import java.io.IOException | ||
import java.time.Year | ||
|
||
fun hentMappingerKapitalinntekt(): List<MappingPoster> { | ||
return hentMapping("/files/mapping_kaps.yaml") | ||
} | ||
fun hentMappingerLigs(): List<MappingPoster> { | ||
return hentMapping("/files/mapping_ligs.yaml") | ||
} | ||
private fun hentMapping(path: String): List<MappingPoster> { | ||
try { | ||
val objectMapper = ObjectMapper(YAMLFactory()) | ||
objectMapper.findAndRegisterModules() | ||
val pathKapsfil = ClassPathResource(path).inputStream | ||
val mapping: Map<Post, List<PostKonfig>> = objectMapper.readValue(pathKapsfil) | ||
return mapping.flatMap { (post, postKonfigs) -> | ||
postKonfigs.map { postKonfig -> | ||
MappingPoster( | ||
fulltNavnInntektspost = post.fulltNavnInntektspost, | ||
plussMinus = PlussMinus.valueOf(postKonfig.plussMinus), | ||
sekkepost = postKonfig.sekkepost == "JA", | ||
fom = Year.parse(postKonfig.fom), | ||
tom = Year.parse(postKonfig.tom), | ||
) | ||
} | ||
} | ||
} catch (e: IOException) { | ||
throw RuntimeException("Kunne ikke laste fil", e) | ||
} | ||
} |