Welcome to the OPA Hub Website

Blog

Custom Entity Container JavaScript Extension Example #3

Custom Entity Container JavaScript Extension Example #3

Custom Entity Container JavaScript Extension Example #3

By now most of you will have realised that as far as JavaScript goes, I am a bit of a generalist. As one wise person once put it “the kind of person who can code themselves into a mess but not out of one”. I learn by exploring and doing. I’ve been “doing” for a long time (I started with a ZX 81 and pretty much kept mucking about from there). My first ever big IT project was replacing IBM 5520 word processors with Windows 3, Word and a custom application written using Visual Basic.  I get kind of obsessive about understanding the “big picture” without necessarily wanting to have every detail. And so it is with Custom Entity Container JavaScript Extension Example #3.

All that to explain what I have mentioned before : everything in relation to JavaScript which I offer to you here is purely for entertainment or educational purposes : many times I have to sketch out a need or specification, and what you see on this blog relating to Oracle Policy Automation JavaScript extensions is just the results of some head-scratching or an idea that I have needed to show to someone more technical than myself to be “tidied up” (a.k.a professionalized).

The reason I mention it is because I often work in Siebel CRM (visit www.siebelhub.com the other site in this family) and JavaScript is a big part of moving forward with Siebel too. So I get to mix and match. Today I found myself looking at the two previous incarnations of the Custom Entity Container JavaScript Extension Example #3 (#1, #2) and thinking “this looks like a List Applet in Siebel”. So I decided to place the layout of the custom entity list in the hands of jQuery and jsGrid. Siebel CRM actually uses jqGrid but I needed something very lightweight for this example requirement, so jsGrid was a better choice. Of course I needed minified jQuery as well.

My goal is to make this a fairly simple routine to present instances of an inferred entity. So the code for the jsGrid looks very minimalist. It basically takes the for..each loop and extracts the two attributes from the array created in Custom Entity Container JavaScript Extension Example #2, and then passes that to jsGrid as a flattened dataset without the attribute child nodes. I also set up the grid to only have two columns, and no editing (since this is an inferred entity). I set the page size and the size of the actual space taken up by the entire list:

Custom Entity Container JavaScript Extension Example #3

  1. The loop creates a flattened data structure just right for jsGrid
  2. The data is passed to the jsGrid
  3. The column headers are sized appropriately

The end result is rather nice, smooth scrolling (not in the Debugger, only in Ctrl+F5 debugging in a modern browser).

Custom Entity Container JavaScript Extension Example #3

 

Now that’s what I call a list! Using the jsGrid library gives me (and the reader) the added bonus of scrolling or jumping using the paging links at the bottom of the list. Cool!

As ever this is available from the OPA Hub Shop, look out for Custom Entity Container JavaScript Extension Example #3 in the product list.

Custom Entity Container JavaScript Extension Example #2

Custom Entity Container JavaScript Extension Example #2

Following on from the previous post, we now have a working example that let’s us access an array of data in our inferred entity from the JavaScript extension code we write to manage our Control extension(s). But what about when we want to use this code outside of Debug mode? And why does it only work in Debug mode? Let’s make Custom Entity Container JavaScript Extension Example #2!

Debug Mode

The OraclePolicyAutomation object in your JavaScript has EnableDebugMode tucked away deep in the interview.js static resource file. This produces the beloved Debug Console window you see when you are working the debug in your browser or in the embedded browser, which pipes the console output into this pink box:

Custom Entity Container JavaScript Extension Example #2

When working in Debug mode, I have also noticed (and this is not a surprise) that some interesting objects and functions are available that do not show up when the project is deployed. This is not a surprise really. But in our case, we would like to have access to that array of data for our own (perhaps twisted and even unprecedented) purposes. So where do we go from here? The answer, as always, turns out to be relatively simple.

