About changing the root entity of a rule

PolicyCenter bases each Gosu rule on a specific business entity. In general, the rule set name reflects this entity. For example, in the Validation rule set category, you have Contact Validation rules and Person Validation rules. These rule set names indicate that the root entity for each rule set is—respectively—the Contact object and the Person object.

PolicyCenter provides the ability to change the root entity of a rule through the use of the right-click Change Root Entity command on a rule set. The intent of this command is to enable you to edit a rule that you otherwise cannot open in Studio because the declarations failed to parse. Do not use this command in any other circumstances.

For example, suppose that you have the following sequence of events:

  1. You create a new entity in PolicyCenter, for example, TestEntity. Studio creates a TestEntity.eti file and places it in the following location:
    • modules/configuration/config/extensions
  2. You create a new rule set category called TestEntityRuleSetCategory in Rule Sets, setting TestEntity as the root entity. Studio creates a new folder named TestEntityRuleSetCategory and places it in the following location:
    • modules/configuration/config/rules/rules
  3. You create a new rule set under TestEntityRuleSetCategory named TestEntityRuleSet. Folder TestEntityRuleSetCategory now contains the rule set definition file named TestEntityRuleSet.grs. This file contains the following (simplified) Gosu code:
    @gw.rules.RuleName("TestEntityRuleSet")
    class TestEntityRuleSet extends gw.rules.RuleSetBase {
      static function invoke(bean : entity.TestEntity) : gw.rules.ExecutionSession {
        return invoke( new gw.rules.ExecutionSession(), bean )
      }
      ...
    }

    Notice that the rule set definition explicitly invokes the root entity object: TestEntity.

  4. You create one or more rules in this rule set that use TestEntity object, TestEntityRule, for example. Studio creates a TestEntityRule.gr file that contains the following (simplified) Gosu code:
    internal class TestEntityRule {
      static function doCondition(testEntity : entity.TestEntity) : boolean {
        return /*start00rule*/true/*end00rule*/
      }
      ...
    }

    Notice that this definition file also references the TestEntity object.

  5. Because of upgrade or other reasons, you rename your TestEntity object to TestEntityNew by changing the file name to TestEntityNew.eti and updating the entity name in the XML entity definition:
    <?xml version="1.0"?>
    <entity xmlns="http://guidewire.com/datamodel" 
            entity="TestEntityNew" ... >
    </entity>

    This action effectively removes the TestEntity object from the data model. This action, however, does not remove references to the entity that currently exist in the rules files.

  6. You update the database by stopping and restarting the application server.
  7. You stop and restart Studio.

As Studio reopens, it presents you with an error message dialog. The message states that Studio cannot parse the listed rule set files. It is at this point that you can use the Change Root Entity command to shift the root entity in the rule files to the new root entity. After you do so, Studio recognizes the new root entity for these rule files.