Skip navigation links

Package com.orchestranetworks.addon.rpfl.controller

Classes and interfaces that control the execution of business rules and permission rules.

See: Description

Package com.orchestranetworks.addon.rpfl.controller Description

Classes and interfaces that control the execution of business rules and permission rules.


Example of calling RuleController to execute a business rule

Executing a business rule using the standard EBX® validation service

  1. Use the DefaultConstraintOnTable class or create a class implementing ConstraintOnTable and call RuleController to execute the rules:

            public final class ValidationConstraint implements ConstraintOnTable
            {
                    public void checkTable(ValueContextForValidationOnTable context)
                    {
                            try
                            {
                                    ExecutionContextOnDemand executeOnDemandContext = new ExecutionContextOnDemand();
                                    executeOnDemandContext.setValueContextForValidationOnTable(context);
                                    RuleControllerFactory.getController().executeOnDemand(executeOnDemandContext);
                            }
                            catch (OperationException ex)
                            {
                                    ex.printStackTrace();
                            }
                    }
            
                    public void setup(ConstraintContextOnTable context)
                    {
                    }
            
                    public String toUserDocumentation(Locale arg0, ValueContext arg1) throws InvalidSchemaException
                    {
                            return "";
                    }
            }
    
  2. Go to Modeling > Table > Advanced controls > Constraint on table (rule), add this class to the table on which the rule is executed.

Executing a validation rule via constraint on field

  1. Use the DefaultConstraint (or DefaultConstraintOnNull) class or create a class implementing Constraint (or ConstraintOnNull) and call RuleController to execute the validation rules:

            public class MyConstraint implements Constraint
            {                       
                    public final void checkOccurrence(Object value, ValueContextForValidation context)
                            throws InvalidSchemaException
                    {
                            try
                            {
                                    ExecutionContextOnConstraint executeOnConstraintContext = new ExecutionContextOnConstraint();
                                    executeOnConstraintContext.setValueContextForValidation(context);
                                    RuleController ruleController = RuleControllerFactory.getController();
                                    if (ruleController != null)
                                    {
                                            ruleController.executeOnConstraint(executeOnConstraintContext);
                                    }
                            }
                            catch (OperationException ex)
                            {
                                    context.addMessage(UserMessage.createError(ex.getLocalizedMessage()));
                            }
                    }
            
                    public final void setup(ConstraintContext context)
                    {                       
                    }       
            }
            
            public class MyConstraintOnNull implements Constraint,ConstraintOnNull
            {                       
                    public final void checkOccurrence(Object value, ValueContextForValidation context)
                            throws InvalidSchemaException
                    {
                            try
                            {
                                    ExecutionContextOnConstraint executeOnConstraintContext = new ExecutionContextOnConstraint();
                                    executeOnConstraintContext.setValueContextForValidation(context);
                                    RuleController ruleController = RuleControllerFactory.getController();
                                    if (ruleController != null)
                                    {
                                            ruleController.executeOnConstraint(executeOnConstraintContext);
                                    }
                            }
                            catch (OperationException ex)
                            {
                                    context.addMessage(UserMessage.createError(ex.getLocalizedMessage()));
                            }
                    }
                    
                    public void checkNull(ValueContextForValidation context) throws InvalidSchemaException
                    {
                            try
                            {
                                    ExecutionContextOnConstraint executeOnConstraintContext = new ExecutionContextOnConstraint();
                                    executeOnConstraintContext.setValueContextForValidation(context);
                                    RuleController ruleController = RuleControllerFactory.getController();
                                    if (ruleController != null)
                                    {
                                            ruleController.executeOnConstraint(executeOnConstraintContext);
                                    }
                            }
                            catch (OperationException ex)
                            {
                                    context.addMessage(UserMessage.createError(ex.getLocalizedMessage()));
                            }
                    }
            
                    public final void setup(ConstraintContext context)
                    {                       
                    }       
            }
    
  2. Go to Modeling > Table > Field > Advanced controls > Specific constraint (component), add this class to the field on which the validation rule is executed.


Executing business rule on trigger

  1. Use the DefaultTableTrigger class or create a class extending TableTrigger and call RuleController to execute the rules:

            public class BusinessRuleTrigger extends TableTrigger
            {       
                    public void handleAfterCreate(AfterCreateOccurrenceContext arg0) throws OperationException
                    {
                            ExecutionContextOnTrigger context = new ExecutionContextOnTrigger();
                            context.setWhen(Hook.AfterCreate);
                            context.setSession(arg0.getSession());
                            context.setProcedureContext(arg0.getProcedureContext());
                            context.setValueContext(arg0.getOccurrenceContext());
            
                            RuleControllerFactory.getController().executeOnTrigger(context);                
                    }
                    ...
            }
    
  2. Go to Modeling > Table > Advanced properties > Trigger, add this trigger to the table on which the rule is executed.