The interview object contains a reference to the same array in the form of  interview._session.config.data[1].instances. Note that the number one assumes that you have only two entities, Global and something else. You will have to inspect your code and find out which node you are interested in if you have more. It looks like this in my case.

Custom Entity Container JavaScript Extension Example #2

Once you have that reference, you can do two things easily.

  1. You can figure out the length of the array and use it in your for…each loop
  2. You can select one of the child array called attributes and dig up the information you need to display

So in this new, non-Debug version of the code, you would end up with the following changes compared to the previous post.

Custom Entity Container JavaScript Extension Example #2

  1. In the early part of the script, get a reference to the part of the interview object you need
  2. Use it in a similar way to previously to get the different attribute values you want to display

This code will run even if you are not using the debugger and you have deployed the project to an Interview URL.

Custom Entity Container JavaScript Extension Example #2 Summary

This approach allows us to take the same technique and improve our “Custom Entity Container JavaScript Extension Example #2” to function outside of the Debug window. I would not be surprised if at some point this reference was made easier to access but for now, this seems to do the trick. The documentation is, as ever, available online.

Code Example

As always the code is available for free download from the OPA Hub Shop. Look for Custom Entity Container JavaScript Extension Example #2  in the product list.

Custom Entity Container JavaScript Extension Example #1

Custom Entity Container JavaScript Extension Example

Note : this JavaScript is destined for use in Debug mode. For a version usable outside of Debug Mode, please continue reading the second part of this series).

Once again, we look into an educational JavaScript Extension example for Oracle Policy Automation. As usual the example provided is purely intended for learning purposes. It involves a situation that you probably have come across many times. We wish to display a set of inferred entity instances in our Interview. But we are afraid that our set of instances is going to produce a layout that is rather unfriendly. Here is a visual example, taken from a sample project with a simple inferred entity that has only two attributes :

Custom Entity Container JavaScript Extension Example

There are fifty three items in my list. So the Entity Container provides a very long list. Yes, I’m sure I could play around with labels and containers a goodness knows what, in order to make it shorter. But basically, the Entity Container just spawns an elastic list. Which is the opposite of what I want. Instead I would like to see this:

Custom Entity Container JavaScript Extension Example

The above example is a fixed height, and has a scroll bar in order to visualise the content at my leisure. The page is not affected by a very long list. And that is rather nice, especially if you have a dynamic list of terms and conditions, or something similar. Here is the data model, including the inferred entity, relationship and attributes.

Custom Entity Container JavaScript Extension Example

The Excel spreadsheet is very basic for our example:

Custom Entity Container JavaScript Extension Example

Custom Entity Container JavaScript Extension Example

So now on to the mechanism for displaying the content. This Custom Entity Container JavaScript Extension Example will use a standard JavaScript template based on the Oracle Policy Automation documentation. The code of the mount section is as follows:

 

Custom Entity Container JavaScript Extension Example

Let’s look at it in detail. There is some interesting stuff in there. Firstly, the basic principle is as usual. On line 8, as before, we reference a custom Property in our Screen that allows us to identify the Entity Container Control on the Screen. Then, in lines 11 to 15 we create a simple DIV and add a scrollbar that will appear if the content is too large to display in the 100 pixel height.

Then we begin a loop in line 17, based on a global variable called data.data[1].instances.  Of course we should create a reference to it, but for the purposes of learning we can leave it as is. This object, whose exact index will change depending on the structure of your Oracle Policy Automation data model, will prove very useful indeed. It is clearly visible in the Debugging Console of the Browser, if you insert a handy break-point:

In the case of my inferred entity instances, this array contains all 53 instances in my Browser. The same array is also visible as a Local variable as well:

Note in the screenshots above, the location of the break-point is not really relevant here : it is just used to stop the JavaScript engine in the middle of mount.

So the ability to access the instances is most useful. The code loops based on the number of instances. We add a child DIV element for each instance, and then access the values of the two attributes to concatenate them into a longer string. Word-wrap is switched on in my screenshot so you can see the whole Custom Entity Container JavaScript Extension Example code.

