Skip to content

Commit

Permalink
Merge pull request #381 from navikt/oppgradering-mai-2023
Browse files Browse the repository at this point in the history
Oppgradert avhengigheter + ktlint
  • Loading branch information
charliemidtlyng authored May 24, 2023
2 parents fdea7cb + 31c7f85 commit 5a3e7b8
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 57 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
<jvmTarget>17</jvmTarget>
<main-class>no.nav.familie.dokument.LauncherKt</main-class>
<felles.version>1.20230117091843_19b020f</felles.version>
<kotlin.version>1.8.10</kotlin.version>
<mockk.version>1.13.3</mockk.version>
<kotlin.version>1.8.20</kotlin.version>
<mockk.version>1.13.5</mockk.version>
<token-validation-spring.version>2.1.9</token-validation-spring.version>
<openhtmltopdf.version>1.0.10</openhtmltopdf.version>
<gcp.version>0.184.0</gcp.version>
<gcp.version>0.195.0</gcp.version>
<kontrakter.version>2.0_20230112155838_ab5a243</kontrakter.version>
<tika.core.version>2.6.0</tika.core.version>
<tika.parser.version>2.6.0</tika.parser.version>
<jsoup.version>1.15.3</jsoup.version>
<jsoup.version>1.16.1</jsoup.version>
<!-- Setter disse til token-support sine versjoner, versjoner(9.x) i spring er ikke kompatibel med oauth2-oidc-sdk -->
<nimbus-jose-jwt.version>8.20.2</nimbus-jose-jwt.version>
<testcontainers.version>1.17.6</testcontainers.version>
Expand Down Expand Up @@ -243,7 +243,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.1.0</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
Expand Down Expand Up @@ -339,7 +339,7 @@
<dependency>
<groupId>com.pinterest</groupId>
<artifactId>ktlint</artifactId>
<version>0.47.1</version>
<version>0.49.1</version>
</dependency>
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ApiExceptionHandler : ResponseEntityExceptionHandler() {
body: Any?,
headers: HttpHeaders,
status: HttpStatus,
request: WebRequest
request: WebRequest,
): ResponseEntity<Any> {
if (ex is HttpRequestMethodNotSupportedException || ex is HttpMediaTypeNotSupportedException || ex is HttpMediaTypeNotAcceptableException) {
secureLogger.warn("En feil har oppstått", ex)
Expand Down Expand Up @@ -82,7 +82,7 @@ class ApiExceptionHandler : ResponseEntityExceptionHandler() {
// Denne håndterer eks JwtTokenUnauthorizedException
private fun håndtertResponseStatusFeil(
throwable: Throwable,
responseStatus: ResponseStatus
responseStatus: ResponseStatus,
): ResponseEntity<Ressurs<String>> {
val status = if (responseStatus.value != HttpStatus.INTERNAL_SERVER_ERROR) responseStatus.value else responseStatus.code
val loggMelding = "En håndtert feil har oppstått" +
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/familie/dokument/ApiExceptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ enum class BadRequestCode {
DOCUMENT_MISSING,
IMAGE_TOO_LARGE,
IMAGE_DIMENSIONS_TOO_SMALL,
VIRUS_FOUND
VIRUS_FOUND,
}
6 changes: 3 additions & 3 deletions src/main/kotlin/no/nav/familie/dokument/pdf/PdfService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ class PdfService {
"Source Sans Pro",
400,
BaseRendererBuilder.FontStyle.NORMAL,
true
true,
)
.useFont(
FontSupplier("SourceSansPro-Bold.ttf"),
"Source Sans Pro",
700,
BaseRendererBuilder.FontStyle.OBLIQUE,
true
true,
)
.useFont(
FontSupplier("SourceSansPro-It.ttf"),
"Source Sans Pro",
400,
BaseRendererBuilder.FontStyle.ITALIC,
true
true,
)
.useSVGDrawer(BatikSVGDrawer())
.withW3cDocument(w3cDokument, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ import org.springframework.web.bind.annotation.RestController
@RequestMapping("familie/dokument/api/soknad", "api/soknad")
@RequiredIssuers(
ProtectedWithClaims(issuer = EksternBrukerUtils.ISSUER_SELVBETJENING, claimMap = ["acr=Level4"]),
ProtectedWithClaims(issuer = EksternBrukerUtils.ISSUER_TOKENX, claimMap = ["acr=Level4"])
ProtectedWithClaims(issuer = EksternBrukerUtils.ISSUER_TOKENX, claimMap = ["acr=Level4"]),
)
class StonadController(
@Autowired val storage: MellomLagerService,
@Autowired val contextHolder: TokenValidationContextHolder,
@Autowired val objectMapper: ObjectMapper,
@Autowired val hasher: Hasher
@Autowired val hasher: Hasher,
) {

private val log: Logger = LoggerFactory.getLogger(this::class.java)

@PostMapping(
path = ["/{stonad}"],
consumes = [MediaType.APPLICATION_JSON_VALUE],
produces = [MediaType.APPLICATION_JSON_VALUE]
produces = [MediaType.APPLICATION_JSON_VALUE],
)
fun mellomlagreSøknad(
@PathVariable("stonad") stønad: StønadParameter,
@RequestBody(required = true) søknad: String
@RequestBody(required = true) søknad: String,
): ResponseEntity<Unit> {
log.debug("Mellomlagrer søknad om overgangsstønad")

Expand Down Expand Up @@ -91,6 +91,6 @@ class StonadController(
barnetilsyn("barnetilsyn"),
skolepenger("skolepenger"),
barnetrygd("barnetrygd"),
kontantstotte("kontantstotte")
kontantstotte("kontantstotte"),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ import java.util.UUID
@RequestMapping("familie/dokument/api/mapper", "api/mapper")
@RequiredIssuers(
ProtectedWithClaims(issuer = EksternBrukerUtils.ISSUER_SELVBETJENING, claimMap = ["acr=Level4"]),
ProtectedWithClaims(issuer = EksternBrukerUtils.ISSUER_TOKENX, claimMap = ["acr=Level4"])
ProtectedWithClaims(issuer = EksternBrukerUtils.ISSUER_TOKENX, claimMap = ["acr=Level4"]),
)
class StorageController(
val storage: AttachmentStorage,
val virusScanService: VirusScanService,
val contextHolder: TokenValidationContextHolder,
@Value("\${attachment.max.size.mb}") val maxFileSizeInMb: Int,
val hasher: Hasher,
val pdfService: PdfService
val pdfService: PdfService,
) {

// / TODO: "bucket"-path brukes ikke ennå. "familievedlegg" brukes alltid
@PostMapping(
path = ["{bucket}"],
consumes = [MediaType.MULTIPART_FORM_DATA_VALUE],
produces = [MediaType.APPLICATION_JSON_VALUE]
produces = [MediaType.APPLICATION_JSON_VALUE],
)
fun addAttachment(
@PathVariable("bucket") bucket: String,
@RequestParam("file") multipartFile: MultipartFile
@RequestParam("file") multipartFile: MultipartFile,
): ResponseEntity<Map<String, String>> {
if (multipartFile.isEmpty) {
throw InvalidDocumentSize(BadRequestCode.DOCUMENT_MISSING)
Expand Down Expand Up @@ -78,11 +78,11 @@ class StorageController(
@PostMapping(
path = ["/merge/{bucket}"],
consumes = [MediaType.APPLICATION_JSON_VALUE],
produces = [MediaType.APPLICATION_JSON_VALUE]
produces = [MediaType.APPLICATION_JSON_VALUE],
)
fun mergeAndStoreDocuments(
@PathVariable("bucket") bucket: String,
@RequestBody documentList: List<UUID>
@RequestBody documentList: List<UUID>,
): ResponseEntity<Map<String, String>> {
if (documentList.isEmpty()) {
throw InvalidDocumentSize(BadRequestCode.DOCUMENT_MISSING)
Expand All @@ -106,7 +106,7 @@ class StorageController(
@GetMapping(path = ["{bucket}/{dokumentId}"], produces = [MediaType.APPLICATION_JSON_VALUE])
fun getAttachment(
@PathVariable("bucket") bucket: String,
@PathVariable("dokumentId") dokumentId: String
@PathVariable("dokumentId") dokumentId: String,
): ResponseEntity<Ressurs<ByteArray>> {
val directory = hasher.lagFnrHash(contextHolder.hentFnr())
val data = storage[directory, dokumentId]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AttachmentConfiguration {
@Bean
fun attachmentStorage(
@Qualifier(ATTACHMENT_ENCRYPTED_STORAGE) storage: EncryptedStorage,
storableFormatConverter: AttachmentToStorableFormatConverter
storableFormatConverter: AttachmentToStorableFormatConverter,
): AttachmentStorage {
return AttachmentStorage(storage, storableFormatConverter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.io.ByteArrayInputStream

class AttachmentStorage constructor(
private val delegate: EncryptedStorage,
private val storableFormatConverter: AttachmentToStorableFormatConverter
private val storableFormatConverter: AttachmentToStorableFormatConverter,
) :
Storage<ByteArray, ByteArray> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.apache.tika.Tika

class AttachmentToStorableFormatConverter(
private val imageConversionService: ImageConversionService,
private val flattenPdfService: FlattenPdfService
private val flattenPdfService: FlattenPdfService,
) {

fun toStorageFormat(input: ByteArray): ByteArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ enum class Format(var mimeType: String) {

PDF("application/pdf"),
PNG("image/png"),
JPEG("image/jpeg");
JPEG("image/jpeg"),
;

companion object {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ImageConversionService {
"Portrait h=${portraitImage.height} w=${portraitImage.width} " +
"ImageSize height=${imageSize.height} width=${imageSize.width} " +
" lowHeight=${imageSize.height < page.cropBox.height} lowWidth=${imageSize.width < page.cropBox.width}" +
" inputSize=${input.size / 1024} diffSize=${outputBytes.size / input.size} "
" inputSize=${input.size / 1024} diffSize=${outputBytes.size / input.size} ",
)
outputBytes
}
Expand All @@ -59,7 +59,7 @@ class ImageConversionService {
private fun createPdImage(
document: PDDocument,
portraitImage: BufferedImage,
detectedType: Format
detectedType: Format,
): PDImageXObject {
val quality = 1.0f
return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.io.InputStream
class EncryptedStorage constructor(
private val contextHolder: TokenValidationContextHolder,
private val delegate: GcpStorageWrapper,
private val encryptor: Encryptor
private val encryptor: Encryptor,
) : Storage<InputStream, ByteArray> {

override fun put(directory: String, key: String, data: InputStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EncryptedStorageConfiguration {

@Bean
internal fun secretKeyProvider(
@Value("\${FAMILIE_DOKUMENT_STORAGE_ENCRYPTION_PASSWORD}") passphrase: String
@Value("\${FAMILIE_DOKUMENT_STORAGE_ENCRYPTION_PASSWORD}") passphrase: String,
): SecretKeyProvider {
return SecretKeyProvider(passphrase)
}
Expand All @@ -30,7 +30,7 @@ class EncryptedStorageConfiguration {
internal fun attachmentEncryptedStorage(
@Autowired contextHolder: TokenValidationContextHolder,
@Qualifier(ATTACHMENT_GCP_STORAGE) storage: GcpStorageWrapper,
encryptor: Encryptor
encryptor: Encryptor,
): EncryptedStorage {
return EncryptedStorage(contextHolder, storage, encryptor)
}
Expand All @@ -40,7 +40,7 @@ class EncryptedStorageConfiguration {
internal fun stonadEncryptedStorage(
@Autowired contextHolder: TokenValidationContextHolder,
@Qualifier(STONAD_GCP_STORAGE) storage: GcpStorageWrapper,
encryptor: Encryptor
encryptor: Encryptor,
): EncryptedStorage {
return EncryptedStorage(contextHolder, storage, encryptor)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.Base64
@Component
class Hasher(
@Value("\${FAMILIE_DOKUMENT_FNR_SECRET_SALT}")
val hemmeligSalt: String
val hemmeligSalt: String,
) {

fun lagFnrHash(fnr: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.threeten.bp.Duration
class GcpStorageConfiguration {

val MAX_FILE_SIZE_FACTOR = 10 // Dersom vi slår sammen flere filer og lagrer ned må vi kunne lagre ned vesentlig større filer enn én og én

@Bean
fun retrySettings(@Value("\${storage_service.timeout.ms:3000}") timeoutMs: Long): RetrySettings? {
return RetrySettings.newBuilder()
Expand All @@ -25,7 +26,7 @@ class GcpStorageConfiguration {
fun gcpStorage(
storage: Storage,
@Value("\${gcp.storage.bucketname}") bucketName: String,
@Value("\${attachment.max.size.mb}") maxFileSizeMB: Int
@Value("\${attachment.max.size.mb}") maxFileSizeMB: Int,
): GcpStorage {
return GcpStorage(bucketName, maxFileSizeMB * MAX_FILE_SIZE_FACTOR, storage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.ByteArrayInputStream
@Service
class MellomLagerService internal constructor(
@Qualifier(STONAD_ENCRYPTED_STORAGE)
private val delegate: EncryptedStorage
private val delegate: EncryptedStorage,
) : Storage<String, String> {

override fun put(directory: String, key: String, data: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ data class ScanResult(@JsonProperty("Result") val result: Result)

enum class Result {
FOUND,
OK
OK,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service

@Service
class VirusScanService(
private val client: VirusScanClient
private val client: VirusScanClient,
) {

private val logger = LoggerFactory.getLogger(VirusScanService::class.java)
Expand All @@ -23,7 +23,7 @@ class VirusScanService(
if (Result.OK != scanResult.result) {
throw BadRequestException(
BadRequestCode.VIRUS_FOUND,
"Fil ikke godkjent - virus detektert status=${scanResult.result} fil=$name"
"Fil ikke godkjent - virus detektert status=${scanResult.result} fil=$name",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ApiFeilIntegrationTest {
issuerId: String = "selvbetjening",
clientId: String = UUID.randomUUID().toString(),
audience: String = "aud-localhost",
claims: Map<String, Any> = mapOf("acr" to "Level4")
claims: Map<String, Any> = mapOf("acr" to "Level4"),

): String {
return this.issueToken(
Expand All @@ -135,8 +135,8 @@ class ApiFeilIntegrationTest {
subject = subject,
audience = listOf(audience),
claims = claims,
expiry = 3600
)
expiry = 3600,
),
).serialize()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TestStorageConfiguration {
@Primary
fun attachmentStorage(
@Qualifier(ATTACHMENT_ENCRYPTED_STORAGE) encryptedStorage: EncryptedStorage,
storableFormatConverter: AttachmentToStorableFormatConverter
storableFormatConverter: AttachmentToStorableFormatConverter,
): AttachmentStorage {
val storage: AttachmentStorage = mockk()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PdfGenerartorTest {
private fun getDocument(fixtureName: String): String {
return IOUtils.toString(
this.javaClass.getResourceAsStream("/$PDF_RESOURSE_PATH/$fixtureName"),
StandardCharsets.UTF_8
StandardCharsets.UTF_8,
)
}

Expand Down Expand Up @@ -86,15 +86,15 @@ class PdfGenerartorTest {
expectedPdfBytes,
actualPdfBytes,
resource,
false
false,
)

// Get a list of results.
if (problems.isNotEmpty()) {
System.err.println("Found problems with test case ($resource):")
System.err.println(
problems.stream().map { p: PdfVisualTester.PdfCompareResult -> p.logMessage }
.collect(Collectors.joining("\n ", "[\n ", "\n]"))
.collect(Collectors.joining("\n ", "[\n ", "\n]")),
)
System.err.println("For test case ($resource) writing failure artifacts to '$TEST_OUTPUT_PATH'")
File(TEST_OUTPUT_PATH, "$resource---actual.pdf").writeBytes(actualPdfBytes)
Expand Down
Loading

0 comments on commit 5a3e7b8

Please sign in to comment.