From 160bc5d2d674de2e825b17f439f0c95ea3caea84 Mon Sep 17 00:00:00 2001 From: bercianor Date: Tue, 3 Feb 2026 00:38:55 +0000 Subject: [PATCH] feat: remove SQL and MongoDB Sync templates as they have their own repo now --- .github/workflows/release.yml | 14 --- .../flamingock.project-structure.gradle.kts | 9 +- .../flamingock.release-management.gradle.kts | 2 - .../flamingock-community-bom/build.gradle.kts | 4 +- .../mongock-importer-mongodb/build.gradle.kts | 3 +- .../_0003__CreateUsersCollectionChange.java | 32 +++++ .../_0003__create_users_collections.yaml | 9 -- .../changes/_0004__SeedUsersChange.java | 39 ++++++ .../mongodb/changes/_0004__seed_users.yaml | 16 --- settings.gradle.kts | 15 --- .../flamingock-mongodb-sync-template/TODO.md | 6 - .../build.gradle.kts | 33 ----- .../template/mongodb/MongoChangeTemplate.java | 52 -------- .../mongodb/mapper/IndexOptionsMapper.java | 107 ---------------- .../mongodb/mapper/InsertOptionsMapper.java | 53 -------- .../template/mongodb/mapper/MapperUtil.java | 119 ------------------ .../mongodb/model/MongoOperation.java | 86 ------------- .../mongodb/model/MongoOperationType.java | 55 -------- .../operator/CreateCollectionOperator.java | 40 ------ .../model/operator/CreateIndexOperator.java | 41 ------ .../model/operator/InsertOperator.java | 88 ------------- .../mongodb/model/operator/MongoOperator.java | 64 ---------- .../io.flamingock.api.template.ChangeTemplate | 1 - .../mongodb/MongoChangeTemplateTest.java | 118 ----------------- .../_0001__create_users_collections.yaml | 9 -- .../mongodb/changes/_0002__seed_users.yaml | 16 --- .../test/resources/flamingock/pipeline.yaml | 4 - templates/flamingock-sql-template/README.md | 20 --- .../flamingock-sql-template/build.gradle.kts | 11 -- .../flamingock/template/sql/SqlTemplate.java | 48 ------- .../io.flamingock.api.template.ChangeTemplate | 1 - 31 files changed, 74 insertions(+), 1041 deletions(-) create mode 100644 legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__CreateUsersCollectionChange.java delete mode 100644 legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__create_users_collections.yaml create mode 100644 legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__SeedUsersChange.java delete mode 100644 legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__seed_users.yaml delete mode 100644 templates/flamingock-mongodb-sync-template/TODO.md delete mode 100644 templates/flamingock-mongodb-sync-template/build.gradle.kts delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/MongoChangeTemplate.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/IndexOptionsMapper.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/InsertOptionsMapper.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/MapperUtil.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperation.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperationType.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateCollectionOperator.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateIndexOperator.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/InsertOperator.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/MongoOperator.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate delete mode 100644 templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/MongoChangeTemplateTest.java delete mode 100644 templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0001__create_users_collections.yaml delete mode 100644 templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0002__seed_users.yaml delete mode 100644 templates/flamingock-mongodb-sync-template/src/test/resources/flamingock/pipeline.yaml delete mode 100644 templates/flamingock-sql-template/README.md delete mode 100644 templates/flamingock-sql-template/build.gradle.kts delete mode 100644 templates/flamingock-sql-template/src/main/java/io/flamingock/template/sql/SqlTemplate.java delete mode 100644 templates/flamingock-sql-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0f0a55ed8..f9d2da748 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -383,19 +383,6 @@ jobs: FLAMINGOCK_JRELEASER_GPG_SECRET_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_SECRET_KEY }} FLAMINGOCK_JRELEASER_GPG_PASSPHRASE: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PASSPHRASE }} - flamingock-sql-template: - needs: [ build ] - uses: ./.github/workflows/module-release-graalvm.yml - with: - module: flamingock-sql-template - secrets: - FLAMINGOCK_JRELEASER_GITHUB_TOKEN: ${{ secrets.FLAMINGOCK_JRELEASER_GITHUB_TOKEN }} - FLAMINGOCK_JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_USERNAME }} - FLAMINGOCK_JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.FLAMINGOCK_JRELEASER_MAVENCENTRAL_PASSWORD }} - FLAMINGOCK_JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PUBLIC_KEY }} - FLAMINGOCK_JRELEASER_GPG_SECRET_KEY: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_SECRET_KEY }} - FLAMINGOCK_JRELEASER_GPG_PASSPHRASE: ${{ secrets.FLAMINGOCK_JRELEASER_GPG_PASSPHRASE }} - general-util: needs: [ build ] uses: ./.github/workflows/module-release-graalvm.yml @@ -552,7 +539,6 @@ jobs: dynamodb-target-system, couchbase-external-system-api, couchbase-target-system, - flamingock-sql-template, general-util, test-util, mongodb-util, diff --git a/buildSrc/src/main/kotlin/flamingock.project-structure.gradle.kts b/buildSrc/src/main/kotlin/flamingock.project-structure.gradle.kts index 3681f6b1d..184610c92 100644 --- a/buildSrc/src/main/kotlin/flamingock.project-structure.gradle.kts +++ b/buildSrc/src/main/kotlin/flamingock.project-structure.gradle.kts @@ -49,10 +49,6 @@ val externalSystemProjects = setOf( "sql-external-system-api" ) -val templateProjects = setOf( - "flamingock-sql-template" -) - val utilProjects = setOf( "general-util", "test-util", @@ -69,7 +65,7 @@ val legacyProjects = setOf( "mongock-importer-couchbase" ) -val allProjects = coreProjects + cloudProjects + communityProjects + pluginProjects + targetSystemProjects + externalSystemProjects + templateProjects + utilProjects + legacyProjects +val allProjects = coreProjects + cloudProjects + communityProjects + pluginProjects + targetSystemProjects + externalSystemProjects + utilProjects + legacyProjects // Project classification utilities fun Project.isBomModule(): Boolean = name.endsWith("-bom") @@ -83,7 +79,6 @@ fun Project.getProjectCategory(): String? = when (name) { in pluginProjects -> "plugins" in targetSystemProjects -> "targetSystems" in externalSystemProjects -> "externalSystems" - in templateProjects -> "templates" in utilProjects -> "utils" in legacyProjects -> "legacy" else -> null @@ -97,7 +92,6 @@ fun getProjectsForBundle(bundle: String?): Set = when (bundle) { "plugins" -> pluginProjects "targetSystems" -> targetSystemProjects "externalSystems" -> externalSystemProjects - "templates" -> templateProjects "utils" -> utilProjects "legacy" -> legacyProjects "all" -> allProjects @@ -111,7 +105,6 @@ extra["communityProjects"] = communityProjects extra["pluginProjects"] = pluginProjects extra["targetSystemProjects"] = targetSystemProjects extra["externalSystemProjects"] = externalSystemProjects -extra["templateProjects"] = templateProjects extra["utilProjects"] = utilProjects extra["legacyProjects"] = legacyProjects extra["allProjects"] = allProjects diff --git a/buildSrc/src/main/kotlin/flamingock.release-management.gradle.kts b/buildSrc/src/main/kotlin/flamingock.release-management.gradle.kts index ea4d788d2..2d0504c8a 100644 --- a/buildSrc/src/main/kotlin/flamingock.release-management.gradle.kts +++ b/buildSrc/src/main/kotlin/flamingock.release-management.gradle.kts @@ -32,7 +32,6 @@ val projectsToRelease = if (module != null) { val pluginProjects = project.extra["pluginProjects"] as Set val targetSystemProjects = project.extra["targetSystemProjects"] as Set val externalSystemProjects = project.extra["externalSystemProjects"] as Set - val templateProjects = project.extra["templateProjects"] as Set val utilProjects = project.extra["utilProjects"] as Set val legacyProjects = project.extra["legacyProjects"] as Set @@ -43,7 +42,6 @@ val projectsToRelease = if (module != null) { "plugins" -> pluginProjects "targetSystems" -> targetSystemProjects "externalSystems" -> externalSystemProjects - "templates" -> templateProjects "utils" -> utilProjects "legacy" -> legacyProjects "all" -> allProjects diff --git a/community/flamingock-community-bom/build.gradle.kts b/community/flamingock-community-bom/build.gradle.kts index 4ea7d3ae4..f292e552f 100644 --- a/community/flamingock-community-bom/build.gradle.kts +++ b/community/flamingock-community-bom/build.gradle.kts @@ -12,8 +12,6 @@ dependencies { api("io.flamingock:flamingock-auditstore-dynamodb:$version") api("io.flamingock:flamingock-auditstore-sql:$version") api("io.flamingock:flamingock-test-support:${version}") - api("io.flamingock:flamingock-sql-template:$version") - api("io.flamingock:flamingock-mongodb-sync-template:${version}") api("io.flamingock:flamingock-springboot-integration:${version}") api("io.flamingock:flamingock-springboot-test-support:${version}") api("io.flamingock:flamingock-graalvm:${version}") @@ -21,4 +19,4 @@ dependencies { } } -description = "Bill of Materials for Community Edition dependency management" \ No newline at end of file +description = "Bill of Materials for Community Edition dependency management" diff --git a/legacy/mongock-importer-mongodb/build.gradle.kts b/legacy/mongock-importer-mongodb/build.gradle.kts index fe1fca141..c5abb9210 100644 --- a/legacy/mongock-importer-mongodb/build.gradle.kts +++ b/legacy/mongock-importer-mongodb/build.gradle.kts @@ -7,7 +7,6 @@ dependencies { testImplementation(project(":legacy:mongock-support")) testImplementation(project(":core:target-systems:mongodb-sync-target-system")) testImplementation(project(":community:flamingock-auditstore-mongodb-sync")) - testImplementation(project(":templates:flamingock-mongodb-sync-template")) testImplementation(project(":utils:test-util")) testImplementation(project(":utils:mongodb-util")) @@ -42,4 +41,4 @@ tasks.withType().configureEach { } configurations.testImplementation { extendsFrom(configurations.compileOnly.get()) -} \ No newline at end of file +} diff --git a/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__CreateUsersCollectionChange.java b/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__CreateUsersCollectionChange.java new file mode 100644 index 000000000..b377ef183 --- /dev/null +++ b/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__CreateUsersCollectionChange.java @@ -0,0 +1,32 @@ +/* + * Copyright 2023 Flamingock (https://www.flamingock.io) + * + * 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.flamingock.importer.mongock.mongodb.changes; + +import com.mongodb.client.MongoDatabase; +import io.flamingock.api.annotations.Apply; +import io.flamingock.api.annotations.Change; +import io.flamingock.api.annotations.NonLockGuarded; +import io.flamingock.api.annotations.TargetSystem; + +@TargetSystem( id = "mongodb-target-system") +@Change(id = "create-users-collection-with-index", author = "bercianor", transactional = false) +public class _0003__CreateUsersCollectionChange { + + @Apply + public void apply(@NonLockGuarded MongoDatabase mongoDatabase) { + mongoDatabase.createCollection("users"); + } +} diff --git a/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__create_users_collections.yaml b/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__create_users_collections.yaml deleted file mode 100644 index 555e3f317..000000000 --- a/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0003__create_users_collections.yaml +++ /dev/null @@ -1,9 +0,0 @@ -id: create-users-collection-with-index -#transactional: false -template: MongoChangeTemplate -targetSystem: - id: "mongodb-target-system" -apply: - type: createCollection - collection: users - diff --git a/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__SeedUsersChange.java b/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__SeedUsersChange.java new file mode 100644 index 000000000..5f28f3cf2 --- /dev/null +++ b/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__SeedUsersChange.java @@ -0,0 +1,39 @@ +/* + * Copyright 2023 Flamingock (https://www.flamingock.io) + * + * 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.flamingock.importer.mongock.mongodb.changes; + +import com.mongodb.client.ClientSession; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import io.flamingock.api.annotations.Apply; +import io.flamingock.api.annotations.Change; +import io.flamingock.api.annotations.NonLockGuarded; +import io.flamingock.api.annotations.TargetSystem; +import org.bson.Document; + +@TargetSystem( id = "mongodb-target-system") +@Change(id = "seed-users", author = "bercianor") +public class _0004__SeedUsersChange { + + @Apply + public void apply(@NonLockGuarded MongoDatabase mongoDatabase, @NonLockGuarded ClientSession clientSession) { + MongoCollection collection = mongoDatabase.getCollection("users"); + collection.insertMany(clientSession, java.util.Arrays.asList( + new Document().append("name", "Admin").append("email", "admin@company.com").append("roles", java.util.Arrays.asList("superuser")), + new Document().append("name", "Backup").append("email", "backup@company.com").append("roles", java.util.Arrays.asList("readonly")) + )); + } +} diff --git a/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__seed_users.yaml b/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__seed_users.yaml deleted file mode 100644 index ca5b78b8d..000000000 --- a/legacy/mongock-importer-mongodb/src/test/java/io/flamingock/importer/mongock/mongodb/changes/_0004__seed_users.yaml +++ /dev/null @@ -1,16 +0,0 @@ -id: seed-users -transactional: true -template: MongoChangeTemplate -targetSystem: - id: "mongodb-target-system" -apply: - type: insert - collection: users - parameters: - documents: - - name: "Admin" - email: "admin@company.com" - roles: [ "superuser" ] - - name: "Backup" - email: "backup@company.com" - roles: [ "readonly" ] \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 825a7457a..65384c0c6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -132,21 +132,6 @@ include("core:target-systems:couchbase-target-system") project(":core:target-systems:couchbase-target-system").projectDir = file("core/target-systems/couchbase-target-system") project(":core:target-systems:couchbase-target-system").name = "couchbase-target-system" -////////////////////////////////////// -// TEMPLATES -////////////////////////////////////// - -//SQL -include("templates:flamingock-sql-template") -project(":templates:flamingock-sql-template").name = "flamingock-sql-template" -project(":templates:flamingock-sql-template").projectDir = file("templates/flamingock-sql-template") - - -//MONGODB -include("templates:flamingock-mongodb-sync-template") -project(":templates:flamingock-mongodb-sync-template").name = "flamingock-mongodb-sync-template" -project(":templates:flamingock-mongodb-sync-template").projectDir = file("templates/flamingock-mongodb-sync-template") - ////////////////////////////////////// // UTILS diff --git a/templates/flamingock-mongodb-sync-template/TODO.md b/templates/flamingock-mongodb-sync-template/TODO.md deleted file mode 100644 index c4249bcf2..000000000 --- a/templates/flamingock-mongodb-sync-template/TODO.md +++ /dev/null @@ -1,6 +0,0 @@ -- add Client session when transactional -- Problem: transactional is passed dynamically while the clientSession is statically in the signature - - Check how transaction is handle in the entire framework - - Should we add an annotation to the change parameter to allow nulls, like `@Nullable` -- test -- rename template to changeTemplate \ No newline at end of file diff --git a/templates/flamingock-mongodb-sync-template/build.gradle.kts b/templates/flamingock-mongodb-sync-template/build.gradle.kts deleted file mode 100644 index c4526cdd2..000000000 --- a/templates/flamingock-mongodb-sync-template/build.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -dependencies { - implementation(project(":core:flamingock-core-commons")) - compileOnly("org.mongodb:mongodb-driver-sync:4.0.0") - - - testAnnotationProcessor(project(":core:flamingock-processor")) - testImplementation(project(":community:flamingock-auditstore-mongodb-sync")) - testImplementation(project(":core:target-systems:mongodb-sync-target-system")) - testImplementation(project(":utils:test-util")) - testImplementation(project(":utils:mongodb-util")) - testImplementation("org.testcontainers:testcontainers-mongodb:2.0.2") - testImplementation("org.testcontainers:testcontainers-junit-jupiter:2.0.2") -} - -description = "MongoDB change templates for document database operations" - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } -} - -tasks.withType().configureEach { - if (name.contains("Test", ignoreCase = true)) { - options.compilerArgs.addAll(listOf( - "-Asources=${projectDir}/src/test/java", - "-Aresources=${projectDir}/src/test/resources" - )) - } -} -configurations.testImplementation { - extendsFrom(configurations.compileOnly.get()) -} \ No newline at end of file diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/MongoChangeTemplate.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/MongoChangeTemplate.java deleted file mode 100644 index 9890ec4ae..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/MongoChangeTemplate.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2023 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb; - -import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoDatabase; -import io.flamingock.api.annotations.Apply; -import io.flamingock.api.annotations.Nullable; -import io.flamingock.api.annotations.Rollback; -import io.flamingock.api.template.AbstractChangeTemplate; -import io.flamingock.template.mongodb.model.MongoOperation; - -public class MongoChangeTemplate extends AbstractChangeTemplate { - - public MongoChangeTemplate() { - super(MongoOperation.class); - } - - @Apply - public void apply(MongoDatabase db, @Nullable ClientSession clientSession) { - if (this.isTransactional && clientSession == null) { - throw new IllegalArgumentException(String.format("Transactional change[%s] requires transactional ecosystem with ClientSession", changeId)); - } - executeOp(db, applyPayload, clientSession); - } - - @Rollback - public void rollback(MongoDatabase db, @Nullable ClientSession clientSession) { - if (this.isTransactional && clientSession == null) { - throw new IllegalArgumentException(String.format("Transactional change[%s] requires transactional ecosystem with ClientSession", changeId)); - } - executeOp(db, rollbackPayload, clientSession); - } - - private void executeOp(MongoDatabase db, MongoOperation op, ClientSession clientSession) { - op.getOperator(db).apply(clientSession); - } - -} \ No newline at end of file diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/IndexOptionsMapper.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/IndexOptionsMapper.java deleted file mode 100644 index 8f119977e..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/IndexOptionsMapper.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.mapper; -import com.mongodb.client.model.IndexOptions; - - -import java.util.Map; - -import static io.flamingock.template.mongodb.mapper.MapperUtil.getBoolean; -import static io.flamingock.template.mongodb.mapper.MapperUtil.getBson; -import static io.flamingock.template.mongodb.mapper.MapperUtil.getCollation; -import static io.flamingock.template.mongodb.mapper.MapperUtil.getDouble; -import static io.flamingock.template.mongodb.mapper.MapperUtil.getInteger; -import static io.flamingock.template.mongodb.mapper.MapperUtil.getLong; -import static io.flamingock.template.mongodb.mapper.MapperUtil.getString; - -import java.util.concurrent.TimeUnit; - - -public class IndexOptionsMapper { - - public static IndexOptions mapToIndexOptions(Map options) { - IndexOptions indexOptions = new IndexOptions(); - - if (options.containsKey("background")) { - indexOptions.background(getBoolean(options, "background")); - } - if (options.containsKey("unique")) { - indexOptions.unique(getBoolean(options, "unique")); - } - if (options.containsKey("name")) { - indexOptions.name(getString(options, "name")); - } - if (options.containsKey("sparse")) { - indexOptions.sparse(getBoolean(options, "sparse")); - } - if (options.containsKey("expireAfterSeconds")) { - indexOptions.expireAfter(getLong(options, "expireAfterSeconds"), TimeUnit.SECONDS); - } - if (options.containsKey("version")) { - indexOptions.version(getInteger(options, "version")); - } - if (options.containsKey("weights")) { - indexOptions.weights(getBson(options, "weights")); - } - if (options.containsKey("defaultLanguage")) { - indexOptions.defaultLanguage(getString(options, "defaultLanguage")); - } - if (options.containsKey("languageOverride")) { - indexOptions.languageOverride(getString(options, "languageOverride")); - } - if (options.containsKey("textVersion")) { - indexOptions.textVersion(getInteger(options, "textVersion")); - } - if (options.containsKey("sphereVersion")) { - indexOptions.sphereVersion(getInteger(options, "sphereVersion")); - } - if (options.containsKey("bits")) { - indexOptions.bits(getInteger(options, "bits")); - } - if (options.containsKey("min")) { - indexOptions.min(getDouble(options, "min")); - } - if (options.containsKey("max")) { - indexOptions.max(getDouble(options, "max")); - } - if (options.containsKey("bucketSize")) { - throw new UnsupportedOperationException("bulkSize option is not supported in MongoDB driver versions 4.4.0 and above"); - } - if (options.containsKey("storageEngine")) { - indexOptions.storageEngine(getBson(options, "storageEngine")); - } - if (options.containsKey("partialFilterExpression")) { - indexOptions.partialFilterExpression(getBson(options, "partialFilterExpression")); - } - if (options.containsKey("collation")) { - indexOptions.collation(getCollation(options, "collation")); - } - if (options.containsKey("wildcardProjection")) { - throw new UnsupportedOperationException("wildcardProjection option is not supported in MongoDB driver versions 4.1.0 and above"); - } - if (options.containsKey("hidden")) { - throw new UnsupportedOperationException("hidden option is not supported in MongoDB driver versions 4.1.0 and above"); - } - - return indexOptions; - } - - - // Utility methods for safe type checking with exception handling - - -} - diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/InsertOptionsMapper.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/InsertOptionsMapper.java deleted file mode 100644 index f2c9aacdf..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/InsertOptionsMapper.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.mapper; - -import com.mongodb.client.model.InsertManyOptions; -import com.mongodb.client.model.InsertOneOptions; - -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import static io.flamingock.template.mongodb.mapper.MapperUtil.getBoolean; - -public class InsertOptionsMapper { - - public static InsertOneOptions mapToInertOneOptions(Map options) { - InsertOneOptions insertOneOptions = new InsertOneOptions(); - - if (options.containsKey("bypassDocumentValidation")) { - insertOneOptions.bypassDocumentValidation(getBoolean(options, "bypassDocumentValidation")); - } - - return insertOneOptions; - } - - public static InsertManyOptions mapToInertManyOptions(Map options) { - InsertManyOptions insertOneOptions = new InsertManyOptions(); - - if (options.containsKey("bypassDocumentValidation")) { - insertOneOptions.bypassDocumentValidation(getBoolean(options, "bypassDocumentValidation")); - } - - if (options.containsKey("ordered")) { - insertOneOptions.bypassDocumentValidation(getBoolean(options, "ordered")); - } - - return insertOneOptions; - } - -} - diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/MapperUtil.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/MapperUtil.java deleted file mode 100644 index 6a136b418..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/mapper/MapperUtil.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.mapper; - -import com.mongodb.client.model.Collation; -import org.bson.BsonDocument; -import org.bson.BsonValue; -import org.bson.conversions.Bson; - -import java.util.Map; - -public final class MapperUtil { - private MapperUtil(){} - - - public static Boolean getBoolean(Map options, String key) { - Object value = options.get(key); - if (value instanceof Boolean) { - return (Boolean) value; - } else { - throw new IllegalArgumentException(String.format("field[%s] should be Boolean", key)); - } - } - - public static String getString(Map options, String key) { - Object value = options.get(key); - if (value instanceof String) { - return (String) value; - } else { - throw new IllegalArgumentException(String.format("field[%s] should be String", key)); - } - } - - public static Integer getInteger(Map options, String key) { - Object value = options.get(key); - if (value instanceof Number) { - return ((Number) value).intValue(); - } else { - throw new IllegalArgumentException(String.format("field[%s] should be Integer", key)); - } - } - - public static Long getLong(Map options, String key) { - Object value = options.get(key); - if (value instanceof Number) { - return ((Number) value).longValue(); - } else { - throw new IllegalArgumentException(String.format("field[%s] should be Long", key)); - } - } - - public static Double getDouble(Map options, String key) { - Object value = options.get(key); - if (value instanceof Number) { - return ((Number) value).doubleValue(); - } else { - throw new IllegalArgumentException(String.format("field[%s] should be Double", key)); - } - } - - public static Bson getBson(Map options, String key) { - Object value = options.get(key); - if (value instanceof Bson) { - return (Bson) value; - } else if (value instanceof Map) { - return toBsonDocument((Map) value); - } else { - throw new IllegalArgumentException(String.format("field[%s] should be Bson", key)); - } - } - - public static Collation getCollation(Map options, String key) { - Object value = options.get(key); - if (value instanceof Collation) { - return (Collation) value; - } else { - throw new IllegalArgumentException(String.format("field[%s] should be Collation", key)); - } - } - - // Recursively converts a Map to BsonDocument - public static BsonDocument toBsonDocument(Map map) { - BsonDocument document = new BsonDocument(); - map.forEach((key, value) -> document.append(key, toBsonValue(value))); - return document; - } - - // Converts Java types into BSON types - @SuppressWarnings("unchecked") - public static BsonValue toBsonValue(Object value) { - if (value instanceof String) { - return new org.bson.BsonString((String) value); - } else if (value instanceof Integer) { - return new org.bson.BsonInt32((Integer) value); - } else if (value instanceof Long) { - return new org.bson.BsonInt64((Long) value); - } else if (value instanceof Double) { - return new org.bson.BsonDouble((Double) value); - } else if (value instanceof Boolean) { - return new org.bson.BsonBoolean((Boolean) value); - } else if (value instanceof Map) { - return toBsonDocument((Map) value); - } - throw new IllegalArgumentException("Unsupported BSON type: " + value.getClass().getSimpleName()); - } -} diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperation.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperation.java deleted file mode 100644 index 4d931e157..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperation.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.model; - -import com.mongodb.client.MongoDatabase; -import io.flamingock.api.annotations.NonLockGuarded; -import io.flamingock.api.NonLockGuardedType; -import io.flamingock.template.mongodb.model.operator.MongoOperator; -import org.bson.Document; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@NonLockGuarded(NonLockGuardedType.NONE) -public class MongoOperation { - private String type; - private String collection; - private Map parameters; - - public String getType() { return type; } - - public String getCollection() { return collection; } - - public Map getParameters() { return parameters; } - - public void setType(String type) { this.type = type; } - - public void setCollection(String collection) { this.collection = collection; } - - public void setParameters(Map parameters) { this.parameters = parameters; } - - @SuppressWarnings("unchecked") - public List getDocuments() { - return ((List>) parameters.get("documents")) - .stream().map(Document::new) - .collect(Collectors.toList()); - } - - @SuppressWarnings("unchecked") - public Document getKeys() { - return new Document((Map) parameters.get("keys")); - } - - - - @SuppressWarnings("unchecked") - public Document getOptions() { - return parameters.containsKey("options") - ? new Document((Map) parameters.get("options")) - : new Document(); - } - - @SuppressWarnings("unchecked") - public Document getFilter() { - return new Document((Map) parameters.get("filter")); - } - - - public MongoOperator getOperator(MongoDatabase db) { - return MongoOperationType.getFromValue(getType()).getOperator(db, this); - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("MongoOperation{"); - sb.append("type='").append(type).append('\''); - sb.append(", collection='").append(collection).append('\''); - sb.append(", parameters=").append(parameters); - sb.append('}'); - return sb.toString(); - } -} \ No newline at end of file diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperationType.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperationType.java deleted file mode 100644 index f54c893e2..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/MongoOperationType.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.model; - -import com.mongodb.client.MongoDatabase; -import io.flamingock.template.mongodb.model.operator.CreateCollectionOperator; -import io.flamingock.template.mongodb.model.operator.CreateIndexOperator; -import io.flamingock.template.mongodb.model.operator.InsertOperator; -import io.flamingock.template.mongodb.model.operator.MongoOperator; - -import java.util.Arrays; -import java.util.function.BiFunction; - -public enum MongoOperationType { - - CREATE_COLLECTION("createCollection", CreateCollectionOperator::new), - CREATE_INDEX("createIndex", CreateIndexOperator::new), - INSERT("insert", InsertOperator::new); - - private final String value; - private final BiFunction createOperatorFunction; - - MongoOperationType(String value, BiFunction createOperatorFunction) { - this.value = value; - this.createOperatorFunction = createOperatorFunction; - } - - public static MongoOperationType getFromValue(String typeValue) { - return Arrays.stream(MongoOperationType.values()) - .filter(type -> type.matches(typeValue)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("MongoOperation not supported: " + typeValue)); - } - - public MongoOperator getOperator(MongoDatabase mongoDatabase, MongoOperation operation) { - return createOperatorFunction.apply(mongoDatabase, operation); - } - - private boolean matches(String operationType) { - return this.value.equals(operationType); - } -} diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateCollectionOperator.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateCollectionOperator.java deleted file mode 100644 index 9096f036a..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateCollectionOperator.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.model.operator; - -import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoDatabase; -import io.flamingock.template.mongodb.model.MongoOperation; -import io.flamingock.internal.util.log.FlamingockLoggerFactory; -import org.slf4j.Logger; - -public class CreateCollectionOperator extends MongoOperator { - protected static final Logger logger = FlamingockLoggerFactory.getLogger("CreateCollection"); - - - public CreateCollectionOperator(MongoDatabase mongoDatabase, MongoOperation operation) { - super(mongoDatabase, operation, false); - } - - @Override - public void applyInternal(ClientSession clientSession) { - if (clientSession != null) { - logger.warn("MongoDB does not support transactions for createCollection operation. Ignoring transactional flag."); - } - mongoDatabase.createCollection(op.getCollection()); - } - -} diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateIndexOperator.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateIndexOperator.java deleted file mode 100644 index 684a641a0..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/CreateIndexOperator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.model.operator; - -import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.model.IndexOptions; -import io.flamingock.template.mongodb.model.MongoOperation; -import io.flamingock.template.mongodb.mapper.IndexOptionsMapper; - -public class CreateIndexOperator extends MongoOperator { - - - public CreateIndexOperator(MongoDatabase mongoDatabase, MongoOperation operation) { - super(mongoDatabase, operation, true); - } - - @Override - protected void applyInternal(ClientSession clientSession) { - if (clientSession != null) { - logger.warn("MongoDB does not support transactions for createCollection operation. Ignoring transactional flag."); - } - IndexOptions indexOptions = IndexOptionsMapper.mapToIndexOptions(op.getOptions()); - mongoDatabase.getCollection(op.getCollection()) - .createIndex(op.getKeys(), indexOptions); - } - -} diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/InsertOperator.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/InsertOperator.java deleted file mode 100644 index 9d866b9b6..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/InsertOperator.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.model.operator; - -import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.model.InsertManyOptions; -import com.mongodb.client.model.InsertOneOptions; -import io.flamingock.template.mongodb.mapper.InsertOptionsMapper; -import io.flamingock.template.mongodb.model.MongoOperation; -import org.bson.Document; - -import java.util.List; - -public class InsertOperator extends MongoOperator { - - - public InsertOperator(MongoDatabase mongoDatabase, MongoOperation operation) { - super(mongoDatabase, operation, true); - } - - @Override - protected void applyInternal(ClientSession clientSession) { - MongoCollection collection = mongoDatabase.getCollection(op.getCollection()); - if(op.getDocuments() == null || op.getDocuments().size() == 0) { - return; - } - - if(op.getDocuments().size() == 1) { - insertOne(clientSession, collection); - } else { - insertMany(clientSession, collection); - } - } - - private void insertMany(ClientSession clientSession, MongoCollection collection) { - if(clientSession != null) { - if(op.getOptions().size() != 0) { - InsertManyOptions insertManyOptions = InsertOptionsMapper.mapToInertManyOptions(op.getOptions()); - collection.insertMany(clientSession, op.getDocuments(), insertManyOptions); - } else { - collection.insertMany(clientSession, op.getDocuments()); - } - - } else { - if(op.getOptions().size() != 0) { - InsertManyOptions insertManyOptions = InsertOptionsMapper.mapToInertManyOptions(op.getOptions()); - collection.insertMany(op.getDocuments(), insertManyOptions); - } else { - collection.insertMany(op.getDocuments()); - } - } - } - - private void insertOne(ClientSession clientSession, MongoCollection collection) { - - if(clientSession != null) { - if(op.getOptions().size() != 0) { - InsertOneOptions insertOneOptions = InsertOptionsMapper.mapToInertOneOptions(op.getOptions()); - collection.insertOne(clientSession, op.getDocuments().get(0), insertOneOptions); - } else { - collection.insertOne(clientSession, op.getDocuments().get(0)); - } - - } else { - if(op.getOptions().size() != 0) { - InsertOneOptions insertOneOptions = InsertOptionsMapper.mapToInertOneOptions(op.getOptions()); - collection.insertOne(op.getDocuments().get(0), insertOneOptions); - } else { - collection.insertOne(op.getDocuments().get(0)); - } - } - } -} diff --git a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/MongoOperator.java b/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/MongoOperator.java deleted file mode 100644 index 7e30f76ec..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/java/io/flamingock/template/mongodb/model/operator/MongoOperator.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2025 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb.model.operator; - -import com.mongodb.client.ClientSession; -import com.mongodb.client.MongoDatabase; -import io.flamingock.template.mongodb.model.MongoOperation; -import io.flamingock.internal.util.log.FlamingockLoggerFactory; -import org.slf4j.Logger; - -public abstract class MongoOperator { - protected static final Logger logger = FlamingockLoggerFactory.getLogger("MongoTemplate"); - - protected final MongoDatabase mongoDatabase; - protected final MongoOperation op; - protected final boolean transactional; - - protected MongoOperator(MongoDatabase mongoDatabase, MongoOperation op, boolean transactional) { - this.op = op; - this.mongoDatabase = mongoDatabase; - this.transactional = transactional; - } - - public final void apply(ClientSession clientSession) { - logOperation(clientSession != null); - applyInternal(clientSession); - } - - private void logOperation(boolean withClientSession) { - String simpleName = getClass().getSimpleName(); - - if (transactional) { - if (withClientSession) { - logger.warn("{} is a transactional operation but is not being applied within a transaction. " + - "Recommend marking Change as transactional.", - simpleName); - } else { - logger.debug("Applying operation [{}] with transaction: ", simpleName); - } - } else { - if(withClientSession) { - logger.info("{} is not transactional, but Change has been marked as transactional. Transaction ignored.", simpleName); - } else { - logger.debug("Applying non-transactional operation [{}]: ", simpleName); - } - } - } - - - protected abstract void applyInternal(ClientSession clientSession); -} diff --git a/templates/flamingock-mongodb-sync-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate b/templates/flamingock-mongodb-sync-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate deleted file mode 100644 index b662deb61..000000000 --- a/templates/flamingock-mongodb-sync-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate +++ /dev/null @@ -1 +0,0 @@ -io.flamingock.template.mongodb.MongoChangeTemplate \ No newline at end of file diff --git a/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/MongoChangeTemplateTest.java b/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/MongoChangeTemplateTest.java deleted file mode 100644 index 4aae4cd2e..000000000 --- a/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/MongoChangeTemplateTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2023 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.mongodb; - -import com.mongodb.ConnectionString; -import com.mongodb.MongoClientSettings; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import com.mongodb.client.MongoDatabase; -import io.flamingock.api.annotations.EnableFlamingock; -import io.flamingock.store.mongodb.sync.MongoDBSyncAuditStore; -import io.flamingock.internal.common.core.audit.AuditEntry; -import io.flamingock.internal.core.builder.FlamingockFactory; -import io.flamingock.targetsystem.mongodb.sync.MongoDBSyncTargetSystem; -import org.bson.Document; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.testcontainers.containers.MongoDBContainer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.utility.DockerImageName; - -import java.util.ArrayList; -import java.util.List; - -import static io.flamingock.internal.util.constants.CommunityPersistenceConstants.DEFAULT_AUDIT_STORE_NAME; -import static org.junit.jupiter.api.Assertions.assertEquals; - -@EnableFlamingock(configFile = "flamingock/pipeline.yaml") -@Testcontainers -class MongoChangeTemplateTest { - - private static final String DB_NAME = "test"; - - - private static MongoClient mongoClient; - - private static MongoDatabase mongoDatabase; - - - @Container - public static final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:6")); - - @BeforeAll - static void beforeAll() { - mongoClient = MongoClients.create(MongoClientSettings - .builder() - .applyConnectionString(new ConnectionString(mongoDBContainer.getConnectionString())) - .build()); - mongoDatabase = mongoClient.getDatabase(DB_NAME); - } - - @BeforeEach - void setupEach() { - mongoDatabase.getCollection(DEFAULT_AUDIT_STORE_NAME).drop(); - mongoDatabase.getCollection(DEFAULT_AUDIT_STORE_NAME).drop(); - } - - - @Test - @DisplayName("WHEN mongodb template THEN runs fine IF Flamingock mongodb sync ce") - void happyPath() { - - MongoDBSyncTargetSystem mongoDBSyncTargetSystem = new MongoDBSyncTargetSystem("mongodb", mongoClient, DB_NAME); - FlamingockFactory.getCommunityBuilder() - .setAuditStore(MongoDBSyncAuditStore.from(mongoDBSyncTargetSystem)) - .addTargetSystem(mongoDBSyncTargetSystem) - .build() - .run(); - - - List auditLog = mongoDatabase.getCollection(DEFAULT_AUDIT_STORE_NAME) - .find() - .into(new ArrayList<>()); - - assertEquals(4, auditLog.size()); - - assertEquals("create-users-collection-with-index", auditLog.get(0).getString("changeId")); - assertEquals(AuditEntry.Status.STARTED.name(), auditLog.get(0).getString("state")); - assertEquals("create-users-collection-with-index", auditLog.get(1).getString("changeId")); - assertEquals(AuditEntry.Status.APPLIED.name(), auditLog.get(1).getString("state")); - - assertEquals("seed-users", auditLog.get(2).getString("changeId")); - assertEquals(AuditEntry.Status.STARTED.name(), auditLog.get(2).getString("state")); - assertEquals("seed-users", auditLog.get(3).getString("changeId")); - assertEquals(AuditEntry.Status.APPLIED.name(), auditLog.get(3).getString("state")); - - List users = mongoDatabase.getCollection("users") - .find() - .into(new ArrayList<>()); - - assertEquals(2, users.size()); - assertEquals("Admin", users.get(0).getString("name")); - assertEquals("admin@company.com", users.get(0).getString("email")); - assertEquals("superuser", users.get(0).getList("roles", String.class).get(0)); - - assertEquals("Backup", users.get(1).getString("name")); - assertEquals("backup@company.com", users.get(1).getString("email")); - assertEquals("readonly", users.get(1).getList("roles", String.class).get(0)); - } - - -} diff --git a/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0001__create_users_collections.yaml b/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0001__create_users_collections.yaml deleted file mode 100644 index df6cb6c23..000000000 --- a/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0001__create_users_collections.yaml +++ /dev/null @@ -1,9 +0,0 @@ -id: create-users-collection-with-index -transactional: false -template: MongoChangeTemplate -targetSystem: - id: "mongodb" -apply: - type: createCollection - collection: users - diff --git a/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0002__seed_users.yaml b/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0002__seed_users.yaml deleted file mode 100644 index 1d2f53822..000000000 --- a/templates/flamingock-mongodb-sync-template/src/test/java/io/flamingock/template/mongodb/changes/_0002__seed_users.yaml +++ /dev/null @@ -1,16 +0,0 @@ -id: seed-users -transactional: true -template: MongoChangeTemplate -targetSystem: - id: "mongodb" -apply: - type: insert - collection: users - parameters: - documents: - - name: "Admin" - email: "admin@company.com" - roles: [ "superuser" ] - - name: "Backup" - email: "backup@company.com" - roles: [ "readonly" ] \ No newline at end of file diff --git a/templates/flamingock-mongodb-sync-template/src/test/resources/flamingock/pipeline.yaml b/templates/flamingock-mongodb-sync-template/src/test/resources/flamingock/pipeline.yaml deleted file mode 100644 index e95f386b0..000000000 --- a/templates/flamingock-mongodb-sync-template/src/test/resources/flamingock/pipeline.yaml +++ /dev/null @@ -1,4 +0,0 @@ -pipeline: - stages: - - description: "With templates" - location: "io.flamingock.template.mongodb.changes" \ No newline at end of file diff --git a/templates/flamingock-sql-template/README.md b/templates/flamingock-sql-template/README.md deleted file mode 100644 index c35e66e15..000000000 --- a/templates/flamingock-sql-template/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Setup -1. docker pull mysql/mysql-server:8.0.32 -2. `docker run --name='my_sql_container' -d -p 3306:3306 mysql/mysql-server` -3. `docker logs my_sql_container` -> Pick password where it says "[Entrypoint] GENERATED ROOT PASSWORD : ..." -4. `docker exec -it my_sql_container bash` -5. `cd /var/lib/mysql` -6. run `mysql -u root -p` and enter the password retrieved in step(3) -7. run `ALTER USER 'root'@'localhost' IDENTIFIED BY 'root_password';` -8. run `use mysql;` -9. run `CREATE USER 'flamingock_user'@'%' IDENTIFIED BY 'password';` -10. run `GRANT ALL PRIVILEGES ON *.* TO 'flamingock_user'@'%' WITH GRANT OPTION;` -11. run `FLUSH PRIVILEGES;` -12. run `create database flamingock;` -13. connect from client to localhost on 3306 with flamingock_user/password - -# TODO -- Currently, there is no a way to know if the rollback should be applied - - Potential solution: Add a method in the template to know if the rollback is provided - - Interpret the rollback method's return. For example,providing an enum as response. Downside is that we may want to - use the return value in the future for something...but it could be wrapped in a Result type. \ No newline at end of file diff --git a/templates/flamingock-sql-template/build.gradle.kts b/templates/flamingock-sql-template/build.gradle.kts deleted file mode 100644 index 4fc3acdce..000000000 --- a/templates/flamingock-sql-template/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -dependencies { - implementation(project(":core:flamingock-core-commons")) -} - -description = "SQL change templates for declarative database schema and data changes" - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } -} \ No newline at end of file diff --git a/templates/flamingock-sql-template/src/main/java/io/flamingock/template/sql/SqlTemplate.java b/templates/flamingock-sql-template/src/main/java/io/flamingock/template/sql/SqlTemplate.java deleted file mode 100644 index c583207cc..000000000 --- a/templates/flamingock-sql-template/src/main/java/io/flamingock/template/sql/SqlTemplate.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2023 Flamingock (https://www.flamingock.io) - * - * 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.flamingock.template.sql; - -import io.flamingock.api.annotations.Apply; -import io.flamingock.api.annotations.Rollback; -import io.flamingock.api.template.AbstractChangeTemplate; - -import java.sql.Connection; -import java.sql.SQLException; - -public class SqlTemplate extends AbstractChangeTemplate { - - public SqlTemplate() { - super(); - } - - @Apply - public void apply(Connection connection) { - execute(connection, applyPayload); - } - - @Rollback - public void rollback(Connection connection) { - execute(connection, rollbackPayload); - } - - private static void execute(Connection connection, String sql) { - try { - connection.createStatement().executeUpdate(sql); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} diff --git a/templates/flamingock-sql-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate b/templates/flamingock-sql-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate deleted file mode 100644 index e4e4a5f7e..000000000 --- a/templates/flamingock-sql-template/src/main/resources/META-INF/services/io.flamingock.api.template.ChangeTemplate +++ /dev/null @@ -1 +0,0 @@ -io.flamingock.template.sql.SqlTemplate \ No newline at end of file