Finally we add a horizontal rule just to break the list up a bit. Of course there are lots of things we could do here : but we are just building a simple list and don’t really worry about styling the elements in line, which is not good practice of course.

The rest of the code simply gets rid of the element when the unmount section is called.

Custom Entity Container JavaScript Extension Example

This example is interesting since it reveals a little about the inevitable content of our JavaScript extension. There are probably other ways to get hold of the content of the inferred entity but this is useful for educational purposes.

Summary

But as you have no doubt seen, the code example here will only work with the Debugger. It has it’s usefulness of course, to be able to understand that the content is structured in a certain way. But what about after Debug? That’s what’s coming next.

As always the code is available for free download from the OPA Hub Shop. Look for Custom Entity Container JavaScript Extension Example in the product list.

Custom Year Picker JavaScript Extension Example

Custom Year Picker JavaScript Extension Example

Continuing in our random series of examples of using the Oracle Policy Automation JavaScript Control Extension API, this one came up the other day. How to allow the user to only enter a year in a calendar? The data type underneath fully expects there to be a day, month and year to complete the picture, but suppose you are entering an attribute such as “Year of Registration” and the business rule states that the product is always registered as of January 1st of that year. We can call it a Custom Year Picker JavaScript Extension.

Of course as always there are many ways to achieve this, and JavaScript is definitely not the only solution. As good citizens of the Oracle Policy Automation world, we should always try and reach our goals without resorting to scripting unless it is completely necessary. Since this is supposed to be an article about the technique rather than the business requirement, let’s push on and find out how you might do it.

Firstly, there are a couple of pre-requisites. This example uses jQuery, and jQuery UI plugin called, unsurprisingly perhaps given the topic, Year-Select. I am sure there are a multitude of different plugins or tools to do this. Year-Select has the advantage of being super small and easily styleable. In addition it requires minimal coding to get it to work. Two good reasons to use it for this example. Download the file and place it in your folder. Add the jQuery files that you can download from the official site.

Now your resources folder will probably look like this : note the three external files (two from jQuery and “yearpicker.js” for the Year Picker) and your own custom JavaScript file that you are about to create “datepicker.js”. For this example, you should also create the following

  1. A Word document with a global goal that relates to couple of date attributes
  2. The two date attributes just mentioned that you should also create. Give them names as well.
  3. A label which displays these pieces of information.
  4. A date control on the Screen with a custom Property called name, value “xDate” or anything else you might like to use instead. This is similar to the other examples already described on this site.

Here are the images to help you work all that out. First the screen, with the Date control and the two attributes in the label:

Custom Year Picker JavaScript Extension Example

And secondly, the actual content of the Word document. You will notice that I am just trying to usefully have two attributes, one which is the session timestamp (which we can use when the Interview starts up, to default the Year Picker to the current year, for example) and the second attribute is going to store the selected value chosen by the user.

For the avoidance of doubt, in this Custom Year Picker JavaScript Extension Example, dt_sess is the name given to the date of the session and dt_circ is the name given to the date of registration.

On to the JavaScript code. As usual this will take the form of several different sections. In the first mount section we will

  • Create an Input control, which is the basis of our Year Picker
  • Get the Session Timestamp
  • Convert it to a Date object
  • Extract the Year
  • Apply the magic CSS class and call the yearselect.js code to intialise the jQuery UI widget

Custom Year Picker JavaScript Extension Example

  • If the date of registration has no value, then set the value to the year of the Session Timestamp, January 1st (since this was the requirement)
  • If the date of registration already has a value – because someone has already edited the year in this Interview session, then get that value and apply it to the Year Selector

Custom Year Picker JavaScript Extension Example

That’s quite a lot going on there. Most of the code is actually spent getting the actual date from the attribute and converting it into something JavaScript believes is actually a Date. Then looking to see if the date is already set, and updating the picker control.

