Interface IRuleBase


  • public interface IRuleBase

    The RuleBase is a repository for all rule resources. The RuleBase itself does not contain runtime data, instead sessions are created from the RuleBase in which data can be inserted and processed.

    The RuleBase is invalidated when there are rules loaded from namespace and one of the required PMVs gets deactivated.
    The RuleBase is reloaded when the rules were loaded from namespace ONLY and all the required PVMs are activated.

    When a rule base is invalidated, all method calls to create new rule session or execute rules from created sessions will throw InvalidatedRuleBaseException.

    API:
    This is a public API.
    • Method Detail

      • loadRulesFromNamespace

        void loadRulesFromNamespace​(String namespace)

        Add all rules in the provided namespace into this rule base. The rules inside subfolders of the namespace will not be loaded.
        If the namespace is available in the required projects, the rules will be combined orthogonally. And only the rule file with the highest level is loaded if there are two or more rule files with same name.

        Example:

         IRuleBase ruleBase = Rules.engine().createRuleBase();
         ruleBase.loadRulesFromNamespace("namespace.of.rules");
         

        Note: Current official supported rule resource types are decision table (*.xls) and native rule language (*.drl) from Drools.

        Parameters:
        namespace - is the folder hierarchy that contains rule resources and inside the root rules folder of the Ivy project. It's similar to java's package. Example, there is a folder structure in the project: [Rules folder]\namespace\of\rules
        Then, the namespace of the rules is: namespace.of.rules
        API:
        This public API is available in IvyScript and Java. It has the visibility NOVICE.
      • createSession

        IStatelessRuleSession createSession()
        Create a new stateless rule session to execute the rules that defined by the rule resources in this rule base. The rule session can execute the rules on an object or a collection of objects
        Returns:
        A new rule session.
        Throws:
        InvalidatedRuleBaseException - if this RuleBase is invalidated.
        See Also:
        IStatelessRuleSession.execute(Object), IStatelessRuleSession.execute(Iterable)
        API:
        This public API is available in IvyScript and Java. It has the visibility NOVICE.
      • loadRules

        void loadRules​(IRuleResource ruleResource)
        Load a specific rule resource into this rule base. This rule resource will override the existing resource in current rule base which has the same identifier.

        Example:

         IRuleResource ruleFromFile = ... // Load rule resource from external file system.
         IRuleResource ruleFromDb = ... // Load rule resource from database.
         ruleBase.loadRules(ruleFromFile);
         ruleBase.loadRules(ruleFromDb);
         

        Parameters:
        ruleResource - is a rule resource
        See Also:
        IRuleResource
        API:
        This public API is available in IvyScript and Java. It has the visibility ADVANCED.
      • isInvalidated

        boolean isInvalidated()
        Check whether this RuleBase is invalidated or not. A RuleBase is invalidated when the Process Model Version
        If it is invalidated, an InvalidatedRuleBaseException will be thrown when:
        • The user try to create new session from this RuleBase.
        • The user try to execute rules with the sessions which were created from this RuleBase.
        Returns:
        true if this RuleBase is invalidated, otherwise false
        API:
        This public API is available in IvyScript and Java. It has the visibility ADVANCED.