From b26fc5a82264295138e1deb870781d0772f4ac72 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Wed, 25 Oct 2023 10:54:20 +0800 Subject: [PATCH] feat: support `FlowableIdGeneratorAutoConfiguration` --- cosid-spring-boot-starter/build.gradle.kts | 8 +++- .../FlowableIdGeneratorAutoConfiguration.java | 47 +++++++++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + ...wableIdGeneratorAutoConfigurationTest.java | 38 +++++++++++++++ gradle/libs.versions.toml | 2 + 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfiguration.java create mode 100644 cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfigurationTest.java diff --git a/cosid-spring-boot-starter/build.gradle.kts b/cosid-spring-boot-starter/build.gradle.kts index 9925542605..54b262992c 100644 --- a/cosid-spring-boot-starter/build.gradle.kts +++ b/cosid-spring-boot-starter/build.gradle.kts @@ -40,6 +40,10 @@ java { usingSourceSet(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]) capability(group.toString(), "data-jdbc-support", version.toString()) } + registerFeature("flowableSupport") { + usingSourceSet(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]) + capability(group.toString(), "flowable-support", version.toString()) + } registerFeature("cloudSupport") { usingSourceSet(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]) capability(group.toString(), "cloud-support", version.toString()) @@ -63,7 +67,9 @@ dependencies { "proxySupportImplementation"(project(":cosid-proxy")) "mongoSupportImplementation"(project(":cosid-mongo")) - + "flowableSupportImplementation"(project(":cosid-flowable")) + "flowableSupportImplementation"(libs.flowableSpring) + "flowableSupportImplementation"(libs.flowableSpringBootAutoconfigure) "mybatisSupportImplementation"(project(":cosid-mybatis")) "dataJdbcSupportImplementation"(project(":cosid-spring-data-jdbc")) api("org.springframework.boot:spring-boot-starter") diff --git a/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfiguration.java b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfiguration.java new file mode 100644 index 0000000000..e2c123d445 --- /dev/null +++ b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfiguration.java @@ -0,0 +1,47 @@ +/* + * 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.spring.boot.starter.flowable; + +import me.ahoo.cosid.flowable.FlowableIdGenerator; +import me.ahoo.cosid.spring.boot.starter.ConditionalOnCosIdEnabled; + +import org.flowable.spring.SpringProcessEngineConfiguration; +import org.flowable.spring.boot.EngineConfigurationConfigurer; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; + +/** + * Flowable IdGenerator Auto Configuration. + * + * @author ahoo wang + */ +@AutoConfiguration +@ConditionalOnCosIdEnabled +@ConditionalOnClass(FlowableIdGenerator.class) +public class FlowableIdGeneratorAutoConfiguration { + + @Bean + public EngineConfigurationConfigurer engineConfigurationConfigurer() { + return new CosIdEngineConfigurationConfigurer(); + } + + static class CosIdEngineConfigurationConfigurer implements EngineConfigurationConfigurer { + + @Override + public void configure(SpringProcessEngineConfiguration engineConfiguration) { + engineConfiguration.setIdGenerator(new FlowableIdGenerator()); + } + } +} diff --git a/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 5d689f5109..1629e118ad 100644 --- a/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -18,3 +18,4 @@ me.ahoo.cosid.spring.boot.starter.segment.CosIdProxySegmentAutoConfiguration me.ahoo.cosid.spring.boot.starter.mybatis.CosIdMybatisAutoConfiguration me.ahoo.cosid.spring.boot.starter.actuate.CosIdEndpointAutoConfiguration me.ahoo.cosid.spring.boot.starter.jdbc.CosIdJdbcAutoConfiguration +me.ahoo.cosid.spring.boot.starter.flowable.FlowableIdGeneratorAutoConfiguration diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfigurationTest.java new file mode 100644 index 0000000000..00608e0364 --- /dev/null +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/flowable/FlowableIdGeneratorAutoConfigurationTest.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.spring.boot.starter.flowable; + +import me.ahoo.cosid.spring.boot.starter.machine.ConditionalOnCosIdMachineEnabled; + +import org.assertj.core.api.AssertionsForInterfaceTypes; +import org.flowable.spring.boot.EngineConfigurationConfigurer; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +class FlowableIdGeneratorAutoConfigurationTest { + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); + + @Test + void contextLoads() { + this.contextRunner + .withPropertyValues(ConditionalOnCosIdMachineEnabled.ENABLED_KEY + "=true") + .withUserConfiguration(FlowableIdGeneratorAutoConfiguration.class) + .run(context -> { + AssertionsForInterfaceTypes.assertThat(context) + .hasSingleBean(FlowableIdGeneratorAutoConfiguration.class) + .hasSingleBean(EngineConfigurationConfigurer.class) + ; + }); + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 60f7584344..c12f994b1a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,6 +31,8 @@ mybatis = { module = "org.mybatis:mybatis", version.ref = "mybatis" } mybatisSpringBoot = { module = "org.mybatis.spring.boot:mybatis-spring-boot-starter", version.ref = "mybatisSpringBoot" } springDocStarterWebfluxUi = { module = "org.springdoc:springdoc-openapi-starter-webflux-ui", version.ref = "springDoc" } 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" } 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" }