From 8fb4d3343a8d714e7aa0df6e53bd47a92352ebe9 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Wed, 20 Nov 2024 17:39:25 +0100 Subject: [PATCH] fix: lint, try to troubleshoot test failures --- .../tolgee/configuration/HibernateConfig.kt | 31 ++++++++++++++++++ .../kotlin/io/tolgee/email/EmailService.kt | 14 +++++--- .../io/tolgee/email/EmailTemplateConfig.kt | 2 +- .../io/tolgee/email/EmailServiceTest.kt | 32 +++++++++++-------- gradle/email.gradle | 5 ++- 5 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 backend/data/src/main/kotlin/io/tolgee/configuration/HibernateConfig.kt diff --git a/backend/data/src/main/kotlin/io/tolgee/configuration/HibernateConfig.kt b/backend/data/src/main/kotlin/io/tolgee/configuration/HibernateConfig.kt new file mode 100644 index 0000000000..df265f9481 --- /dev/null +++ b/backend/data/src/main/kotlin/io/tolgee/configuration/HibernateConfig.kt @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2024 Tolgee s.r.o. and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.tolgee.configuration + +import io.hypersistence.utils.hibernate.query.QueryStackTraceLogger +import org.hibernate.cfg.AvailableSettings +import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer +import org.springframework.context.annotation.Profile +import org.springframework.stereotype.Component + +@Component +@Profile("hibernate-trace") +class HibernateConfig : HibernatePropertiesCustomizer { + override fun customize(hibernateProperties: MutableMap) { + hibernateProperties[AvailableSettings.STATEMENT_INSPECTOR] = QueryStackTraceLogger("io.tolgee") + } +} diff --git a/backend/data/src/main/kotlin/io/tolgee/email/EmailService.kt b/backend/data/src/main/kotlin/io/tolgee/email/EmailService.kt index f8428714ca..679fc33031 100644 --- a/backend/data/src/main/kotlin/io/tolgee/email/EmailService.kt +++ b/backend/data/src/main/kotlin/io/tolgee/email/EmailService.kt @@ -34,8 +34,12 @@ class EmailService( @Qualifier("emailTemplateEngine") private val templateEngine: TemplateEngine, ) { private val smtpFrom - get() = smtpProperties.from - ?: throw IllegalStateException("SMTP sender is not configured. See https://docs.tolgee.io/platform/self_hosting/configuration#smtp") + get() = + smtpProperties.from + ?: throw IllegalStateException( + "SMTP sender is not configured. " + + "See https://docs.tolgee.io/platform/self_hosting/configuration#smtp", + ) @Async fun sendEmailTemplate( @@ -43,7 +47,7 @@ class EmailService( template: String, locale: Locale, properties: Map = mapOf(), - attachments: List = listOf() + attachments: List = listOf(), ) { val context = Context(locale, properties) val html = templateEngine.process(template, context) @@ -57,10 +61,10 @@ class EmailService( recipient: String, subject: String, contents: String, - attachments: List = listOf() + attachments: List = listOf(), ) { val message = mailSender.createMimeMessage() - val helper = MimeMessageHelper(message, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,"UTF8") + val helper = MimeMessageHelper(message, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED, "UTF8") helper.setFrom(smtpFrom) helper.setTo(recipient) diff --git a/backend/data/src/main/kotlin/io/tolgee/email/EmailTemplateConfig.kt b/backend/data/src/main/kotlin/io/tolgee/email/EmailTemplateConfig.kt index b4b0c735b0..7aea48641b 100644 --- a/backend/data/src/main/kotlin/io/tolgee/email/EmailTemplateConfig.kt +++ b/backend/data/src/main/kotlin/io/tolgee/email/EmailTemplateConfig.kt @@ -52,7 +52,7 @@ class EmailTemplateConfig { @Bean("emailTemplateEngine") fun templateEngine( @Qualifier("emailTemplateResolver") templateResolver: ITemplateResolver, - @Qualifier("emailMessageSource") messageSource: MessageSource + @Qualifier("emailMessageSource") messageSource: MessageSource, ): TemplateEngine { val templateEngine = SpringTemplateEngine() templateEngine.templateResolvers = setOf(templateResolver) diff --git a/backend/data/src/test/kotlin/io/tolgee/email/EmailServiceTest.kt b/backend/data/src/test/kotlin/io/tolgee/email/EmailServiceTest.kt index af7f63c8de..007c7c6500 100644 --- a/backend/data/src/test/kotlin/io/tolgee/email/EmailServiceTest.kt +++ b/backend/data/src/test/kotlin/io/tolgee/email/EmailServiceTest.kt @@ -100,22 +100,26 @@ class EmailServiceTest { } companion object { - private val TEST_PROPERTIES = mapOf( - "testVar" to "test!!", - "testList" to listOf( - mapOf("name" to "Name #1"), - mapOf("name" to "Name #2"), - mapOf("name" to "Name #3"), + private val TEST_PROPERTIES = + mapOf( + "testVar" to "test!!", + "testList" to + listOf( + mapOf("name" to "Name #1"), + mapOf("name" to "Name #2"), + mapOf("name" to "Name #3"), + ), ) - ) - private val TEST_PROPERTIES_MEOW = mapOf( - "testVar" to "meow", - "testList" to listOf( - mapOf("name" to "Name #1"), - mapOf("name" to "Name #2"), - mapOf("name" to "Name #3"), + private val TEST_PROPERTIES_MEOW = + mapOf( + "testVar" to "meow", + "testList" to + listOf( + mapOf("name" to "Name #1"), + mapOf("name" to "Name #2"), + mapOf("name" to "Name #3"), + ), ) - ) } } diff --git a/gradle/email.gradle b/gradle/email.gradle index 138fb787fe..a7084ef52b 100644 --- a/gradle/email.gradle +++ b/gradle/email.gradle @@ -46,7 +46,10 @@ tasks.register('buildEmails', Exec) { workingDir = emailPath commandLine npmCommandName, "run", "export" - inputs.dir("${emailPath}/") + inputs.dir("${emailPath}/emails") + inputs.dir("${emailPath}/components") + inputs.file("${emailPath}/package.json") + inputs.file("${emailPath}/package-lock.json") outputs.dir("${emailPath}/out/") }