-
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.
Lagt til endepunkt for å opprette med validering (#7)
- Loading branch information
1 parent
ccb740d
commit 84ddbc2
Showing
7 changed files
with
126 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package no.nav.familie.pdf.pdf | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import java.io.FileNotFoundException | ||
|
||
val objectMapper: ObjectMapper = | ||
jacksonObjectMapper() | ||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
.registerModule(JavaTimeModule()) | ||
|
||
fun lesJSON(): Map<String, Any> { | ||
val inndataStreng = | ||
object {} | ||
.javaClass | ||
.getResourceAsStream("/søknad.json") | ||
?.bufferedReader() | ||
?.readText() | ||
?: throw FileNotFoundException("Kan ikke lese søknad.json") | ||
return objectMapper.readValue(inndataStreng, Map::class.java) as Map<String, Any> | ||
} |
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/no/nav/familie/pdf/pdf/PdfOppretterController.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,44 @@ | ||
package no.nav.familie.pdf.pdf | ||
|
||
import no.nav.familie.pdf.pdf.types.PdfMedStandarder | ||
import no.nav.familie.pdf.pdf.types.lagPdfMedStandarder | ||
import org.springframework.web.bind.annotation.CrossOrigin | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("api") | ||
class PdfOppretterController { | ||
@PostMapping("/lag-pdf") | ||
fun lagPdf( | ||
@RequestBody søknad: Map<String, Any>, | ||
): ByteArray { | ||
val generertPdf = PdfOppretterService().lagPdf(søknad) | ||
return generertPdf | ||
} | ||
|
||
@CrossOrigin(origins = ["http://localhost:5173"]) | ||
@PostMapping("generate-pdf") | ||
fun lagPdfMedValidering( | ||
@RequestBody søknad: Map<String, Any>, | ||
): PdfMedStandarder { | ||
val pdf = | ||
PdfOppretterService() | ||
.lagPdf(søknad) | ||
|
||
return lagPdfMedStandarder(pdf) | ||
} | ||
|
||
@CrossOrigin(origins = ["http://localhost:5173"]) | ||
@GetMapping("lag-pdf-med-standarder") | ||
fun hentPdfFraResourceMedStandarder(): PdfMedStandarder { | ||
val søknad = lesJSON() | ||
val pdf = | ||
PdfOppretterService() | ||
.lagPdf(søknad) | ||
return lagPdfMedStandarder(pdf) | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/no/nav/familie/pdf/pdf/types/PdfMedStandarder.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,28 @@ | ||
package no.nav.familie.pdf.pdf.types | ||
|
||
import no.nav.familie.pdf.pdf.validerPdf | ||
|
||
data class PdfMedStandarder( | ||
val pdf: ByteArray, | ||
val standarder: Standarder, | ||
) | ||
|
||
fun lagPdfMedStandarder(pdf: ByteArray): PdfMedStandarder = | ||
PdfMedStandarder( | ||
pdf, | ||
Standarder( | ||
ua1 = validerPdf(pdf, "ua1"), | ||
ua2 = validerPdf(pdf, "ua2"), | ||
`1a` = validerPdf(pdf, "1a"), | ||
`1b` = validerPdf(pdf, "1b"), | ||
`2a` = validerPdf(pdf, "2a"), | ||
`2b` = validerPdf(pdf, "2b"), | ||
`2u` = validerPdf(pdf, "2u"), | ||
`3a` = validerPdf(pdf, "3a"), | ||
`3b` = validerPdf(pdf, "3b"), | ||
`3u` = validerPdf(pdf, "3u"), | ||
`4` = validerPdf(pdf, "4"), | ||
`4f` = validerPdf(pdf, "4f"), | ||
`4e` = validerPdf(pdf, "4e"), | ||
), | ||
) |
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,20 @@ | ||
package no.nav.familie.pdf.no.nav.familie.pdf.pdf | ||
|
||
import no.nav.familie.pdf.pdf.lesJSON | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class JSONLeserTest { | ||
@Test | ||
fun `tester readJSON for søknadjson gir forventede verdier`() { | ||
// Act | ||
val resultat = lesJSON() | ||
// Assert | ||
assertEquals("Søknad om overgangsstønad (NAV 15-00.01)", resultat["label"]) | ||
val verdiliste = resultat["verdiliste"] as List<Map<String, Any>> | ||
assertEquals("Innsendingsdetaljer", verdiliste[0]["label"]) | ||
val innsendingsdetaljer = verdiliste[0]["verdiliste"] as List<Map<String, Any>> | ||
assertEquals("Dato mottatt", innsendingsdetaljer[0]["label"]) | ||
assertEquals("09.10.2024 09:59:35", innsendingsdetaljer[0]["verdi"]) | ||
} | ||
} |
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