Executing access permission rules

  1. Go to Configuration > Data model properties > Model properties > Special extensions

  2. Add schema extension class to the schema.

    1. Use com.orchestranetworks.addon.rpfl.DefaultSchemaExtension
    2. Or create your own classes implementing AccessRule and SchemaExtensions to call RuleController
      1. Create a class which implements AccessRule interface and call RuleController to execute the access rule

        The following example is an access rule applied for table node. The user can check the context and add their own code before (or after) calling the add-on:

                public final class MyAccessRuleForTableNode implements AccessRule
                {
                        public AccessPermission getPermission(Adaptation adaptation, Session session, SchemaNode node)
                        {
                                try
                                {
                                        //Add your own code here
                                        //...
                                        //...                   
                                        //Otherwise, call the add-on
                                        RuleController ruleController = RuleControllerFactory.getController();
                                        if (ruleController != null)
                                        {
                                                return ruleController.getAccessPermission(new AccessPermissionExecutionContext(
                                                        adaptation,
                                                        session,
                                                        node,
                                                        PermissionScope.TABLE));
                                        }
                                        return AccessPermission.getReadWrite();
                                }
                                catch (OperationException ex)
                                {
                                        //Return max permission in case exception
                                        return AccessPermission.getReadWrite();
                                }
                        }
                }
        
      2. Create a class which implements SchemaExtensions interface and declares access rule for each node

        After creating access rule classes, user can create a class implement the SchemaExtensions interface to declare these access rule classes to nodes.
        For example:

                public final class MySchemaExtensions implements SchemaExtensions
                {               
                        public void defineExtensions(SchemaExtensionsContext context)
                        {                       
                                //Data set
                                context.setAccessRuleOnInstance(new MyAccessRuleForDataset());
                                Path tablePath = Path.parse("/root/myTable");
                                //Tables
                                context.setAccessRuleOnNode(tablePath, new MyAccessRuleForTableNode());
                                //Occurrence
                                context.setAccessRuleOnOccurrence(tablePath, new MyAccessRuleForTableOccurence());
                                //Field
                                Path fieldPath = Path.parse("/root/myTable/myField");
                                context.setAccessRuleOnNode(fieldPath, new MyAccessRuleForFieldNode());
                        }
                }
        

        Or create a class to encapsulate the DefaultSchemaExtension class. This class will call DefaultSchemaExtension to add DefaultAccessRule on all nodes first, then user can declare their own access rule class on some particular nodes to overwrite the DefaultAccessRule:

                public final class MySchemaExtensions implements SchemaExtensions
                {
                        private final DefaultSchemaExtension defaultSchemaExtension;
                        public MySchemaExtensions()
                        {
                                this.defaultSchemaExtension = new DefaultSchemaExtension();
                        }
                        public void defineExtensions(SchemaExtensionsContext context)
                        {
                                //Call the DefaultSchemaExtension to declare the DefaultAccessRule on all nodes first
                                this.defaultSchemaExtension.defineExtensions(context);
                
                                //Then declare another access rule class on some particular nodes to overwrite the access rule on these nodes
                                //Data set
                                context.setAccessRuleOnInstance(new MyAccessRuleForDataset());
                                Path tablePath = Path.parse("/root/myTable");
                                //Tables
                                context.setAccessRuleOnNode(tablePath, new MyAccessRuleForTableNode());
                                //Occurrence
                                context.setAccessRuleOnOccurrence(tablePath, new MyAccessRuleForTableOccurence());
                                //Field
                                Path fieldPath = Path.parse("/root/myTable/myField");
                                context.setAccessRuleOnNode(fieldPath, new MyAccessRuleForFieldNode());
                        }
                }
        

Executing action permission rules

  1. Service declared in the data model

      Use the DefaultRulesSchemaServicePermission as service permission for the declared service and define the service name by using tag <serviceName></serviceName>

              <xs:complexType name="MyService">
                      <xs:annotation>
                              <xs:appinfo>
                                      <osd:service resourcePath="/services-dispatcher?action=MyService" 
                                              class="com.orchestranetworks.addon.rpfl.DefaultRulesSchemaServicePermission" >
                                              <serviceName>MyService</serviceName>
                                              ...
                                      </osd:service>
                              </xs:appinfo>
                              ...
                      </xs:annotation>
              </xs:complexType>
      
  2. Service declared in the module.xml

    1. Create an extension class of DefaultRulesServicePermission. Define the service name by implementing the abstract method getServiceName()

              public final class MyServicePermission extends DefaultRulesServicePermission
              {
                      public String getServiceName()
                      {
                              return "MyService";
                      }
              
              }
      
    2. Declare this class as service permission for the declared service in module.xml

              <service name="MyService">
                      <resourcePath>/services-dispatcher?service=MyService</resourcePath>
                      <instanceActivation all="true">
                              <scope availableOnChild="true">
                                      ...
                                      <permission class="com.foo.MyServicePermission"/>
                              </scope> 
                      </instanceActivation>
                      ...
              </service>
      

 

 

 

Skip navigation links

Add-ons Version 4.5.9.

Copyright TIBCO Software Inc. 2001-2022. All rights reserved.
All third party product and company names and third party marks mentioned in this document are the property of their respective owners and are mentioned for identification.