Oracle ODA and Apache FreeMarker

This is part 3 of my foray into Oracle ODA (Oracle Digital Assistant). After the intro in slaying ODA pizzaBot and then subduing Composite Bag, I managed to reach into a new uncharted water called Apache FreeMarker. ODA uses FreeMarker to display, evaluate or format the variables and entities.

Ok, so we are getting you a ${pizza.value.PizzaSize?lower_case} ${pizza.value.PizzaTopping?capitalize} pizza.

Oracle
Biggest Challenge in FreeMarker

Handling missing values is the biggest challenge for me! I literally tear my hair trying to figure out how to handle missing or null values. Needless to sad, Oracle ODA documentation is not helpful and I have to refer to Apache FreeMarker documents. Many scripting languages allows you to display the variables even they do not exist. Unfortunately, FreeMarker is more strict and helpfully dedicate an entire section. Like all coding documents, help is cryptic. It takes a lot of trial and error to figure out where it goes wrong with its critical ! and (( )).

Default value and Formatting

FreeMarker have a funny way to evaluate default values. It is easy for simple variables in ODA or you are not formatting the variables. However, things gets very tricky when you are using composite bag with formatting. Below are some cheats for you to figure out the correct syntax.

${pizza!’Not Set’} – Simple variable with no formatting and default value after !.

${(pizza.value.PizzaSize)!’Not Set’} – Composite Bag with no formatting with ( ) to encapsulate the (composite bag variable)

${((pizza.value.PizzaSize)!’Not Set’)?upper_case}} – Composite Bag with formatting with ( ) to (encapsulate the variable and default value) and another ( ) to encapsulate (both values for formatting).

Hope these tips will save you a lot of time in formatting with FreeMarker in ODA. Just in case you are wondering, validation do not flag FreeMarket expressions. You only get the error when you test the skill. Below is a standard error shown due to above.

error is: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing: ==> eReadyPickUpDateTime.value [in template “FlowTemplate” at line 1, column 324] —- Tip: It’s the step after the last dot that caused this error, not those before it. —- Tip: If the failing expression is known to legally refer to something that’s sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use when-presentwhen-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??

Advertisement

One thought on “Oracle ODA and Apache FreeMarker

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s