As usual the code is absolutely filled with console logging, and the code is willfully non-optimized in order to make it as easy to read as possible for someone who just wants to know what it does. The final parts of the code handles if the user decides to update the year with the picker, and the usual unmount clears the element from the DOM.

Custom Year Picker JavaScript Extension Example

Now, in your debug session if you have added a new Screen, you can flick back and forth between the End Screen and your New Screen to observe the changes. Your new Custom Year Picker JavaScript Extension should be up and running like the following screenshot.

Custom Year Picker JavaScript Extension Example

The OPA Hub Shop – Download the Script for Custom Year Picker JavaScript Extension Example

And now for some good news (I got a lot of requests for this!). The code example, and all the other code examples, are free to download in the OPA Hub Website Shop as PDF files.

Remember if you have any ideas for examples, or you want to contribute your own, just leave a comment below!

Whats New in Oracle Policy Automation November 2017 #2

Whats New in Oracle Policy Automation November 2017 #2

As in the previous post in this series, the OPA Hub Website is concentrating on the new features, or “Whats New in Oracle Policy Automation November 2017” to be more precise. This is the second in the series. In this post we will explore two different functionalities that have been improved. Firstly, we have all probably at some point found ourselves creating attributes, and thinking about default values : setting them on the different screens of our Interview and so on. We probably also have then spent time creating Rule Tables to handle what happens when we have to default values based on the certainty of other information.

Default Values in Web Service inbound attributes

These days, managing default values in a Web Service environment just got easier. Consider the following simple example. The insurance premium is inbound in a data Connection. It is copied into an attribute called the baseline annual premium. If the inbound value is uncertain, then the default value (in this case £500) will be used. If the inbound value is different to £500, then that value will be used instead. If the inbound value is unknown, then the value of the baseline annual premium will be unknown.

Whats New in Oracle Policy Automation November 2017

Set True and False values in one shot

Another feature from the Whats New in Oracle Policy Automation November 2017 collection : in the same vein, you can now use the If function to set values for a true or false result of a condition, like you would for example in Microsoft Excel formulae. Think of it as “If(expression, value if true, value if false)”.

Whats New in Oracle Policy Automation November 2017

If the baseline annual premium is greater than 500, then the percentage of legal fees will be 100. Otherwise it will be 50. The documentation refers to “condition” but in different places it refers to Boolean attributes or conditions. In any case, it seems to work with both.

Both of these will provide decent shortcuts to existing workflow for developers looking to create cleaner rules. You can find the details in the online documentation here. Catch up with more “Whats New in Oracle Policy Automation November 2017” in the upcoming third post, where we will look at cool new features in the Interview.

PS : Note that my example assumes a Project using the English United Kingdom regional settings.

Whats New in Oracle Policy Automation November 2017 #1

Whats New in Oracle Policy Automation November 2017 #1

With the regularity of a Swiss watch, the Oracle Policy Automation team have released the latest and greatest version of their flagship natural language business rules and automated decision tool : and as usual it is packed with lots of new things for us to get excited about. Here are just a few of the key points that are in the list this time, along with some examples. Let’s look at whats new in Oracle Policy Automation November 2017, this is part one of a multi-part post.

Load During an Interview (conditionally)

One of the commonest requirements that seems to show up regularly is the need to load, for example, reference data during an interview. And for Public Cloud users, the ability to do just that is now built into the Service Cloud Connection. Let’s look at a very simple example. Suppose that you want to load some product information, depending on some criteria such as the dates of the last few purchases. What you absolutely don’t want to do is load the entire product hierarchy. Just the parts you want relative to your customer scenario : perhaps a customer logging in to the portal.

If you look carefully at the attached image above, you will notice that there is now, on the left hand side, the possibility to add a “New Unrelated Mapping”. I have already added one, based on Product. I can select an unrelated object from Service Cloud and map it into my Oracle Policy Automation November 2017 Project. Although this is delivered as out of the box functionality for the Oracle Policy Automation Cloud Service, it is in theory possible to deliver the same functionality for any Connection, provided you use the newest WSDL (which is referenced here in the documentation).

