Skip to content

Commit

Permalink
Bedre feilhåndtering hvis fil ikke finnes og lagt til hjelper for å h…
Browse files Browse the repository at this point in the history
…ente dagens dato
  • Loading branch information
ugur93 committed Nov 21, 2023
1 parent e30ad45 commit 2e53334
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/kotlin/no/nav/pdfgen/core/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ data class PDFGenResource(val path: String) {
val filePath = filename?.let { _path.resolve(it) } ?: _path
log.trace { "Reading file from path $filePath. File exists on path = ${filePath.exists()}" }
return if (filePath.exists()) filePath
else Path.of(Environment::class.java.classLoader.getResource(filePath.pathString)!!.toURI())
else Environment::class.java.classLoader.getResource(filePath.pathString)?.let{
Path.of(it.toURI()) } ?: throw RuntimeException("Could not find file at path $filePath")
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/no/nav/pdfgen/core/template/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import no.nav.pdfgen.core.domain.Periode
import no.nav.pdfgen.core.domain.PeriodeMapper
import no.nav.pdfgen.core.objectMapper
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.util.Locale
Expand Down Expand Up @@ -384,6 +385,17 @@ fun registerNavHelpers(
"stringify",
Helper<Any> { value, _ -> objectMapper.writeValueAsString(value) },
)

registerHelper(
"now",
Helper<Any> { _, _ -> LocalDateTime.now().toString()}
)

registerHelper(
"now_date",
Helper<Any> { _, _ -> LocalDate.now().toString()}
)

additionalHelpers.forEach { (t, u) -> registerHelper(t, u) }
}
}
Expand Down

0 comments on commit 2e53334

Please sign in to comment.