自定义状态转变谓词
状态转变谓词会针对
状态转变实现一个条件或筛选器,用于检查特定状态转变是否适用于特定上下文中的特定跟踪器项。
要使用
Java 语言开发专属/自定义谓词,需要使用 Java 7 或更新的标准版
Java Development Kit (JDK) 外加以下框架/库:
|
框架/库
|
组件
|
版本
|
|
|
|
3.4
|
|
|
spring-core
|
5.3.x
|
|
|
spring-context
|
5.3.x
|
|
|
spring-beans
|
5.3.x
|
若要开发新的自定义转变谓词,还需要从 Codebeamer 7.8.0 或更新安装版本的 ~/CB-../tomcat/webapps/cb/WEB-INF/lib 目录下获取 cb.jar。
例如:
package com.intland.codebeamer.example.predicates;
import org.springframework.stereotype.Component;
import com.intland.codebeamer.manager.workflow.TransitionPredicate;
import com.intland.codebeamer.manager.workflow.TransitionApplicable;
import com.intland.codebeamer.persistence.dto.TrackerItemDto;
import com.intland.codebeamer.persistence.dto.WorkflowTransitionDto;
@Component("customPredicate")
@TransitionPredicate("customPredicate")
public class CustomPredicate {
@TransitionApplicable
public boolean isApplicable(WorkflowTransitionDto transition, TrackerItemDto item) {
boolean result = ...
return result;
}
}
PTC 建议自定义谓词
包应为
com.intland.codebeamer 的子包,例如:
com.intland.codebeamer.<mycompany>.predicates
您可以使用任何包名称,但如果使用
com.intland.codebeamer 的子包,可以在启动
Codebeamer 期间,通过
组件扫描自动检测和部署您的新谓词:
package com.intland.codebeamer.example.predicates;
import org.springframework.stereotype.Component;
@Component("customPredicate")
public class CustomPredicate {
...
}
组件 ID/名称 (如果二者中任意一个存在) 应与 @TransitionPredicate Id/name 名称相同。
如果您的自定义转变谓词不是
com.intland.codebeamer 子包中的
组件,必须在以下位置为自定义谓词提供额外的
<bean> 配置:
~/CB-../tomcat/webapps/cb/WEB-INF/classes/my-ApplicationContext.xml
提供状态转变谓词的 Java 类,必须注释为 @TransitionPredicate。
import com.intland.codebeamer.manager.workflow.TransitionPredicate;
@TransitionPredicate("customPredicate")
public classCustomPredicate {
...
}
@TransitionPredicate 注释只有一个参数:
• value 谓词的唯一 ID/名称。在谓词的生命周期内,不能更改此 value,否则,此谓词的配置状态转变条件将不再起作用。
但每个注释为
@TransitionPredicate 的类必须至少具有一个注释为
@TransitionApplicable 的
方法:
package com.intland.codebeamer.example.predicates;
import com.intland.codebeamer.manager.workflow.TransitionPredicate;
import com.intland.codebeamer.manager.workflow.TransitionApplicable;
import com.intland.codebeamer.persistence.dto.TrackerItemDto;
import com.intland.codebeamer.persistence.dto.WorkflowTransitionDto;
@TransitionPredicate("customPredicate")
public classCustomPredicate{
@TransitionApplicable
public boolean isApplicable(WorkflowTransitionDto transition, TrackerItemDto item) {
booleanresult = ...
return result;
}
}
注释为 @TransitionApplicable 的方法必须是:
• 公共的
• 如果指定转变适用于指定上下文中的指定跟踪器项,则返回布尔值 true,否则它必须为 false。
必须将做出决策所需的上下文特定信息声明为方法
参数。
以下上下文信息可供使用:
• UserDto:用于接收要对项执行状态转变的用户。
• HttpServletRequest:用于接收当前请求。
• WorkflowTransitionDto:用于接收要应用于项的状态转变。
• TrackerItemDto:用于接收应该应用状态转变的跟踪器项。
• ProjectDto:用于接收上下文项目。
• TrackerDto:用于接收上下文跟踪器。
• TrackerTypeDto:是上下文跟踪器的类型。
• TrackerTypeDto.Kind:是上下文跟踪器的种类,例如:
◦ 工作项的跟踪器。
◦ 配置项的类别。
◦ 源代码提交/推送存储库。