Filtering the Data Load

Furthermore, the data load can include the equivalent of an SQL where clause. In the Entity Properties, you now have access to a filtering feature.

The filter can use any field from the underlying table, even if it is not mapped inbound in Oracle Policy Modelling in your Project. The syntax is similar to the natural language of OPA. Notice also, you can limit the number of records retrieved.

This is a very exciting feature that has been requested for a long time. Outside of Service Cloud, Siebel CRM for example with it’s incredibly rich data model, this allows for considerable optimisation of data transfer to Oracle Policy Automation. In the next post in this series we will see some new functions relating to default values, which are going to be a terrific time saver!

Oracle Policy Automation – JavaScript Custom Options

Oracle Policy Automation – JavaScript Custom Options

Following on from the occasional series of posts that has dealt with  Oracle Policy Automation JavaScript Custom Labels and Oracle Policy Automation JavaScript Custom Search extensions, this short post is going to demonstrate how to use the custom Options extension to build an Oracle Policy Automation – JavaScript Custom Options example. The scenario is very simple, and can mostly be achieved using non-JavaScript functionality but the goal is to showcase the capability. You will need to imagine your own business requirement.

Let’s get started. In a simple Oracle Policy Automation Project I have three attributes : the Country, the Town and the Town Level. In each Country, there are a certain number of Towns. These can be considered as a dynamic list for the purposes of our demonstration. They will be stored in an Array of Objects. They could, naturally, be obtained from a REST call to some service or other, much like the example of Search Extension. For our purposes we will have only four towns per country. Each town has a level, which corresponds to its population size.

When the user selects a Country and Town Level, we will display in a Custom Options list, the Towns that have the same Town Level or higher. So if you choose level three, we would like to see towns of levels one, two and three. If we choose level two, we would like to see levels one and two in our Oracle Policy Automation – JavaScript Custom Options list. We wish to display them as radio buttons.

Oracle Policy Automation – JavaScript Custom Options Example

How can we achieve this goal:  here is the example in more detail.

The User Interface is prepared according to the following screenshots:

Oracle Policy Automation - JavaScript Custom Options - Setup CountryThe above shows the first Screen.

Oracle Policy Automation - JavaScript Custom Options - Setup Options Extension

The second Screen displays the future dynamic Options. Note how it is a simple Textbox.

Oracle Policy Automation - JavaScript Custom Options - Code Introduction

In the above image, the basic setup is performed. Values of the Country and Town Level are acquired. An empty Array of towns is created.

Oracle Policy Automation - JavaScript Custom Options - Code Array Creation

The second part of the code is too long to reproduce here, but the above image will give you the idea. According to the Country, the array of Town objects is built. Note the text and value properties which are required, and I have added a level property. I have also, of course, created an alternative set of towns for Ireland (but I won’t show it to save space). Now I will filter the array based on the town level chosen:

Oracle Policy Automation - JavaScript Custom Options - Code Return Array Filtered

In this final screenshot, you can see the filter is based on the level and the filtered array is passed out. In addition I have specified the display as radio buttons.

Oracle Policy Automation – JavaScript Custom Options Result

Executing the code in the Project we can see the following when we select the country as Ireland, and the town level as 2, for example:

Oracle Policy Automation - JavaScript Custom Options - Result Example One

In the same vein, when France is chosen, and town level 1, this is the result:

Oracle Policy Automation - JavaScript Custom Options - Result Example Two

Have a nice day! If you would like a copy of the example code and Oracle Policy Automation – JavaScript Custom Options Project, just leave a comment to that effect. As always the official documentation can be found on the Oracle website.

Getting Started with Oracle Service Cloud Second Edition

Getting Started with Oracle Service Cloud Second Edition

