Custom State Transition Predicates
A state transition predicate implements a Condition or a filter for State Transitions, that checks, whether a specific state transition is applicable for a specific tracker item in a specific context.
Developing own/custom predicates in Java requires a Java 7 or newer Standard Edition Java Development Kit (JDK) plus the following frameworks/libraries:
Framework/Library
Component
Version
3.4
spring-core
5.3.x
spring-context
5.3.x
spring-beans
5.3.x
You also need cb.jar from the directory ~/CB-../tomcat/webapps/cb/WEB-INF/lib of the Codebeamer 7.8.0 or newer installation, you want to develop new custom transition predicates for.
A predicate is simply a method of a Java class.
For example:

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 recommends, that the package of your custom predicates should be a sub-package of com.intland.codebeamer, for example,
com.intland.codebeamer.<mycompany>.predicates
You can use any package name, but when using a sub-package of com.intland.codebeamer, your new predicate can be automatically detected and deployed by the Component scan during Codebeamer startup:


package com.intland.codebeamer.example.predicates;

import org.springframework.stereotype.Component;

@Component("customPredicate")
public class CustomPredicate {
...
}
The component id/name, if any of these two is present, should be the same as the @TransitionPredicate id/name.
If your custom transition predicate is not a Component in a sub-package of com.intland.codebeamer, then you must provide extra <bean> configuration for your custom predicate in
~/CB-../tomcat/webapps/cb/WEB-INF/classes/my-ApplicationContext.xml
Java classes providing state transition predicates must be annotated as @TransitionPredicate.
import com.intland.codebeamer.manager.workflow.TransitionPredicate;

@TransitionPredicate("customPredicate")
public classCustomPredicate {

...
}
The @TransitionPredicate annotation has only one parameter:
value the unique id/name of the predicate. This value must not be changed over the lifetime of a predicate, otherwise configured state transitions conditions for this predicate will not work.
There is no special interface to implement or base class to extend.
But each class annotated as @TransitionPredicate, must have at least one method annotated with @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;
}
}
Methods annotated as @TransitionApplicable must be:
Public
Return boolean true if the specified transition is applicable for the specified tracker item in the specified context, else it must be false.
Context specific information required by the method in order to make it's decision, must be declared as method parameters.
The following context information is available:
UserDto: To receive the user, that wants to execute the state transition on the item.
HttpServletRequest: To receive the current request.
WorkflowTransitionDto: To receive the state transition to be applied to the item.
TrackerItemDto: To receive the tracker item where the state transition should be applied to.
ProjectDto: To receive the context project.
TrackerDto: To receive the context tracker.
TrackerTypeDto: Is the type of the context tracker.
TrackerTypeDto.Kind: Is the kind of the context tracker such as:
Tracker for work items.
Category for configuration items.
Repository for source code commits/pushs.
Was this helpful?