Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Make liquibase diffChangeLog task working again #2052

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ class V2ExportControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Test
@ProjectJWTAuthTestMethod
fun `it reports business event once in a day`() {
retry(
retries = 10,
exceptionMatcher = { it is ConcurrentModificationException || it is DataIntegrityViolationException }
) {
retryingOnCommonIssues {
initBaseData()
try {
executeInNewTransaction {
Expand All @@ -108,10 +105,10 @@ class V2ExportControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Transactional
@ProjectJWTAuthTestMethod
fun `it exports to single json`() {
executeInNewTransaction {
initBaseData()
}
retry {
retryingOnCommonIssues {
executeInNewTransaction {
initBaseData()
}
val response = performProjectAuthGet("export?languages=en&zip=false")
.andDo { obj: MvcResult -> obj.asyncResult }
response.andPrettyPrint.andAssertThatJson {
Expand All @@ -128,10 +125,10 @@ class V2ExportControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Transactional
@ProjectJWTAuthTestMethod
fun `it exports to single xliff`() {
executeInNewTransaction {
initBaseData()
}
retry {
retryingOnCommonIssues {
executeInNewTransaction {
initBaseData()
}
val response = performProjectAuthGet("export?languages=en&zip=false&format=XLIFF")
.andDo { obj: MvcResult -> obj.getAsyncResult(30000) }

Expand All @@ -146,49 +143,54 @@ class V2ExportControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Transactional
@ProjectJWTAuthTestMethod
fun `it filters by keyId in`() {
testData = TranslationsTestData()
testData.generateLotOfData(1000)
testDataService.saveTestData(testData.root)
prepareUserAndProject(testData)
commitTransaction()

val time = measureTimeMillis {
val selectAllResult = performProjectAuthGet("translations/select-all")
.andIsOk
.andGetContentAsString
val keyIds = jacksonObjectMapper().readValue<Map<String, List<Long>>>(selectAllResult)["ids"]?.take(500)
val parsed = performExportPost(mapOf("filterKeyId" to keyIds))
assertThatJson(parsed["en.json"]!!) {
isObject.hasSize(499)
retryingOnCommonIssues {
testData = TranslationsTestData()
testData.generateLotOfData(1000)
testDataService.saveTestData(testData.root)
prepareUserAndProject(testData)
commitTransaction()

val time = measureTimeMillis {
val selectAllResult = performProjectAuthGet("translations/select-all")
.andIsOk
.andGetContentAsString
val keyIds = jacksonObjectMapper()
.readValue<Map<String, List<Long>>>(selectAllResult)["ids"]?.take(500)
val parsed = performExportPost(mapOf("filterKeyId" to keyIds))
assertThatJson(parsed["en.json"]!!) {
isObject.hasSize(499)
}
}
}

assertThat(time).isLessThan(2000)
assertThat(time).isLessThan(2000)
}
}

@Test
@Transactional
@ProjectJWTAuthTestMethod
fun `the structureDelimiter works`() {
testData = TranslationsTestData()
testData.generateScopedData()
testDataService.saveTestData(testData.root)
prepareUserAndProject(testData)
commitTransaction()

performExport("structureDelimiter=").let { parsed ->
assertThatJson(parsed["en.json"]!!) {
node("hello\\.i\\.am\\.scoped").isEqualTo("yupee!")
retryingOnCommonIssues {
testData = TranslationsTestData()
testData.generateScopedData()
testDataService.saveTestData(testData.root)
prepareUserAndProject(testData)
commitTransaction()

performExport("structureDelimiter=").let { parsed ->
assertThatJson(parsed["en.json"]!!) {
node("hello\\.i\\.am\\.scoped").isEqualTo("yupee!")
}
}
}
performExport("structureDelimiter=+").let { parsed ->
assertThatJson(parsed["en.json"]!!) {
node("hello.i.am.plus.scoped").isEqualTo("yupee!")
performExport("structureDelimiter=+").let { parsed ->
assertThatJson(parsed["en.json"]!!) {
node("hello.i.am.plus.scoped").isEqualTo("yupee!")
}
}
}
performExport("").let { parsed ->
assertThatJson(parsed["en.json"]!!) {
node("hello.i.am.scoped").isEqualTo("yupee!")
performExport("").let { parsed ->
assertThatJson(parsed["en.json"]!!) {
node("hello.i.am.scoped").isEqualTo("yupee!")
}
}
}
}
Expand Down Expand Up @@ -223,72 +225,78 @@ class V2ExportControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Transactional
@ProjectJWTAuthTestMethod
fun `it exports to json with namespaces`() {
val namespacesTestData = NamespacesTestData()
testDataService.saveTestData(namespacesTestData.root)
projectSupplier = { namespacesTestData.projectBuilder.self }
userAccount = namespacesTestData.user
retryingOnCommonIssues {
val namespacesTestData = NamespacesTestData()
testDataService.saveTestData(namespacesTestData.root)
projectSupplier = { namespacesTestData.projectBuilder.self }
userAccount = namespacesTestData.user

val parsed = performExport()
val parsed = performExport()

assertThatJson(parsed["ns-1/en.json"]!!) {
node("key").isEqualTo("hello")
}
assertThatJson(parsed["en.json"]!!) {
node("key").isEqualTo("hello")
assertThatJson(parsed["ns-1/en.json"]!!) {
node("key").isEqualTo("hello")
}
assertThatJson(parsed["en.json"]!!) {
node("key").isEqualTo("hello")
}
}
}

@Test
@Transactional
@ProjectJWTAuthTestMethod
fun `it exports only allowed languages`() {
val testData = LanguagePermissionsTestData()
testDataService.saveTestData(testData.root)
projectSupplier = { testData.projectBuilder.self }
userAccount = testData.viewEnOnlyUser

val parsed = performExport()
val files = parsed.keys
files.assert.containsExactly("en.json")
retryingOnCommonIssues {
val testData = LanguagePermissionsTestData()
testDataService.saveTestData(testData.root)
projectSupplier = { testData.projectBuilder.self }
userAccount = testData.viewEnOnlyUser

val parsed = performExport()
val files = parsed.keys
files.assert.containsExactly("en.json")
}
}

@Test
@Transactional
@ProjectJWTAuthTestMethod
fun `it exports all languages by default`() {
val testData = TestDataBuilder()
val user = testData.addUserAccount {
username = "user"
}
val projectBuilder = testData.addProject {
name = "Oh my project"
organizationOwner = user.defaultOrganizationBuilder.self
}
retryingOnCommonIssues {
val testData = TestDataBuilder()
val user = testData.addUserAccount {
username = "user"
}
val projectBuilder = testData.addProject {
name = "Oh my project"
organizationOwner = user.defaultOrganizationBuilder.self
}

val langs = arrayOf(
projectBuilder.addEnglish(),
projectBuilder.addCzech(),
projectBuilder.addGerman(),
projectBuilder.addFrench()
)

val key = projectBuilder.addKey { name = "key" }.self
langs.forEach { lang ->
projectBuilder.addTranslation {
this.language = lang.self
this.key = key
this.text = "yey"
val langs = arrayOf(
projectBuilder.addEnglish(),
projectBuilder.addCzech(),
projectBuilder.addGerman(),
projectBuilder.addFrench()
)

val key = projectBuilder.addKey { name = "key" }.self
langs.forEach { lang ->
projectBuilder.addTranslation {
this.language = lang.self
this.key = key
this.text = "yey"
}
}
}

testDataService.saveTestData(testData)
testDataService.saveTestData(testData)

projectSupplier = { projectBuilder.self }
userAccount = user.self
projectSupplier = { projectBuilder.self }
userAccount = user.self

val parsed = performExport()
val files = parsed.keys
files.assert.containsExactlyInAnyOrder(*langs.map { "${it.self.tag}.json" }.toTypedArray())
val parsed = performExport()
val files = parsed.keys
files.assert.containsExactlyInAnyOrder(*langs.map { "${it.self.tag}.json" }.toTypedArray())
}
}

private fun initBaseData() {
Expand All @@ -301,4 +309,13 @@ class V2ExportControllerTest : ProjectAuthControllerTest("/v2/projects/") {
userAccount = testData.user
projectSupplier = { testData.project }
}

private fun retryingOnCommonIssues(fn: () -> Unit) {
retry(
retries = 10,
exceptionMatcher = { it is ConcurrentModificationException || it is DataIntegrityViolationException }
) {
fn()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,7 @@ class V2ImportControllerResultTest : AuthorizedControllerTest() {
@Test
fun `onlyUnresolved filter on translations works`() {
val testData = ImportTestData()
val resolvedText = "Hello, I am resolved"

testData {
data.importFiles[0].addImportTranslation {

conflict = testData.conflict
this.resolve()
key = data.importFiles[0].data.importKeys[0].self
text = resolvedText
language = testData.importEnglish
}.self
}

testData.translationWithConflict.resolve()
testDataService.saveTestData(testData.root)
loginAsUser(testData.root.data.userAccounts[0].self.username)

Expand All @@ -215,13 +203,13 @@ class V2ImportControllerResultTest : AuthorizedControllerTest() {
"/import/result/languages/${testData.importEnglish.id}/" +
"translations?onlyConflicts=true"
).andIsOk
.andPrettyPrint.andAssertThatJson { node("_embedded.translations").isArray.hasSize(4) }
.andPrettyPrint.andAssertThatJson { node("_embedded.translations").isArray.hasSize(3) }

performAuthGet(
"/v2/projects/${testData.project.id}" +
"/import/result/languages/${testData.importEnglish.id}/translations?onlyUnresolved=true"
).andIsOk
.andPrettyPrint.andAssertThatJson { node("_embedded.translations").isArray.hasSize(3) }
.andPrettyPrint.andAssertThatJson { node("_embedded.translations").isArray.hasSize(2) }
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion backend/data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ apply from: "$rootDir/gradle/liquibase.gradle"
configureLiquibase("public", "hibernate:spring:io.tolgee", 'src/main/resources/db/changelog/schema.xml')

diff.dependsOn compileKotlin
diffChangeLog.dependsOn compileKotlin
diffChangelog.dependsOn compileKotlin

kotlin {
jvmToolchain(17)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.tolgee.model.activity

import io.hypersistence.utils.hibernate.type.json.JsonBinaryType
import io.tolgee.activity.data.EntityDescriptionRef
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.IdClass
Expand All @@ -26,9 +27,11 @@ class ActivityDescribingEntity(
val entityId: Long
) : Serializable {

@Column(columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
var data: Map<String, Any?> = mutableMapOf()

@Type(JsonBinaryType::class)
@Column(columnDefinition = "jsonb")
var describingRelations: Map<String, EntityDescriptionRef>? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.hypersistence.utils.hibernate.type.json.JsonBinaryType
import io.tolgee.activity.data.EntityDescriptionRef
import io.tolgee.activity.data.PropertyModification
import io.tolgee.activity.data.RevisionType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Enumerated
import jakarta.persistence.Id
Expand Down Expand Up @@ -39,19 +40,22 @@ class ActivityModifiedEntity(
/**
* Map of field to object containing old and new values
*/
@Column(columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
var modifications: MutableMap<String, PropertyModification> = mutableMapOf()

/**
* Data, which are discribing the entity, but are not modified by the change
*/
@Column(columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
var describingData: Map<String, Any?>? = null

/**
* Relations describing the entity.
* e.g. For translation, we would also need key and language data
*/
@Column(columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
var describingRelations: Map<String, EntityDescriptionRef>? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ActivityRevision : java.io.Serializable {
*/
var authorId: Long? = null

@Column(columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
var meta: MutableMap<String, Any?>? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.tolgee.model.Project
import io.tolgee.model.StandardAuditModel
import io.tolgee.model.UserAccount
import io.tolgee.model.activity.ActivityRevision
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType.STRING
import jakarta.persistence.Enumerated
Expand All @@ -27,6 +28,7 @@ class BatchJob : StandardAuditModel(), IBatchJob {
@ManyToOne(fetch = FetchType.LAZY)
var author: UserAccount? = null

@Column(columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
var target: List<Any> = listOf()

Expand All @@ -45,6 +47,7 @@ class BatchJob : StandardAuditModel(), IBatchJob {
@OneToOne(mappedBy = "batchJob", fetch = FetchType.LAZY)
var activityRevision: ActivityRevision? = null

@Column(columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
var params: Any? = null

Expand Down
Loading
Loading