OCT REM: 1. 补全标准javadoc文档

This commit is contained in:
HuangXin 2025-03-08 09:32:32 +08:00
parent 9243d2a081
commit 113d7e577c
9 changed files with 222 additions and 52 deletions

View File

@ -16,15 +16,37 @@ import org.springframework.core.io.support.ResourcePatternResolver;
import java.io.IOException;
/**
* Drools配置类用于配置Drools规则引擎的相关Bean
*
* <p>该类负责加载和配置Drools规则包括KieFileSystemKieContainer和KieBase的创建与管理</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
@Configuration
public class DroolsConfig {
private static final String RULES_PATH = "rules/";
/**
* 获取KieServices实例用于后续规则引擎的操作
*
* @return KieServices实例
*/
private KieServices getKieServices() {
return KieServices.Factory.get();
}
/**
* 创建KieFileSystem的Bean用于管理Drools规则文件
*
* <p>此方法会遍历指定路径下的规则文件并将其写入KieFileSystem</p>
*
* @return 配置好的KieFileSystem实例
* @throws IOException 如果在读取规则文件时发生IO异常
*/
@Bean
@ConditionalOnMissingBean(KieFileSystem.class)
public KieFileSystem kieFileSystem() throws IOException {
@ -35,11 +57,27 @@ public class DroolsConfig {
return kieFileSystem;
}
/**
* 获取规则文件的Resource数组
*
* <p>该方法使用Spring的资源解析器查找classpath下指定路径的所有规则文件</p>
*
* @return 规则文件的Resource数组
* @throws IOException 如果在读取资源时发生IO异常
*/
private Resource[] getRuleFiles() throws IOException {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
return resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*");
}
/**
* 创建KieContainer的Bean用于管理Drools规则的执行环境
*
* <p>该方法会构建KieModule并返回KieContainer实例</p>
*
* @return 配置好的KieContainer实例
* @throws IOException 如果在创建KieContainer时发生IO异常
*/
@Bean
@ConditionalOnMissingBean(KieContainer.class)
public KieContainer kieContainer() throws IOException {
@ -53,6 +91,12 @@ public class DroolsConfig {
return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
}
/**
* 创建KieBase的Bean用于提供Drools规则的基础操作接口
*
* @return 配置好的KieBase实例
* @throws IOException 如果在获取KieBase时发生IO异常
*/
@Bean
@ConditionalOnMissingBean(KieBase.class)
public KieBase kieBase() throws IOException {

View File

@ -7,13 +7,30 @@ import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.util.ArrayList;
/**
* Flowable 配置类用于配置 Flowable 引擎的相关参数
*
* <p>该类定义了 Flowable 的流程引擎配置包括数据库连接ID 生成器数据库模式更新策略等
* 并且初始化并添加了 {@link RulesDeployer} 作为自定义后部署器</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
@Configuration
public class FlowableConfig {
/**
* 创建 SpringProcessEngineConfiguration Bean
*
* <p>此方法配置了 Flowable 的数据库连接信息ID 生成器配置及其他引擎参数</p>
*
* @return 配置好的 Flowable 进程引擎配置对象
*/
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() throws IOException {
public SpringProcessEngineConfiguration processEngineConfiguration() {
DbIdGenerator dbIdGenerator = new DbIdGenerator();
dbIdGenerator.setIdBlockSize(2500);
@ -35,5 +52,4 @@ public class FlowableConfig {
return config;
}
}

View File

@ -7,14 +7,39 @@ import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 本地Shell上下文类用于封装Shell脚本执行所需的上下文信息
*
* <p>该类实现了Serializable接口以便可以在网络中传输或持久化</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
@Data
@AllArgsConstructor
public class LocalShellContext implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String workDir;
private String scriptContext;
private String deploymentTaskId;
/**
* 工作目录表示Shell脚本执行时的当前目录
*/
private String workDir;
/**
* 脚本内容表示要执行的Shell脚本的具体内容或路径
*/
private String scriptContext;
/**
* 部署任务ID表示与当前执行相关的任务标识
*/
private String deploymentTaskId;
/**
* 命令类型表示执行的中间件管理器命令类型
*/
private MiddlewareManagerCommand cmdType;
}

View File

@ -6,27 +6,44 @@ import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 远程文件上下文类用于封装与远程文件相关的上下文信息
*
* <p>该类实现了Serializable接口以便可以在网络中传输或持久化</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
@Data
@AllArgsConstructor
public class RemoteFileContext implements Serializable {
@Serial
private static final long serialVersionUID = 2L;
private String workDir;
private String deploymentTaskId;
/**
* 文件URL
* 工作目录表示远程文件存储时的当前目录
*/
public String url;
private String workDir;
/**
* 文件名
* 部署任务ID表示与当前远程文件相关的任务标识
*/
private String deploymentTaskId;
/**
* 文件URL表示远程文件的下载地址
*/
public String url;
/**
* 文件名表示远程文件的名称
*/
public String fileName;
/**
* 文件校验和
* 文件校验和用于验证文件的完整性和一致性
*/
public String checksum;
;
}

View File

@ -3,9 +3,26 @@ package com.cmcc.magent.service.workflow;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
/**
* 部署Shell服务类实现了Flowable的JavaDelegate接口
*
* <p>该类用于处理与部署相关的业务逻辑具体的执行逻辑在execute方法中实现</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
public class DeploymentShellService implements JavaDelegate {
/**
* 执行部署相关的业务逻辑
*
* <p>在此方法中可以实现具体的部署逻辑传入的执行参数可以用于获取流程变量或执行上下文</p>
*
* @param execution Flowable的DelegateExecution对象代表当前流程实例的执行上下文
*/
@Override
public void execute(DelegateExecution execution) {
// TODO: 在此实现具体的部署逻辑
}
}

View File

@ -5,25 +5,41 @@ import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.FlowableFutureJavaDelegate;
/**
* 异步下载文件服务类实现了Flowable的FlowableFutureJavaDelegate接口
*
* <p>该类负责处理文件的异步下载逻辑包括准备下载参数执行下载操作以及下载后的处理</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
@Slf4j
public class DownloadFileAsyncService implements FlowableFutureJavaDelegate<RemoteFileContext, RemoteFileContext> {
/**
* 准备执行数据
*
* <p>从流程上下文中获取下载参数并记录当前下载的状态信息</p>
*
* @param delegateExecution 异步服务上下文信息
* @return {@link RemoteFileContext} 下载参数
*/
@Override
public RemoteFileContext prepareExecutionData(DelegateExecution delegateExecution) {
RemoteFileContext c = (RemoteFileContext)delegateExecution.getVariable("downloadInfo");
RemoteFileContext c = (RemoteFileContext) delegateExecution.getVariable("downloadInfo");
log.debug("+++ DownloadFile({}/{}) --> {}",
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
c);
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
c);
return c;
}
/**
* 执行下载操作
*
* <p>根据提供的下载参数进行文件下载并返回下载参数</p>
*
* @param remoteFileContext 下载参数
* @return {@link RemoteFileContext} 下载参数
@ -34,6 +50,9 @@ public class DownloadFileAsyncService implements FlowableFutureJavaDelegate<Remo
}
/**
* 执行完成后的处理
*
* <p>记录下载的状态信息并设置流程上下文中的完成下载标识</p>
*
* @param delegateExecution 异步服务上下文信息
* @param remoteFileContext 下载参数
@ -41,9 +60,9 @@ public class DownloadFileAsyncService implements FlowableFutureJavaDelegate<Remo
@Override
public void afterExecution(DelegateExecution delegateExecution, RemoteFileContext remoteFileContext) {
log.debug("--- DownloadFile({}/{}) --> {}",
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
remoteFileContext);
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
remoteFileContext);
// 设置 assignee
delegateExecution.setVariable("finisheConfigDownload", remoteFileContext.getDeploymentTaskId());

View File

@ -1,20 +0,0 @@
package com.cmcc.magent.service.workflow;
import com.cmcc.magent.pojo.po.RemoteFileContext;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.engine.impl.context.Context;
import org.flowable.task.service.delegate.DelegateTask;
@Slf4j
public class RemoteFileFinishedService implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
RemoteFileContext fileContext = (RemoteFileContext) delegateTask.getVariable("downloadInfo");
log.info("WriteLocalShellService notify({}): {}", delegateTask.getId(), fileContext);
TaskService taskService = Context.getProcessEngineConfiguration().getTaskService();
taskService.complete(delegateTask.getId());
}
}

View File

@ -12,30 +12,48 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 规则处理服务类继承自Flowable的BusinessRuleTaskActivityBehavior
*
* <p>该类用于执行Drools规则引擎的规则处理逻辑并将结果回传到流程变量中</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
@Slf4j
public class RuleProcessService extends BusinessRuleTaskActivityBehavior {
/**
* 执行规则处理逻辑
*
* <p>该方法创建和配置KieSession设置全局变量插入事实对象执行规则并将结果存储到流程变量中</p>
*
* @param execution 代表当前流程实例的执行上下文
*/
@Override
public void execute(DelegateExecution execution) {
KieSession kieSession = null;
try {
// 创建新的Kie会话
kieSession = new DroolsConfig().kieContainer().newKieSession();
// 2. 设置全局变量与drl文件中的global定义匹配
// 设置全局变量与drl文件中的global定义匹配
Map<MiddlewareManagerCommand, String> results = new HashMap<>(10);
kieSession.setGlobal("results", results);
List<String> retCommand = new ArrayList<>();
kieSession.setGlobal("returnCommand", retCommand);
// 3. 插入事实对象从流程变量获取命令数据
// 插入事实对象从流程变量获取命令数据
kieSession.insert(execution.getVariable("execCommand"));
// 4. 执行规则
// 执行规则
int firedRules = kieSession.fireAllRules();
log.debug("Trigger {} Rules", firedRules);
// 5. 回收结果到流程变量增强版
// 回收结果到流程变量增强版
if (resultVariable != null && !resultVariable.isEmpty()) {
// 将结果同时存入显式指定的变量和默认变量
execution.setVariable(resultVariable, retCommand);
@ -43,7 +61,7 @@ public class RuleProcessService extends BusinessRuleTaskActivityBehavior {
kieSession.dispose();
} catch (Exception e) {
log.error("Rule Exeception: {0}", e);
log.error("Rule Exception: {}", e);
} finally {
if (kieSession != null) {
kieSession.dispose();

View File

@ -8,32 +8,66 @@ import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.FlowableFutureJavaDelegate;
/**
* 异步写入本地Shell服务类实现了Flowable的FlowableFutureJavaDelegate接口
*
* <p>该类用于处理与本地Shell相关的异步执行逻辑包括准备执行数据和执行后的处理</p>
*
* @author huangxin@cmhi.chinamobile.com
* @version 1.0.0
* @since 2025-03-07
*/
@Slf4j
public class WriteLocalShellAsyncService implements FlowableFutureJavaDelegate<LocalShellContext, LocalShellContext> {
@Resource
private MiddlewareManagerService middlewareManagerService = SpringBootBeanUtils.getBean(MiddlewareManagerService.class);
/**
* 准备执行数据
*
* <p>从流程上下文中获取本地Shell上下文数据记录调试日志并返回该数据</p>
*
* @param delegateExecution 代表当前流程实例的执行上下文
* @return 准备好的本地Shell上下文对象
*/
@Override
public LocalShellContext prepareExecutionData(DelegateExecution delegateExecution) {
LocalShellContext s = (LocalShellContext) delegateExecution.getVariable("middlewareManagerCommand");
log.debug("+++ WriteLocalShell({}/{}) --> {}",
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
s);
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
s);
return s;
}
/**
* 执行逻辑
*
* <p>当前方法直接返回传入的本地Shell上下文对象具有潜在的扩展性以执行更多操作</p>
*
* @param s 本地Shell上下文对象
* @return 执行后的本地Shell上下文对象
*/
@Override
public LocalShellContext execute(LocalShellContext s) {
return s;
}
/**
* 执行后的处理逻辑
*
* <p>记录调试日志并设置流程上下文中的完成命令ID</p>
*
* @param delegateExecution 代表当前流程实例的执行上下文
* @param s 本地Shell上下文对象
*/
@Override
public void afterExecution(DelegateExecution delegateExecution, LocalShellContext s) {
log.debug("--- WriteLocalShell({}/{}) --> {}",
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
s);
(Integer) delegateExecution.getVariable("loopCounter") + 1,
delegateExecution.getVariable("nrOfInstances"),
s);
// 设置 assignee
delegateExecution.setVariable("finishePrepareCommand", s.getDeploymentTaskId());