From abc0304c9ad9a40ec3a74f7121287206368b7171 Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Fri, 4 Dec 2026 14:43:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=84=9A=E6=9C=AC=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E4=B8=8E=20framework=20=E9=9B=B6=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E4=BE=9D=E8=B5=96=20(#316)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - framework 主源码删除 springboot-starter-script 编译依赖(仅 test scope 保留集成测试引擎),由 FrameworkScriptDependencyTest 守护 - 新增 IScriptExecutor / IScriptResolver / IScriptEditor 三端口与 FlowScriptGatewayContext(显式注册优先,ServiceLoader 兜底) - 自有 @FlowScriptRef 注解与 ScriptRefScanner 替代外部注解扫描器;流程定义 script 字段为不透明引用,framework 不生成、不改写 key - 删除 getGroovyScript 回退通道与强制 key 归一化;FlowGroovyScriptFactory 下移 infra-groovy;DefaultScriptRegistry 直接返回脚本文本 - infra 改 pom 聚合:infra-db(原 JPA 实现包名不变)/ infra-groovy(脚本能力与三类脚本持久化,从 example 迁入 12 个类) - infra-groovy 提供 key(默认)与 inline(flow.script.ref-mode=inline)两套 Gateway 实现,@ConditionalOnMissingBean 保留接入方自定义优先 - 文档同批更新:README / AGENTS / Integration / capabilities / model-design - 验证:./mvnw -o clean install 通过,583 用例 0 失败;新增架构守护、端口契约与 inline 模式用例 Closes #316 --- AGENTS.md | 14 +- README.md | 26 +- docs/Integration/repository-integration.md | 30 +- docs/Integration/script-integration.md | 79 ++--- .../flow-engine-framework/script.md | 23 +- docs/capabilities/index.md | 2 +- docs/conventions/design/model-design.md | 2 +- .../FlowIssue235AnyRejectTerminateTest.java | 2 +- .../FlowIssue240MergePartialApproveTest.java | 2 +- flow-engine-framework/pom.xml | 8 + .../gateway/FlowScriptGatewayContext.java | 81 +++++ .../codingapi/flow/gateway/IScriptEditor.java | 33 ++ .../flow/gateway/IScriptExecutor.java | 28 ++ .../flow/gateway/IScriptGatewayProvider.java | 13 + .../flow/gateway/IScriptResolver.java | 22 ++ .../script/action/ActionCustomScript.java | 14 +- .../script/action/ActionDisplayScript.java | 7 +- .../script/action/ActionRejectScript.java | 7 +- .../flow/script/node/ConditionScript.java | 7 +- .../flow/script/node/ErrorTriggerScript.java | 7 +- .../flow/script/node/NodeTitleScript.java | 7 +- .../flow/script/node/OperatorLoadScript.java | 7 +- .../flow/script/node/OperatorMatchScript.java | 7 +- .../flow/script/node/RouterNodeScript.java | 7 +- .../script/node/SubProcessResultScript.java | 7 +- .../flow/script/node/SubProcessScript.java | 7 +- .../flow/script/node/TriggerScript.java | 7 +- .../flow/script/ref/FlowScriptRef.java | 19 ++ .../flow/script/ref/ScriptRefFields.java | 95 ++++++ .../flow/script/ref/ScriptRefScanner.java | 92 +++++ .../registry/DefaultScriptRegistry.java | 37 +- .../flow/script/request/GroovyScriptBind.java | 59 ++-- .../script/request/GroovyScriptRequest.java | 149 ++++---- .../script/request/GroovyWorkflowRequest.java | 8 +- .../runtime/FlowScriptRuntimeContext.java | 67 ++-- .../service/WorkflowGroovyScriptUtils.java | 71 ++-- .../WorkflowGroovyScriptTransferService.java | 259 +++----------- .../workflow/runtime/WorkflowRuntime.java | 62 +--- .../FrameworkScriptDependencyTest.java | 40 +++ .../gateway/ScriptGatewayContractTest.java | 175 ++++++++++ .../flow/mock/TestScriptGatewayProvider.java | 229 +++++++++++++ .../factory/FlowGroovyScriptFactory.java | 0 .../runtime/FlowScriptRuntimeContextTest.java | 64 ++-- .../flow/service/FlowSampleServiceTest.java | 4 +- .../transfer/WorkflowTransferServiceTest.java | 6 +- ...ingapi.flow.gateway.IScriptGatewayProvider | 1 + flow-engine-starter-api/pom.xml | 2 +- .../flow-engine-starter-infra-db/pom.xml | 57 ++++ .../flow/infra/AutoConfiguration.java | 0 .../flow/infra/FlowJpaPackageRegistrar.java | 0 .../infra/convert/DelayTaskConvertor.java | 0 .../convert/FlowRecordContentConvertor.java | 0 .../infra/convert/FlowRecordConvertor.java | 0 .../convert/FlowReissueRecordConvertor.java | 0 .../infra/convert/FlowTodoMargeConvertor.java | 0 .../convert/FlowTodoRecordConvertor.java | 0 .../convert/SubProcessRecordConvertor.java | 0 .../infra/convert/UrgeIntervalConvertor.java | 0 .../flow/infra/convert/WorkflowConvertor.java | 0 .../convert/WorkflowRuntimeConvertor.java | 0 .../convert/WorkflowVersionConvertor.java | 0 .../flow/infra/entity/DelayTaskEntity.java | 0 .../entity/FlowOperatorAssignmentEntity.java | 0 .../flow/infra/entity/FlowRecordEntity.java | 0 .../infra/entity/FlowReissueRecordEntity.java | 0 .../infra/entity/FlowTodoMargeEntity.java | 0 .../infra/entity/FlowTodoRecordEntity.java | 0 .../infra/entity/ParallelControlEntity.java | 0 .../infra/entity/SubProcessRecordEntity.java | 0 .../flow/infra/entity/UrgeIntervalEntity.java | 0 .../flow/infra/entity/WorkflowEntity.java | 0 .../infra/entity/WorkflowRuntimeEntity.java | 0 .../infra/entity/WorkflowVersionEntity.java | 0 .../entity/convert/FlowNodeListConvertor.java | 0 .../entity/convert/FlowOperatorConvertor.java | 0 .../entity/convert/FormMetaConvertor.java | 0 .../infra/entity/convert/MapConvertor.java | 0 .../convert/OperatorMatchScriptConvertor.java | 0 .../WorkflowStrategyListConvertor.java | 0 .../infra/jpa/DelayTaskEntityRepository.java | 0 ...lowOperatorAssignmentEntityRepository.java | 0 .../infra/jpa/FlowRecordEntityRepository.java | 0 .../FlowReissueRecordEntityRepository.java | 0 .../jpa/FlowTodoMargeEntityRepository.java | 0 .../jpa/FlowTodoRecordEntityRepository.java | 0 .../jpa/ParallelControlEntityRepository.java | 0 .../jpa/SubProcessRecordEntityRepository.java | 0 .../jpa/UrgeIntervalEntityRepository.java | 0 .../infra/jpa/WorkflowEntityRepository.java | 0 .../jpa/WorkflowRuntimeEntityRepository.java | 0 .../jpa/WorkflowVersionEntityRepository.java | 0 .../flow/infra/pojo/WorkflowOption.java | 0 .../infra/pojo/WorkflowVersionOption.java | 0 .../impl/DelayTaskRepositoryImpl.java | 0 .../FlowOperatorAssignmentRepositoryImpl.java | 0 .../impl/FlowRecordRepositoryImpl.java | 0 .../impl/FlowReissueRepositoryImpl.java | 0 .../impl/FlowTodoMergeRepositoryImpl.java | 0 .../impl/FlowTodoRecordRepositoryImpl.java | 0 .../impl/ParallelBranchRepositoryImpl.java | 0 .../impl/SubProcessRepositoryImpl.java | 0 .../impl/UrgeIntervalRepositoryImpl.java | 0 .../impl/WorkflowRepositoryImpl.java | 0 .../impl/WorkflowRuntimeRepositoryImpl.java | 0 .../impl/WorkflowVersionRepositoryImpl.java | 0 .../main/resources/META-INF/spring.factories | 0 ...ot.autoconfigure.AutoConfiguration.imports | 0 .../FlowRecordContentConvertorTest.java | 0 .../FlowRecordIdentityConvertorTest.java | 0 .../FlowReissueRecordConvertorTest.java | 0 .../SubProcessRecordConvertorTest.java | 0 .../flow-engine-starter-infra-groovy/pom.xml | 47 +++ .../flow/infra/groovy/AutoConfiguration.java | 67 ++++ .../groovy/InlineScriptGatewayProvider.java | 103 ++++++ .../groovy/KeyModeScriptGatewayProvider.java | 228 +++++++++++++ .../convert}/GroovyScriptConvertor.java | 4 +- .../convert}/NodeViewJavaScriptConvertor.java | 4 +- .../convert}/TempGroovyScriptConvertor.java | 4 +- .../groovy}/entity/GroovyScriptEntity.java | 2 +- .../entity/NodeViewJavaScriptEntity.java | 2 +- .../entity/TempGroovyScriptEntity.java | 2 +- .../factory/FlowGroovyScriptFactory.java | 318 ++++++++++++++++++ .../jpa}/GroovyScriptEntityRepository.java | 4 +- .../NodeViewJavaScriptEntityRepository.java | 4 +- .../TempGroovyScriptEntityRepository.java | 4 +- .../register/ScriptGatewayRegister.java | 20 ++ .../impl/GroovyScriptRepositoryImpl.java | 10 +- .../NodeViewJavaScriptRepositoryImpl.java | 8 +- .../impl/TempGroovyScriptRepositoryImpl.java | 10 +- .../main/resources/META-INF/spring.factories | 2 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../infra/groovy/ScriptReferenceModeTest.java | 49 +++ flow-engine-starter-infra/pom.xml | 43 +-- flow-engine-starter-query/pom.xml | 2 +- flow-engine-starter/pom.xml | 7 +- pom.xml | 8 +- 136 files changed, 2158 insertions(+), 747 deletions(-) create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/gateway/FlowScriptGatewayContext.java create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptEditor.java create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptExecutor.java create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptGatewayProvider.java create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptResolver.java create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/FlowScriptRef.java create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefFields.java create mode 100644 flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefScanner.java create mode 100644 flow-engine-framework/src/test/java/com/codingapi/flow/architecture/FrameworkScriptDependencyTest.java create mode 100644 flow-engine-framework/src/test/java/com/codingapi/flow/gateway/ScriptGatewayContractTest.java create mode 100644 flow-engine-framework/src/test/java/com/codingapi/flow/mock/TestScriptGatewayProvider.java rename flow-engine-framework/src/{main => test}/java/com/codingapi/flow/script/factory/FlowGroovyScriptFactory.java (100%) create mode 100644 flow-engine-framework/src/test/resources/META-INF/services/com.codingapi.flow.gateway.IScriptGatewayProvider create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-db/pom.xml rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/AutoConfiguration.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/FlowJpaPackageRegistrar.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/DelayTaskConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/FlowRecordConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/FlowTodoMargeConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/FlowTodoRecordConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/UrgeIntervalConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/WorkflowConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/WorkflowRuntimeConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/convert/WorkflowVersionConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/DelayTaskEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/FlowOperatorAssignmentEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/FlowRecordEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/FlowReissueRecordEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/FlowTodoMargeEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/FlowTodoRecordEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/ParallelControlEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/SubProcessRecordEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/UrgeIntervalEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/WorkflowEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/WorkflowRuntimeEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/WorkflowVersionEntity.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/convert/FlowNodeListConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/convert/FlowOperatorConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/convert/FormMetaConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/convert/MapConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/convert/OperatorMatchScriptConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/entity/convert/WorkflowStrategyListConvertor.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/DelayTaskEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/FlowOperatorAssignmentEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/FlowRecordEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/FlowReissueRecordEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoMargeEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoRecordEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/ParallelControlEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/SubProcessRecordEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/UrgeIntervalEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/WorkflowEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/WorkflowRuntimeEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/jpa/WorkflowVersionEntityRepository.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/pojo/WorkflowOption.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/pojo/WorkflowVersionOption.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/DelayTaskRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/FlowOperatorAssignmentRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/FlowRecordRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/FlowReissueRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoMergeRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoRecordRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/ParallelBranchRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/SubProcessRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/UrgeIntervalRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRuntimeRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowVersionRepositoryImpl.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/resources/META-INF/spring.factories (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/test/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertorTest.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/test/java/com/codingapi/flow/infra/convert/FlowRecordIdentityConvertorTest.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/test/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertorTest.java (100%) rename flow-engine-starter-infra/{ => flow-engine-starter-infra-db}/src/test/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertorTest.java (100%) create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/pom.xml create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/AutoConfiguration.java create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/InlineScriptGatewayProvider.java create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/KeyModeScriptGatewayProvider.java rename {flow-engine-example/src/main/java/com/codingapi/example/convertor => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert}/GroovyScriptConvertor.java (96%) rename {flow-engine-example/src/main/java/com/codingapi/example/convertor => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert}/NodeViewJavaScriptConvertor.java (87%) rename {flow-engine-example/src/main/java/com/codingapi/example/convertor => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert}/TempGroovyScriptConvertor.java (95%) rename {flow-engine-example/src/main/java/com/codingapi/example => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy}/entity/GroovyScriptEntity.java (95%) rename {flow-engine-example/src/main/java/com/codingapi/example => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy}/entity/NodeViewJavaScriptEntity.java (92%) rename {flow-engine-example/src/main/java/com/codingapi/example => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy}/entity/TempGroovyScriptEntity.java (96%) create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/factory/FlowGroovyScriptFactory.java rename {flow-engine-example/src/main/java/com/codingapi/example/repository => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa}/GroovyScriptEntityRepository.java (67%) rename {flow-engine-example/src/main/java/com/codingapi/example/repository => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa}/NodeViewJavaScriptEntityRepository.java (68%) rename {flow-engine-example/src/main/java/com/codingapi/example/repository => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa}/TempGroovyScriptEntityRepository.java (68%) create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/register/ScriptGatewayRegister.java rename {flow-engine-example/src/main/java/com/codingapi/example => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy}/repository/impl/GroovyScriptRepositoryImpl.java (80%) rename {flow-engine-example/src/main/java/com/codingapi/example => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy}/repository/impl/NodeViewJavaScriptRepositoryImpl.java (77%) rename {flow-engine-example/src/main/java/com/codingapi/example => flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy}/repository/impl/TempGroovyScriptRepositoryImpl.java (83%) create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring.factories create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/test/java/com/codingapi/flow/infra/groovy/ScriptReferenceModeTest.java diff --git a/AGENTS.md b/AGENTS.md index 05a690df..f62824cf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,7 +13,7 @@ Flow Engine 是一个企业级工作流引擎,基于 Java 17 和 Spring Boot 3 | `flow-engine-framework` | 核心工作流引擎框架(节点/动作/策略/脚本/服务) | | `flow-engine-starter` | Spring Boot 自动配置入口 | | `flow-engine-starter-api` | REST API 层 | -| `flow-engine-starter-infra` | 持久化层(JPA 实体、仓储实现) | +| `flow-engine-starter-infra` | 实现集合(pom 聚合,下含 `infra-db` / `infra-groovy`) | | `flow-engine-starter-query` | 查询层 | | `flow-engine-example` | 示例应用 | @@ -24,7 +24,7 @@ Flow Engine 是一个企业级工作流引擎,基于 Java 17 和 Spring Boot 3 | `com.codingapi.flow.node` | 19 种流程节点类型 | | `com.codingapi.flow.action` | 9 种动作类型 | | `com.codingapi.flow.strategy` | 节点策略和工作流策略 | -| `com.codingapi.flow.script` | Groovy 脚本运行时 | +| `com.codingapi.flow.script` | 脚本引用与执行编排(不依赖脚本引擎) | | `com.codingapi.flow.repository` | 仓储接口定义 | | `com.codingapi.flow.builder` | 建造者模式实现 | | `com.codingapi.flow.manager` | 业务管理器 | @@ -62,6 +62,13 @@ REST 层通过请求参数 `mockKey` 分流到 Mock 实例(见 `FlowRecordCont - `ActionManager` 持有节点动作 - 节点类型常量见 `StartNode.NODE_TYPE`(= `NodeType.START.name()`),`FlowRecord.isNodeType(String)` 用于按类型判定 + +### 脚本 Gateway(issue #316) + +`flow-engine-framework` 主源码零脚本引擎依赖。流程定义的 `script` 字段是不透明引用,由 `com.codingapi.flow.gateway` 的 `IScriptExecutor` / `IScriptResolver` / `IScriptEditor` 三个端口解释,装配入口是 `FlowScriptGatewayContext`(显式注册优先,否则 JDK `ServiceLoader` 发现 `IScriptGatewayProvider`)。自有 `@FlowScriptRef` 注解与 `ScriptRefScanner` 负责扫描并回写引用,替代外部脚本库的注解扫描器。 + +`infra-groovy` 默认 key 模式、可选 `flow.script.ref-mode=inline` 正文模式;前端 `flow-design` 通过上下文注入对应 Provider。接入方提供自定义 `IScriptGatewayProvider` Bean 时优先(` @ConditionalOnMissingBean`)。修改脚本相关代码前须确认「framework 主源码不得出现 `com.codingapi.springboot.script` import」,由 `FrameworkScriptDependencyTest` 守护。 + ### 事件(IFlowEvent + FlowEventPublisher) 12 种事件:开始 / 待办 / 已办 / 完成 / 催办 / 撤销(`FlowRecordRevokeEvent`)/ 删除(`FlowRecordDeleteEvent`)/ 子流程重置(`FlowSubProcessResetEvent`)/ 减签(`FlowRecordReduceAuditEvent`)/ 二次发起(`FlowRecordReissueEvent`)/ 保存(`FlowRecordSaveEvent`,由 `FlowRecordSaveService.saveAll()` 按实际落库记录逐条推送)/ 强制同步(`FlowRecordForceSyncEvent`,每个被同步实例一条)。操作完成后用 `FlowEventPublisher.push(event)` 推送(**禁止**直接调用 `EventPusher`);引入 starter 时由 `SpringFlowEventPublisher` 保证「事务提交后投递 + 按 `eventKey()`(默认 processId)分区串行」,未注册实现时自动回退 `EventPusher`。记录类事件携带 `FlowRecord` + `mock` 标记,重置事件携带新旧聚合组快照。外部可用 Spring `@EventListener` 订阅。 @@ -70,7 +77,8 @@ REST 层通过请求参数 `mockKey` 分流到 Mock 实例(见 `FlowRecordCont - **命令操作**:`flow-engine-starter-api` — `FlowRecordController`(`/api/cmd/record`:create / action / revoke / delete / urge / detail / processNodes / subProcess/reset / reissue)、`WorkflowController`(`/api/cmd/workflow`:流程设计 CRUD 及导入导出)与 `NodeViewJavaScriptController`(`/api/cmd/node-view`:节点视图脚本 getScript / save) - **查询**:`flow-engine-starter-query` — `FlowRecordQueryController`(`/api/query/record`:list / todo / done / notify)与 `WorkflowQueryController`(`/api/query/workflow`:list / options / versions) -- **持久化**:`flow-engine-starter-infra` — JPA 实体与仓储实现(含达梦方言) +- **持久化**:`flow-engine-starter-infra-db` — JPA 实体与仓储实现(达梦方言配置见 example) +- **脚本能力**:`flow-engine-starter-infra-groovy` — 三个脚本 Gateway 端口的 key / inline 实现与三类脚本持久化 ## 常用命令 diff --git a/README.md b/README.md index 6cb3d5b7..7b79c04e 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,9 @@ flow-engine ├── flow-engine-framework # 核心流程引擎框架 ├── flow-engine-starter # Spring Boot 自动配置入口 ├── flow-engine-starter-api # REST API 层(命令操作:create / action / revoke / delete / urge / detail / processNodes / subProcess/reset,含节点视图脚本接口) -├── flow-engine-starter-infra # 持久化层(JPA 实体、12 个仓储实现、含达梦方言) +├── flow-engine-starter-infra # 实现集合(pom 聚合) +│ ├── flow-engine-starter-infra-db # JPA 实体与仓储实现(达梦方言配置见 example) +│ └── flow-engine-starter-infra-groovy # 脚本 Gateway 实现与三类脚本持久化 ├── flow-engine-starter-query # 查询层(流程记录与流程定义只读 API) ├── flow-engine-example # 示例应用(H2/达梦数据库、JWT 认证、端口 8090) └── flow-frontend # 前端项目(独立 Git 仓库,PC + 移动端,详见下文“前端模块架构”) @@ -46,14 +48,14 @@ flow-engine | `node` | 19 种流程节点、节点工厂与节点助手 | | `action` | 9 种流程动作与动作工厂 | | `strategy` | 策略层:15 种节点策略 + 2 种工作流策略 | -| `script` | Groovy 脚本系统:9 种节点脚本、3 种动作脚本、运行时、注册表、工厂 | +| `script` | 脚本引用与执行编排:9 种节点脚本、3 种动作脚本、运行时、注册表、自有 `@FlowScriptRef` 注解与引用扫描器;执行经 `IScriptExecutor` 端口 | | `transfer` | 流程定义导入导出(旧版 Schema 兼容、脚本迁移) | | `service` | 业务服务层:FlowService 事务门面 + 各流程操作独立服务(创建 / 动作 / 撤销 / 删除 / 催办 / 详情 / 子流程重置等) | | `query` | 流程记录查询服务 | | `manager` | 管理器层:动作、节点、策略、操作者管理 | | `session` | 执行上下文:FlowSession、FlowAdvice、IRepositoryHolder | | `record` | 流程记录:FlowRecord、FlowTodoRecord、FlowTodoMerge | -| `repository` | 13 个仓储接口(持久化抽象,由 infra 模块实现) | +| `repository` | 13 个仓储接口(持久化抽象,由 `infra-db` 实现) | | `event` | 9 种流程事件:开始 / 待办 / 已办 / 完成 / 催办 / 撤销 / 删除 / 减签 / 子流程重置 | | `exception` | 框架异常体系:异常基类 + 6 种具体异常(验证 / 未找到 / 状态 / 权限 / 执行 / 导入导出) | | `form` | 表单系统:字段定义、数据校验、字段权限、值转换 | @@ -373,3 +375,21 @@ pnpm run test:flow-mobile # 移动端组件测试 ## 贡献 欢迎提交 Issue 和 Pull Request! + +## 脚本引用形态(issue #316) + +`flow-engine-framework` 主源码不依赖任何脚本引擎:流程定义中的 `script` 字段是**不透明的脚本引用**(裸 `String`,JSON 与既有数据零迁移),由 `com.codingapi.flow.gateway` 下的三个端口解释: + +| 端口 | 职责 | +|---|---| +| `IScriptExecutor` | 按引用执行脚本、按运行时快照正文执行、读取脚本正文 | +| `IScriptResolver` | 引用解析为正文、生成运行时快照、导出脚本正文 | +| `IScriptEditor` | 保存、版本隔离、删除、归一化、导入重建 | + +`flow-engine-starter-infra-groovy` 提供两套实现,由接入方决定: + +- **key 模式(默认)**:`flow.script.ref-mode=key`(或留空)。引用是脚本 key,正文由三类脚本仓储提供;表名、脚本 key、REST 契约不变,无数据迁移。 +- **inline 模式**:`flow.script.ref-mode=inline`。引用即脚本正文,不落脚本库;运行时快照为空(定义自固化),保存/版本复制/删除/导入重建为空操作。 + +前端 `flow-frontend` 的 `flow-design` 通过 `configureScriptReference({ mode })` 或 `` 注入对应模式(`KeyModeProvider` / `InlineModeProvider`),**前后端模式需由接入方保持一致**。`springboot-starter-script` 在 framework 中仅为 `test` scope,用于集成测试的真实引擎,发布产物与下游依赖不含脚本框架。 + diff --git a/docs/Integration/repository-integration.md b/docs/Integration/repository-integration.md index 3ac4f73d..442c46b8 100644 --- a/docs/Integration/repository-integration.md +++ b/docs/Integration/repository-integration.md @@ -1,6 +1,6 @@ # 仓储抽象与持久化 -引擎核心(`flow-engine-framework`)与 Spring 无关,所有存储/服务访问统一经过 `IRepositoryHolder` 抽象。持久化层由 `flow-engine-starter-infra` 提供 JPA 实现;业务方也可以自行实现仓储接口替换存储。 +引擎核心(`flow-engine-framework`)与 Spring 无关,所有存储/服务访问统一经过 `IRepositoryHolder` 抽象。持久化层由 `flow-engine-starter-infra-db` 提供 JPA 实现,脚本 Gateway 与三类脚本持久化由 `flow-engine-starter-infra-groovy` 提供;业务方也可以自行实现仓储接口或 `IScriptGatewayProvider` 替换。 ## 1. 资源持有者抽象:`IRepositoryHolder` @@ -118,7 +118,7 @@ public interface FlowOperatorAssignmentRepository { List findOperatorIds(String processId, String nodeId); // 不存在时返回空列表 } -/** 节点视图 JS 持久化(⚠️ infra 不提供实现,必须由业务方提供) */ +/** 节点视图 JS 持久化(默认实现由 infra-groovy 提供,可替换) */ public interface NodeViewJavaScriptRepository { void save(NodeViewJavaScript javaScript); void delete(String code); @@ -162,7 +162,7 @@ public interface FlowReissueRepository { } ``` -## 3. JPA 实现(`flow-engine-starter-infra`) +## 3. JPA 实现(`flow-engine-starter-infra-db`) ### 3.1 自动装配 @@ -186,7 +186,7 @@ public interface FlowReissueRepository { | `subProcessRepository` | `SubProcessRepositoryImpl` | | `flowReissueRepository` | `FlowReissueRepositoryImpl` | -> ⚠️ **infra 不提供** `NodeViewJavaScriptRepository` 与 `FlowOperatorGateway` 的实现,必须由业务方提供。 +> `NodeViewJavaScriptRepository` 由 infra-groovy 提供默认实现;`FlowOperatorGateway` 仍需业务方提供。 ### 3.3 JPA 实体与表 @@ -217,32 +217,30 @@ Spring Data 仓储接口位于 `jpa/` 包,全部继承外部 `FastRepository` 保存统一走 `FlowRecordSaveService.saveAll()`,单次调用按 `saveRecords → saveTodoMargeRecords → removeTodoMergeRecords` 顺序执行。 -## 5. 脚本持久化(业务方必须提供) +## 5. 脚本持久化(默认提供,可替换) -来自外部 `springboot-starter-script` 的 SPI: +`flow-engine-starter-infra-groovy` 为下列 SPI 提供默认 JPA 实现,引入 starter 后自动装配,无需业务方复制实体与仓储。来自外部 `springboot-starter-script` 的 SPI: | SPI | 方法 | 注册方式 | |---|---|---| | `GroovyScriptRepository` | `save / delete / get(String key)` | `GroovyScriptRepositoryContext.getInstance().setGroovyScriptRepository(...)` | | `TempGroovyScriptRepository` | `get / save / delete / find(PageRequest)` | `TempGroovyScriptRepositoryContext.getInstance().setTempGroovyScriptRepository(...)` | -参考实现(`flow-engine-example/.../repository/impl/`): +默认实现位于 `flow-engine-starter-infra-groovy` 的 `repository/impl/` 包,由 `AutoConfiguration` 注册: ```java -@Repository -public class GroovyScriptRepositoryImpl implements GroovyScriptRepository, InitializingBean { - private final GroovyScriptEntityRepository repository; - // ... - @Override - public void afterPropertiesSet() { - GroovyScriptRepositoryContext.getInstance().setGroovyScriptRepository(this); - } +@Bean +@ConditionalOnMissingBean(GroovyScriptRepository.class) +public GroovyScriptRepository groovyScriptRepository(GroovyScriptEntityRepository repository) { + return new GroovyScriptRepositoryImpl(repository); } ``` +`InitializingBean#afterPropertiesSet` 把实现注册到 `GroovyScriptRepositoryContext`。业务方提供同类型自定义 Bean 时默认实现让位。 + ## 6. 替换存储 -- **引入 `flow-engine-starter-infra`**:开箱即用(推荐)。 +- **引入 `flow-engine-starter`**:传递依赖 infra-db 与 infra-groovy,开箱即用(推荐)。 - **不引入 infra**:自行实现 12 个有 JPA 实现的仓储接口 + `NodeViewJavaScriptRepository`(共 13 个)为 Spring Bean 即可。starter 的 `RepositoryHolderContextRegister` 会自动注入。framework 测试包(`src/test/java/com/codingapi/flow/repository/`)提供了一套内存实现可作参考。 ## 7. 离线/最小装配(脱离 Spring) diff --git a/docs/Integration/script-integration.md b/docs/Integration/script-integration.md index e4459967..57a87100 100644 --- a/docs/Integration/script-integration.md +++ b/docs/Integration/script-integration.md @@ -1,10 +1,15 @@ # 流程默认脚本(Groovy 脚本机制) -流程引擎的节点行为、动作行为、操作人加载等大量能力通过 **Groovy 脚本**表达。脚本内容以 18 位动态生成的 key 注册,并固化进流程运行时快照。本文档介绍脚本的类型、执行上下文 API、默认脚本、以及如何替换默认脚本。 +流程引擎的节点行为、动作行为、操作人加载等大量能力通过 **Groovy 脚本**表达。本文档介绍脚本的类型、执行上下文 API、默认脚本、以及如何替换默认脚本。 + +> **issue #316 起**:流程定义的 `script` 字段是**不透明引用**,framework 不依赖任何脚本引擎。 +> 默认 key 模式下引用仍是 18 位动态生成的 key 并固化进运行时快照; +> 设置 `flow.script.ref-mode=inline` 时引用即脚本正文,不落脚本库、不生成快照。 +> 详见本文第 4、6 节与 `README.md` 的「脚本引用形态」。 ## 1. 脚本类型总览(12 种) -脚本由 `FlowGroovyScriptFactory`(`flow-engine-framework/.../script/factory/FlowGroovyScriptFactory.java`)创建。每种脚本有固定的 `typeOne`(恒为 `"flow"`)、`typeTwo`(脚本类型标识)、返回类型与请求对象: +脚本由 `FlowGroovyScriptFactory`(`flow-engine-starter-infra/flow-engine-starter-infra-groovy/.../factory/FlowGroovyScriptFactory.java`)创建;framework 主源码不再包含该工厂。每种脚本有固定的 `typeOne`(恒为 `"flow"`)、`typeTwo`(脚本类型标识)、返回类型与请求对象: | 脚本类型(typeTwo) | 工厂方法 | returnType | 请求对象 | 所在包装类 | |---|---|---|---|---| @@ -198,19 +203,15 @@ GroovyScript groovyScript = GroovyScript.builder(key) .build(); ``` -### 4.2 生命周期(临时 → 正式 → 版本隔离) +### 4.2 生命周期(由 `IScriptEditor` 决定) -``` -工厂创建(key = FlowIDGeneratorGatewayContext.generateFlowScriptKey(),18 位) - → groovyScript.temp() 临时注册(TempGroovyScriptContext,15 分钟有效) - → 保存流程时扫描 @GroovyScript 字段批量 save() 落库(正式注册) - → 版本创建时 resetScripts() 将每个 key copy(新key) 实现版本隔离 -``` +> issue #316 起,framework 不再生成脚本 key。流程定义的 `script` 字段是**不透明引用**, +> 由 `@FlowScriptRef` 标记、`ScriptRefScanner` 扫描;保存、版本隔离、删除交给 `IScriptEditor`。 -- **扫描**:`GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(workflow)` 扫描对象图中所有 `@GroovyScript` 标记的 String 字段(存的是 key)。 -- **保存**:`WorkflowService.saveWorkflowVersion` 内调用 `WorkflowGroovyScriptUtils.saveScripts(workflow)`。 -- **版本隔离**:`WorkflowGroovyScriptUtils.resetScripts` 把每个 key 的脚本内容 `copy()` 到新 key 并保存、回写字段。 -- **删除**:`WorkflowGroovyScriptUtils.deleteScripts` → `GroovyScriptRepositoryContext.delete(key)`。 +- **key 模式(默认)**:`KeyModeScriptGatewayProvider` 沿用「工厂创建临时脚本 → 保存流程时正式落库 → 版本创建时复制为新 key」的既有流程,表名与脚本 key 不变。 +- **inline 模式**(`flow.script.ref-mode=inline`):引用即脚本正文,`onSave` / `onVersionCopy` / `onDelete` / `onImport` 为空操作,不产生 key、不访问脚本仓储。 +- **扫描**:framework 自有的 `ScriptRefScanner.scan(workflow)`,替代外部 `GroovyScriptAnnotationScannerUtils`。 +- **保存 / 版本隔离 / 删除**:`WorkflowGroovyScriptUtils` 只做扫描与引用回写,实际行为由端口实现决定。 ### 4.3 运行时快照隔离(关键机制) @@ -218,31 +219,14 @@ GroovyScript groovyScript = GroovyScript.builder(key) - 引擎各入口(`FlowCreateService`/`FlowActionService`/……)把快照写入 `FlowRuntimeScriptLocalCache`(ThreadLocal)。 - `FlowScriptRuntimeContext.getGroovyScript(key)` 在运行态用**快照内容**重建独立 `GroovyScript`,而编译缓存以脚本内容 SHA256 为键 —— 因此**设计期修改脚本不会影响在途流程**。 -### 4.4 脚本仓储(下游必须提供) +### 4.4 脚本仓储(默认提供,可替换) -脚本持久化依赖外部 SPI,业务方必须提供两个实现并自注册(参考 `flow-engine-example`): +`flow-engine-starter-infra-groovy` 已迁入三类脚本持久化(3 实体 / 3 JPA 仓储 / 3 实现 / 3 转换器), +表名 `t_groovy_script`、`t_groovy_script_temp`、`t_node_view_javascript` 不变,由 `AutoConfiguration` +以 `@ConditionalOnMissingBean` 装配;接入方提供同类型 Bean 时默认实现让位。 +`flow-engine-example` 不再需要复制这些类。 -```java -// 1. 正式脚本仓储 -public class GroovyScriptRepositoryImpl implements GroovyScriptRepository, - InitializingBean { - @Override - public void afterPropertiesSet() { - GroovyScriptRepositoryContext.getInstance().setGroovyScriptRepository(this); - } - // save/delete/get 委托自己的持久化 -} - -// 2. 临时脚本仓储 -public class TempGroovyScriptRepositoryImpl implements TempGroovyScriptRepository, - InitializingBean { - @Override - public void afterPropertiesSet() { - TempGroovyScriptRepositoryContext.getInstance().setTempGroovyScriptRepository(this); - } - // get/save/delete/find(PageRequest) -} -``` +inline 模式下这些仓储不会被访问:脚本正文直接保存在流程定义中。 ## 5. 替换默认脚本 @@ -280,18 +264,29 @@ public interface IScriptRegistry { } ``` -默认实现 `DefaultScriptRegistry.getXxxScript()` 调用 `FlowGroovyScriptFactory.createXxxScript(ScriptDefaultConstants.SCRIPT_DEFAULT_XXX)` 创建临时脚本并返回其 key。 +默认实现 `DefaultScriptRegistry.getXxxScript()` 直接返回 `ScriptDefaultConstants` 中的脚本文本作为引用;是否转换为 key 由 `IScriptEditor` 实现决定(inline 模式原样保留正文)。 ### 5.2 单流程配置(`@GroovyScript` 字段) 每个节点的策略/动作对象中的脚本字段(如 `OperatorLoadStrategy.operatorLoadScript`)本身就是 `@GroovyScript` 标记的字符串字段,通过设计器或编程式构建写入具体的脚本 key 即可实现单流程定制。 -## 6. 脚本执行引擎(外部 starter-script) +## 6. 脚本执行引擎(`infra-groovy`) + +`flow-engine-framework` 主源码**不依赖** `springboot-starter-script`;该依赖仅为 test scope, +用于集成测试的真实引擎,发布产物与下游依赖中不含脚本框架(由 `FrameworkScriptDependencyTest` 守护)。 -- 编译/执行:`GroovyScriptRuntime`(`GroovyShell` + 按 SHA256 内容键控的 LRU 编译缓存,默认上限 10240)。 -- 临时脚本缓存:`TempGroovyScriptContext`,默认 15 分钟过期(`codingapi.script.tempValidTime`)。 -- 脚本对象缓存:`GroovyScriptCacheContext`(按 key,LRU 10*1024)。 -- REST 接口:`/api/groovy-script/*`(compile / getScript / getMetadata / save),由依赖 starter 自动注册。 +执行与解析统一经 `com.codingapi.flow.gateway` 的三个端口,装配入口 `FlowScriptGatewayContext`: + +| 端口 | key 模式 | inline 模式 | +|---|---|---| +| `IScriptExecutor` | 按 key 从 `GroovyScriptCacheContext` 取脚本执行 | 按正文直接编译执行 | +| `IScriptResolver` | 正文来自缓存 / 仓储,生成运行时快照 | 正文即引用,快照为空 | +| `IScriptEditor` | 临时脚本落库、版本复制新 key | 全部空操作 | + +- 编译 / 执行:`GroovyScriptRuntime`(`GroovyShell` + 按内容 SHA256 键控的 LRU 编译缓存)。 +- 临时脚本缓存:`TempGroovyScriptContext`(key 模式使用)。 +- 运行时快照:`WorkflowRuntime` 通过 `IScriptResolver#snapshot` 生成;`FlowRuntimeScriptLocalCache` 的 ThreadLocal 读写仍属 framework。 +- 既有 REST `/api/groovy-script/*` 与 `/api/cmd/node-view/*` 保留兼容;前端模式由应用侧通过 `configureScriptReference({ mode })` 注入,不做后端探测。 ## 7. 脚本辅助工具 diff --git a/docs/capabilities/flow-engine-framework/script.md b/docs/capabilities/flow-engine-framework/script.md index 2526a4c3..a87aebdf 100644 --- a/docs/capabilities/flow-engine-framework/script.md +++ b/docs/capabilities/flow-engine-framework/script.md @@ -1,7 +1,7 @@ --- name: flow-engine-framework/script module: flow-engine-framework -description: Groovy 脚本运行时,包含脚本注册表、脚本类型封装和脚本执行上下文 +description: 脚本引用与执行编排,含注册表、脚本类型封装、执行上下文与三个脚本 Gateway 端口 status: 已实现 scope: 后端 source: 项目自有 @@ -10,7 +10,12 @@ symbols: - IScriptRegistry - DefaultScriptRegistry - ScriptRegistryContext - - FlowGroovyScriptFactory + - IScriptExecutor + - IScriptResolver + - IScriptEditor + - FlowScriptGatewayContext + - FlowScriptRef + - ScriptRefScanner - ScriptDefaultConstants - ActionCustomScript - ActionRejectScript @@ -103,3 +108,17 @@ Object result = script.execute(flowSession); // 替换默认脚本注册 ScriptRegistryContext.getInstance().setRegistry(customRegistry); ``` + +## 脚本 Gateway 端口(issue #316) + +`script` 字段是**不透明的脚本引用**(裸 `String`),framework 不解析、不生成、不改写。三个端口位于 `com.codingapi.flow.gateway`: + +| 端口 | 职责 | 实现位置 | +|---|---|---| +| `IScriptExecutor` | 按引用执行、按快照正文执行、读取正文 | `infra-groovy` 的 `KeyModeScriptGatewayProvider` / `InlineScriptGatewayProvider` | +| `IScriptResolver` | 引用解析为正文、运行时快照、导出正文 | 同上 | +| `IScriptEditor` | 保存、版本隔离、删除、归一化、导入重建 | 同上 | + +`FlowScriptGatewayContext` 是唯一装配入口(显式注册优先,否则 `ServiceLoader` 发现 `IScriptGatewayProvider`)。`@FlowScriptRef` 与 `ScriptRefScanner` 是 framework 自有的引用标记与扫描器;`DefaultScriptRegistry` 直接返回脚本文本常量,由实现决定是否需要生成 key。 + +key 模式(默认)保持既有数据与 REST 不变;`flow.script.ref-mode=inline` 时正文即引用,不落脚本库、快照为空、生命周期空操作。前端通过 `configureScriptReference({ mode })` 注入相同模式。 diff --git a/docs/capabilities/index.md b/docs/capabilities/index.md index 20fa5e71..780463b5 100644 --- a/docs/capabilities/index.md +++ b/docs/capabilities/index.md @@ -19,7 +19,7 @@ | [flow-engine-framework/operator-assignment](./flow-engine-framework/operator-assignment.md) | flow-engine-framework | 操作人分配能力,支持发起人/审批人设定的分配校验与落库 | 后端 | 项目自有 | | [flow-engine-framework/operator-identity](./flow-engine-framework/operator-identity.md) | flow-engine-framework | 多身份参与模型,身份值对象、参与人标识、匹配模式策略与两个唯一真源(相等判定、键生成) | 后端 | 项目自有 | | [flow-engine-framework/repository](./flow-engine-framework/repository.md) | flow-engine-framework | 仓储抽象层,定义流程引擎的持久化接口和仓储持有者上下文 | 后端 | 项目自有 | -| [flow-engine-framework/script](./flow-engine-framework/script.md) | flow-engine-framework | Groovy 脚本运行时,包含脚本注册表、脚本类型封装和脚本执行上下文 | 后端 | 项目自有 | +| [flow-engine-framework/script](./flow-engine-framework/script.md) | flow-engine-framework | 脚本引用与执行编排,含注册表、脚本类型封装、执行上下文与三个脚本 Gateway 端口 | 后端 | 项目自有 | | [flow-engine-framework/sub-process](./flow-engine-framework/sub-process.md) | flow-engine-framework | 子流程聚合执行能力,支持批量创建、主流程等待、脚本结果判定、异常跳转与数据重置(退回重走) | 后端 | 项目自有 | | [flow-engine-framework/workflow-strategy](./flow-engine-framework/workflow-strategy.md) | flow-engine-framework | 工作流级别策略体系,包含策略接口、工厂和具体策略实现 | 后端 | 项目自有 | | [flow-engine-framework/workflow](./flow-engine-framework/workflow.md) | flow-engine-framework | 工作流引擎核心模型,包含流程定义、构建器、版本管理和运行时快照 | 后端 | 项目自有 | diff --git a/docs/conventions/design/model-design.md b/docs/conventions/design/model-design.md index d023648e..d1ab56e9 100644 --- a/docs/conventions/design/model-design.md +++ b/docs/conventions/design/model-design.md @@ -65,7 +65,7 @@ DDD 的核心不是聚合根、不是值对象,是**分层**:把业务、数 1. **`IRepositoryHolder` 一个端口暴露了四种角色**:`XxxRepository`(数据)、`FlowService` / `FlowRecordService` / `WorkflowService`(业务编排)、`FlowOperatorGateway`(外部能力)、`createDelayTriggerService(...)`(工厂方法)。调用方从类型上已经看不出自己站在哪一层——这和「工具类返回值没有归属」是同一个病:**端口没有层**。 -2. **`flow-engine-framework` 直接依赖 `springboot-starter-script`(Groovy 运行时)。** `script` 包本质是「领域规则的可配置化表达」,但它的执行引擎是技术细节。理想形态是 Domain 只依赖 `IScriptExecutor` 端口,Groovy 实现留在 infrastructure。 +2. ~~**`flow-engine-framework` 直接依赖 `springboot-starter-script`(Groovy 运行时)。**~~ **已由 #316 解决**:主源码删除该依赖,改由 `IScriptExecutor` / `IScriptResolver` / `IScriptEditor` 三个端口承接,Groovy 实现留在 `infra-groovy`;`springboot-starter-script` 仅保留 test scope 供集成测试使用,`FrameworkScriptDependencyTest` 守护主源码零引用。 3. **`WorkflowService.importWorkflow` 调 `Base64Utils.toJson(body)` 做 base64 + `data:` 前缀剥离。** 上传格式属于接入层,却出现在业务服务里;而 `Base64Utils` 这个名字承诺「Base64 编解码」,方法却叫 `toJson` 且只做解码,返回的其实是原始文本——名字、方法名、实际职责三者都不一致。它的异常分支 `base64.substring(0, 30)` 在长度不足 30 时还会抛 `StringIndexOutOfBoundsException`,因为这段代码没有测试守护。 diff --git a/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue235AnyRejectTerminateTest.java b/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue235AnyRejectTerminateTest.java index 7dcb74d1..728613c8 100644 --- a/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue235AnyRejectTerminateTest.java +++ b/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue235AnyRejectTerminateTest.java @@ -23,7 +23,7 @@ import com.codingapi.flow.pojo.request.FlowProcessNodeRequest; import com.codingapi.flow.record.FlowRecord; import com.codingapi.flow.repository.FlowRecordRepository; -import com.codingapi.flow.script.factory.FlowGroovyScriptFactory; +import com.codingapi.flow.infra.groovy.factory.FlowGroovyScriptFactory; import com.codingapi.flow.service.FlowService; import com.codingapi.flow.service.WorkflowService; import com.codingapi.flow.strategy.node.FormFieldPermissionStrategy; diff --git a/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue240MergePartialApproveTest.java b/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue240MergePartialApproveTest.java index a42db87b..336f8e3a 100644 --- a/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue240MergePartialApproveTest.java +++ b/flow-engine-example/src/test/java/com/codingapi/example/FlowIssue240MergePartialApproveTest.java @@ -24,7 +24,7 @@ import com.codingapi.flow.node.IFlowNode; import com.codingapi.flow.record.FlowRecord; import com.codingapi.flow.repository.FlowRecordRepository; -import com.codingapi.flow.script.factory.FlowGroovyScriptFactory; +import com.codingapi.flow.infra.groovy.factory.FlowGroovyScriptFactory; import com.codingapi.flow.service.FlowService; import com.codingapi.flow.service.WorkflowService; import com.codingapi.flow.strategy.node.FormFieldPermissionStrategy; diff --git a/flow-engine-framework/pom.xml b/flow-engine-framework/pom.xml index 1f774a8b..a64ffe1c 100644 --- a/flow-engine-framework/pom.xml +++ b/flow-engine-framework/pom.xml @@ -27,9 +27,17 @@ commons-lang3 + + + com.codingapi.springboot + springboot-starter + + + com.codingapi.springboot springboot-starter-script + test diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/FlowScriptGatewayContext.java b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/FlowScriptGatewayContext.java new file mode 100644 index 00000000..bf585ee3 --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/FlowScriptGatewayContext.java @@ -0,0 +1,81 @@ +package com.codingapi.flow.gateway; + +import java.util.ServiceLoader; + +/** + * 脚本 Gateway 上下文。framework 唯一访问脚本能力的入口,主源码不依赖任何脚本引擎。 + */ +public class FlowScriptGatewayContext { + + private static final FlowScriptGatewayContext INSTANCE = new FlowScriptGatewayContext(); + + public static FlowScriptGatewayContext getInstance() { + return INSTANCE; + } + + private volatile IScriptExecutor executor; + private volatile IScriptResolver resolver; + private volatile IScriptEditor editor; + private volatile boolean discovered; + + /** 显式装配,优先级高于 ServiceLoader 发现。 */ + public void register(IScriptGatewayProvider provider) { + this.executor = provider.executor(); + this.resolver = provider.resolver(); + this.editor = provider.editor(); + this.discovered = true; + } + + public IScriptExecutor executor() { + ensureDiscovered(); + return require(executor, "IScriptExecutor"); + } + + public IScriptResolver resolver() { + ensureDiscovered(); + return require(resolver, "IScriptResolver"); + } + + public IScriptEditor editor() { + ensureDiscovered(); + return require(editor, "IScriptEditor"); + } + + /** 仅供测试清理,恢复到未装配状态。 */ + public void clear() { + this.executor = null; + this.resolver = null; + this.editor = null; + this.discovered = false; + } + + private synchronized void ensureDiscovered() { + if (discovered) { + return; + } + discovered = true; + if (executor != null && resolver != null && editor != null) { + return; + } + for (IScriptGatewayProvider provider : ServiceLoader.load(IScriptGatewayProvider.class)) { + if (executor == null) { + executor = provider.executor(); + } + if (resolver == null) { + resolver = provider.resolver(); + } + if (editor == null) { + editor = provider.editor(); + } + break; + } + } + + private T require(T value, String name) { + if (value == null) { + throw new IllegalStateException("脚本 Gateway 未注册:" + name + + ",请引入 flow-engine-starter 或注册 IScriptGatewayProvider"); + } + return value; + } +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptEditor.java b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptEditor.java new file mode 100644 index 00000000..dfce44b7 --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptEditor.java @@ -0,0 +1,33 @@ +package com.codingapi.flow.gateway; + +import java.util.Collection; +import java.util.Map; + +/** + * 脚本引用写侧端口:管理流程定义中脚本引用的保存、版本隔离、删除与导入重建。 + *

+ * 实现自行决定引用形态:key 模式生成并持久化脚本 key,正文模式全部返回原值且不落库。 + */ +public interface IScriptEditor { + + /** 流程定义保存时调用。 */ + void onSave(Collection refs); + + /** 版本复制时返回新的脚本引用。 */ + String onVersionCopy(String ref); + + /** 流程定义删除时调用。 */ + void onDelete(Collection refs); + + /** 兼容历史设计数据时把内联正文转换为引用;实现可原样返回。 */ + String normalize(String ref, String scriptType); + + /** + * 导入流程时按正文重建脚本。 + * + * @param contents 旧引用 -> 脚本正文 + * @param refTypes 旧引用 -> 脚本类型标签 + * @return 旧引用 -> 新引用 + */ + Map onImport(Map contents, Map refTypes); +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptExecutor.java b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptExecutor.java new file mode 100644 index 00000000..d5a9be63 --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptExecutor.java @@ -0,0 +1,28 @@ +package com.codingapi.flow.gateway; + +import java.util.Map; + +/** + * 脚本执行端口。framework 只认识不透明的脚本引用,解释与执行由 infrastructure 实现。 + */ +public interface IScriptExecutor { + + /** + * 按脚本引用执行。 + * + * @param ref 流程定义中的脚本引用(key、正文或其他实现自定义形态) + * @param binds 绑定变量(如 {@code $bind}),不作为脚本方法的位置参数 + * @param args 脚本方法的位置参数 + */ + T execute(String ref, Map binds, Object... args); + + /** + * 按运行时固化的脚本正文执行,不读取设计态脚本对象。 + */ + T executeContent(String ref, String content, Map binds, Object... args); + + /** + * 读取脚本正文,供不执行脚本的静态解析使用。 + */ + String getScript(String ref); +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptGatewayProvider.java b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptGatewayProvider.java new file mode 100644 index 00000000..309b988c --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptGatewayProvider.java @@ -0,0 +1,13 @@ +package com.codingapi.flow.gateway; + +/** + * 脚本 Gateway 装配入口。由 JDK ServiceLoader 发现,或由 starter 显式注册覆盖。 + */ +public interface IScriptGatewayProvider { + + IScriptExecutor executor(); + + IScriptResolver resolver(); + + IScriptEditor editor(); +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptResolver.java b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptResolver.java new file mode 100644 index 00000000..37562e11 --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/gateway/IScriptResolver.java @@ -0,0 +1,22 @@ +package com.codingapi.flow.gateway; + +import java.util.Collection; +import java.util.Map; + +/** + * 脚本引用解析端口:把流程定义中的引用转换为可编辑、可导出的脚本文本。 + */ +public interface IScriptResolver { + + String resolve(String ref); + + /** + * 生成运行时快照(引用 -> 正文)。实现可返回空 Map 表示流程定义已自固化脚本正文。 + */ + Map snapshot(Collection refs); + + /** + * 导出脚本正文(引用 -> 正文)。 + */ + Map export(Collection refs); +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionCustomScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionCustomScript.java index fa33275e..99aaeac0 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionCustomScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionCustomScript.java @@ -6,11 +6,10 @@ import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.script.utils.GroovyScriptUtils; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; -import org.springframework.util.StringUtils; import java.util.Map; @@ -21,7 +20,7 @@ public class ActionCustomScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; @@ -30,12 +29,10 @@ public class ActionCustomScript { */ public String getTriggerType(){ if(script!=null){ - String scriptData = FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .getScript(); + String scriptData = FlowScriptRuntimeContext.getInstance().getScript(script); String returnData = GroovyScriptUtils.getReturnScript(scriptData); - if(StringUtils.hasText(returnData)){ + if(returnData != null && !returnData.isBlank()){ return returnData.replace("\"","").replace("'",""); } } @@ -48,8 +45,7 @@ public String getTriggerType(){ public String execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); return FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); } /** diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionDisplayScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionDisplayScript.java index e7b4d948..75d28914 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionDisplayScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionDisplayScript.java @@ -7,7 +7,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; @@ -17,7 +17,7 @@ public class ActionDisplayScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; /** @@ -26,8 +26,7 @@ public class ActionDisplayScript { public boolean execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); return FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); } /** diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionRejectScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionRejectScript.java index 24aa1dd5..c8e9b0fc 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionRejectScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/action/ActionRejectScript.java @@ -5,7 +5,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -22,14 +22,13 @@ public class ActionRejectScript { public static final String TYPE_TERMINATE = "TERMINATE"; @Getter - @GroovyScript + @FlowScriptRef private final String script; public RejectResult execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); String result = FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); return new RejectResult(result); } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ConditionScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ConditionScript.java index c4931a94..bad8797e 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ConditionScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ConditionScript.java @@ -5,7 +5,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -16,14 +16,13 @@ public class ConditionScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public boolean execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); return FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); } public static ConditionScript defaultScript() { diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java index 7ebd702a..7a22eb13 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java @@ -7,7 +7,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -40,14 +40,13 @@ public class ErrorTriggerScript { private static final String SCRIPT_TYPE = "errorTrigger"; @Getter - @GroovyScript + @FlowScriptRef private final String script; public ErrorThrow execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); Object value = FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); if (value instanceof Map map) { return parseMap(session, map); } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/NodeTitleScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/NodeTitleScript.java index 1486559d..c7131bd2 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/NodeTitleScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/NodeTitleScript.java @@ -5,7 +5,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -19,15 +19,14 @@ public class NodeTitleScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public String execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); return FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); } /** diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorLoadScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorLoadScript.java index 2b51e4b0..60a2de15 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorLoadScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorLoadScript.java @@ -7,7 +7,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -31,14 +31,13 @@ public class OperatorLoadScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public List execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); Object scriptResult = FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); return new OperatorScriptResultResolver(session.getRepositoryHolder(), SCRIPT_TYPE).resolve(scriptResult); } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorMatchScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorMatchScript.java index 5ed0cd14..f9321f46 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorMatchScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/OperatorMatchScript.java @@ -4,7 +4,7 @@ import com.codingapi.flow.script.request.GroovyScriptBind; import com.codingapi.flow.script.request.GroovyWorkflowRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -18,13 +18,12 @@ public class OperatorMatchScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public boolean execute(GroovyWorkflowRequest request) { return FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); } /** diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/RouterNodeScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/RouterNodeScript.java index 17930fa1..cf50f08c 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/RouterNodeScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/RouterNodeScript.java @@ -5,7 +5,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -19,15 +19,14 @@ public class RouterNodeScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public String execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); return FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); } /** diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessResultScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessResultScript.java index 4e05cf08..20b6e2bb 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessResultScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessResultScript.java @@ -6,7 +6,7 @@ import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import lombok.AllArgsConstructor; import lombok.Getter; @@ -19,13 +19,12 @@ public class SubProcessResultScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public boolean execute(FlowSession session) { Object value = FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), new GroovyScriptRequest(session)); return Boolean.TRUE.equals(value); } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessScript.java index 5b340468..937f6968 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessScript.java @@ -7,7 +7,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -24,15 +24,14 @@ public class SubProcessScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public List execute(FlowSession session) { FlowRecord flowRecord = session.getCurrentRecord(); GroovyScriptRequest request = new GroovyScriptRequest(session); Object value = FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); List flowCreateRequests; if (value instanceof FlowCreateRequest flowCreateRequest) { flowCreateRequests = List.of(flowCreateRequest); diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/TriggerScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/TriggerScript.java index 34504b57..acbb7401 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/TriggerScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/TriggerScript.java @@ -5,7 +5,7 @@ import com.codingapi.flow.script.request.GroovyScriptRequest; import com.codingapi.flow.script.runtime.FlowScriptContext; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.GroovyScript; +import com.codingapi.flow.script.ref.FlowScriptRef; import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; import lombok.AllArgsConstructor; import lombok.Getter; @@ -19,14 +19,13 @@ public class TriggerScript { @Getter - @GroovyScript + @FlowScriptRef private final String script; public void execute(FlowSession session) { GroovyScriptRequest request = new GroovyScriptRequest(session); FlowScriptRuntimeContext.getInstance() - .getGroovyScript(script) - .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); + .execute(script, Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); } public static TriggerScript defaultScript() { diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/FlowScriptRef.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/FlowScriptRef.java new file mode 100644 index 00000000..9c69a1c6 --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/FlowScriptRef.java @@ -0,0 +1,19 @@ +package com.codingapi.flow.script.ref; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 标记流程定义中的脚本引用字段。 + *

+ * 字段值是不透明字符串:可以是脚本 key、脚本正文或业务实现方自定义的任何形态, + * 由 {@code IScriptExecutor} / {@code IScriptResolver} / {@code IScriptEditor} 解释。 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface FlowScriptRef { +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefFields.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefFields.java new file mode 100644 index 00000000..b92fc2ad --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefFields.java @@ -0,0 +1,95 @@ +package com.codingapi.flow.script.ref; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.UnaryOperator; + +/** + * 一次对象图扫描得到的全部脚本引用字段,支持读取引用与回写新引用。 + */ +public class ScriptRefFields { + + private final List refs = new ArrayList<>(); + + void add(Object owner, Field field) { + refs.add(new Ref(owner, field)); + } + + public boolean isEmpty() { + return refs.isEmpty(); + } + + /** 按字段顺序返回全部引用(不去重,保持「每个字段独立持有引用」的既有语义)。 */ + public List values() { + List values = new ArrayList<>(); + for (Ref ref : refs) { + String value = ref.get(); + if (value != null) { + values.add(value); + } + } + return values; + } + + /** 引用 -> 字段所属对象类型标签,供导入时按脚本类型重建。 */ + public Map types() { + Map types = new LinkedHashMap<>(); + for (Ref ref : refs) { + String value = ref.get(); + if (value != null) { + types.putIfAbsent(value, ref.owner.getClass().getSimpleName()); + } + } + return types; + } + + /** 用映射结果回写字段,返回旧引用到新引用的映射。 */ + public Map update(UnaryOperator mapper) { + Map mapping = new LinkedHashMap<>(); + for (Ref ref : refs) { + String oldValue = ref.get(); + if (oldValue == null) { + continue; + } + String newValue = mapper.apply(oldValue); + if (!Objects.equals(oldValue, newValue)) { + ref.set(newValue); + mapping.put(oldValue, newValue); + } + } + return mapping; + } + + private static class Ref { + + private final Object owner; + private final Field field; + + Ref(Object owner, Field field) { + this.owner = owner; + this.field = field; + } + + String get() { + try { + field.setAccessible(true); + return (String) field.get(owner); + } catch (IllegalAccessException exception) { + throw new IllegalStateException("读取脚本引用字段失败:" + field.getName(), exception); + } + } + + void set(String value) { + try { + field.setAccessible(true); + field.set(owner, value); + } catch (IllegalAccessException exception) { + throw new IllegalStateException("回写脚本引用字段失败:" + field.getName(), exception); + } + } + } +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefScanner.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefScanner.java new file mode 100644 index 00000000..968be185 --- /dev/null +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ref/ScriptRefScanner.java @@ -0,0 +1,92 @@ +package com.codingapi.flow.script.ref; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * 扫描流程对象图中全部 {@link FlowScriptRef} 字段。framework 自有实现,不依赖脚本引擎的注解扫描器。 + */ +public final class ScriptRefScanner { + + private ScriptRefScanner() { + } + + public static ScriptRefFields scan(Object target) { + return scanAll(List.of(target)); + } + + public static ScriptRefFields scanAll(Collection targets) { + ScriptRefFields fields = new ScriptRefFields(); + Set visited = Collections.newSetFromMap(new IdentityHashMap<>()); + for (Object target : targets) { + visit(target, visited, fields); + } + return fields; + } + + private static void visit(Object value, Set visited, ScriptRefFields out) { + if (value == null || value instanceof String || value instanceof Number + || value instanceof Boolean || value instanceof Character + || value instanceof Enum || value instanceof Class) { + return; + } + if (visited.contains(value)) { + return; + } + if (value instanceof Map map) { + visited.add(value); + for (Object child : map.values()) { + visit(child, visited, out); + } + return; + } + if (value instanceof Iterable iterable) { + visited.add(value); + for (Object child : iterable) { + visit(child, visited, out); + } + return; + } + Class type = value.getClass(); + if (type.isArray()) { + visited.add(value); + int length = java.lang.reflect.Array.getLength(value); + for (int i = 0; i < length; i++) { + visit(java.lang.reflect.Array.get(value, i), visited, out); + } + return; + } + String typeName = type.getName(); + if (typeName.startsWith("java.") || typeName.startsWith("javax.") + || typeName.startsWith("jdk.") || typeName.startsWith("sun.")) { + return; + } + visited.add(value); + for (Class current = type; current != null && current != Object.class; current = current.getSuperclass()) { + for (Field field : current.getDeclaredFields()) { + if (Modifier.isStatic(field.getModifiers())) { + continue; + } + try { + field.setAccessible(true); + if (field.isAnnotationPresent(FlowScriptRef.class)) { + out.add(value, field); + continue; + } + Object child = field.get(value); + if (child != null) { + visit(child, visited, out); + } + } catch (RuntimeException | IllegalAccessException ignored) { + // 不可访问的字段(JDK 内部类等)不参与脚本引用扫描 + } + } + } + } +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/registry/DefaultScriptRegistry.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/registry/DefaultScriptRegistry.java index e48dc6a3..1522f27a 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/registry/DefaultScriptRegistry.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/registry/DefaultScriptRegistry.java @@ -1,74 +1,73 @@ package com.codingapi.flow.script.registry; import com.codingapi.flow.script.ScriptDefaultConstants; -import com.codingapi.flow.script.factory.FlowGroovyScriptFactory; /** - * 默认脚本注册实现 + * 默认脚本注册实现。 *

- * 当用户未自定义脚本时,使用此默认实现返回 {@link ScriptDefaultConstants} 中定义的脚本。 + * 直接返回脚本正文作为引用——framework 不生成、不解释脚本 key。 + * 由 {@code IScriptExecutor} 实现决定如何解析:key 模式把正文视作内联脚本直接编译, + * 正文模式原样使用。 */ public class DefaultScriptRegistry implements IScriptRegistry { - @Override public String getRouterScript() { - return FlowGroovyScriptFactory.createRouterScript(ScriptDefaultConstants.SCRIPT_DEFAULT_ROUTER).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_ROUTER; } @Override public String getNodeTitleScript() { - return FlowGroovyScriptFactory.createNodeTitleScript(ScriptDefaultConstants.SCRIPT_DEFAULT_NODE_TITLE).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_NODE_TITLE; } @Override public String getConditionScript() { - return FlowGroovyScriptFactory.createConditionScript(ScriptDefaultConstants.SCRIPT_DEFAULT_CONDITION).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_CONDITION; } @Override public String getTriggerScript() { - return FlowGroovyScriptFactory.createTriggerScript(ScriptDefaultConstants.SCRIPT_DEFAULT_TRIGGER).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_TRIGGER; } @Override public String getSubProcessScript() { - return FlowGroovyScriptFactory.createSubProcessScript(ScriptDefaultConstants.SCRIPT_DEFAULT_SUB_PROCESS).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_SUB_PROCESS; } @Override public String getSubProcessResultScript() { - return FlowGroovyScriptFactory.createSubProcessResultScript( - ScriptDefaultConstants.SCRIPT_DEFAULT_SUB_PROCESS_RESULT).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_SUB_PROCESS_RESULT; } @Override public String getOperatorLoadScript() { - return FlowGroovyScriptFactory.createOperatorLoadScript(ScriptDefaultConstants.SCRIPT_DEFAULT_OPERATOR_LOAD).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_OPERATOR_LOAD; } @Override public String getOperatorMatchScript() { - return FlowGroovyScriptFactory.createOperatorMatchScript(ScriptDefaultConstants.SCRIPT_DEFAULT_OPERATOR_MATCH).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_OPERATOR_MATCH; } @Override public String getErrorTriggerScript() { - return FlowGroovyScriptFactory.createErrorTriggerScript(ScriptDefaultConstants.SCRIPT_DEFAULT_ERROR_TRIGGER).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_ERROR_TRIGGER; } @Override public String getActionCustomScript() { - return FlowGroovyScriptFactory.createActionCustomScript(ScriptDefaultConstants.SCRIPT_DEFAULT_ACTION_CUSTOM).getKey(); + return ScriptDefaultConstants.SCRIPT_DEFAULT_ACTION_CUSTOM; } @Override - public String getActionRejectScript() { - return FlowGroovyScriptFactory.createActionRejectScript(ScriptDefaultConstants.SCRIPT_DEFAULT_ACTION_REJECT).getKey(); + public String getActionDisplayScript() { + return ScriptDefaultConstants.SCRIPT_DEFAULT_ACTION_DISPLAY; } @Override - public String getActionDisplayScript() { - return FlowGroovyScriptFactory.createActionDisplayScript(ScriptDefaultConstants.SCRIPT_DEFAULT_ACTION_DISPLAY).getKey(); + public String getActionRejectScript() { + return ScriptDefaultConstants.SCRIPT_DEFAULT_ACTION_REJECT; } } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptBind.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptBind.java index ce93d22d..e0b1ac79 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptBind.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptBind.java @@ -4,9 +4,6 @@ import com.codingapi.flow.operator.OperatorKey; import com.codingapi.flow.record.FlowRecord; import com.codingapi.flow.script.runtime.FlowScriptContext; -import com.codingapi.springboot.script.annotation.ScriptFunction; -import com.codingapi.springboot.script.annotation.ScriptParameter; -import com.codingapi.springboot.script.annotation.ScriptType; import lombok.AllArgsConstructor; import java.util.List; @@ -17,69 +14,51 @@ * $bind.getRecordById(1); * } */ -@ScriptType(description = "流程groovy脚本绑定对象") + @AllArgsConstructor public class GroovyScriptBind { private final FlowScriptContext context; - @ScriptFunction( - name = "getBean", - description = "获取spring bean对象") - public T getBean(@ScriptParameter(description = "Class类型") Class clazz) { + + public T getBean( Class clazz) { return context.getBean(clazz); } - @ScriptFunction( - name = "getBean", - description = "获取spring bean对象" - ) - public T getBean(@ScriptParameter(description = "bean名称") String name, @ScriptParameter(description = "Class类型") Class clazz) { + + public T getBean( String name, Class clazz) { return context.getBean(name, clazz); } - @ScriptFunction( - name = "getBeans", - description = "获取spring bean对象列表") - public List getBeans(@ScriptParameter(description = "Class类型") Class clazz) { + + public List getBeans( Class clazz) { return context.getBeans(clazz); } - @ScriptFunction( - name = "getRecordById", - description = "根据流程id获取流程记录") - public FlowRecord getRecordById(@ScriptParameter(description = "流程记录id") long id) { + + public FlowRecord getRecordById( long id) { return context.getRecordById(id); } - @ScriptFunction( - name = "getOperatorById", - description = "根据用户id获取流程用户对象") - public IFlowOperator getOperatorById(@ScriptParameter(description = "用户id") long userId) { + + public IFlowOperator getOperatorById( long userId) { return context.getOperatorById(userId); } - @ScriptFunction( - name = "getOperatorByIdentity", - description = "根据用户id与身份标识获取流程用户对象(issue #288),身份为空表示默认身份") - public IFlowOperator getOperatorByIdentity(@ScriptParameter(description = "用户id") long userId, - @ScriptParameter(description = "身份标识") String identity) { + + public IFlowOperator getOperatorByIdentity( long userId, + String identity) { return context.getOperatorById(userId, identity); } - @ScriptFunction( - name = "getOperatorKey", - description = "根据用户id与身份标识构造操作者标识(不回查),可直接作为取人脚本返回值(issue #303)") - public OperatorKey getOperatorKey(@ScriptParameter(description = "用户id") long userId, - @ScriptParameter(description = "身份标识") String identity) { + + public OperatorKey getOperatorKey( long userId, + String identity) { return OperatorKey.of(userId, identity); } - @ScriptFunction( - name = "findOperatorsByIds", - description = "根据用户id获取流程用户列表" - ) - public List findOperatorsByIds(@ScriptParameter(description = "用户id列表") List ids) { + + public List findOperatorsByIds( List ids) { return context.findOperatorsByIds(ids); } } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptRequest.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptRequest.java index c730d788..c0f4292e 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptRequest.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptRequest.java @@ -9,9 +9,6 @@ import com.codingapi.flow.pojo.request.FlowCreateRequest; import com.codingapi.flow.record.FlowRecord; import com.codingapi.flow.session.FlowSession; -import com.codingapi.springboot.script.annotation.ScriptFunction; -import com.codingapi.springboot.script.annotation.ScriptParameter; -import com.codingapi.springboot.script.annotation.ScriptType; import java.util.List; import java.util.Map; @@ -22,7 +19,7 @@ * request.getOperatorName() * } */ -@ScriptType(description = "流程脚本请求对象") + public class GroovyScriptRequest { /** @@ -115,32 +112,32 @@ public GroovyScriptRequest(FlowSession session) { } - @ScriptFunction(name = "getWorkflowTitle", description = "获取流程名称") + public String getWorkflowTitle() { return workflowTitle; } - @ScriptFunction(name = "getWorkflowId", description = "获取流程workId") + public String getWorkflowId() { return workflowId; } - @ScriptFunction(name = "getWorkflowCode", description = "获取流程workCode") + public String getWorkflowCode() { return workflowCode; } - @ScriptFunction(name = "getNodeName", description = "获取节点名称") + public String getNodeName() { return nodeName; } - @ScriptFunction(name = "getNodeType", description = "获取节点类型") + public String getNodeType() { return nodeType; } - @ScriptFunction(name = "getFormData", description = "获取当前流程数据") + public Map getFormData() { return formData; } @@ -150,24 +147,24 @@ public Map getFormData() { * * @param formData 表单数据 */ - @ScriptFunction(name = "resetFormData", description = "重置当前流程表单数据") + public void resetFormData( - @ScriptParameter(description = "表单数据") Map formData) { + Map formData) { flowSession.getFormData().reset(formData); this.formData = flowSession.getFormData().toMapData(); } - @ScriptFunction(name = "getCreatedOperator", description = "获取流程创建人信息") + public IFlowOperator getCreatedOperator() { return createdOperator; } - @ScriptFunction(name = "getCurrentOperator", description = "获取当前审批人信息") + public IFlowOperator getCurrentOperator() { return currentOperator; } - @ScriptFunction(name = "getSubmitOperator", description = "获取流程审批者信息") + public IFlowOperator getSubmitOperator() { return submitOperator; } @@ -179,15 +176,15 @@ public IFlowOperator getSubmitOperator() { * @param nodeId 节点id * @return 节点 */ - @ScriptFunction(name = "getNode", description = "获取流程节点信息") - public IFlowNode getNode(@ScriptParameter(description = "流程节点Id") String nodeId) { + + public IFlowNode getNode( String nodeId) { return flowSession.getNode(nodeId); } /** * 是否流程管理员 */ - @ScriptFunction(name = "isFlowManager", description = "当前用户是否为流程管理员") + public boolean isFlowManager() { return this.currentOperator.isFlowManager(); } @@ -195,7 +192,7 @@ public boolean isFlowManager() { /** * 获取当前节点对象 */ - @ScriptFunction(name = "getCurrentNode", description = "获取当前节点对象") + public IFlowNode getCurrentNode() { return this.flowSession.getCurrentNode(); } @@ -212,7 +209,7 @@ public IFlowNode getCurrentNode() { * * @return 上一节点的审批人员Id列表,无法确定时返回空列表 */ - @ScriptFunction(name = "findPreviousNodeOperatorIds", description = "获取上一节点的审批人员Id列表") + public List findPreviousNodeOperatorIds() { return this.flowSession.loadPreviousNodeOperatorIds(); } @@ -229,7 +226,7 @@ public List findPreviousNodeOperatorIds() { * * @return 上一节点的审批人员列表,无法确定时返回空列表 */ - @ScriptFunction(name = "findPreviousNodeOperators", description = "获取上一节点审批人员列表(含身份)") + public List findPreviousNodeOperators() { return this.flowSession.loadPreviousNodeOperators(); } @@ -237,7 +234,7 @@ public List findPreviousNodeOperators() { /** * 获取当前操作对象 */ - @ScriptFunction(name = "getCurrentAction", description = "获取当前操作对象") + public IFlowAction getCurrentAction() { return this.flowSession.getCurrentAction(); } @@ -245,7 +242,7 @@ public IFlowAction getCurrentAction() { /** * 是否模拟测试 */ - @ScriptFunction(name = "isMock", description = "是否模拟测试") + public boolean isMock() { return this.flowSession.isMock(); } @@ -253,7 +250,7 @@ public boolean isMock() { /** * 流程创建者Id */ - @ScriptFunction(name = "getCreatedOperatorId", description = "获取流程创建者Id") + public long getCreatedOperatorId() { return this.createdOperator.getUserId(); } @@ -261,7 +258,7 @@ public long getCreatedOperatorId() { /** * 流程创建者名称 */ - @ScriptFunction(name = "getCreatedOperatorName", description = "获取流程创建者名称") + public String getCreatedOperatorName() { return this.createdOperator.getName(); } @@ -270,7 +267,7 @@ public String getCreatedOperatorName() { /** * 流程审批者Id */ - @ScriptFunction(name = "getCurrentOperatorId", description = "获取流程审批者Id") + public long getCurrentOperatorId() { return this.currentOperator.getUserId(); } @@ -278,7 +275,7 @@ public long getCurrentOperatorId() { /** * 流程审批者名称 */ - @ScriptFunction(name = "getCurrentOperatorName", description = "获取流程审批者名称") + public String getCurrentOperatorName() { return this.currentOperator.getName(); } @@ -286,7 +283,7 @@ public String getCurrentOperatorName() { /** * 流程审批者Id */ - @ScriptFunction(name = "getSubmitOperatorId", description = "获取流程审批者Id") + public long getSubmitOperatorId() { return this.submitOperator.getUserId(); } @@ -294,7 +291,7 @@ public long getSubmitOperatorId() { /** * 流程审批者名称 */ - @ScriptFunction(name = "getSubmitOperatorName", description = "流程审批者名称") + public String getSubmitOperatorName() { return this.submitOperator.getName(); } @@ -307,7 +304,7 @@ public String getSubmitOperatorName() { * * @return 创建者身份标识 */ - @ScriptFunction(name = "getCreatedOperatorIdentity", description = "获取流程创建者身份标识") + public String getCreatedOperatorIdentity() { return OperatorIdentity.of(this.createdOperator).value(); } @@ -317,7 +314,7 @@ public String getCreatedOperatorIdentity() { * * @return 当前审批者身份标识 */ - @ScriptFunction(name = "getCurrentOperatorIdentity", description = "获取流程审批者身份标识") + public String getCurrentOperatorIdentity() { return OperatorIdentity.of(this.currentOperator).value(); } @@ -327,7 +324,7 @@ public String getCurrentOperatorIdentity() { * * @return 提交人身份标识 */ - @ScriptFunction(name = "getSubmitOperatorIdentity", description = "获取流程提交人身份标识") + public String getSubmitOperatorIdentity() { return OperatorIdentity.of(this.submitOperator).value(); } @@ -338,7 +335,7 @@ public String getSubmitOperatorIdentity() { * * @return 创建者标识 */ - @ScriptFunction(name = "getCreatedOperatorKey", description = "获取流程创建者标识(含身份)") + public OperatorKey getCreatedOperatorKey() { return OperatorKey.of(this.createdOperator.getUserId(), OperatorIdentity.of(this.createdOperator).value()); } @@ -348,7 +345,7 @@ public OperatorKey getCreatedOperatorKey() { * * @return 当前审批者标识 */ - @ScriptFunction(name = "getCurrentOperatorKey", description = "获取流程审批者标识(含身份)") + public OperatorKey getCurrentOperatorKey() { return OperatorKey.of(this.currentOperator.getUserId(), OperatorIdentity.of(this.currentOperator).value()); } @@ -358,7 +355,7 @@ public OperatorKey getCurrentOperatorKey() { * * @return 提交人标识 */ - @ScriptFunction(name = "getSubmitOperatorKey", description = "获取流程提交人标识(含身份)") + public OperatorKey getSubmitOperatorKey() { return OperatorKey.of(this.submitOperator.getUserId(), OperatorIdentity.of(this.submitOperator).value()); } @@ -369,7 +366,7 @@ public OperatorKey getSubmitOperatorKey() { * * @return 开始节点 */ - @ScriptFunction(name = "getStartNode", description = "获取开始节点") + public IFlowNode getStartNode() { return flowSession.getStartNode(); } @@ -380,7 +377,7 @@ public IFlowNode getStartNode() { * * @return 流程请求对象 */ - @ScriptFunction(name = "toCreateRequest", description = "转换为当前流程的请求对象") + public FlowCreateRequest toCreateRequest() { return flowSession.toCreateRequest(); } @@ -393,15 +390,12 @@ public FlowCreateRequest toCreateRequest() { * @param actionId 动作类型 * @param formData 流程数据 */ - @ScriptFunction( - name = "toCreateRequest", - description = "创建流程请求,用于自流程的创建" - ) + public FlowCreateRequest toCreateRequest( - @ScriptParameter(description = "流程workCode") String workCode, - @ScriptParameter(description = "流程发起人id") long operatorId, - @ScriptParameter(description = "流程动作actionId") String actionId, - @ScriptParameter(description = "流程数据formData(JSON格式)") String formData) { + String workCode, + long operatorId, + String actionId, + String formData) { return flowSession.toCreateRequest(workCode, operatorId, actionId, formData); } @@ -414,16 +408,13 @@ public FlowCreateRequest toCreateRequest( * @param formData 流程数据 * @param workTitle 手动传入的流程标题;为空时回落流程定义标题 */ - @ScriptFunction( - name = "toCreateRequest", - description = "创建流程请求,用于自流程的创建(支持手动传入流程标题)" - ) + public FlowCreateRequest toCreateRequest( - @ScriptParameter(description = "流程workCode") String workCode, - @ScriptParameter(description = "流程发起人id") long operatorId, - @ScriptParameter(description = "流程动作actionId") String actionId, - @ScriptParameter(description = "流程数据formData(JSON格式)") String formData, - @ScriptParameter(description = "流程标题workTitle(可为空)") String workTitle) { + String workCode, + long operatorId, + String actionId, + String formData, + String workTitle) { return flowSession.toCreateRequest(workCode, operatorId, actionId, formData, workTitle); } @@ -435,14 +426,11 @@ public FlowCreateRequest toCreateRequest( * @param actionId 动作类型 * @param formData 流程数据 */ - @ScriptFunction( - name = "toCreateRequest", - description = "创建流程请求,用于自流程的创建" - ) - public FlowCreateRequest toCreateRequest(@ScriptParameter(description = "流程workCode") String workCode, - @ScriptParameter(description = "流程发起人id") long operatorId, - @ScriptParameter(description = "流程动作actionId") String actionId, - @ScriptParameter(description = "流程数据formData(Map格式)") Map formData) { + + public FlowCreateRequest toCreateRequest( String workCode, + long operatorId, + String actionId, + Map formData) { return flowSession.toCreateRequest(workCode, operatorId, actionId, formData); } @@ -455,15 +443,12 @@ public FlowCreateRequest toCreateRequest(@ScriptParameter(description = "流程w * @param formData 流程数据 * @param workTitle 手动传入的流程标题;为空时回落流程定义标题 */ - @ScriptFunction( - name = "toCreateRequest", - description = "创建流程请求,用于自流程的创建(支持手动传入流程标题)" - ) - public FlowCreateRequest toCreateRequest(@ScriptParameter(description = "流程workCode") String workCode, - @ScriptParameter(description = "流程发起人id") long operatorId, - @ScriptParameter(description = "流程动作actionId") String actionId, - @ScriptParameter(description = "流程数据formData(Map格式)") Map formData, - @ScriptParameter(description = "流程标题workTitle(可为空)") String workTitle) { + + public FlowCreateRequest toCreateRequest( String workCode, + long operatorId, + String actionId, + Map formData, + String workTitle) { return flowSession.toCreateRequest(workCode, operatorId, actionId, formData, workTitle); } @@ -474,11 +459,8 @@ public FlowCreateRequest toCreateRequest(@ScriptParameter(description = "流程w * @param fieldCode 字段Code * @return 字段值 */ - @ScriptFunction( - name = "getFormData", - description = "获取表单字段值" - ) - public Object getFormData(@ScriptParameter(description = "表单字段编码") String fieldCode) { + + public Object getFormData( String fieldCode) { return flowSession.getFormData(fieldCode); } @@ -488,11 +470,8 @@ public Object getFormData(@ScriptParameter(description = "表单字段编码") S * @param subFormCode 子表单code * @return 子表单数据列表 */ - @ScriptFunction( - name = "getSubFormData", - description = "获取子表单的数据,返回list格式数据" - ) - public List> getSubFormData(@ScriptParameter(description = "字表编码") String subFormCode) { + + public List> getSubFormData( String subFormCode) { return flowSession.getFormData().getSubDataBody(subFormCode) .stream() .map(FormData.DataBody::toMapData) @@ -502,16 +481,16 @@ public List> getSubFormData(@ScriptParameter(description = " /** * 查询指定子流程节点已经结束的最终记录。 */ - @ScriptFunction(name = "findSubProcessRecords", description = "查询指定子流程节点已经结束的最终记录") + public List findSubProcessRecords( - @ScriptParameter(description = "子流程节点Id") String subProcessNodeId) { + String subProcessNodeId) { return flowSession.findSubProcessRecords(subProcessNodeId); } /** * 获取本次子流程节点创建的实例总数。 */ - @ScriptFunction(name = "getSubProcessTotal", description = "获取本次子流程节点创建的实例总数") + public int getSubProcessTotal() { return flowSession.getSubProcessTotal(); } @@ -519,7 +498,7 @@ public int getSubProcessTotal() { /** * 获取本次刚结束的子流程最终记录。 */ - @ScriptFunction(name = "getCurrentSubProcessRecord", description = "获取本次刚结束的子流程最终记录") + public FlowRecord getCurrentSubProcessRecord() { return flowSession.getCurrentSubProcessRecord(); } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyWorkflowRequest.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyWorkflowRequest.java index 47bcf382..c81c14cc 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyWorkflowRequest.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyWorkflowRequest.java @@ -2,8 +2,6 @@ import com.codingapi.flow.operator.IFlowOperator; import com.codingapi.flow.workflow.Workflow; -import com.codingapi.springboot.script.annotation.ScriptFunction; -import com.codingapi.springboot.script.annotation.ScriptType; import lombok.AllArgsConstructor; /** @@ -13,18 +11,18 @@ * } */ @AllArgsConstructor -@ScriptType(description = "流程发起请求验证对象") + public class GroovyWorkflowRequest { private final IFlowOperator currentOperator; private final Workflow workflow; - @ScriptFunction(name = "getCurrentOperator",description = "当前操作人") + public IFlowOperator getCurrentOperator() { return currentOperator; } - @ScriptFunction(name = "getWorkflow",description = "流程对象") + public Workflow getWorkflow() { return workflow; } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContext.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContext.java index e15fdb9d..28bf3a33 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContext.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContext.java @@ -1,22 +1,17 @@ package com.codingapi.flow.script.runtime; import com.codingapi.flow.cache.FlowRuntimeScriptLocalCache; -import com.codingapi.flow.exception.FlowStateException; -import com.codingapi.springboot.script.GroovyScript; -import com.codingapi.springboot.script.cache.GroovyScriptCacheContext; +import com.codingapi.flow.gateway.FlowScriptGatewayContext; +import com.codingapi.flow.gateway.IScriptExecutor; + +import java.util.Map; /** - * 流程运行时脚本代理。 + * 流程运行时脚本入口。 *

- * 脚本统一获取入口,用于隔离流程设计阶段与运行时: - *

    - *
  • 运行态(线程缓存中存在当前运行时的脚本快照):优先使用快照内容构造一个 - * 独立的脚本对象返回,不会修改全局缓存中的脚本对象,从而避免设计期修改污染在途流程。
  • - *
  • 非运行态(无运行时快照):直接返回全局脚本缓存中的脚本对象,代理逻辑不干预, - * 行为与原有实现完全一致。
  • - *
- * 说明:脚本编译产物缓存以脚本内容的 SHA256 为键,因此使用同一脚本key执行快照内容 - * 时会按内容独立编译缓存,与设计期修改后的新内容互不串扰。 + * framework 不认识脚本引擎:脚本引用的解释、正文读取与执行全部委托 {@link IScriptExecutor}。 + * 运行时快照的判定留在此处(业务语义)——运行态优先执行流程发起时固化的正文, + * 避免设计期修改脚本污染在途流程。 */ public class FlowScriptRuntimeContext { @@ -27,34 +22,28 @@ public static FlowScriptRuntimeContext getInstance() { } /** - * 获取脚本对象。运行时优先使用快照内容,否则走全局脚本缓存。 + * 执行脚本引用。 * - * @param key 脚本key - * @return 脚本对象 + * @param ref 流程定义中的脚本引用 + * @param binds 绑定变量(如 {@code $bind}),不作为位置参数 + * @param args 脚本方法的位置参数 */ - public GroovyScript getGroovyScript(String key) { - GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(key); - String snapshot = FlowRuntimeScriptLocalCache.getInstance().get(key); - if (cached == null && snapshot == null) { - // 全局缓存、临时缓存、持久化仓储与运行时快照均找不到脚本, - // 直接抛出明确异常,避免调用方在 invoke 处出现难以定位的空指针 - throw FlowStateException.scriptNotFound(key); - } - if (snapshot == null) { - // 非运行态:不干预,返回全局缓存中的脚本对象 - return cached; - } - // 运行态:使用运行时快照内容构造独立脚本对象,不修改全局缓存对象 - GroovyScript.Builder builder = GroovyScript.builder(key) - .script(snapshot) - .method(cached != null && cached.getMethod() != null ? cached.getMethod() : "run"); - if (cached != null) { - builder.returnType(cached.getReturnType()) - .typeOne(cached.getTypeOne()) - .typeTwo(cached.getTypeTwo()) - .binds(cached.getBinds()) - .requests(cached.getRequests()); + public T execute(String ref, Map binds, Object... args) { + String snapshot = FlowRuntimeScriptLocalCache.getInstance().get(ref); + IScriptExecutor executor = FlowScriptGatewayContext.getInstance().executor(); + return snapshot != null + ? executor.executeContent(ref, snapshot, binds, args) + : executor.execute(ref, binds, args); + } + + /** + * 读取脚本正文。运行态优先返回快照正文;引用未注册时由端口给出明确异常。 + */ + public String getScript(String ref) { + String snapshot = FlowRuntimeScriptLocalCache.getInstance().get(ref); + if (snapshot != null) { + return snapshot; } - return builder.build(); + return FlowScriptGatewayContext.getInstance().executor().getScript(ref); } } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/service/WorkflowGroovyScriptUtils.java b/flow-engine-framework/src/main/java/com/codingapi/flow/service/WorkflowGroovyScriptUtils.java index abd33ed6..46c7d686 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/service/WorkflowGroovyScriptUtils.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/service/WorkflowGroovyScriptUtils.java @@ -1,31 +1,34 @@ package com.codingapi.flow.service; -import com.codingapi.flow.exception.FlowStateException; -import com.codingapi.flow.generator.FlowIDGeneratorGatewayContext; +import com.codingapi.flow.gateway.FlowScriptGatewayContext; +import com.codingapi.flow.gateway.IScriptEditor; import com.codingapi.flow.javscript.NodeViewJavaScript; import com.codingapi.flow.javscript.NodeViewJavaScriptCacheContext; import com.codingapi.flow.javscript.NodeViewScriptAnnotationScannerUtils; import com.codingapi.flow.javscript.NodeViewScriptFieldResult; -import com.codingapi.springboot.script.GroovyScript; -import com.codingapi.springboot.script.cache.GroovyScriptCacheContext; -import com.codingapi.springboot.script.repository.GroovyScriptRepositoryContext; -import com.codingapi.springboot.script.scanner.GroovyScriptAnnotationScannerUtils; -import com.codingapi.springboot.script.scanner.GroovyScriptFieldResult; -import com.codingapi.springboot.script.temp.TempGroovyScriptContext; +import com.codingapi.flow.generator.FlowIDGeneratorGatewayContext; +import com.codingapi.flow.script.ref.ScriptRefFields; +import com.codingapi.flow.script.ref.ScriptRefScanner; import java.util.List; +/** + * 流程定义的脚本引用生命周期编排。 + *

+ * Groovy 侧的保存 / 版本隔离 / 删除全部委托 {@link IScriptEditor};framework 只负责 + * 扫描自有 {@code @FlowScriptRef} 字段并回写新引用。节点视图 JS 仍走自有的缓存实现。 + */ public class WorkflowGroovyScriptUtils { + private static IScriptEditor editor() { + return FlowScriptGatewayContext.getInstance().editor(); + } private static void saveGroovyScripts(Object target) { if (target != null) { - List keys = GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(target).getKeys(); - for (String key : keys) { - GroovyScript groovyScript = TempGroovyScriptContext.getInstance().getGroovyScript(key); - if (groovyScript != null) { - groovyScript.save(); - } + ScriptRefFields fields = ScriptRefScanner.scan(target); + if (!fields.isEmpty()) { + editor().onSave(fields.values()); } } } @@ -44,15 +47,13 @@ private static void saveJavascriptScripts(Object target) { public static void deleteGroovyScripts(Object target) { if (target != null) { - List keys = GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(target).getKeys(); - for (String key : keys) { - GroovyScriptRepositoryContext.getInstance().delete(key); - GroovyScriptCacheContext.getInstance().remove(key); + ScriptRefFields fields = ScriptRefScanner.scan(target); + if (!fields.isEmpty()) { + editor().onDelete(fields.values()); } } } - public static void deleteJavaScripts(Object target) { if (target != null) { List keys = NodeViewScriptAnnotationScannerUtils.findNodeViewScriptFields(target).getKeys(); @@ -64,18 +65,8 @@ public static void deleteJavaScripts(Object target) { public static void resetGroovyScripts(Object target) { if (target != null) { - GroovyScriptFieldResult result = GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(target); - result.update((key) -> { - GroovyScript groovyScript = GroovyScriptCacheContext.getInstance().getGroovyScript(key); - if (groovyScript == null) { - // 脚本内容已丢失(例如设计器临时脚本超过有效期),若继续保存会把悬空的脚本key写入流程定义, - // 直到对应节点执行时才以空指针的形式暴露,因此保存阶段直接给出明确错误 - throw FlowStateException.scriptNotFound(key); - } - GroovyScript latestScript = groovyScript.copy(FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey()); - latestScript.save(); - return latestScript.getKey(); - }); + ScriptRefFields fields = ScriptRefScanner.scan(target); + fields.update(editor()::onVersionCopy); } } @@ -94,31 +85,19 @@ public static void resetJavaScripts(Object target) { } } - /** - * 同步保存脚本对象 - * - * @param target 目标对象 - */ + /** 同步保存脚本对象。 */ public static void saveScripts(Object target) { saveGroovyScripts(target); saveJavascriptScripts(target); } - /** - * 同步删除脚本数据 - * - * @param target 目标对象 - */ + /** 同步删除脚本数据。 */ public static void deleteScripts(Object target) { deleteGroovyScripts(target); deleteJavaScripts(target); } - /** - * 替换脚本数据对象 - * - * @param target 目标对象 - */ + /** 版本隔离:替换脚本数据引用。 */ public static void resetScripts(Object target) { resetGroovyScripts(target); resetJavaScripts(target); diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/transfer/WorkflowGroovyScriptTransferService.java b/flow-engine-framework/src/main/java/com/codingapi/flow/transfer/WorkflowGroovyScriptTransferService.java index 8f3737eb..99e051a2 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/transfer/WorkflowGroovyScriptTransferService.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/transfer/WorkflowGroovyScriptTransferService.java @@ -1,25 +1,10 @@ package com.codingapi.flow.transfer; import com.codingapi.flow.exception.WorkflowTransferException; -import com.codingapi.flow.script.action.ActionCustomScript; -import com.codingapi.flow.script.action.ActionDisplayScript; -import com.codingapi.flow.script.action.ActionRejectScript; -import com.codingapi.flow.script.factory.FlowGroovyScriptFactory; -import com.codingapi.flow.script.node.ConditionScript; -import com.codingapi.flow.script.node.ErrorTriggerScript; -import com.codingapi.flow.script.node.NodeTitleScript; -import com.codingapi.flow.script.node.OperatorLoadScript; -import com.codingapi.flow.script.node.OperatorMatchScript; -import com.codingapi.flow.script.node.RouterNodeScript; -import com.codingapi.flow.script.node.SubProcessResultScript; -import com.codingapi.flow.script.node.SubProcessScript; -import com.codingapi.flow.script.node.TriggerScript; -import com.codingapi.springboot.framework.reflect.ObjectAnnotationFieldUtils; -import com.codingapi.springboot.framework.reflect.pojo.AnnotationTargetFieldResult; -import com.codingapi.springboot.script.GroovyScript; -import com.codingapi.springboot.script.cache.GroovyScriptCacheContext; +import com.codingapi.flow.gateway.FlowScriptGatewayContext; +import com.codingapi.flow.script.ref.ScriptRefFields; +import com.codingapi.flow.script.ref.ScriptRefScanner; -import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -28,238 +13,74 @@ import java.util.Set; /** - * 与Schema版本无关的Groovy脚本收集、重建和引用替换能力。 + * 与 Schema 版本无关的脚本引用收集、重建与替换能力。 + *

+ * framework 只扫描自有 {@code @FlowScriptRef} 字段并回写引用; + * 「引用 -> 正文」「正文 -> 引用」的转换全部交给脚本 Gateway 实现。 */ public class WorkflowGroovyScriptTransferService { - /** - * 收集目标对象引用的全部Groovy脚本正文。 - */ + /** 收集目标对象引用的全部脚本正文。 */ public Map exportScripts(Collection targets) { + ScriptRefFields fields = ScriptRefScanner.scanAll(targets); + if (fields.isEmpty()) { + return new LinkedHashMap<>(); + } + List refs = fields.values(); + Map exported = FlowScriptGatewayContext.getInstance().resolver().export(refs); Map scripts = new LinkedHashMap<>(); - for (Object target : targets) { - if (target == null) { - continue; + for (String ref : refs) { + String content = exported == null ? null : exported.get(ref); + if (content == null) { + throw WorkflowTransferException.scriptNotFound(ref); } - AnnotationTargetFieldResult fields = findFields(target); - fields.fetch(field -> { - String key = field.getValue(); - if (scripts.containsKey(key)) { - return; - } - GroovyScript groovyScript = GroovyScriptCacheContext.getInstance().getGroovyScript(key); - if (groovyScript == null || groovyScript.getScript() == null) { - throw WorkflowTransferException.scriptNotFound(key); - } - scripts.put(key, groovyScript.getScript()); - }); + scripts.putIfAbsent(ref, content); } return scripts; } /** - * 将字段中直接保存的脚本正文归一化为脚本key。 - *

- * 旧版设计器可能把脚本正文直接写入动作/节点的脚本字段,而引擎的保存、运行时与导入导出 - * 都以脚本key为准。保存流程前先做一次归一化:把正文按字段所属脚本类型注册为临时脚本 - * 并回填脚本key,随后由 {@code WorkflowGroovyScriptUtils.resetScripts} 统一生成持久化脚本。 - * - * @param target 目标对象 + * 兼容历史设计数据:把字段中的内联正文交给实现归一化为引用。 + * 实现若采用正文模式,可原样返回,framework 不再强制转换为 key。 */ public void normalizeInlineScripts(Object target) { if (target == null) { return; } - AnnotationTargetFieldResult fields = findFields(target); - Map keyMapping = new LinkedHashMap<>(); - fields.fetch(field -> { - String value = field.getValue(); - if (keyMapping.containsKey(value) || !looksLikeInlineScript(value)) { - return; - } - GroovyScript groovyScript = ScriptType.from(field.getTarget()).create(value); - keyMapping.put(value, groovyScript.getKey()); - }); - if (!keyMapping.isEmpty()) { - fields.update(value -> keyMapping.getOrDefault(value, value)); - } + ScriptRefFields fields = ScriptRefScanner.scan(target); + Map types = fields.types(); + fields.update(ref -> FlowScriptGatewayContext.getInstance() + .editor().normalize(ref, types.get(ref))); } - /** - * 按脚本引用所属类型重建脚本,并将所有旧key替换为新key。 - * - * @return 旧key到新key的映射 - */ + /** 按脚本引用所属类型重建,并把所有旧引用替换为新引用。 */ public Map rebuildScripts(Collection targets, Map scriptContents) { - Map scriptTypes = new LinkedHashMap<>(); - List> targetFields = new ArrayList<>(); - for (Object target : targets) { - if (target == null) { - continue; - } - AnnotationTargetFieldResult fields = findFields(target); - targetFields.add(fields); - fields.fetch(field -> { - String key = field.getValue(); - ScriptType currentType = ScriptType.from(field.getTarget()); - ScriptType previousType = scriptTypes.putIfAbsent(key, currentType); - if (previousType != null && previousType != currentType) { - throw WorkflowTransferException.invalidSchema( - String.format("Script key %s is referenced by both %s and %s", - key, previousType, currentType)); - } - }); - } + ScriptRefFields fields = ScriptRefScanner.scanAll(targets); + List refs = fields.values(); + Map types = fields.types(); Set unreferencedScriptKeys = new LinkedHashSet<>(scriptContents.keySet()); - unreferencedScriptKeys.removeAll(scriptTypes.keySet()); + unreferencedScriptKeys.removeAll(refs); if (!unreferencedScriptKeys.isEmpty()) { throw WorkflowTransferException.invalidSchema( String.format("groovyScripts contains unreferenced keys: %s", unreferencedScriptKeys)); } - Map rebuiltScripts = new LinkedHashMap<>(); - Map keyMapping = new LinkedHashMap<>(); - try { - for (Map.Entry entry : scriptTypes.entrySet()) { - String oldKey = entry.getKey(); - String content = resolveScriptContent(oldKey, scriptContents); - GroovyScript rebuiltScript = entry.getValue().create(content); - rebuiltScripts.put(oldKey, rebuiltScript); - keyMapping.put(oldKey, rebuiltScript.getKey()); + Map contents = new LinkedHashMap<>(); + for (String ref : refs) { + String content = scriptContents.get(ref); + if (content == null && looksLikeInlineScript(ref)) { + content = ref; } - - for (AnnotationTargetFieldResult fields : targetFields) { - fields.update(oldKey -> keyMapping.getOrDefault(oldKey, oldKey)); - } - rebuiltScripts.values().forEach(GroovyScript::save); - return keyMapping; - } catch (RuntimeException exception) { - rebuiltScripts.values().forEach(GroovyScript::remove); - throw exception; + contents.put(ref, content); } - } - - private String resolveScriptContent(String key, Map scriptContents) { - String content = scriptContents.get(key); - if (content != null) { - return content; - } - - // 兼容历史文件:旧文件可能将脚本正文直接放在脚本字段中。 - if (looksLikeInlineScript(key)) { - return key; - } - - // 兼容同环境导入的旧key-only文件;跨环境缺少正文时必须明确失败。 - GroovyScript existing = GroovyScriptCacheContext.getInstance().getGroovyScript(key); - if (existing != null && existing.getScript() != null) { - return existing.getScript(); - } - throw WorkflowTransferException.scriptNotFound(key); + Map mapping = FlowScriptGatewayContext.getInstance() + .editor().onImport(contents, types); + fields.update(ref -> mapping.getOrDefault(ref, ref)); + return mapping; } private boolean looksLikeInlineScript(String value) { return value != null && (value.contains("def run") || value.contains("\n") || value.contains("\r")); } - - private AnnotationTargetFieldResult findFields(Object target) { - return ObjectAnnotationFieldUtils.findFieldAnnotationValue( - target, - com.codingapi.springboot.script.annotation.GroovyScript.class, - String.class); - } - - private enum ScriptType { - ROUTER { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createRouterScript(content); - } - }, - NODE_TITLE { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createNodeTitleScript(content); - } - }, - CONDITION { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createConditionScript(content); - } - }, - TRIGGER { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createTriggerScript(content); - } - }, - SUB_PROCESS { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createSubProcessScript(content); - } - }, - SUB_PROCESS_RESULT { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createSubProcessResultScript(content); - } - }, - OPERATOR_LOAD { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createOperatorLoadScript(content); - } - }, - OPERATOR_MATCH { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createOperatorMatchScript(content); - } - }, - ERROR_TRIGGER { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createErrorTriggerScript(content); - } - }, - ACTION_DISPLAY { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createActionDisplayScript(content); - } - }, - ACTION_CUSTOM { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createActionCustomScript(content); - } - }, - ACTION_REJECT { - @Override - GroovyScript create(String content) { - return FlowGroovyScriptFactory.createActionRejectScript(content); - } - }; - - abstract GroovyScript create(String content); - - static ScriptType from(Object target) { - if (target instanceof RouterNodeScript) return ROUTER; - if (target instanceof NodeTitleScript) return NODE_TITLE; - if (target instanceof ConditionScript) return CONDITION; - if (target instanceof TriggerScript) return TRIGGER; - if (target instanceof SubProcessScript) return SUB_PROCESS; - if (target instanceof SubProcessResultScript) return SUB_PROCESS_RESULT; - if (target instanceof OperatorLoadScript) return OPERATOR_LOAD; - if (target instanceof OperatorMatchScript) return OPERATOR_MATCH; - if (target instanceof ErrorTriggerScript) return ERROR_TRIGGER; - if (target instanceof ActionDisplayScript) return ACTION_DISPLAY; - if (target instanceof ActionCustomScript) return ACTION_CUSTOM; - if (target instanceof ActionRejectScript) return ACTION_REJECT; - throw WorkflowTransferException.scriptTypeUnsupported(target.getClass().getName()); - } - } } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/workflow/runtime/WorkflowRuntime.java b/flow-engine-framework/src/main/java/com/codingapi/flow/workflow/runtime/WorkflowRuntime.java index 1cd8f4f5..5cd9efc6 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/workflow/runtime/WorkflowRuntime.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/workflow/runtime/WorkflowRuntime.java @@ -1,19 +1,18 @@ package com.codingapi.flow.workflow.runtime; +import com.codingapi.flow.gateway.FlowScriptGatewayContext; +import com.codingapi.flow.script.ref.ScriptRefFields; +import com.codingapi.flow.script.ref.ScriptRefScanner; import com.codingapi.flow.workflow.Workflow; -import com.codingapi.springboot.script.GroovyScript; -import com.codingapi.springboot.script.cache.GroovyScriptCacheContext; -import com.codingapi.springboot.script.scanner.GroovyScriptAnnotationScannerUtils; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import java.util.HashMap; -import java.util.List; import java.util.Map; /** - * 运行时的流程配置 + * 运行时的流程配置。 */ @Getter @AllArgsConstructor @@ -21,40 +20,22 @@ public class WorkflowRuntime { @Setter private long id; - /** - * 工作id - */ private String workId; - /** - * 流程编码 - */ private String workCode; - - /** - * 工作版本 - */ private long workVersion; - /** - * 流程名称 - */ private String workTitle; - /** - * 创建时间 - */ private long createTime; - /** - * 流程字节码 - */ private String workflow; + /** - * 脚本快照(脚本key -> 脚本内容)。 + * 脚本快照(脚本引用 -> 脚本内容)。 *

* 运行时创建时固化流程引用的全部脚本内容,使流程设计阶段对脚本内容的修改 - * 不会影响已经在运行的流程。 + * 不影响已在运行的流程。内容由 {@code IScriptResolver} 提供; + * 流程定义直接保存正文的实现可返回空 Map(定义本身已固化)。 */ private Map scripts; - public WorkflowRuntime(Workflow workflow) { this.workflow = workflow.toJson(); this.workId = workflow.getId(); @@ -65,32 +46,17 @@ public WorkflowRuntime(Workflow workflow) { this.scripts = snapshotScripts(workflow); } - public Workflow toWorkflow() { return Workflow.formJson(workflow); } - /** - * 扫描流程引用的全部脚本key,并从脚本缓存中固化其内容,形成运行时脚本快照。 - * - * @param workflow 流程对象 - * @return 脚本key到脚本内容的映射 - */ private static Map snapshotScripts(Workflow workflow) { - Map scripts = new HashMap<>(); - List keys = GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(workflow).getKeys(); - if (keys == null) { - return scripts; - } - for (String key : keys) { - if (key == null) { - continue; - } - GroovyScript groovyScript = GroovyScriptCacheContext.getInstance().getGroovyScript(key); - if (groovyScript != null && groovyScript.getScript() != null) { - scripts.put(key, groovyScript.getScript()); - } + ScriptRefFields fields = ScriptRefScanner.scan(workflow); + if (fields.isEmpty()) { + return new HashMap<>(); } - return scripts; + Map snapshot = FlowScriptGatewayContext.getInstance() + .resolver().snapshot(fields.values()); + return snapshot == null ? new HashMap<>() : new HashMap<>(snapshot); } } diff --git a/flow-engine-framework/src/test/java/com/codingapi/flow/architecture/FrameworkScriptDependencyTest.java b/flow-engine-framework/src/test/java/com/codingapi/flow/architecture/FrameworkScriptDependencyTest.java new file mode 100644 index 00000000..a1e9ce0d --- /dev/null +++ b/flow-engine-framework/src/test/java/com/codingapi/flow/architecture/FrameworkScriptDependencyTest.java @@ -0,0 +1,40 @@ +package com.codingapi.flow.architecture; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * 守护分层:Domain 主源码不得引用脚本引擎。 + */ +class FrameworkScriptDependencyTest { + + @Test + void main_sources_should_not_reference_any_script_engine() throws IOException { + Path root = Path.of("src/main/java"); + assertTrue(Files.isDirectory(root), "测试需从 flow-engine-framework 模块目录执行"); + try (Stream stream = Files.walk(root)) { + List violations = stream + .filter(path -> path.toString().endsWith(".java")) + .filter(path -> { + try { + String text = Files.readString(path); + return text.contains("com.codingapi.springboot.script") + || text.contains("org.apache.groovy"); + } catch (IOException exception) { + throw new IllegalStateException(exception); + } + }) + .map(Path::toString) + .toList(); + assertTrue(violations.isEmpty(), + "flow-engine-framework 主源码不得依赖脚本引擎,违规文件:" + violations); + } + } +} diff --git a/flow-engine-framework/src/test/java/com/codingapi/flow/gateway/ScriptGatewayContractTest.java b/flow-engine-framework/src/test/java/com/codingapi/flow/gateway/ScriptGatewayContractTest.java new file mode 100644 index 00000000..c7dda4ec --- /dev/null +++ b/flow-engine-framework/src/test/java/com/codingapi/flow/gateway/ScriptGatewayContractTest.java @@ -0,0 +1,175 @@ +package com.codingapi.flow.gateway; + +import com.codingapi.flow.cache.FlowRuntimeScriptLocalCache; +import com.codingapi.flow.script.node.ConditionScript; +import com.codingapi.flow.script.ref.ScriptRefFields; +import com.codingapi.flow.script.ref.ScriptRefScanner; +import com.codingapi.flow.script.runtime.FlowScriptRuntimeContext; +import com.codingapi.flow.service.WorkflowGroovyScriptUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * 脚本 Gateway 契约:framework 只依赖端口,不认识任何脚本引擎。 + */ +class ScriptGatewayContractTest { + + private static final String REF = "script-ref-1"; + + @AfterEach + void tearDown() { + FlowScriptGatewayContext.getInstance().clear(); + FlowRuntimeScriptLocalCache.getInstance().clear(); + } + + @Test + void execute_should_delegate_to_registered_port() { + FakeProvider fake = new FakeProvider(); + FlowScriptGatewayContext.getInstance().register(fake); + + Object result = FlowScriptRuntimeContext.getInstance().execute(REF, Map.of("$bind", "bind"), "request"); + + assertEquals("FROM_PORT", result); + assertEquals(REF, fake.executedRef); + assertEquals("bind", fake.binds.get("$bind")); + assertEquals("request", fake.args[0]); + assertTrue(fake.contentRef == null, "无运行时快照时不应按正文执行"); + } + + @Test + void runtime_snapshot_should_route_to_execute_content() { + FakeProvider fake = new FakeProvider(); + FlowScriptGatewayContext.getInstance().register(fake); + FlowRuntimeScriptLocalCache.getInstance().set(Map.of(REF, "def run(x){ 'SNAPSHOT' }")); + + Object result = FlowScriptRuntimeContext.getInstance().execute(REF, Map.of(), "request"); + + assertEquals("FROM_PORT_CONTENT", result); + assertEquals(REF, fake.contentRef); + assertEquals("def run(x){ 'SNAPSHOT' }", fake.content); + } + + @Test + void scanner_should_read_and_update_script_refs() { + ConditionScript script = new ConditionScript(REF); + ScriptRefFields fields = ScriptRefScanner.scan(script); + + assertEquals(List.of(REF), fields.values()); + Map mapping = fields.update(ref -> "new-" + ref); + + assertEquals("new-" + REF, script.getScript()); + assertEquals("new-" + REF, mapping.get(REF)); + } + + @Test + void version_copy_should_be_decided_by_editor_port() { + FakeProvider fake = new FakeProvider(); + FlowScriptGatewayContext.getInstance().register(fake); + ConditionScript script = new ConditionScript(REF); + + WorkflowGroovyScriptUtils.resetScripts(script); + + assertEquals(List.of(REF), fake.copiedRefs); + assertEquals("PORT_" + REF, script.getScript()); + } + + private static class FakeProvider implements IScriptGatewayProvider, + IScriptExecutor, IScriptResolver, IScriptEditor { + + private String executedRef; + private String contentRef; + private String content; + private Map binds; + private Object[] args; + private List copiedRefs; + + @Override + public IScriptExecutor executor() { + return this; + } + + @Override + public IScriptResolver resolver() { + return this; + } + + @Override + public IScriptEditor editor() { + return this; + } + + @Override + @SuppressWarnings("unchecked") + public T execute(String ref, Map binds, Object... args) { + this.executedRef = ref; + this.binds = binds; + this.args = args; + return (T) "FROM_PORT"; + } + + @Override + @SuppressWarnings("unchecked") + public T executeContent(String ref, String content, Map binds, Object... args) { + this.contentRef = ref; + this.content = content; + this.args = args; + return (T) "FROM_PORT_CONTENT"; + } + + @Override + public String getScript(String ref) { + return "CONTENT_OF_" + ref; + } + + @Override + public String resolve(String ref) { + return getScript(ref); + } + + @Override + public Map snapshot(Collection refs) { + return Collections.emptyMap(); + } + + @Override + public Map export(Collection refs) { + return new LinkedHashMap<>(); + } + + @Override + public void onSave(Collection refs) { + } + + @Override + public String onVersionCopy(String ref) { + if (copiedRefs == null) { + copiedRefs = new java.util.ArrayList<>(); + } + copiedRefs.add(ref); + return "PORT_" + ref; + } + + @Override + public void onDelete(Collection refs) { + } + + @Override + public String normalize(String ref, String scriptType) { + return ref; + } + + @Override + public Map onImport(Map contents, Map refTypes) { + return Collections.emptyMap(); + } + } +} diff --git a/flow-engine-framework/src/test/java/com/codingapi/flow/mock/TestScriptGatewayProvider.java b/flow-engine-framework/src/test/java/com/codingapi/flow/mock/TestScriptGatewayProvider.java new file mode 100644 index 00000000..d0365ccc --- /dev/null +++ b/flow-engine-framework/src/test/java/com/codingapi/flow/mock/TestScriptGatewayProvider.java @@ -0,0 +1,229 @@ +package com.codingapi.flow.mock; + +import com.codingapi.flow.exception.FlowStateException; +import com.codingapi.flow.exception.WorkflowTransferException; +import com.codingapi.flow.gateway.IScriptEditor; +import com.codingapi.flow.gateway.IScriptExecutor; +import com.codingapi.flow.gateway.IScriptGatewayProvider; +import com.codingapi.flow.gateway.IScriptResolver; +import com.codingapi.flow.generator.FlowIDGeneratorGatewayContext; +import com.codingapi.flow.script.factory.FlowGroovyScriptFactory; +import com.codingapi.springboot.script.GroovyScript; +import com.codingapi.springboot.script.cache.GroovyScriptCacheContext; +import com.codingapi.springboot.script.repository.GroovyScriptRepositoryContext; +import com.codingapi.springboot.script.temp.TempGroovyScriptContext; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * framework 集成测试用的真实 Groovy 实现。 + *

+ * 仅存在于 test 源码,由 ServiceLoader 发现;发布产物不包含任何脚本引擎实现。 + * key 与内联正文两种引用形态都支持,覆盖历史数据与默认脚本。 + */ +public class TestScriptGatewayProvider implements IScriptGatewayProvider, + IScriptExecutor, IScriptResolver, IScriptEditor { + + @Override + public IScriptExecutor executor() { + return this; + } + + @Override + public IScriptResolver resolver() { + return this; + } + + @Override + public IScriptEditor editor() { + return this; + } + + private static boolean isInline(String ref) { + return ref != null && (ref.contains("def run") || ref.contains("\n") || ref.contains("\r")); + } + + private static GroovyScript buildInline(String content) { + return GroovyScript.builder("inline-" + Integer.toHexString(content.hashCode())) + .script(content) + .method("run") + .build(); + } + + @Override + @SuppressWarnings("unchecked") + public T execute(String ref, Map binds, Object... args) { + if (isInline(ref)) { + return (T) buildInline(ref).invoke(binds, args); + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached == null) { + throw FlowStateException.scriptNotFound(ref); + } + return (T) cached.invoke(binds, args); + } + + @Override + @SuppressWarnings("unchecked") + public T executeContent(String ref, String content, Map binds, Object... args) { + GroovyScript cached = isInline(ref) ? null + : GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + GroovyScript.Builder builder = GroovyScript.builder(ref) + .script(content) + .method(cached != null && cached.getMethod() != null ? cached.getMethod() : "run"); + if (cached != null) { + builder.returnType(cached.getReturnType()) + .typeOne(cached.getTypeOne()) + .typeTwo(cached.getTypeTwo()) + .binds(cached.getBinds()) + .requests(cached.getRequests()); + } + return (T) builder.build().invoke(binds, args); + } + + @Override + public String getScript(String ref) { + if (isInline(ref)) { + return ref; + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached == null) { + throw FlowStateException.scriptNotFound(ref); + } + return cached.getScript(); + } + + @Override + public String resolve(String ref) { + return getScript(ref); + } + + @Override + public Map snapshot(Collection refs) { + Map scripts = new LinkedHashMap<>(); + for (String ref : refs) { + if (isInline(ref)) { + continue; + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached != null && cached.getScript() != null) { + scripts.put(ref, cached.getScript()); + } + } + return scripts; + } + + @Override + public Map export(Collection refs) { + Map scripts = new LinkedHashMap<>(); + for (String ref : refs) { + String content = contentForImport(ref); + if (content == null) { + throw WorkflowTransferException.scriptNotFound(ref); + } + scripts.put(ref, content); + } + return scripts; + } + + @Override + public void onSave(Collection refs) { + for (String ref : refs) { + if (isInline(ref)) { + continue; + } + GroovyScript temp = TempGroovyScriptContext.getInstance().getGroovyScript(ref); + if (temp != null) { + temp.save(); + } + } + } + + @Override + public String onVersionCopy(String ref) { + if (isInline(ref)) { + return ref; + } + GroovyScript current = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (current == null) { + throw FlowStateException.scriptNotFound(ref); + } + GroovyScript latest = current.copy(FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey()); + latest.save(); + return latest.getKey(); + } + + @Override + public void onDelete(Collection refs) { + for (String ref : refs) { + if (isInline(ref)) { + continue; + } + GroovyScriptRepositoryContext.getInstance().delete(ref); + GroovyScriptCacheContext.getInstance().remove(ref); + } + } + + @Override + public String normalize(String ref, String scriptType) { + if (!isInline(ref)) { + return ref; + } + return create(scriptType, ref).getKey(); + } + + @Override + public Map onImport(Map contents, Map refTypes) { + Map mapping = new LinkedHashMap<>(); + Map rebuilt = new LinkedHashMap<>(); + try { + for (Map.Entry entry : contents.entrySet()) { + String oldRef = entry.getKey(); + String content = entry.getValue() != null ? entry.getValue() : contentForImport(oldRef); + GroovyScript script = create(refTypes.get(oldRef), content); + rebuilt.put(oldRef, script); + mapping.put(oldRef, script.getKey()); + } + rebuilt.values().forEach(GroovyScript::save); + return mapping; + } catch (RuntimeException exception) { + rebuilt.values().forEach(GroovyScript::remove); + throw exception; + } + } + + private String contentForImport(String ref) { + if (isInline(ref)) { + return ref; + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached != null && cached.getScript() != null) { + return cached.getScript(); + } + throw WorkflowTransferException.scriptNotFound(ref); + } + + private GroovyScript create(String type, String content) { + if (type == null) { + throw WorkflowTransferException.scriptTypeUnsupported("null"); + } + return switch (type) { + case "RouterNodeScript" -> FlowGroovyScriptFactory.createRouterScript(content); + case "NodeTitleScript" -> FlowGroovyScriptFactory.createNodeTitleScript(content); + case "ConditionScript" -> FlowGroovyScriptFactory.createConditionScript(content); + case "TriggerScript" -> FlowGroovyScriptFactory.createTriggerScript(content); + case "SubProcessScript" -> FlowGroovyScriptFactory.createSubProcessScript(content); + case "SubProcessResultScript" -> FlowGroovyScriptFactory.createSubProcessResultScript(content); + case "OperatorLoadScript" -> FlowGroovyScriptFactory.createOperatorLoadScript(content); + case "OperatorMatchScript" -> FlowGroovyScriptFactory.createOperatorMatchScript(content); + case "ErrorTriggerScript" -> FlowGroovyScriptFactory.createErrorTriggerScript(content); + case "ActionDisplayScript" -> FlowGroovyScriptFactory.createActionDisplayScript(content); + case "ActionCustomScript" -> FlowGroovyScriptFactory.createActionCustomScript(content); + case "ActionRejectScript" -> FlowGroovyScriptFactory.createActionRejectScript(content); + default -> throw WorkflowTransferException.scriptTypeUnsupported(type); + }; + } +} diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/factory/FlowGroovyScriptFactory.java b/flow-engine-framework/src/test/java/com/codingapi/flow/script/factory/FlowGroovyScriptFactory.java similarity index 100% rename from flow-engine-framework/src/main/java/com/codingapi/flow/script/factory/FlowGroovyScriptFactory.java rename to flow-engine-framework/src/test/java/com/codingapi/flow/script/factory/FlowGroovyScriptFactory.java diff --git a/flow-engine-framework/src/test/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContextTest.java b/flow-engine-framework/src/test/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContextTest.java index 091897d9..36c42435 100644 --- a/flow-engine-framework/src/test/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContextTest.java +++ b/flow-engine-framework/src/test/java/com/codingapi/flow/script/runtime/FlowScriptRuntimeContextTest.java @@ -11,18 +11,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** - * 流程运行时脚本代理测试。 + * 运行时脚本快照隔离。 *

- * 验证:运行态优先使用运行时快照内容,且不影响全局脚本缓存;非运行态走原路径。 + * 断言只针对脚本正文与执行结果,不再断言 framework 返回 Groovy 脚本引擎类型。 */ class FlowScriptRuntimeContextTest { private static final String KEY = "test-script-key"; + private static final String NEW_CONTENT = "def run(request){ return 'NEW' }"; + private static final String OLD_CONTENT = "def run(request){ return 'OLD' }"; @AfterEach void tearDown() { @@ -39,104 +40,77 @@ private void registerGlobalScript(String content) { GroovyScriptCacheContext.getInstance().cache(script); } - private static final String NEW_CONTENT = "def run(request){ return 'NEW' }"; - private static final String OLD_CONTENT = "def run(request){ return 'OLD' }"; - @Test void should_return_snapshot_content_when_runtime_cache_present() { - // given 设计期将脚本内容改为 NEW registerGlobalScript(NEW_CONTENT); - // 运行时快照固化的是旧内容 OLD FlowRuntimeScriptLocalCache.getInstance().set(Map.of(KEY, OLD_CONTENT)); - // when 运行态获取脚本 - GroovyScript script = FlowScriptRuntimeContext.getInstance().getGroovyScript(KEY); - - // then 使用快照内容 - assertEquals(OLD_CONTENT, script.getScript()); - // 且全局缓存对象未被修改 + assertEquals(OLD_CONTENT, FlowScriptRuntimeContext.getInstance().getScript(KEY)); assertEquals(NEW_CONTENT, GroovyScriptCacheContext.getInstance().getScript(KEY)); } @Test void should_execute_snapshot_content_not_design_content() { - // given registerGlobalScript(NEW_CONTENT); FlowRuntimeScriptLocalCache.getInstance().set(Map.of(KEY, OLD_CONTENT)); - // when 运行态执行脚本 - String runtimeResult = FlowScriptRuntimeContext.getInstance().getGroovyScript(KEY).invoke("request"); - // 设计期(无快照)执行同一脚本key + String runtimeResult = FlowScriptRuntimeContext.getInstance().execute(KEY, Map.of(), "request"); FlowRuntimeScriptLocalCache.getInstance().clear(); - String designResult = FlowScriptRuntimeContext.getInstance().getGroovyScript(KEY).invoke("request"); + String designResult = FlowScriptRuntimeContext.getInstance().execute(KEY, Map.of(), "request"); - // then 运行时执行快照内容, 设计期执行最新内容, 互不串扰 assertEquals("OLD", runtimeResult); assertEquals("NEW", designResult); } @Test void should_execute_snapshot_after_design_script_deleted() { - // given 运行时已固化脚本正文,随后设计态脚本被物理删除 registerGlobalScript(NEW_CONTENT); FlowRuntimeScriptLocalCache.getInstance().set(Map.of(KEY, OLD_CONTENT)); GroovyScriptCacheContext.getInstance().remove(KEY); - // when - GroovyScript runtimeScript = FlowScriptRuntimeContext.getInstance().getGroovyScript(KEY); - - // then 不再依赖设计态脚本对象,仍可使用运行时正文执行 - assertEquals(OLD_CONTENT, runtimeScript.getScript()); - assertEquals("OLD", runtimeScript.invoke("request")); + assertEquals(OLD_CONTENT, FlowScriptRuntimeContext.getInstance().getScript(KEY)); + assertEquals("OLD", FlowScriptRuntimeContext.getInstance().execute(KEY, Map.of(), "request")); } @Test void should_return_global_script_when_no_runtime_cache() { - // given 无运行时快照 registerGlobalScript(NEW_CONTENT); FlowRuntimeScriptLocalCache.getInstance().clear(); - // when - GroovyScript script = FlowScriptRuntimeContext.getInstance().getGroovyScript(KEY); + assertEquals(NEW_CONTENT, FlowScriptRuntimeContext.getInstance().getScript(KEY)); + } - // then 代理不干预, 直接返回全局缓存中的同一对象 - assertSame(GroovyScriptCacheContext.getInstance().getGroovyScript(KEY), script); - assertEquals(NEW_CONTENT, script.getScript()); + @Test + void should_execute_inline_script_content_without_storage() { + assertEquals("OLD", FlowScriptRuntimeContext.getInstance() + .execute(OLD_CONTENT, Map.of(), "request")); + assertEquals(OLD_CONTENT, FlowScriptRuntimeContext.getInstance().getScript(OLD_CONTENT)); } @Test void should_throw_clear_exception_when_script_missing_everywhere() { - // given 脚本在任何缓存与仓储中都不存在(模拟脚本未持久化或数据丢失) String missingKey = "missing-script-" + System.nanoTime(); FlowRuntimeScriptLocalCache.getInstance().clear(); - // when / then 不再返回 null 导致调用方空指针,而是抛出明确的流程状态异常 FlowStateException exception = assertThrows(FlowStateException.class, - () -> FlowScriptRuntimeContext.getInstance().getGroovyScript(missingKey)); + () -> FlowScriptRuntimeContext.getInstance().getScript(missingKey)); assertTrue(exception.getMessage().contains(missingKey), - "异常信息应包含缺失的脚本key,便于定位"); + "异常信息应包含缺失的脚本引用,便于定位"); } @Test void should_throw_clear_exception_when_runtime_snapshot_missing_key() { - // given 存在运行时快照,但快照中不包含目标脚本key,且全局缓存也没有 String missingKey = "missing-runtime-script-" + System.nanoTime(); FlowRuntimeScriptLocalCache.getInstance().set(Map.of(KEY, OLD_CONTENT)); - // when / then assertThrows(FlowStateException.class, - () -> FlowScriptRuntimeContext.getInstance().getGroovyScript(missingKey)); + () -> FlowScriptRuntimeContext.getInstance().getScript(missingKey)); } @Test void should_return_null_from_local_cache_when_not_set() { - // given FlowRuntimeScriptLocalCache.getInstance().clear(); - - // when / then assertNull(FlowRuntimeScriptLocalCache.getInstance().get(KEY)); - - // set(null) 等价于清理 FlowRuntimeScriptLocalCache.getInstance().set(Map.of(KEY, "x")); FlowRuntimeScriptLocalCache.getInstance().set(null); assertNull(FlowRuntimeScriptLocalCache.getInstance().get(KEY)); diff --git a/flow-engine-framework/src/test/java/com/codingapi/flow/service/FlowSampleServiceTest.java b/flow-engine-framework/src/test/java/com/codingapi/flow/service/FlowSampleServiceTest.java index d3583f1b..7587b11a 100644 --- a/flow-engine-framework/src/test/java/com/codingapi/flow/service/FlowSampleServiceTest.java +++ b/flow-engine-framework/src/test/java/com/codingapi/flow/service/FlowSampleServiceTest.java @@ -25,7 +25,7 @@ import com.codingapi.flow.user.User; import com.codingapi.flow.workflow.Workflow; import com.codingapi.flow.workflow.WorkflowBuilder; -import com.codingapi.springboot.script.scanner.GroovyScriptAnnotationScannerUtils; +import com.codingapi.flow.script.ref.ScriptRefScanner; import org.junit.jupiter.api.Test; import java.util.HashMap; @@ -93,7 +93,7 @@ void create() { .addNode(endNode) .build(); - List keys = GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(workflow).getKeys(); + List keys = ScriptRefScanner.scan(workflow).values(); System.out.println(keys); // 审批节点默认动作新增「减签」,其人员范围脚本字段一并计入(issue #266) assertEquals(16,keys.size()); diff --git a/flow-engine-framework/src/test/java/com/codingapi/flow/transfer/WorkflowTransferServiceTest.java b/flow-engine-framework/src/test/java/com/codingapi/flow/transfer/WorkflowTransferServiceTest.java index c85101f5..c89de2dd 100644 --- a/flow-engine-framework/src/test/java/com/codingapi/flow/transfer/WorkflowTransferServiceTest.java +++ b/flow-engine-framework/src/test/java/com/codingapi/flow/transfer/WorkflowTransferServiceTest.java @@ -29,7 +29,7 @@ import com.codingapi.flow.workflow.runtime.WorkflowRuntime; import com.codingapi.springboot.script.GroovyScript; import com.codingapi.springboot.script.cache.GroovyScriptCacheContext; -import com.codingapi.springboot.script.scanner.GroovyScriptAnnotationScannerUtils; +import com.codingapi.flow.script.ref.ScriptRefScanner; import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; @@ -242,7 +242,7 @@ void shouldDeleteAllVersionScriptsAndKeepRuntimeSnapshot() { Set designScriptKeys = workflowScriptKeys(versions); designScriptKeys.addAll( - GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(workflow).getKeys()); + ScriptRefScanner.scan(workflow).values()); WorkflowRuntime runtime = new WorkflowRuntime(workflow); factory.workflowService.saveWorkflowRuntime(runtime); Map runtimeScripts = new HashMap<>(runtime.getScripts()); @@ -409,7 +409,7 @@ private User saveOperator(MyFlowServiceFactory factory, long id, String name) { private Set workflowScriptKeys(List versions) { Set keys = new HashSet<>(); versions.forEach(version -> keys.addAll( - GroovyScriptAnnotationScannerUtils.findGroovyScriptFields(version).getKeys())); + ScriptRefScanner.scan(version).values())); return keys; } diff --git a/flow-engine-framework/src/test/resources/META-INF/services/com.codingapi.flow.gateway.IScriptGatewayProvider b/flow-engine-framework/src/test/resources/META-INF/services/com.codingapi.flow.gateway.IScriptGatewayProvider new file mode 100644 index 00000000..776d10f0 --- /dev/null +++ b/flow-engine-framework/src/test/resources/META-INF/services/com.codingapi.flow.gateway.IScriptGatewayProvider @@ -0,0 +1 @@ +com.codingapi.flow.mock.TestScriptGatewayProvider diff --git a/flow-engine-starter-api/pom.xml b/flow-engine-starter-api/pom.xml index 1158225b..0e526e00 100644 --- a/flow-engine-starter-api/pom.xml +++ b/flow-engine-starter-api/pom.xml @@ -25,7 +25,7 @@ com.codingapi.flow - flow-engine-starter-infra + flow-engine-starter-infra-db diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-db/pom.xml b/flow-engine-starter-infra/flow-engine-starter-infra-db/pom.xml new file mode 100644 index 00000000..0a6e7662 --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-db/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + com.codingapi.flow + flow-engine-parent + ${revision} + ../../pom.xml + + + flow-engine-starter-infra-db + flow-engine-starter-infra-db + + 流程数据的 JPA 持久化实现(issue #316) + + + UTF-8 + + + + + + com.codingapi.flow + flow-engine-framework + + + + com.codingapi.springboot + springboot-starter-data-fast + + + + com.h2database + h2 + runtime + + + com.mysql + mysql-connector-j + runtime + + + org.postgresql + postgresql + runtime + + + org.projectlombok + lombok + true + + + + + diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/AutoConfiguration.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/AutoConfiguration.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/AutoConfiguration.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/AutoConfiguration.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/FlowJpaPackageRegistrar.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/FlowJpaPackageRegistrar.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/FlowJpaPackageRegistrar.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/FlowJpaPackageRegistrar.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/DelayTaskConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/DelayTaskConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/DelayTaskConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/DelayTaskConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowRecordConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowRecordConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowRecordConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowRecordConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowTodoMargeConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowTodoMargeConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowTodoMargeConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowTodoMargeConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowTodoRecordConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowTodoRecordConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/FlowTodoRecordConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/FlowTodoRecordConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/UrgeIntervalConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/UrgeIntervalConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/UrgeIntervalConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/UrgeIntervalConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/WorkflowConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/WorkflowConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/WorkflowConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/WorkflowConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/WorkflowRuntimeConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/WorkflowRuntimeConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/WorkflowRuntimeConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/WorkflowRuntimeConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/WorkflowVersionConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/WorkflowVersionConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/convert/WorkflowVersionConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/convert/WorkflowVersionConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/DelayTaskEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/DelayTaskEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/DelayTaskEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/DelayTaskEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowOperatorAssignmentEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowOperatorAssignmentEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowOperatorAssignmentEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowOperatorAssignmentEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowRecordEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowRecordEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowRecordEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowRecordEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowReissueRecordEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowReissueRecordEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowReissueRecordEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowReissueRecordEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowTodoMargeEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowTodoMargeEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowTodoMargeEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowTodoMargeEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowTodoRecordEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowTodoRecordEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/FlowTodoRecordEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/FlowTodoRecordEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/ParallelControlEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/ParallelControlEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/ParallelControlEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/ParallelControlEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/SubProcessRecordEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/SubProcessRecordEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/SubProcessRecordEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/SubProcessRecordEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/UrgeIntervalEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/UrgeIntervalEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/UrgeIntervalEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/UrgeIntervalEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/WorkflowEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/WorkflowEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/WorkflowEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/WorkflowEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/WorkflowRuntimeEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/WorkflowRuntimeEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/WorkflowRuntimeEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/WorkflowRuntimeEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/WorkflowVersionEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/WorkflowVersionEntity.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/WorkflowVersionEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/WorkflowVersionEntity.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/FlowNodeListConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/FlowNodeListConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/FlowNodeListConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/FlowNodeListConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/FlowOperatorConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/FlowOperatorConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/FlowOperatorConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/FlowOperatorConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/FormMetaConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/FormMetaConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/FormMetaConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/FormMetaConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/MapConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/MapConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/MapConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/MapConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/OperatorMatchScriptConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/OperatorMatchScriptConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/OperatorMatchScriptConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/OperatorMatchScriptConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/WorkflowStrategyListConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/WorkflowStrategyListConvertor.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/entity/convert/WorkflowStrategyListConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/entity/convert/WorkflowStrategyListConvertor.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/DelayTaskEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/DelayTaskEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/DelayTaskEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/DelayTaskEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowOperatorAssignmentEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowOperatorAssignmentEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowOperatorAssignmentEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowOperatorAssignmentEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowRecordEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowRecordEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowRecordEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowRecordEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowReissueRecordEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowReissueRecordEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowReissueRecordEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowReissueRecordEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoMargeEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoMargeEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoMargeEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoMargeEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoRecordEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoRecordEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoRecordEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/FlowTodoRecordEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/ParallelControlEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/ParallelControlEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/ParallelControlEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/ParallelControlEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/SubProcessRecordEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/SubProcessRecordEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/SubProcessRecordEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/SubProcessRecordEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/UrgeIntervalEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/UrgeIntervalEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/UrgeIntervalEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/UrgeIntervalEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/WorkflowEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/WorkflowEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/WorkflowEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/WorkflowEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/WorkflowRuntimeEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/WorkflowRuntimeEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/WorkflowRuntimeEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/WorkflowRuntimeEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/WorkflowVersionEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/WorkflowVersionEntityRepository.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/jpa/WorkflowVersionEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/jpa/WorkflowVersionEntityRepository.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/pojo/WorkflowOption.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/pojo/WorkflowOption.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/pojo/WorkflowOption.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/pojo/WorkflowOption.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/pojo/WorkflowVersionOption.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/pojo/WorkflowVersionOption.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/pojo/WorkflowVersionOption.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/pojo/WorkflowVersionOption.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/DelayTaskRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/DelayTaskRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/DelayTaskRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/DelayTaskRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowOperatorAssignmentRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowOperatorAssignmentRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowOperatorAssignmentRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowOperatorAssignmentRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowRecordRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowRecordRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowRecordRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowRecordRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowReissueRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowReissueRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowReissueRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowReissueRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoMergeRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoMergeRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoMergeRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoMergeRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoRecordRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoRecordRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoRecordRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/FlowTodoRecordRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/ParallelBranchRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/ParallelBranchRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/ParallelBranchRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/ParallelBranchRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/SubProcessRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/SubProcessRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/SubProcessRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/SubProcessRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/UrgeIntervalRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/UrgeIntervalRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/UrgeIntervalRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/UrgeIntervalRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRuntimeRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRuntimeRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRuntimeRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowRuntimeRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowVersionRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowVersionRepositoryImpl.java similarity index 100% rename from flow-engine-starter-infra/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowVersionRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/java/com/codingapi/flow/infra/repository/impl/WorkflowVersionRepositoryImpl.java diff --git a/flow-engine-starter-infra/src/main/resources/META-INF/spring.factories b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/resources/META-INF/spring.factories similarity index 100% rename from flow-engine-starter-infra/src/main/resources/META-INF/spring.factories rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/resources/META-INF/spring.factories diff --git a/flow-engine-starter-infra/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports similarity index 100% rename from flow-engine-starter-infra/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertorTest.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertorTest.java similarity index 100% rename from flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertorTest.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/FlowRecordContentConvertorTest.java diff --git a/flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/FlowRecordIdentityConvertorTest.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/FlowRecordIdentityConvertorTest.java similarity index 100% rename from flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/FlowRecordIdentityConvertorTest.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/FlowRecordIdentityConvertorTest.java diff --git a/flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertorTest.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertorTest.java similarity index 100% rename from flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertorTest.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/FlowReissueRecordConvertorTest.java diff --git a/flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertorTest.java b/flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertorTest.java similarity index 100% rename from flow-engine-starter-infra/src/test/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertorTest.java rename to flow-engine-starter-infra/flow-engine-starter-infra-db/src/test/java/com/codingapi/flow/infra/convert/SubProcessRecordConvertorTest.java diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/pom.xml b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/pom.xml new file mode 100644 index 00000000..ef8559bd --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + com.codingapi.flow + flow-engine-parent + ${revision} + ../../pom.xml + + + flow-engine-starter-infra-groovy + flow-engine-starter-infra-groovy + + 脚本执行端口的 Groovy 实现与脚本持久化(issue #316) + + + UTF-8 + + + + + + com.codingapi.flow + flow-engine-framework + + + + com.codingapi.springboot + springboot-starter-script + + + + com.codingapi.springboot + springboot-starter-data-fast + + + + org.projectlombok + lombok + true + + + + + diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/AutoConfiguration.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/AutoConfiguration.java new file mode 100644 index 00000000..3788d180 --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/AutoConfiguration.java @@ -0,0 +1,67 @@ +package com.codingapi.flow.infra.groovy; + +import com.codingapi.flow.gateway.IScriptGatewayProvider; +import com.codingapi.flow.infra.groovy.jpa.GroovyScriptEntityRepository; +import com.codingapi.flow.infra.groovy.jpa.NodeViewJavaScriptEntityRepository; +import com.codingapi.flow.infra.groovy.jpa.TempGroovyScriptEntityRepository; +import com.codingapi.flow.infra.groovy.register.ScriptGatewayRegister; +import com.codingapi.flow.infra.groovy.repository.impl.GroovyScriptRepositoryImpl; +import com.codingapi.flow.infra.groovy.repository.impl.NodeViewJavaScriptRepositoryImpl; +import com.codingapi.flow.infra.groovy.repository.impl.TempGroovyScriptRepositoryImpl; +import com.codingapi.flow.repository.NodeViewJavaScriptRepository; +import com.codingapi.springboot.script.repository.GroovyScriptRepository; +import com.codingapi.springboot.script.repository.TempGroovyScriptRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 脚本能力自动装配(issue #316)。 + *

+ * 默认 key 模式:引用为脚本 key,正文由脚本仓储提供。设置 + * {@code flow.script.ref-mode=inline} 切换为正文模式:引用即脚本正文,不落脚本库。 + * 接入方提供自定义 {@link IScriptGatewayProvider} 时优先使用自定义实现。 + */ +@Configuration +@ConditionalOnClass(name = "com.codingapi.springboot.script.GroovyScript") +public class AutoConfiguration { + + @Bean + @ConditionalOnMissingBean(GroovyScriptRepository.class) + public GroovyScriptRepository groovyScriptRepository(GroovyScriptEntityRepository repository) { + return new GroovyScriptRepositoryImpl(repository); + } + + @Bean + @ConditionalOnMissingBean(TempGroovyScriptRepository.class) + public TempGroovyScriptRepository tempGroovyScriptRepository(TempGroovyScriptEntityRepository repository) { + return new TempGroovyScriptRepositoryImpl(repository); + } + + @Bean + @ConditionalOnMissingBean(NodeViewJavaScriptRepository.class) + public NodeViewJavaScriptRepository nodeViewJavaScriptRepository(NodeViewJavaScriptEntityRepository repository) { + return new NodeViewJavaScriptRepositoryImpl(repository); + } + + @Bean + @ConditionalOnMissingBean(IScriptGatewayProvider.class) + @ConditionalOnProperty(name = "flow.script.ref-mode", havingValue = "key", matchIfMissing = true) + public IScriptGatewayProvider keyModeScriptGatewayProvider() { + return new KeyModeScriptGatewayProvider(); + } + + @Bean + @ConditionalOnMissingBean(IScriptGatewayProvider.class) + @ConditionalOnProperty(name = "flow.script.ref-mode", havingValue = "inline") + public IScriptGatewayProvider inlineScriptGatewayProvider() { + return new InlineScriptGatewayProvider(); + } + + @Bean + public ScriptGatewayRegister scriptGatewayRegister(IScriptGatewayProvider provider) { + return new ScriptGatewayRegister(provider); + } +} diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/InlineScriptGatewayProvider.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/InlineScriptGatewayProvider.java new file mode 100644 index 00000000..76a6d884 --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/InlineScriptGatewayProvider.java @@ -0,0 +1,103 @@ +package com.codingapi.flow.infra.groovy; + +import com.codingapi.flow.gateway.IScriptEditor; +import com.codingapi.flow.gateway.IScriptExecutor; +import com.codingapi.flow.gateway.IScriptGatewayProvider; +import com.codingapi.flow.gateway.IScriptResolver; +import com.codingapi.springboot.script.GroovyScript; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 正文模式:流程定义直接保存脚本正文,framework 与实现都不生成脚本 key。 + *

+ * 定义本身已固化脚本,因此运行时快照为空;保存、版本隔离、删除与导入重建均为空操作。 + */ +public class InlineScriptGatewayProvider implements IScriptGatewayProvider, + IScriptExecutor, IScriptResolver, IScriptEditor { + + @Override + public IScriptExecutor executor() { + return this; + } + + @Override + public IScriptResolver resolver() { + return this; + } + + @Override + public IScriptEditor editor() { + return this; + } + + private GroovyScript build(String content) { + return GroovyScript.builder("inline-" + Integer.toHexString(content.hashCode())) + .script(content) + .method("run") + .build(); + } + + @Override + @SuppressWarnings("unchecked") + public T execute(String ref, Map binds, Object... args) { + return (T) build(ref).invoke(binds, args); + } + + @Override + @SuppressWarnings("unchecked") + public T executeContent(String ref, String content, Map binds, Object... args) { + return (T) build(content).invoke(binds, args); + } + + @Override + public String getScript(String ref) { + return ref; + } + + @Override + public String resolve(String ref) { + return ref; + } + + /** 流程定义已自固化正文,无需运行时快照。 */ + @Override + public Map snapshot(Collection refs) { + return Collections.emptyMap(); + } + + @Override + public Map export(Collection refs) { + Map scripts = new LinkedHashMap<>(); + for (String ref : refs) { + scripts.put(ref, ref); + } + return scripts; + } + + @Override + public void onSave(Collection refs) { + } + + @Override + public String onVersionCopy(String ref) { + return ref; + } + + @Override + public void onDelete(Collection refs) { + } + + @Override + public String normalize(String ref, String scriptType) { + return ref; + } + + @Override + public Map onImport(Map contents, Map refTypes) { + return Collections.emptyMap(); + } +} diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/KeyModeScriptGatewayProvider.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/KeyModeScriptGatewayProvider.java new file mode 100644 index 00000000..9066842e --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/KeyModeScriptGatewayProvider.java @@ -0,0 +1,228 @@ +package com.codingapi.flow.infra.groovy; + +import com.codingapi.flow.exception.FlowStateException; +import com.codingapi.flow.exception.WorkflowTransferException; +import com.codingapi.flow.gateway.IScriptEditor; +import com.codingapi.flow.gateway.IScriptExecutor; +import com.codingapi.flow.gateway.IScriptGatewayProvider; +import com.codingapi.flow.gateway.IScriptResolver; +import com.codingapi.flow.generator.FlowIDGeneratorGatewayContext; +import com.codingapi.flow.infra.groovy.factory.FlowGroovyScriptFactory; +import com.codingapi.springboot.script.GroovyScript; +import com.codingapi.springboot.script.cache.GroovyScriptCacheContext; +import com.codingapi.springboot.script.repository.GroovyScriptRepositoryContext; +import com.codingapi.springboot.script.temp.TempGroovyScriptContext; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * key 模式(默认):脚本引用是脚本 key,正文由Groovy 脚本缓存与仓储提供。 + *

+ * 同时兼容内联正文引用,保证历史设计数据与默认脚本可直接执行。 + */ +public class KeyModeScriptGatewayProvider implements IScriptGatewayProvider, + IScriptExecutor, IScriptResolver, IScriptEditor { + + @Override + public IScriptExecutor executor() { + return this; + } + + @Override + public IScriptResolver resolver() { + return this; + } + + @Override + public IScriptEditor editor() { + return this; + } + + private static boolean isInline(String ref) { + return ref != null && (ref.contains("def run") || ref.contains("\n") || ref.contains("\r")); + } + + private static GroovyScript buildInline(String content) { + return GroovyScript.builder("inline-" + Integer.toHexString(content.hashCode())) + .script(content) + .method("run") + .build(); + } + + @Override + @SuppressWarnings("unchecked") + public T execute(String ref, Map binds, Object... args) { + if (isInline(ref)) { + return (T) buildInline(ref).invoke(binds, args); + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached == null) { + throw FlowStateException.scriptNotFound(ref); + } + return (T) cached.invoke(binds, args); + } + + @Override + @SuppressWarnings("unchecked") + public T executeContent(String ref, String content, Map binds, Object... args) { + GroovyScript cached = isInline(ref) ? null + : GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + GroovyScript.Builder builder = GroovyScript.builder(ref) + .script(content) + .method(cached != null && cached.getMethod() != null ? cached.getMethod() : "run"); + if (cached != null) { + builder.returnType(cached.getReturnType()) + .typeOne(cached.getTypeOne()) + .typeTwo(cached.getTypeTwo()) + .binds(cached.getBinds()) + .requests(cached.getRequests()); + } + return (T) builder.build().invoke(binds, args); + } + + @Override + public String getScript(String ref) { + if (isInline(ref)) { + return ref; + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached == null) { + throw FlowStateException.scriptNotFound(ref); + } + return cached.getScript(); + } + + @Override + public String resolve(String ref) { + return getScript(ref); + } + + @Override + public Map snapshot(Collection refs) { + Map scripts = new LinkedHashMap<>(); + for (String ref : refs) { + if (isInline(ref)) { + continue; + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached != null && cached.getScript() != null) { + scripts.put(ref, cached.getScript()); + } + } + return scripts; + } + + @Override + public Map export(Collection refs) { + Map scripts = new LinkedHashMap<>(); + for (String ref : refs) { + String content = contentForImport(ref); + if (content == null) { + throw WorkflowTransferException.scriptNotFound(ref); + } + scripts.put(ref, content); + } + return scripts; + } + + @Override + public void onSave(Collection refs) { + for (String ref : refs) { + if (isInline(ref)) { + continue; + } + GroovyScript temp = TempGroovyScriptContext.getInstance().getGroovyScript(ref); + if (temp != null) { + temp.save(); + } + } + } + + @Override + public String onVersionCopy(String ref) { + if (isInline(ref)) { + return ref; + } + GroovyScript current = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (current == null) { + throw FlowStateException.scriptNotFound(ref); + } + GroovyScript latest = current.copy(FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey()); + latest.save(); + return latest.getKey(); + } + + @Override + public void onDelete(Collection refs) { + for (String ref : refs) { + if (isInline(ref)) { + continue; + } + GroovyScriptRepositoryContext.getInstance().delete(ref); + GroovyScriptCacheContext.getInstance().remove(ref); + } + } + + @Override + public String normalize(String ref, String scriptType) { + if (!isInline(ref)) { + return ref; + } + return create(scriptType, ref).getKey(); + } + + @Override + public Map onImport(Map contents, Map refTypes) { + Map mapping = new LinkedHashMap<>(); + Map rebuilt = new LinkedHashMap<>(); + try { + for (Map.Entry entry : contents.entrySet()) { + String oldRef = entry.getKey(); + String content = entry.getValue() != null ? entry.getValue() : contentForImport(oldRef); + GroovyScript script = create(refTypes.get(oldRef), content); + rebuilt.put(oldRef, script); + mapping.put(oldRef, script.getKey()); + } + rebuilt.values().forEach(GroovyScript::save); + return mapping; + } catch (RuntimeException exception) { + rebuilt.values().forEach(GroovyScript::remove); + throw exception; + } + } + + private String contentForImport(String ref) { + if (isInline(ref)) { + return ref; + } + GroovyScript cached = GroovyScriptCacheContext.getInstance().getGroovyScript(ref); + if (cached != null && cached.getScript() != null) { + return cached.getScript(); + } + throw WorkflowTransferException.scriptNotFound(ref); + } + + private GroovyScript create(String type, String content) { + if (type == null) { + throw WorkflowTransferException.scriptTypeUnsupported("null"); + } + return switch (type) { + case "RouterNodeScript" -> FlowGroovyScriptFactory.createRouterScript(content); + case "NodeTitleScript" -> FlowGroovyScriptFactory.createNodeTitleScript(content); + case "ConditionScript" -> FlowGroovyScriptFactory.createConditionScript(content); + case "TriggerScript" -> FlowGroovyScriptFactory.createTriggerScript(content); + case "SubProcessScript" -> FlowGroovyScriptFactory.createSubProcessScript(content); + case "SubProcessResultScript" -> FlowGroovyScriptFactory.createSubProcessResultScript(content); + case "OperatorLoadScript" -> FlowGroovyScriptFactory.createOperatorLoadScript(content); + case "OperatorMatchScript" -> FlowGroovyScriptFactory.createOperatorMatchScript(content); + case "ErrorTriggerScript" -> FlowGroovyScriptFactory.createErrorTriggerScript(content); + case "ActionDisplayScript" -> FlowGroovyScriptFactory.createActionDisplayScript(content); + case "ActionCustomScript" -> FlowGroovyScriptFactory.createActionCustomScript(content); + case "ActionRejectScript" -> FlowGroovyScriptFactory.createActionRejectScript(content); + default -> throw WorkflowTransferException.scriptTypeUnsupported(type); + }; + } +} diff --git a/flow-engine-example/src/main/java/com/codingapi/example/convertor/GroovyScriptConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/GroovyScriptConvertor.java similarity index 96% rename from flow-engine-example/src/main/java/com/codingapi/example/convertor/GroovyScriptConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/GroovyScriptConvertor.java index a4fe04bc..fe046ac8 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/convertor/GroovyScriptConvertor.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/GroovyScriptConvertor.java @@ -1,7 +1,7 @@ -package com.codingapi.example.convertor; +package com.codingapi.flow.infra.groovy.convert; import com.alibaba.fastjson.JSON; -import com.codingapi.example.entity.GroovyScriptEntity; +import com.codingapi.flow.infra.groovy.entity.GroovyScriptEntity; import com.codingapi.springboot.script.GroovyScript; import lombok.SneakyThrows; import org.springframework.util.StringUtils; diff --git a/flow-engine-example/src/main/java/com/codingapi/example/convertor/NodeViewJavaScriptConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/NodeViewJavaScriptConvertor.java similarity index 87% rename from flow-engine-example/src/main/java/com/codingapi/example/convertor/NodeViewJavaScriptConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/NodeViewJavaScriptConvertor.java index 630e9606..75c5595f 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/convertor/NodeViewJavaScriptConvertor.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/NodeViewJavaScriptConvertor.java @@ -1,6 +1,6 @@ -package com.codingapi.example.convertor; +package com.codingapi.flow.infra.groovy.convert; -import com.codingapi.example.entity.NodeViewJavaScriptEntity; +import com.codingapi.flow.infra.groovy.entity.NodeViewJavaScriptEntity; import com.codingapi.flow.javscript.NodeViewJavaScript; public class NodeViewJavaScriptConvertor { diff --git a/flow-engine-example/src/main/java/com/codingapi/example/convertor/TempGroovyScriptConvertor.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/TempGroovyScriptConvertor.java similarity index 95% rename from flow-engine-example/src/main/java/com/codingapi/example/convertor/TempGroovyScriptConvertor.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/TempGroovyScriptConvertor.java index 081e41d3..7588b277 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/convertor/TempGroovyScriptConvertor.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/convert/TempGroovyScriptConvertor.java @@ -1,7 +1,7 @@ -package com.codingapi.example.convertor; +package com.codingapi.flow.infra.groovy.convert; import com.alibaba.fastjson.JSON; -import com.codingapi.example.entity.TempGroovyScriptEntity; +import com.codingapi.flow.infra.groovy.entity.TempGroovyScriptEntity; import com.codingapi.springboot.script.GroovyScript; import com.codingapi.springboot.script.temp.TempGroovyScript; import lombok.SneakyThrows; diff --git a/flow-engine-example/src/main/java/com/codingapi/example/entity/GroovyScriptEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/GroovyScriptEntity.java similarity index 95% rename from flow-engine-example/src/main/java/com/codingapi/example/entity/GroovyScriptEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/GroovyScriptEntity.java index 61d8c315..5d0cd55c 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/entity/GroovyScriptEntity.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/GroovyScriptEntity.java @@ -1,4 +1,4 @@ -package com.codingapi.example.entity; +package com.codingapi.flow.infra.groovy.entity; import jakarta.persistence.*; import lombok.Data; diff --git a/flow-engine-example/src/main/java/com/codingapi/example/entity/NodeViewJavaScriptEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/NodeViewJavaScriptEntity.java similarity index 92% rename from flow-engine-example/src/main/java/com/codingapi/example/entity/NodeViewJavaScriptEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/NodeViewJavaScriptEntity.java index 0c955753..167bef01 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/entity/NodeViewJavaScriptEntity.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/NodeViewJavaScriptEntity.java @@ -1,4 +1,4 @@ -package com.codingapi.example.entity; +package com.codingapi.flow.infra.groovy.entity; import jakarta.persistence.Entity; import jakarta.persistence.Id; diff --git a/flow-engine-example/src/main/java/com/codingapi/example/entity/TempGroovyScriptEntity.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/TempGroovyScriptEntity.java similarity index 96% rename from flow-engine-example/src/main/java/com/codingapi/example/entity/TempGroovyScriptEntity.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/TempGroovyScriptEntity.java index 67a8fca0..c054ca3f 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/entity/TempGroovyScriptEntity.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/entity/TempGroovyScriptEntity.java @@ -1,4 +1,4 @@ -package com.codingapi.example.entity; +package com.codingapi.flow.infra.groovy.entity; import jakarta.persistence.*; import lombok.Data; diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/factory/FlowGroovyScriptFactory.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/factory/FlowGroovyScriptFactory.java new file mode 100644 index 00000000..28de67a0 --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/factory/FlowGroovyScriptFactory.java @@ -0,0 +1,318 @@ +package com.codingapi.flow.infra.groovy.factory; + +import com.codingapi.flow.generator.FlowIDGeneratorGatewayContext; +import com.codingapi.flow.pojo.request.FlowCreateRequest; +import com.codingapi.flow.script.request.GroovyScriptBind; +import com.codingapi.flow.script.request.GroovyScriptRequest; +import com.codingapi.flow.script.request.GroovyWorkflowRequest; +import com.codingapi.springboot.script.GroovyScript; + +import java.util.List; +import java.util.Map; + +public class FlowGroovyScriptFactory { + + public static final String DEFAULT_SCRIPT_TYPE_ONE = "flow"; + + public static GroovyScript createRouterScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 路由触发脚本 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 String 类型。 + 返回的是为跳转的流程节点 id,即 nodeId。 + """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("router-script") + .description(description) + .method("run") + .returnType(String.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createNodeTitleScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 节点待办标题脚本 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 String 类型,即为展示的待办标题数据。 + 标题数据支持 HTML 语法格式,以适配不同的标题表现形式。例如:
return '你好,<span style="color:red">XXX</span>你有一个待办数据' + """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("node-title") + .description(description) + .method("run") + .returnType(String.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createConditionScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 条件匹配脚本 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 Boolean 类型。返回 true 则为满足条件,执行后续操作;返回 false 则不执行后续条件。 + 当所有条件都不满足时,默认会执行其他情况,即 else 的操作逻辑。 + """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("condition") + .description(description) + .method("run") + .returnType(Boolean.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createTriggerScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 触发节点脚本 + 脚本说明:即用户自定义处理逻辑。 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 Void 类型,即不需要返回数据。 + """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("trigger") + .description(description) + .method("run") + .returnType(Void.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createSubProcessScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 子流程任务脚本 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 FlowCreateRequest 类型。 + 该对象是流程发起的参数对象,通过构建该对象控制子流程触发的流程节点。 + """; + + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("sub-process") + .description(description) + .method("run") + .returnType(Object.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createSubProcessResultScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 子流程结果确认脚本 + 每个子流程结束时执行,返回 true 时主流程继续;全部结束仍返回 false 时执行异常配置。 + request 可获取子流程总数、本次结束记录以及指定节点的全部最终记录。 + """; + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("sub-process-result") + .description(description) + .method("run") + .returnType(Boolean.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createOperatorLoadScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 匹配人员列表脚本 + 传入对象为 GroovyScriptRequest 对象,返回数据格式支持三种,且允许在同一列表中混用: +

    +
  • List<Long>:人员 id 列表(默认身份),示例 [1,2,3];
  • +
  • List<OperatorKey>:带身份的人员标识,示例 [request.getCreatedOperatorKey()]、[$bind.getOperatorKey(2,'department1')];
  • +
  • List<IFlowOperator>:操作者对象,直接采用且不回查,示例 [$bind.getOperatorByIdentity(2,'department1')]、request.findPreviousNodeOperators()。
  • +
+ 返回的人员将会作为该节点的审批者,身份随记录落库。 + """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("operator-load") + .description(description) + .method("run") + .returnType(List.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createOperatorMatchScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 人员匹配脚本 + 传入对象为 GroovyWorkflowRequest 类型的 request 对象,返回数据为 Boolean 类型。返回 true 时表明该人拥有发起流程的权限,否则反之。 + """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("operator-match") + .description(description) + .method("run") + .returnType(Boolean.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyWorkflowRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createErrorTriggerScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 异常触发脚本 + 脚本说明:所谓的异常脚本,是指流程在执行时没有匹配到审批人员时触发的情况。 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 Object 类型,实际支持以下数据结构: +
    +
  • String 格式:对应的节点 id(nodeId)。当返回字符串类型的节点 id 时,出现异常时会跳转到对应的节点上执行审批。
  • +
  • 人员列表格式:支持 List<Long>(默认身份,示例 return [1,2,3])、List<OperatorKey>(带身份,示例 return [request.getCreatedOperatorKey()])、List<IFlowOperator>(对象直接采用,示例 return [$bind.getOperatorByIdentity(2,'department1')])。当返回人员列表时,代表指定审批人员,即当异常时将会将这个流程转交给指定的这些人员来审批。
  • +
  • Map 格式:[type:'prompt', message:'...'] 异常提示,或 [type:'node', node:'节点id']、[type:'operators', operators:[...]] 显式声明类型。
  • +
+ """; + + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("error-trigger") + .description(description) + .method("run") + .returnType(Object.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + + public static GroovyScript createActionDisplayScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 动作按钮展示脚本 + 脚本说明:实现是否展示改动作按钮的控制。 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 boolean 类型,当为true时则展示按钮: + """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("action-display") + .description(description) + .method("run") + .returnType(Boolean.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createActionCustomScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 自定义脚本 + 脚本说明:即当点击自定义按钮时的操作逻辑,在完成自定义的业务之后,需要再联动一个动作。 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 String 类型,为操作类型。数据分类及对应的业务含义如下: +
    +
  • SAVE — 保存
  • +
  • PASS — 通过
  • +
  • REJECT — 拒绝
  • +
  • ADD_AUDIT — 加签
  • +
  • DELEGATE — 委派
  • +
  • RETURN — 退回
  • +
  • TRANSFER — 转办
  • +
+ """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("action-custom") + .description(description) + .method("run") + .returnType(String.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + + public static GroovyScript createActionRejectScript(String script) { + String key = FlowIDGeneratorGatewayContext.getInstance().generateFlowScriptKey(); + String description = """ + 拒绝操作脚本 + 脚本说明:即当用户点击拒绝时会发生的处理逻辑。 + 传入对象为 GroovyScriptRequest 对象,返回数据格式为 String 类型,数据分为两种情况: +
    +
  • 返回固定的 TERMINATE 字符串,代表终止流程。
  • +
  • 返回节点 id,即 nodeId 的字符串,代表跳转到指定的节点。
  • +
+ """; + + GroovyScript groovyScript = GroovyScript.builder(key) + .script(script) + .typeOne(DEFAULT_SCRIPT_TYPE_ONE) + .typeTwo("action-reject") + .description(description) + .method("run") + .returnType(String.class) + .binds(Map.of("$bind", GroovyScriptBind.class)) + .requests(Map.of("request", GroovyScriptRequest.class)) + .build(); + + groovyScript.temp(); + return groovyScript; + } + +} diff --git a/flow-engine-example/src/main/java/com/codingapi/example/repository/GroovyScriptEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/GroovyScriptEntityRepository.java similarity index 67% rename from flow-engine-example/src/main/java/com/codingapi/example/repository/GroovyScriptEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/GroovyScriptEntityRepository.java index b08ed072..371a9164 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/repository/GroovyScriptEntityRepository.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/GroovyScriptEntityRepository.java @@ -1,6 +1,6 @@ -package com.codingapi.example.repository; +package com.codingapi.flow.infra.groovy.jpa; -import com.codingapi.example.entity.GroovyScriptEntity; +import com.codingapi.flow.infra.groovy.entity.GroovyScriptEntity; import com.codingapi.springboot.fast.jpa.repository.FastRepository; public interface GroovyScriptEntityRepository extends FastRepository { diff --git a/flow-engine-example/src/main/java/com/codingapi/example/repository/NodeViewJavaScriptEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/NodeViewJavaScriptEntityRepository.java similarity index 68% rename from flow-engine-example/src/main/java/com/codingapi/example/repository/NodeViewJavaScriptEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/NodeViewJavaScriptEntityRepository.java index ea3930d7..f46cf376 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/repository/NodeViewJavaScriptEntityRepository.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/NodeViewJavaScriptEntityRepository.java @@ -1,6 +1,6 @@ -package com.codingapi.example.repository; +package com.codingapi.flow.infra.groovy.jpa; -import com.codingapi.example.entity.NodeViewJavaScriptEntity; +import com.codingapi.flow.infra.groovy.entity.NodeViewJavaScriptEntity; import com.codingapi.springboot.fast.jpa.repository.FastRepository; public interface NodeViewJavaScriptEntityRepository extends FastRepository { diff --git a/flow-engine-example/src/main/java/com/codingapi/example/repository/TempGroovyScriptEntityRepository.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/TempGroovyScriptEntityRepository.java similarity index 68% rename from flow-engine-example/src/main/java/com/codingapi/example/repository/TempGroovyScriptEntityRepository.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/TempGroovyScriptEntityRepository.java index 42d18200..46a971e1 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/repository/TempGroovyScriptEntityRepository.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/jpa/TempGroovyScriptEntityRepository.java @@ -1,6 +1,6 @@ -package com.codingapi.example.repository; +package com.codingapi.flow.infra.groovy.jpa; -import com.codingapi.example.entity.TempGroovyScriptEntity; +import com.codingapi.flow.infra.groovy.entity.TempGroovyScriptEntity; import com.codingapi.springboot.fast.jpa.repository.FastRepository; public interface TempGroovyScriptEntityRepository extends FastRepository { diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/register/ScriptGatewayRegister.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/register/ScriptGatewayRegister.java new file mode 100644 index 00000000..0280d2e6 --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/register/ScriptGatewayRegister.java @@ -0,0 +1,20 @@ +package com.codingapi.flow.infra.groovy.register; + +import com.codingapi.flow.gateway.FlowScriptGatewayContext; +import com.codingapi.flow.gateway.IScriptGatewayProvider; +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.InitializingBean; + +/** + * 把脚本 Gateway 装配进 framework 的静态上下文(与 GatewayContextRegister 同一模式)。 + */ +@AllArgsConstructor +public class ScriptGatewayRegister implements InitializingBean { + + private final IScriptGatewayProvider provider; + + @Override + public void afterPropertiesSet() { + FlowScriptGatewayContext.getInstance().register(provider); + } +} diff --git a/flow-engine-example/src/main/java/com/codingapi/example/repository/impl/GroovyScriptRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/GroovyScriptRepositoryImpl.java similarity index 80% rename from flow-engine-example/src/main/java/com/codingapi/example/repository/impl/GroovyScriptRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/GroovyScriptRepositoryImpl.java index 0e9a7f76..69fe5a44 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/repository/impl/GroovyScriptRepositoryImpl.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/GroovyScriptRepositoryImpl.java @@ -1,16 +1,14 @@ -package com.codingapi.example.repository.impl; +package com.codingapi.flow.infra.groovy.repository.impl; -import com.codingapi.example.convertor.GroovyScriptConvertor; -import com.codingapi.example.entity.GroovyScriptEntity; -import com.codingapi.example.repository.GroovyScriptEntityRepository; +import com.codingapi.flow.infra.groovy.convert.GroovyScriptConvertor; +import com.codingapi.flow.infra.groovy.entity.GroovyScriptEntity; +import com.codingapi.flow.infra.groovy.jpa.GroovyScriptEntityRepository; import com.codingapi.springboot.script.GroovyScript; import com.codingapi.springboot.script.repository.GroovyScriptRepository; import com.codingapi.springboot.script.repository.GroovyScriptRepositoryContext; import lombok.AllArgsConstructor; import org.springframework.beans.factory.InitializingBean; -import org.springframework.stereotype.Repository; -@Repository @AllArgsConstructor public class GroovyScriptRepositoryImpl implements GroovyScriptRepository, InitializingBean { diff --git a/flow-engine-example/src/main/java/com/codingapi/example/repository/impl/NodeViewJavaScriptRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/NodeViewJavaScriptRepositoryImpl.java similarity index 77% rename from flow-engine-example/src/main/java/com/codingapi/example/repository/impl/NodeViewJavaScriptRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/NodeViewJavaScriptRepositoryImpl.java index 19e64220..8927c1b9 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/repository/impl/NodeViewJavaScriptRepositoryImpl.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/NodeViewJavaScriptRepositoryImpl.java @@ -1,13 +1,11 @@ -package com.codingapi.example.repository.impl; +package com.codingapi.flow.infra.groovy.repository.impl; -import com.codingapi.example.convertor.NodeViewJavaScriptConvertor; -import com.codingapi.example.repository.NodeViewJavaScriptEntityRepository; +import com.codingapi.flow.infra.groovy.convert.NodeViewJavaScriptConvertor; +import com.codingapi.flow.infra.groovy.jpa.NodeViewJavaScriptEntityRepository; import com.codingapi.flow.javscript.NodeViewJavaScript; import com.codingapi.flow.repository.NodeViewJavaScriptRepository; import lombok.AllArgsConstructor; -import org.springframework.stereotype.Repository; -@Repository @AllArgsConstructor public class NodeViewJavaScriptRepositoryImpl implements NodeViewJavaScriptRepository { diff --git a/flow-engine-example/src/main/java/com/codingapi/example/repository/impl/TempGroovyScriptRepositoryImpl.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/TempGroovyScriptRepositoryImpl.java similarity index 83% rename from flow-engine-example/src/main/java/com/codingapi/example/repository/impl/TempGroovyScriptRepositoryImpl.java rename to flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/TempGroovyScriptRepositoryImpl.java index c005ad6a..5e8bca2f 100644 --- a/flow-engine-example/src/main/java/com/codingapi/example/repository/impl/TempGroovyScriptRepositoryImpl.java +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/java/com/codingapi/flow/infra/groovy/repository/impl/TempGroovyScriptRepositoryImpl.java @@ -1,8 +1,8 @@ -package com.codingapi.example.repository.impl; +package com.codingapi.flow.infra.groovy.repository.impl; -import com.codingapi.example.convertor.TempGroovyScriptConvertor; -import com.codingapi.example.entity.TempGroovyScriptEntity; -import com.codingapi.example.repository.TempGroovyScriptEntityRepository; +import com.codingapi.flow.infra.groovy.convert.TempGroovyScriptConvertor; +import com.codingapi.flow.infra.groovy.entity.TempGroovyScriptEntity; +import com.codingapi.flow.infra.groovy.jpa.TempGroovyScriptEntityRepository; import com.codingapi.springboot.script.repository.TempGroovyScriptRepository; import com.codingapi.springboot.script.repository.TempGroovyScriptRepositoryContext; import com.codingapi.springboot.script.temp.TempGroovyScript; @@ -10,9 +10,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.stereotype.Repository; -@Repository @AllArgsConstructor public class TempGroovyScriptRepositoryImpl implements TempGroovyScriptRepository, InitializingBean { diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring.factories b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..1cafafcd --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +com.codingapi.flow.infra.groovy.AutoConfiguration diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..071a7350 --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.codingapi.flow.infra.groovy.AutoConfiguration diff --git a/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/test/java/com/codingapi/flow/infra/groovy/ScriptReferenceModeTest.java b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/test/java/com/codingapi/flow/infra/groovy/ScriptReferenceModeTest.java new file mode 100644 index 00000000..f86f8ac7 --- /dev/null +++ b/flow-engine-starter-infra/flow-engine-starter-infra-groovy/src/test/java/com/codingapi/flow/infra/groovy/ScriptReferenceModeTest.java @@ -0,0 +1,49 @@ +package com.codingapi.flow.infra.groovy; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * 两种脚本引用形态:key 与正文。 + */ +class ScriptReferenceModeTest { + + private static final String INLINE = "def run(request){ return 'INLINE' }"; + + @Test + void inline_mode_should_execute_content_without_any_storage() { + InlineScriptGatewayProvider provider = new InlineScriptGatewayProvider(); + + assertEquals("INLINE", provider.execute(INLINE, Map.of(), "request")); + assertEquals(INLINE, provider.getScript(INLINE)); + assertEquals(INLINE, provider.resolve(INLINE)); + } + + @Test + void inline_mode_lifecycle_should_be_no_op() { + InlineScriptGatewayProvider provider = new InlineScriptGatewayProvider(); + + assertTrue(provider.snapshot(List.of(INLINE)).isEmpty(), "定义自固化时不应生成运行时快照"); + assertEquals(Map.of(INLINE, INLINE), provider.export(List.of(INLINE))); + assertEquals(INLINE, provider.onVersionCopy(INLINE), "版本复制不应改写正文引用"); + assertEquals(INLINE, provider.normalize(INLINE, "ConditionScript"), "不应把正文强制转成 key"); + assertTrue(provider.onImport(Map.of(INLINE, INLINE), Map.of(INLINE, "ConditionScript")).isEmpty()); + provider.onSave(List.of(INLINE)); + provider.onDelete(List.of(INLINE)); + } + + @Test + void key_mode_should_accept_inline_content_for_default_scripts() { + KeyModeScriptGatewayProvider provider = new KeyModeScriptGatewayProvider(); + + assertEquals("INLINE", provider.execute(INLINE, Collections.emptyMap(), "request")); + assertEquals(INLINE, provider.getScript(INLINE)); + assertTrue(provider.snapshot(List.of(INLINE)).isEmpty(), "内联正文无需快照"); + } +} diff --git a/flow-engine-starter-infra/pom.xml b/flow-engine-starter-infra/pom.xml index 28475464..c84a4071 100644 --- a/flow-engine-starter-infra/pom.xml +++ b/flow-engine-starter-infra/pom.xml @@ -11,44 +11,13 @@ flow-engine-starter-infra flow-engine-starter-infra + pom - - UTF-8 - + 持久化与脚本能力的实现集合(issue #316) - - - - com.codingapi.flow - flow-engine-framework - - - - com.codingapi.springboot - springboot-starter-data-fast - - - - com.h2database - h2 - runtime - - - com.mysql - mysql-connector-j - runtime - - - org.postgresql - postgresql - runtime - - - org.projectlombok - lombok - true - - - + + flow-engine-starter-infra-db + flow-engine-starter-infra-groovy + diff --git a/flow-engine-starter-query/pom.xml b/flow-engine-starter-query/pom.xml index be24a19d..189715a5 100644 --- a/flow-engine-starter-query/pom.xml +++ b/flow-engine-starter-query/pom.xml @@ -25,7 +25,7 @@ com.codingapi.flow - flow-engine-starter-infra + flow-engine-starter-infra-db diff --git a/flow-engine-starter/pom.xml b/flow-engine-starter/pom.xml index 6d09f286..f8c39f8c 100644 --- a/flow-engine-starter/pom.xml +++ b/flow-engine-starter/pom.xml @@ -25,7 +25,12 @@ com.codingapi.flow - flow-engine-starter-infra + flow-engine-starter-infra-db + + + + com.codingapi.flow + flow-engine-starter-infra-groovy diff --git a/pom.xml b/pom.xml index 3cc5c7b7..6b9fbc64 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,13 @@ com.codingapi.flow - flow-engine-starter-infra + flow-engine-starter-infra-db + ${project.version} + + + + com.codingapi.flow + flow-engine-starter-infra-groovy ${project.version}