The second edition is here! Helped by some comments from the community (see this conversation in the comments of a previous post), I am very pleased to announce the availability of the second edition of Getting Started with Oracle Service Cloud. A couple of new chapters have been added, and best of all, over fifty exam-style questions have been added to help you prepare for an exam, or an interview or any sort of challenge you might be facing. The answers are available on the publisher’s website (P8 Tech).

The exam layout is as follows, and the Getting Started with Oracle Service Cloud Second Edition chapters are shown alongside for reference purposes. We are going to be adding another 40 or so questions to our online Quiz section, to round out the whole experience.

The book is available now in both paper and electronic formats, from a variety of online and physical vendors. Just go to the publisher’s website and find the easiest way for you to get hold of it.

Here is the list of topics from the Oracle Service Cloud Implementation Essentials exam, and the relevant chapters.

Exam Topic Book Chapter & Comments
Create and implement Workspaces Chapter 4
Create and implement Navigation Sets Chapter 5
Create Customizable Menus Chapter 4
Create Agent Workflows Chapter 11
Create Agent scripts within the Scripts Explorer Chapter 12
Create Profiles Chapter 5
Create Staff Accounts Chapter 4
Describe Password configurations and their functions Chapter 3 and elsewhere
Describe typical answer management components and usage Chapter 9
Manage Search Priority Words Chapter 15
Create and manage Word List Files and the Dictionary Chapter 15
Create and manage Access Levels Chapter 4 & 5
Describe Custom Fields and their usage Chapter 18
Create Business Rules Chapter 10
Explain Standard Text and its application Chapter 8
Explain Service Variables and their application Chapter 6
Create and manage Service Level Agreements Chapter 10
Configure Cloud Monitor Not Service Cloud-specific
Configure Custom Objects Chapter 18
Describe incident management Chapter 8
Manage Message Bases Chapter 3
Manage the System Configuration settings Many Chapters
Explain Mailboxes and their usage Chapter 14
Configure Message Templates and System Interface configurations Chapter 14, Chapter 16
Explain Product, Category, and Disposition usage Chapter 8
Create and manage Guided Assistance and its application Chapter 13
Explain the File Menu and CX options features and their usage Chapter 2
Create and configure Custom Reports Chapter 17
Create and manage Scheduled Reports Chapter 17
Create and manage Surveys and Mailings Chapter 14
Create and manage Chat configurations and rules Chapter 16
Create and manage Co-Browse configurations Chapter 7
Customize and manage Templates, Pages, and Themes Chapter 6, Chapter 7
Describe Customer Portal deployment protocols Chapter 6
Customize and manage Tags, Widgets, and Assets Chapter 6

 

Oracle Policy Automation – JavaScript Custom Search

Oracle Policy Automation – JavaScript Custom Search

As many of you will no doubt  have discovered, the recent version of Oracle Policy Automation now comes equipped with a complete JavaScript Extension API. Simply put, we can create custom Labels, Input Controls and so on using JavaScript objects. Our code, which is part of the Project, is detected at runtime and executed by the JavaScript engine in your browser. In this post we will look at JavaScript Custom Search and how to use it in your own projects.

One of the most fun parts of this new API is of course discovering ways to use it. Following on from the post a couple of weeks ago, I thought I would share an example of using the customSearch. The principle behind using JavaScript Custom Search in Oracle Policy Automation is very easy to understand. Most of us are familiar, for example, with the concept of typing in a little bit of text and then the browser completes it, providing a drop down of potential choices. There are a myriad of ways and places to see it on the Internet. Perhaps you are searching for a street, so you type in the postal code and sure enough, your website might propose the list of streets in that area.

Whatever your reason for using it, here is an example you can play along with. Since we need a data provider, we are going to use JSONPlaceholder – a wonderful fake REST API that you can use for testing just this sort of thing. It is free and easy to use. We can call various different endpoints and the server will report back with fake data. We can use all the verbs and many different sorts of REST call. Great!

