See: Description
Interface | Description |
---|---|
RuleController |
Provides a method to execute business rules on demand or when triggered.
|
Class | Description |
---|---|
AccessPermissionExecutionContext |
Defines parameters to execute
AccessPermissionRule . |
ActionPermissionExecutionContext |
Defines parameters to execute
ActionPermissionRule . |
ExecutionContextOnConstraint |
Defines parameters to execute on constraint.
|
ExecutionContextOnDemand |
Defines parameters to execute on demand.
|
ExecutionContextOnTrigger |
Defines parameters to execute on trigger.
|
RuleControllerFactory |
Factory for instances of
RuleController . |
Classes and interfaces that control the execution of business rules and permission rules.
RuleController
to execute a business ruleUse 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 ""; } }
Go to Modeling > Table > Advanced controls > Constraint on table (rule), add this class to the table on which the rule is executed.
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) { } }
Go to Modeling > Table > Field > Advanced controls > Specific constraint (component), add this class to the field on which the validation rule is executed.
Use the DefaultTableTrigger
class or create a class extending
and call TableTrigger
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); } ... }
Go to Modeling > Table > Advanced properties > Trigger, add this trigger to the table on which the rule is executed.
Go to Configuration > Data model properties > Model properties > Special extensions
Add schema extension class to the schema.
com.orchestranetworks.addon.rpfl.DefaultSchemaExtension
AccessRule
and SchemaExtensions
to call RuleControllerAccessRule
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(); } } }
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()); } }
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>
Service declared in the module.xml
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"; } }
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>