Thursday, October 27, 2022

#935 - Oracle Integration 3 invoking OCI Process Automation

 













We've already met the ubiquitous OrderProcess in previous OPA posts.  Now to invoking that very same process from Oracle Integration 3. In OIC Gen 2, Process is part of the toolkit, this will also be the case in Oracle Integration 3, however, this post concerns itself with the standalone version of OPA.

Step 1 is to create an app in IDCS 







Redirect URL is set to - https://my OIC3.ocp.oraclecloud.com/icsapis/agent/oauth/callback

Set Scopes as follows - note one for process and one for decisions.




   


Step 2 - Create REST Connection in OIC 3

A big thanks to my colleague Stan T. here 





















The Connection URL - Let's begin with the full URL -

https://myOPA.oci.oraclecloud.com/process/api/v1/process-instances?applicationName=OrderApprovals&version=1.0&processName=OrderProcess

Simply remove all after /v1.

Client Id/Secret are from the IDCS app - 









Username / password are required for OPA - I need to specify a user assigned to the relevant OPA role(s).

Note the Scope setting - I specify that for process as well as offline_access (enables token refresh).


Step 3 - Create the Integration in OIC 3

The integration is very simple, a REST trigger, with an <Order> payload, then an invoke leveraging the REST connection I just created. The invoke is configured as follows -






























btw. I copied the request/response from a Postman test I did earlier.
That's it - so let's test - 



















Check out the Activity Stream for the response from OPA -






Note the id - 2ce81538-55cc-11ed-a32f-eeebcfbf9deb - this is the Process Instance Id.

Now to the Process Workspace


Note the Instance Id.

I open the task form - 


 

Tuesday, October 25, 2022

#934 OCI Process Automation -> Decisions

 














Process Decisions

A short post on the mechanics of Process Decisions - quotes from the docs, in bold and italics. Think of Process Decisions as a service that can be invokes from a Process or via its REST api.
 
Let's go through these individually - 

Input Data

Decision services need input data, let's use the simple example of an Order.





Empty Decision

This is simply a placeholder - i.e. used for top level decision modeling, then gets set to a particular decision type when we come to implementation.

 


 











Context

A context is a collection of one or more key-value pairs with an optional result field. Each pair is called a context entry. The key attribute within a context entry acts as an identifier to its corresponding value attribute.

Here's a simple example, based on my ubiquitous Order Approvals scenario.













The context is for auto-approval, and, as such contains the logic to validate whether an order should be auto-approved - 



Note the use of nested contexts here - 

The logic is as follows - if an order is < 20k and the customer has placed more than 10 orders, then it is auto-approved. Here is the first part - 












As you can see, I have added a couple of keys and set some of them to the input values - 


 The output (Result) of this section is a boolean - is the total order value les than the limit? 


Now to part 2 - 













Now to wire input to context and test - 







I expose as a Service and Test - 




 





















I try with a valid order value but only 3 orders to date - 










IF THEN


Here is a simple example - implementing the rule that the product, iScooter, cannot be sold in Ireland.






Let's test again - 






Now test with country = "UK" - 









Expressions

An expression is a logical notation, defined according to the syntax of FEEL, that evaluates to a single value. It may consist of one or more entities, such as a literal, constant, or variable, interconnected by zero or more operators. In Oracle Cloud Infrastructure Process Automation, you can also use outputs of other decisions or built-in functions to define an expression.

That may seem rather cryptic - so here's a simple example

Here's a simple example - here I will create an expression that can be used in the following IF THEN rule.


Being connected to the input payload means my expression can use its values.












Now to the IF THEN rule - 

















If you feel the need to learn more about FEEL (Friendly Enough Expression Language) , then click here.

Let's test our ruleset again now - 



The results - 















LargeOrderValueRule returns false as 10 * 200 is less than 20k.  

Functions

The Decisions Service includes built-in functions e.g.

















These include the using date, string processing, list processing, if/then etc. You can create your own functions for logic not covered by these. Let's have a go at it then!

I want to give a special discount in the month of December, in honour of the Celtic feast of Imbolc. 
Other months also get a discount - the Celts love a party!















As you can see, I have created a new function (fx) along with a new inputField (in_orderMonth). I have also added a new expression (ExprHolidayDiscount). Let's look at each of these - 

in_orderMonth is just a text value e.g. Dec (December) -


 

 















The Function is defined as follows -







Here I  apply a 15% discount for orders during Imbolc (Dec). 
No discounts in Jan, but from Feb onwards we progress by 1% each month!
 

The expression is defined as follows - 


Let's test this out - 





Now test with the month of Nov (November) - 













Lists

A simple example to demo the use of Decision Service Lists - 










Let's begin with the ProductList - 



Self-explanatory. The input, in_product, defines the input variable for this use case e.g. a Text value e.g. iBike.

The IF THEN, ValidProduct, is defined as follows - 



The usual test...




 













Relations















Relations can be used to create a table like structure containing multiple expressions - e.g.









Note how I am leveraging the existing ProductList and HolidayDiscount expression here.

Let's see how it could be used in a IF THEN rule -






Let's test - ensuring the maximum discount -
















Loops

Create loops to iterate over lists or arrays. Using the loop logical notation, you can create three different types of loops, namely For, Some, and Every.

Again, let's have an example - I begin with the following input Order with multiple order lines -
 










 






Now to the Loop definition - 

I begin by just iterating over the product prices -















For - here I just specify a variable - orderPrice
In - here I point to the order price - 



















return - my variable.

Let's test this out - 





Now I can revisit the loop definition and add the duty.


















Invoking Decisions from Business Processes

Firstly, I can decide how to expose the decisions as services - 











Here is my rich set of decisions, now I can decide which ones to expose as Services - 
























Invoking Decisions via the REST api

The URL can be found here -



 

Summary

Process Decisions help you implement complex business logic quickly. Such decision based logic can be easily leveraged from your processes as well as via the REST api.