Overview

This article shows the design pattern of using linked generators with the SwitchGen Generator to control which generated value is switched on to be returned.


Example

Return a male name when the gender is Male and return a female name when the gender is Female. 


Generation Sequence From Left To Right

  1. Generate a Male Name
  2. Generate a Female Name
  3. Reference the value generated by the gender Attribute
  4. If (gender == 'Male') switch to the Male NameGen, if (gender == 'Female') switch to Female Name Gen.  


Object Diagram


Video Example



Step by Step Example

1. Create a user Domain with at least following Attributes:

  • id
  • firstName
  • lastName


2. Add an Attribute to the User Domain and name it "gender" 


3. Assign the BooleanValueGen Generator to the gender Attribute 


4. Set the trueValue to "Male" and the falseValue to "Female"



5. Rearrange the gender Attribute above all of the other Attributes except ID

  • Click the "Rearrange Attributes" button
  • Drag the gender Attribute above all of the Attributes except id
  • Click "Close"


6. Select the firstName Attribute

  • Change the nameType to "maleName"
  • Set the alias to "male"


7. Add another nameGen to the firstName attribute

  1. Change the nameType to "femaleName"
  2. Change sortOrder to random
  3. Set the alias to "female"


8. Add a switchGen generator to the firstName attribute. Set the alias to "result"


8. Set the following parameters for the SwitchGen and click "Save Generator"

  • switch: #{User.gender} this references the gender Attribute
  • default: error
  • caseList
    • Male
    • Female
  • actionList
    • #{self.gen1}
    • #{self.gen2}



9. Navigate to the User Domain Dashboard 

You will see the firstName Attribute returns a male name when the gender is male and return a female name when the gender is female.