From 2ef247df7645f919e0a8ece0aeb520d033bf1d8b Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Wed, 1 Nov 2023 10:29:46 +0800 Subject: [PATCH 1/2] feat: support Activiti IdGenerator Based on CosId. --- cosid-activiti/build.gradle.kts | 6 +++ .../cosid/activiti/ActivitiIdGenerator.java | 38 +++++++++++++++++++ .../activiti/ActivitiIdGeneratorTest.java | 35 +++++++++++++++++ gradle.properties | 2 +- gradle/libs.versions.toml | 2 + settings.gradle.kts | 1 + 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 cosid-activiti/build.gradle.kts create mode 100644 cosid-activiti/src/main/java/me/ahoo/cosid/activiti/ActivitiIdGenerator.java create mode 100644 cosid-activiti/src/test/java/me/ahoo/cosid/activiti/ActivitiIdGeneratorTest.java diff --git a/cosid-activiti/build.gradle.kts b/cosid-activiti/build.gradle.kts new file mode 100644 index 0000000000..001c07cfcc --- /dev/null +++ b/cosid-activiti/build.gradle.kts @@ -0,0 +1,6 @@ +dependencies { + implementation(libs.activitiEngine) + api(project(":cosid-core")) + testImplementation(project(":cosid-test")) + +} diff --git a/cosid-activiti/src/main/java/me/ahoo/cosid/activiti/ActivitiIdGenerator.java b/cosid-activiti/src/main/java/me/ahoo/cosid/activiti/ActivitiIdGenerator.java new file mode 100644 index 0000000000..9de732ca04 --- /dev/null +++ b/cosid-activiti/src/main/java/me/ahoo/cosid/activiti/ActivitiIdGenerator.java @@ -0,0 +1,38 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * 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 me.ahoo.cosid.activiti; + +import me.ahoo.cosid.provider.IdGeneratorProvider; +import me.ahoo.cosid.provider.LazyIdGenerator; + +/** + * Activiti IdGenerator Based on CosId. + */ +public class ActivitiIdGenerator implements org.activiti.engine.impl.cfg.IdGenerator { + /** + * The key of the system property that can be used to set the id generator name. + */ + public static final String ID_KEY = "cosid.activiti"; + private static final String ID_NAME; + private static final LazyIdGenerator ID_GENERATOR; + + static { + ID_NAME = System.getProperty(ID_KEY, IdGeneratorProvider.SHARE); + ID_GENERATOR = new LazyIdGenerator(ID_NAME); + } + + public String getNextId() { + return ID_GENERATOR.generateAsString(); + } +} diff --git a/cosid-activiti/src/test/java/me/ahoo/cosid/activiti/ActivitiIdGeneratorTest.java b/cosid-activiti/src/test/java/me/ahoo/cosid/activiti/ActivitiIdGeneratorTest.java new file mode 100644 index 0000000000..491186e5c6 --- /dev/null +++ b/cosid-activiti/src/test/java/me/ahoo/cosid/activiti/ActivitiIdGeneratorTest.java @@ -0,0 +1,35 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * 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 me.ahoo.cosid.activiti; + +import static me.ahoo.cosid.activiti.ActivitiIdGenerator.ID_KEY; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +import me.ahoo.cosid.provider.DefaultIdGeneratorProvider; +import me.ahoo.cosid.test.MockIdGenerator; + +import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.SetSystemProperty; + +class ActivitiIdGeneratorTest { + + @SetSystemProperty(key = ID_KEY, value = "activiti") + @Test + void getNextId() { + DefaultIdGeneratorProvider.INSTANCE.set("activiti", MockIdGenerator.usePrefix("activiti_")); + String id = new ActivitiIdGenerator().getNextId(); + assertThat(id, startsWith("activiti_")); + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index ee07433997..c630d33e4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ # limitations under the License. # group=me.ahoo.cosid -version=2.5.5 +version=2.5.6 description=Universal, flexible, high-performance distributed ID generator. website=https://github.com/Ahoo-Wang/CosId issues=https://github.com/Ahoo-Wang/CosId/issues diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8d614c2983..d37b90d59b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,7 @@ mybatisSpringBoot = "3.0.2" junitPioneer = "2.1.0" axon = "4.9.0" flowable = "6.8.0" +activiti = "6.0.0" springDoc = "2.2.0" hamcrest = "2.2" mockk = "1.13.8" @@ -33,6 +34,7 @@ springDocStarterWebfluxUi = { module = "org.springdoc:springdoc-openapi-starter- flowableEngineCommon = { module = "org.flowable:flowable-engine-common", version.ref = "flowable" } flowableSpring = { module = "org.flowable:flowable-spring", version.ref = "flowable" } flowableSpringBootAutoconfigure = { module = "org.flowable:flowable-spring-boot-autoconfigure", version.ref = "flowable" } +activitiEngine = { module = "org.activiti:activiti-engine", version.ref = "activiti" } junitPioneer = { module = "org.junit-pioneer:junit-pioneer", version.ref = "junitPioneer" } hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" } mockk = { module = "io.mockk:mockk", version.ref = "mockk" } diff --git a/settings.gradle.kts b/settings.gradle.kts index ee224a81ea..3cd65f708b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -27,6 +27,7 @@ include(":cosid-proxy") include(":cosid-proxy-server") include(":cosid-axon") include(":cosid-flowable") +include(":cosid-activiti") include(":cosid-mongo") include(":cosid-spring-data-jdbc") include(":code-coverage-report") From 06f83f66219134d6a48cceb8e37b04789481c5e2 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Wed, 1 Nov 2023 10:31:29 +0800 Subject: [PATCH 2/2] feat: support Activiti IdGenerator Based on CosId. --- .github/workflows/integration-test.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index b01ac82ef2..0686a8cf60 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -86,6 +86,25 @@ jobs: - name: Test CosId-Axon run: ./gradlew cosid-axon:clean cosid-axon:check + cosid-activiti-test: + name: CosId Activiti Test + needs: [ cosid-core-test ] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + server-id: github + settings-path: ${{ github.workspace }} + + - name: Test CosId-Activiti + run: ./gradlew cosid-activiti:clean cosid-activiti:check + cosid-flowable-test: name: CosId Flowable Test needs: [ cosid-core-test ]