What else do we need?otn We need a JavaScript editor (step forward Notepad ++ for example) and the August 2017 edition of Oracle Policy Modeling. Before we look at the code however, remember the following caveat : anything you read here is for entertainment and education purposes only and should not be relied upon for any reason or situation.

Let’s get a big picture first. You are going to be coding three things

  1. The Search
  2. The Commit, which you can think of as “any post search processing”
  3. You will be building a set of records to be passed to the callback function

JavaScript Custom Search

The search itself, as I mentioned before we will use the JSONPlaceholder service. I have selected the users endpoint, so that I can fire off a query like “‘/users?q='” and pass the text string entered by my user. Hopefully the service will return some people.

JavaScript Custom Search Step by Step

The processing and preparation will involve, purely for the purpose of demonstrating the principles, laboriously removing any elements of the data I am not interested in. In fact I am going to delete everything except the name and the email address. The callback function expects a set of data that respects a specific format: “This can either be an array of strings or an array of objects where each object has a text property.” So now you know why I wanted to demonstrate the following

  1. Renaming a property in the object
  2. Using the other property, email, in the Commit.

Here is the first part, basically I am :

  1. getting the text from the user and then passing it to the REST endpoint in the form of a GET.
  2. The response is coming back at me as a bunch of objects, which I am going to loop through and trim by removing unnecessary stuff.
  3. Then I am going to convert it into an array of results for our JavaScript Custom Search.
  4. Then I call the callback function with the array passed in.

JavaScript Custom Search Script

The user can now select one of the values I have returned. When they select their chosen value, the commit will handle it:

JavaScript Custom Search Commit

In the picture above you can see the value which is passed in actually included the email element from the REST call, so I am free to use it (and any of the other bits I didn’t delete in the previous steps) to populate other attributes, such as the email address.

To help you make sense of all of that, you will find below a video which guides you through the steps and shows the different elements.

Have a nice day and I hope you enjoyed reading an example of JavaScript Custom Search in Oracle Policy Automation.

JavaScript Custom Search Video

Refactoring in Oracle Policy Automation #1

Refactoring in Oracle Policy Automation #1

The OPA Hub Website is extremely happy and very lucky to be able to welcome an esteemed guest author, Dr Jason Sender. Over the course of several months I have had the pleasure of reading Dr Sender’s work and conversing with him. His dissertation, entitled “The Application of Design Patterns to Oracle Policy Automation”, is a fascinating read and after due discussion with him, he has kindly agreed that parts of it might be republished here for the wider community; specifically in this article, an introduction to his excellent work on Refactoring in Oracle Policy Automation.

Dr Sender, of the University of Oxford, was Rules Architect for nearly four years on the most complex Rulebase used by the Legal Aid Agency in the United Kingdom, which is used to determine capital and income eligibility of applicants.

In this, the first of a series of posts, he looks at Refactoring Techniques based on Martin Fowler’s work and applies them to Oracle Policy Automation where appropriate. To simply state the goal of such an exercise, it can do no harm to state the goal of the book I just linked to:

“Refactoring is a controlled technique for improving the design of an existing code base. Its essence is applying a series of small behavior-preserving transformations, each of which “too small to be worth doing”. However the cumulative effect of each of these transformations is quite significant. “

How to Apply Object-Oriented Design Patterns to OPA?

At a broader level, it is possible to apply design patterns from Object-Oriented Design Patterns to OPA. Since OPA does not have objects and classes in the same sense as an object-oriented language, we should not expect a straightforward application to OPA. Not all of the patterns will be technically applicable, and even some of those will be unfeasible or without any great impact. Dr Sender’s work discusses the application of the eight most common patterns. If you would like to read further on this matter, please feel free to contact Jason using the information at the end of this article.

Improving your design Approach to OPA Rulebases

