Skip to content

Commit

Permalink
fix: lint, try to troubleshoot test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyynthia committed Nov 20, 2024
1 parent 59475a7 commit 8fb4d33
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, Any>) {
hibernateProperties[AvailableSettings.STATEMENT_INSPECTOR] = QueryStackTraceLogger("io.tolgee")
}
}
14 changes: 9 additions & 5 deletions backend/data/src/main/kotlin/io/tolgee/email/EmailService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ 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(
recipient: String,
template: String,
locale: Locale,
properties: Map<String, Any> = mapOf(),
attachments: List<EmailAttachment> = listOf()
attachments: List<EmailAttachment> = listOf(),
) {
val context = Context(locale, properties)
val html = templateEngine.process(template, context)
Expand All @@ -57,10 +61,10 @@ class EmailService(
recipient: String,
subject: String,
contents: String,
attachments: List<EmailAttachment> = listOf()
attachments: List<EmailAttachment> = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 18 additions & 14 deletions backend/data/src/test/kotlin/io/tolgee/email/EmailServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
)
)
}
}
5 changes: 4 additions & 1 deletion gradle/email.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
}

Expand Down

0 comments on commit 8fb4d33

Please sign in to comment.