It is very complex to use ConditionBuilder to control visiable or others.
We will use a example to explain how to use ConditionBuilder. We choose the file visiblity.
We need to use ConditionGroups to determine whether or not a given file is
visible to a given Candidate. To see how ConditionGroups work, study the
CandidateRestriction system (login to the app and go to
/durango/do/candidaterestriction/list).
There are several parts to implementing this:
- database and entity bean changes
- back-end code to use ConditionGroupEngine for file visibility
- UI work to use the ConditionBuilder code to set up rules for a given file's visibility
This bug will cover the database and entity bean changes.
Create a new FileEntityConditionGroup table, similar to
CandidateRestrictionConditionGroup, to link the FileEntity and ConditionGroup tables.
Also create a FileEntityConditionGroup entity bean which extends ConditionGroup
(see CandidateRestrictionConditionGroup as an example). Then make the existing
FileEntity class implement the ConditionGroupAdapter interface, similarly to
CandidateRestriction.
To determine whether a given Candidate can see a given File, we'll use the
ConditionGroupEngine. This engine is based on the drools rules engine. It
works like this:
Facts -> Engine+Rules -> Result
That is, you give the engine some facts and some rules, and it applies the
rules to the set of facts, and returns a result.
In our case the engine and rules are pretty much taken care of by the existing
condition group framework. But we'll need to create the facts, and create a
class to hold the results.
First, look at ConditionGroupEngineFactory, which has methods to return various
types of ConditionGroup engines. We want to add a method,
getFileVisibilityConditionGroupEngine(EntityManager, Map<Enum,Object>). Like
the other methods, it should check that the OWNER_ID and CANDIDATE_ID params
are in the map, then call the ConditionGroupEngine constructor to return an
engine.
To make this constructor call we need a lot of new stuff:
First, a new FILEVISIBILITY_CONDITION_RULE_NAME, and a corresponding section in
the conditionRules.xml file. Create a FileVisibilityConditionGroupGenerator
similar to other subclasses of RuleGenerator, and new .vsl files using existing
ones as models.
Create a FileVisibilityResult, similar to FormVisibilityResult: this class
should hold a collection of File ids which can be seen by the Candidate.
Also, create a FileVisibilityConditionFactSource which adds a
FileVisibilityResult to the globals collection. And a
FileVisibilityWorkingMemoryResultProcessor to return the result. Lastly,
you'll need a new ConditionContext for file visibility.
Create a unit test class like those that exist for other ConditionGroup
engines, and test it thoroughly.