Skip to content

Commit

Permalink
fix: Upgrade to Spring 3: compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Oct 10, 2023
1 parent 97e9687 commit 259cd31
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 72 deletions.
1 change: 1 addition & 0 deletions backend/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ dependencies {
implementation libs.amazonSTS
implementation libs.icu4j
implementation libs.jacksonModuleKotlin
api 'org.apache.httpcomponents.client5:httpclient5:5.2.1'

implementation "org.springframework.boot:spring-boot-properties-migrator"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.tolgee.activity.ActivityHandlerInterceptor
import io.tolgee.component.VersionFilter
import io.tolgee.configuration.tolgee.TolgeeProperties
import jakarta.servlet.MultipartConfigElement
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder
import org.springframework.boot.web.servlet.MultipartConfigFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class WebSecurityConfig(
.cors().and()
.headers()
.referrerPolicy().policy(ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN).and()
.xssProtection().block(true).and()
.xssProtection().and()
.contentTypeOptions().and()
.frameOptions().deny()
.and()
Expand All @@ -73,9 +73,9 @@ class WebSecurityConfig(
.addFilterBefore(globalUserRateLimitFilter, UsernamePasswordAuthenticationFilter::class.java)
.addFilterBefore(globalIpRateLimitFilter, UsernamePasswordAuthenticationFilter::class.java)
.authorizeRequests()
.mvcMatchers("/api/public/**", "/v2/public/**").permitAll()
.mvcMatchers("/v2/administration/**", "/v2/ee-license/**").hasRole("ADMIN")
.mvcMatchers("/api/**", "/v2/**").authenticated()
.requestMatchers("/api/public/**", "/v2/public/**").permitAll()
.requestMatchers("/v2/administration/**", "/v2/ee-license/**").hasRole("ADMIN")
.requestMatchers("/api/**", "/v2/**").authenticated()
.anyRequest().permitAll()
.and().build()
}
Expand All @@ -85,7 +85,7 @@ class WebSecurityConfig(
@ConditionalOnProperty(value = ["tolgee.internal.controller-enabled"], havingValue = "false", matchIfMissing = true)
fun internalSecurityFilterChain(httpSecurity: HttpSecurity): SecurityFilterChain {
return httpSecurity
.antMatcher("/internal/**")
.securityMatcher("/internal/**")
.authorizeRequests()
.anyRequest()
.denyAll()
Expand Down
2 changes: 2 additions & 0 deletions backend/app/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spring:
jpa:
properties:
hibernate:
order_by:
default_null_ordering: first
jdbc:
batch_size: 1000
order_inserts: true
Expand Down
7 changes: 4 additions & 3 deletions backend/data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
id "kotlin-jpa"
id "org.jetbrains.kotlin.kapt"
id "kotlin-allopen"
id "org.hibernate.orm" version "6.2.9.Final"
id "org.hibernate.orm"
}

group = 'io.tolgee'
Expand Down Expand Up @@ -104,8 +104,8 @@ dependencies {
* DB
*/
runtimeOnly 'org.postgresql:postgresql'
// implementation 'org.hibernate:hibernate-jpamodelgen:6.2.9.Final'
// kapt "org.hibernate:hibernate-jpamodelgen:6.2.9.Final"
implementation "org.hibernate:hibernate-jpamodelgen:$hibernateVersion"
kapt "org.hibernate:hibernate-jpamodelgen:$hibernateVersion"

/**
* Redisson
Expand Down Expand Up @@ -168,6 +168,7 @@ dependencies {
implementation 'com.eatthepath:java-otp:0.4.0'
implementation libs.postHog
implementation libs.micrometerPrometheus
implementation 'dom4j:dom4j:1.6.1'

/**
* Google translation API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import io.tolgee.configuration.annotations.AdditionalDocsProperties
import io.tolgee.configuration.annotations.DocProperty
import io.tolgee.configuration.tolgee.machineTranslation.MachineTranslationProperties
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConstructorBinding

@ConstructorBinding
@AdditionalDocsProperties(
[
DocProperty(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,19 @@
package io.tolgee.dialects.postgres

import com.vladmihalcea.hibernate.type.array.StringArrayType
import com.vladmihalcea.hibernate.type.json.JsonBinaryType
import org.hibernate.NullPrecedence
import org.hibernate.dialect.PostgreSQL10Dialect
import org.hibernate.dialect.function.SQLFunction
import org.hibernate.engine.spi.Mapping
import org.hibernate.engine.spi.SessionFactoryImplementor
import org.hibernate.type.FloatType
import org.hibernate.type.Type
import java.sql.Types
import org.hibernate.boot.model.FunctionContributions
import org.hibernate.dialect.DatabaseVersion
import org.hibernate.dialect.PostgreSQLDialect
import org.hibernate.type.StandardBasicTypes

@Suppress("unused")
class CustomPostgreSQLDialect : PostgreSQL10Dialect() {
init {
registerHibernateType(2003, StringArrayType::class.java.name)
}

override fun renderOrderByElement(
expression: String?,
collation: String?,
order: String?,
nulls: NullPrecedence?
): String {
if (nulls == NullPrecedence.NONE) {
if (order == "asc") {
return super.renderOrderByElement(expression, collation, order, NullPrecedence.FIRST)
}
if (order == "desc") {
return super.renderOrderByElement(expression, collation, order, NullPrecedence.LAST)
}
}
return super.renderOrderByElement(expression, collation, order, nulls)
}
class CustomPostgreSQLDialect : PostgreSQLDialect(DatabaseVersion.make(10)) {

init {
registerFunction(
override fun contributeFunctions(functionContributions: FunctionContributions) {
super.contributeFunctions(functionContributions)
functionContributions.functionRegistry.registerPattern(
"similarity",
object : SQLFunction {
override fun hasArguments(): Boolean = true

override fun hasParenthesesIfNoArguments() = false

override fun getReturnType(firstArgumentType: Type?, mapping: Mapping?) = FloatType()

override fun render(
firstArgumentType: Type,
arguments: MutableList<Any?>,
factory: SessionFactoryImplementor
): String {
return "similarity(${arguments[0]}, ${arguments[1]})"
}
}
"similarity(?1, ?2)",
functionContributions.typeConfiguration.basicTypeRegistry.resolve(StandardBasicTypes.FLOAT)
)
registerHibernateType(Types.OTHER, JsonBinaryType::class.java.name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class AllOrganizationOwnerJobRunner(
}
val json = jacksonObjectMapper().writeValueAsBytes(mapOf("users" to userIds, "projects" to projectIds))
val hash = DigestUtils.sha256Hex(json)
return JobParameters(mapOf("idsHash" to JobParameter(hash)))
return JobParameters(mapOf("idsHash" to JobParameter(hash, String::class.java)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ class TranslationsStatsUpdateJobRunner(
return null
}
val hash = DigestUtils.sha256Hex(ids.flatMap { it.toBigInteger().toByteArray().toList() }.toByteArray())
return JobParameters(mapOf("idsHash" to JobParameter(hash)))
return JobParameters(mapOf("idsHash" to JobParameter(hash, String::class.java)))
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.tolgee.model.dataImport

import com.sun.istack.NotNull
import io.tolgee.model.StandardAuditModel
import io.tolgee.model.translation.Translation
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToOne
import jakarta.validation.constraints.NotNull
import org.apache.commons.codec.digest.MurmurHash3
import java.nio.ByteBuffer
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.tolgee.model.key

import com.sun.istack.NotNull
import io.tolgee.model.StandardAuditModel
import io.tolgee.model.UserAccount
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.ManyToOne
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull

@Entity
class KeyCodeReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class ImportService(
"""
)
.setParameter("import", import)
.setHint(QueryHints.PASS_DISTINCT_THROUGH, false)
.resultList as List<ImportKey>

result = entityManager.createQuery(
Expand All @@ -195,7 +194,6 @@ class ImportService(
where ik in :keys
"""
).setParameter("keys", result)
.setHint(QueryHints.PASS_DISTINCT_THROUGH, false)
.resultList as List<ImportKey>

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class XliffFileExporter(
return ResultItem(document, fileBodyElement)
}

private fun String.parseHtml(): MutableIterator<Node> {
private fun String.parseHtml(): MutableIterator<Any?> {
val fragment = DocumentHelper
.parseText("<root>$this</root>")
return fragment.rootElement.nodeIterator()
Expand All @@ -102,6 +102,7 @@ class XliffFileExporter(
private fun Element.addFromHtmlOrText(string: String) {
try {
string.parseHtml().forEach { node ->
if (node !is Node) return@forEach
node.parent = null
this.add(node)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.tolgee.repository.KeyCodeReferenceRepository
import io.tolgee.repository.KeyCommentRepository
import io.tolgee.repository.KeyMetaRepository
import jakarta.persistence.EntityManager
import org.hibernate.annotations.QueryHints.PASS_DISTINCT_THROUGH
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Lazy
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -68,7 +67,6 @@ class KeyMetaService(
"""
)
.setParameter("import", import)
.setHint(PASS_DISTINCT_THROUGH, false)
.resultList as List<KeyMeta>

result = entityManager.createQuery(
Expand All @@ -80,7 +78,6 @@ class KeyMetaService(
where ikm in :metas
"""
).setParameter("metas", result)
.setHint(PASS_DISTINCT_THROUGH, false)
.resultList as List<KeyMeta>

return result
Expand All @@ -96,7 +93,6 @@ class KeyMetaService(
"""
)
.setParameter("project", project)
.setHint(PASS_DISTINCT_THROUGH, false)
.resultList as List<KeyMeta>

result = entityManager.createQuery(
Expand All @@ -107,7 +103,6 @@ class KeyMetaService(
where ikm in :metas
"""
).setParameter("metas", result)
.setHint(PASS_DISTINCT_THROUGH, false)
.resultList as List<KeyMeta>

return result
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ kotlinVersion=1.9.10
springBootVersion=3.1.4
springDocVersion=1.7.0
jjwtVersion=0.11.2
hibernateVersion=6.2.9.Final
amazonAwsSdkVersion=2.20.8
springDependencyManagementVersion=1.0.11.RELEASE
org.gradle.jvmargs=-Xmx8g -Dkotlin.daemon.jvm.options=-Xmx6g
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pluginManagement {
if (requested.id.id == 'org.liquibase.gradle') {
useModule('org.liquibase.gradle:org.liquibase.gradle.gradle.plugin:2.1.1')
}
if (requested.id.id == 'org.hibernate.orm') {
useVersion(hibernateVersion)
}
}
}
}
Expand Down

0 comments on commit 259cd31

Please sign in to comment.