Object-Oriented languages come equipped with advanced development environments and a plethora of automation tools to help the refactoring effort. Oracle Policy Automation uses Microsoft Word and Excel, and is classified as a Production Rules System rather than a fully-fledged object-oriented language. As Fowler states (since it is particularly relevant to our daily lives as Oracle Policy Automation Consultants or Architects):

“There are also many languages where you don’t have tools, so knowing how to do it yourself is still important.”

The Application of Object-Oriented Refactoring in Oracle Policy Automation

This introductory article will focus on simple refactoring techniques that everyone can adopt, and which bring clarity and maintainability to Oracle Policy Automation rules. In a later article, Dr Sender will reveal OPA-specific refactoring techniques that were discovered during the course of his work.

Extract Variable Rule

Extract Variable Rule is a more meaningful OPA rebranding of Fowler’s Extract Method, since OPA does not have Methods. Have you ever seen something like this in an Oracle Policy Automation Word document?

Refactoring in Oracle Policy Automation - Extract

By applying the Extract Method: “You have a code fragment that can be grouped together. Turn the fragment into a method whose name explains the purpose of the method.” we find ourselves with a revised version that looks a little like the example below.

Refactoring in Oracle Policy Automation - Extract Example Complete

The gain in readability and ease of maintenance should be obvious. Now that Dr Sender has gotten us on the right track, let’s take a couple more examples from his work. These revolve around the removal of conditional expressions from Microsoft Word or Microsoft Excel tables.

Extract Rules from Rule Table

Extract Rules from Rule Table is a more meaningful OPA rebranding of Fowler’s Decompose Conditional Method. Consider the following table, where conditions and premises meet convoluted conclusions:

Refactoring in Oracle Policy Automation - Decompose Conditional

Now, here is the table, following an OPA-esque application of the Decompose Conditional refactoring technique, for situations where (according to Fowler):

You have a complicated conditional (if-then-else) statement. Extract methods from the condition, then part, and else parts.

Refactoring in Oracle Policy Automation - Decompose Conditional Complete

The aim of Extract Rules from Rule Table is to reduce code duplication and/or duplicated conclusion values.  It should be noted that it can add a level of indirection (i.e., flexibility) too, but its main use would be to extract duplicated rules from a complicated Word rule table, not, as in the example above, to extract only the conditions and conclusions of a single row, which arguably would add indirection at the cost of more code, unneeded flexibility, and complexity.

We would look to refactor to simplify code and increase clarity – if they do not do so in a given situation then they are probably not needed in that situation.

It’s worth restating the above in terms of goals.  One must understand one’s goals before applying a refactoring technique, and not every refactoring technique will be appropriate in every situation, and indeed many refactoring techniques are inverses of each other.  In certain situations flexibility is needed, even if it creates more code.  For example, instead of hard-coding a value in (e.g., an amount) in twenty different conclusions of a rule table you could set a variable equal to the amount and put the variable in the rule table, as this would add the ‘flexibility’ to change the amount if needed.  We would say it adds a level of indirection – but it does create more lines of code and complexity.

Almost everything is a balancing act and understanding one’s goals is hard, and it’s even harder to then figure out approaches that will help you achieve these goals, and that comes with Oracle Policy Automation experience, and a little help from OPA experts in articles like this one!

Refactoring in Oracle Policy Automation : There’s (Much) More!

Obviously these two simple examples can hope only to briefly demonstrate the value of the hard work that Dr Sender has put in to developing tools and techniques to improve the readability, maintenance and effectiveness of Oracle Policy Automation rules. He can be contacted using the link below should you wish to discuss his work, and he has kindly agreed to let me publish a couple more articles on this subject.

Watch this space for more valuable content on the topic of Refactoring in Oracle Policy Automation. The OPA Hub and Dr Sender are currently working towards the launch of advanced training based on his work. If you are interested, please take a moment to answer the 1 question survey below (if you have not already registered for the OPA Hub you can do that here before you answer) . Thank you!

What kind of advanced OPA training would you be interested in purchasing?