The InterviewSession is the core component of an Interview Session. It is responsible for managing the data held within the rule session, creating screens and driving interview flows. As such, it is common to interact with this object when building extensions. This following information describes some of the common things you may wish to use the interview session for.
Most importantly, from a extension perspective, the InterviewSession object contains the current data of the session interview (the Instance Data) as well as data about the interview's rulebase (the Rulebase Model Data). The InterviewSession object exists in the Interview Engine Layer.
The InterviewSession is a member of the SessionContext object.
The InterviewSession encapsulates the RuleSessionManager and InterviewRulebase objects.
The RuleSessionManager provides access to the Session object (com.oracle.determinations.engine.Session) from the Interview Layer, another object in the Determinations Engine containing the instance data.
The InterviewRulebase provides access to the Rulebase object (com.oracle.determinations.engine.Rulebase) from the Interview Layer, another object in the Determinations Engine containing the rulebase model data.
In summary, the InterviewSession encapsulates the Session and Rulebase objects - objects in the Determinations Engine domain that contain the instance data and rulebase model data respectively.
The following diagram demonstrates the class hierarchy and domains:
The InterviewSession object has many other members - it encapsulates session state data in the Determinations Engine layer. But for this section we will focus on its Session member and indirectly the Rulebase object (via its InterviewRulebase member) because those two objects contain the instance data and rulebase model data of the current Web Determinations Interview.
Which Web Determinations Extensions can access the InterviewSession object
The InterviewSession object is accessible to some Plugins and Event Handlers that require access to instance data and/or rulebase model data to provide functionality.
Most plugins have access to the InterviewSession object, as input argument for one or more of their methods.
Availability of the InterviewSession to each Event Handler varies, depending on the intended purpose of the Event. The InterviewSession is accessible to an Event Handler either via the passed Event object (as a member of the Event object), or the sender Object itself. See Events and Event Handlers for more information about each Event type
Accessing Rulebase Model and Instance Data (via InterviewSession object)
It is important to understand the InterviewSession object as this object contains both Rulebase Model Data and Instance Data. Thus it is used by many Plugins and Event Handlers.
Definitions:
Rulebase Model Data - this is commonly referred to as the rulebase. Model data covers the entities, their attributes, and possible relationships between two entities
Instance Data - this is the actual instances of entities, actual values of entity attributes, and actual instances of relationships between two entities provided during Web Determinations Interview
Using the Rulebase Model Data
The Rulebase Model Data is encapsulated in the Rulebase object (com.oracle.determinations.engine.Rulebase). The Rulebase object is accessible if the Web Determinations Extension has access to the SessionContext object, InterviewSession object, or InterviewRulebase object.
The basic hierarchy in the Rulebase is that the Rulebase object contains a List of Entity objects. Each Entity object contains all the Attribute and Relationship objects associated with that Entity. This hierarchy matches the hierarchy of rule authoring in Oracle Policy Modeling - each attribute and relationship is always related to an entity.
With knowledge of the above hierarchy, the most basic way to access each Entity and each Attribute and Relationship of an Entity would be via looping through each Entity, and retrieving and looping through Attributes and Relationships for each Entity. See sample code below.
//Loop through all Entities of the current Rulebase List<Entity> entities = rule.getEntities(); for(Entity entity : entities) { System.out.println("Entity: " + entity.getName());
//Loop through all Attributes of the current Entity List<Attribute> entityAttributes = entity.getAttributes(); for(Attribute attribute : entityAttributes) { System.out.println("Attribute Name: " + attribute.getName());
//Loop through all Custom Properties of the current Attribute Map<String, String> attributeProperties = attribute.getProperties(); Set attributePropKeys = attributeProperties.keySet(); Iterator keyIterator = attributePropKeys.iterator(); System.out.println("==Attribute Properties=="); while(keyIterator.hasNext()) { String key = (String)keyIterator.next(); String value = (String)attributeProperties.get(key); System.out.println("Property key: " + key + ", Property value: " + value); } }
//Loop through all Relationships of the current Entity List<Relationship> entityRelationships = entity.getRelationships(); for(Relationship relationship : entityRelationships) { System.out.println("Relationship Name: " + relationship.getName()); if(relationship.getSymmetricRelationship() != null) { System.out.println("Reverse Relationship Name: " + relationship.getSymmetricRelationship().getName()); }
//Loop through all Custom Properties of the current Relationship Map<String, String> relationshipProperties = relationship.getProperties(); Set relationshipPropKeys = relationshipProperties.keySet(); Iterator keyIterator = relationshipPropKeys.iterator(); System.out.println("==Relationship Properties=="); while(keyIterator.hasNext()) { String key = (String)keyIterator.next(); String value = (String)relationshipProperties.get(key); System.out.println("Property key: " + key + ", Property value: " + value); } } } ... ...
For more information about the Rulebase, Entity, Attribute, and Relationship objects, please consult its API documentation for Java or .NET.
Rulebase object: useful methods - the following is a list of Rulebase object members and also useful methods to access those members. Note that an Entity Attribute or Entity Relationship object can be accessed directly from the Rulebase object via helper methods, to eliminate having to manually find a specific Entity to retrieve an Attribute or Relationship.
|| Member || Description || Access Methods || | Global Entity | This is the Entity object for the Global Entity of the current rulebase | Entity getGlobalEntity() |
| Entities | All the Entities of the current rulebase | List getEntities() Entity getEntity(String name) | | Entity Attribute | Retrieve a specific Attribute object of an entity | Attribute getAttribute(String attributeName, String entityName) |
| Entity Relationship | Retrieve a specific Relationship object of an entity | Relationship getRelationship(String relationshipName, String entityName) |
Properties
Key/value pairs associated by the rulebase author to the rulebase for custom functionality
The Instance Data is encapsulated in the Session object (com.oracle.determinations.engine.Session). The Session object is accessible if the Web Determinations Extension has access to the SessionContext object, or the InterviewSession object.
The various Instance Data objects are as follows:
Entity Instances - Entity Instance data is represented by the object EntityInstance.
Attribute value - The value of an Attribute is represented by various datatype objects corresponding to the various Attribute types supported by Oracle Policy Automation, such as Boolean, Number, Date, Currency, Unknown, Uncertain.
Relationship instance - A Relationship instance works different to Entity or Attribute in that Relationship instance do not exist by themselves, but instead exists through their Source and Target EntityInstance. For example - a particular EntityInstance may have multiple Relationships, and therefore may be linked to various Source or Target EntityInstances. Therefore the Relationship instance exists by having a Source and Target EntityInstance.
Accessing Instance Data is different to Rulebase Model Data - the Instance Data inside the Session is not accessible directly. The most common way to access Instance Data is to use the Rulebase Model data object (Entity, Attribute, or Relationship) and pass session data to their methods (either Session or EntityInstance). This will be explained in detail in the subsections below.
Entity Instance
There are two ways to access Entity Instance Data.
Via the Entity object
Via the Session object
See the Class Diagram below for methods in the Entity and Session object that retrieve EntityInstance objects, and Sample code - Using Instance Data for actual code usage.
Attribute Instance
There is only one way to access Attribute Instance Data (Attribute value), and it is by using the Attribute object, passing an EntityInstance, and retrieving the value of the Attribute for the EntityInstance object passed. See the sample code below and also the section below, Sample code - Using Instance Data.
//Get Attribute value Attribute attribute1 = entity1.getAttribute("attribute1");
Relationship Instance (Source and Target EntityInstances)
As mentioned previously - Relationship Instance Data cannot be retrieved. Rather it is a matter of retrieving Target EntityInstance(s) by providing the Source EntityInstance - or vice versa, retrieving Source EntityInstance(s) by providing the TargetEntityInstance. See the sample code below and also the section below, Sample code - Using Instance Data.
//Get Relationships for the Entity where the Entity is the Source, then get its Target EntityInstances List<Relationship> sourceRelationships = entity1.getRelationships(); for(Relationship sourceRelationship : sourceRelationships) { List<EntityInstance> targetEntityInstances = sourceRelationship.getAllTargets(entity1Instance); }
Sample code - Using Instance Data
Below is sample code that combines all the sample code for Entity, Attribute, and Relationship Instance Data and uses them together.
//Loop through all Entities of the current Rulebase List<Entity> entities = rulebase.getEntities(); for(Entity entity : entities) { //Get all EntityInstances of the current Entity, and loop through them List<EntityInstance> entityInstances = (List<EntityInstance>)entity.getEntityInstances(ruleEngineSession); for(EntityInstance entityInstance : entityInstances) {
//Get all Attributes and their values for the current EntityInstance List<Attribute> attributes = entity.getAttributes(); for(Attribute attribute : attributes ) { Object attributeValue = attribute.getValue(entityInstance); }
//Get all Relationships of the current Entity where the Entity is the Source, and loop through List<Relationship> sourceRelationships = entity.getRelationships(); for(Relationship relationship : sourceRelationships ) { //For each relationship retrieve the Source or Target EntityInstances if(relationship.getRelationshipType().isSingleTarget()) { EntityInstance targetInstance = relationship.getTarget(entityInstance); } else { List<EntityInstance> targetInstances = relationship.getAllTargets(entityInstance); } } } ...
...
Modifying the Instance Data
As mentioned in the overview and in Using the Instance Data, Instance Data of a Web Determinations Interview lives within the Session object in the Determinations Engine Layer. Modification to the Instance Data inside the Session object is different to accessing/retrieving the Instance Data. Modification is done via transactions, and the changes to be made to the Instance Data is encapsulated inside an object.
Modifying the Instance Data inside the Session object is done indirectly via the two objects below:
RuleSessionManager - an object in the Interview Engine layer. Responsible for managing transactions (mainly modifications) to the session data in the Determinations Engine Layer (the Session object) from the Interview Engine Layer.
InterviewUserData - an object in the Interview Engine layer. It represents Instance Data changes that need to be made to the Session object, and is read by the RuleSessionManager as part of a transaction for modifying the Instance Data inside the Session object.
Below are class diagrams for the RuleSessionManager and InterviewUserData objects. Only class members pertinent to modification of Instance Data is displayed.
The most common process for using InterviewUserData is as follows:
An Interview Engine object creates an InterviewUserData
The InterviewUserData is populated with content - the changes to be made; for example, additions and deletions to instance/attribute/relationship instance data, modifications to attribute value of an instance.
The InterviewUserData passed by the Interview Engine object to the RuleSessionManager.setData() method.
The RuleSessionManager reads the InterviewUserData and performs the changes to the Session object
An example of how the InterviewUserData to modify Instance Data is demonstrated by the Web Determinations Extension 'Data Adaptor' and its load() method. The load() method allows Instance Data from a datasource to be loaded into the Interview session before the user starts the Interview (see Data Adaptor Plugin).
When Web Determinations calls the Data Adaptor load() method, the load() creates, populates, and returns an InterviewUserData object that represents the Instance Data to be loaded. Web Determinations then passes the InterviewUserData object to the RuleSessionManager.setData() so the Instance Data can be loaded into the Session object (which would have no Instance Data since it's newly started).
Note: Because DataAdaptor load() is always performed to a newly created Session object, modifications to the Instance Data (signified by the 'Perform Modifications to Session' message) will all be 'additions' instead of additions/modifications/deletions since there is no Instance Data in the Session object to modify or delete.