3. The following is intended for information purposes
only on behalf of Infratects, and may not be
incorporated into any contract. It is not a commitment
to deliver any services or functionality, and should not
be relied upon in making purchasing decisions. This
provides no warranties with respect to the offerings
described within. The development, release, and
timing of any features or functionality described for
Oracle’s products remains at the sole discretion of
Oracle. Any third-party names, trademarks and
copyrights contained in this document are the
property of their respective owners
Safe Harbour
4. Say hello to Jython
Coding standards – PEP8
Best practices when…
Best practices for FDMEE scripts
Highlights
Q&A
Agenda
6. ● Data Integration Leader
● +9 years focused on Data
Integration
● Link between functional
and technical people
● FDMEE Blogger
● fishing with FDMEE
● FDMEE Trainer
● Active member of OTN Next challenge
August-2015
CCC Mont Blanc
100KM
+6000m
7. Goals
What I don’t pretend What I do pretend
● You change all your
scripts after this
session
● You get bored and
leave the room
● You take best practices
into account
● Loose your fear of
Jython
● You enjoy
9. Python implementation for JVM
Functional + object-oriented
Elegant syntax for clearer scripts
Key fundamentals
● Code Indentation
● No need to declare types
● Indexes start at 0
● Slicing notation
● Seamless integration with Java
What is Jython?
+
_______
10. Windows and penguin are both happy
Easy to learn and code
Code reusing
VB Script is obsolete
JAVA APIs across EPM products
Jython 2.5.1
Why Jython in FDMEE?
11. VB syntax = 'Oh God!'
Jython syntax = 'My Goodness!‘
Simpler and clearer solutions
No begin/end tags
Functions are always defined as def (no Sub)
More robust and flexible error handling
Key differentiators with VB Script
12. Idiomatic Jython
● Common scripting idioms
● May not be obvious to newcomers
How do I get Jythonista?
What is Jythonic?
1. Get it working at all
2. Get it working regularly
3. Reuse code and design for reuse
4. Starting to write idiomatic Jython
14. CODING STANDARDS – PEP8
15
“Programs must be written for people to read,
and only incidentally for machines to execute”
—Abelson & Sussman,
Structure and Interpretation of Computer Programs
17. No hard tabs (never mix)
Indentation level 4 spaces
Space after “,” (lists, dicts, args, tuples)
Space around assignment and comparisons
Indentation and whitespaces
Hanging indent
• No args in 1st line
• Additional indent for args
Implied line
• Vertical Align with opening
delimiter
18. Line length < 80 chars (73 for
comments)
Align elements of continuation
lines
● After binary operator
● Vertically below open
delimiter (), [], {}
Long lines and continuations
19. No need to use break lines
Log messages SQL queries using the fdmAPI
Triple quotes for long strings
20. Comments and Documentation strings
● # Comment = Why and how the code works
● Block Comments
● Inline Comments
● Doc String = How to use
Please
keep them
up to date
21. Where do you write your scripts?
Who are you?
● IT Eclipse (PyDev), Netbean, Emacs, etc.
● Business Notepad++, others
Making your way to Jythonista easier
● IDE/Editor integration with PEP8
● Pylint (Python formatting code evaluation utility)
● PEP8 plugin for Notepad++
22. PEP8 online checker (http://pep8online.com/)
Don’t be scared and try it at home
24. Using loops and conditional statements
What are my data structures?
● for iterates thru a collection/iterable/generator
● while loops until a condition is false
List of triggers better than long conditions
● all and any functions
25. True and False (type bool)
Intrinsic truth values
Evaluating conditions
False True
False (== 0) True (==1)
“” (empty string) Any string but “” (“ “, “x”…)
0, 0.0 Any number but 0 (1, 0.2, -2…)
[], (), {}, set () Any non-empty container ([‘Loc’], [‘’]…)
None Almost any object that’s not explicitly False
26. Importing java libraries or modules
Separate lines unless from same module
Top of the script/function (after comments)
Aliases
Absolute imports preferred (x.y.z)
from package import func1, func2
Add path for custom modules to sys.path
27. Handling errors with try-catch
EAFP Vs. LBYL
Specify the exceptions to
catch
Limit code for the try
Module traceback (stack
traces)
sys.exc_info (exception +
msg)
28. Working with numbers and dates
Preferably use java.math.BigDecimal
Cast int(), long(), float()
Module datetime or java class
java.text.SimpleDateFormat
31. Working paths and files IO
Paths
● Use fdmContext[“OUTBOXDIR”] and similar
● Use os module functions
● os.path.join(path1, path2…)
● Raw strings for hard-coded paths r’E:f1.log’
Module codecs
Enumerate if you need line number
32. Working with dictionaries
Dictionaries are great
Dictionary[key] value
Natural replacement of
select case (VB)
33. Complex data structures will look simple
Custom error library (localization)
Working with Dictionaries
34. Working with SQL
FDMEE DB
● Get API functions when possible
● Commit after DML (fdmAPI.commitTransaction())
● Close result sets (fdmAPI.closeResultSet(rs))
● No need to open/close the SQL connection
Remote DB
● Use java.sql (or specific DB modules)
● Open SQL connection (or dblinks, synonym, remote
query…)
● Commit, close ResultSet, close connection
36. IT’S NOT ALL BEING
JYTHONIC
Best Practices for FDMEE Scripts
37
37. Migrating old VB Scripts
Line by Line = FAILURE
Clean up mess
Avoid mixing technologies
JAVA API ≠ FDM VB API
FDM VB API ≠ FDMEE
VB API
This is a good start
(raspberry)
Script Language
Import Jython
Event Jython/VB
Custom Jython/VB
Mapping Jython/SQL
Drill-Thru JavaScript
Logic Accounts Jython
Check Rules Jython
38. Object with context properties
Not all properties available in all scripts
Not all documented
Object fdmContext[“<PROPERTY NAME>”]
39. The JAVA API
Young API
fdmAPI.function(params)
fdmContext > fdmAPI > SQL Query
SQL query better than nothing
Write your own API (modules, aif-custom.jar)
Some examples Description
executeDML Insert, Update SQLs
executeQuery Select SQL
showCustomMessage/File Shows messages/files to end users
getCustomScriptParameters Parameters from custom scripts
40. Event scripts
Actions Bef/Aft workflow steps
FDM Classic events > FDMEE events
Different scripts per target app
def EventName
Select the right one
● When do you want to do what?
● TDATASEG or TDATASEG_T?
41. Example: Inserting new records
No API available
TDATASEG_T preferred over TDATASEG
DATAKEY (MSSQL)
● Identity in TDATASEG_T but not in TDATASEG
● Insert into TDATASEG_T (datakey is generated)
DATAKEY (Oracle)
● Uses a sequence
● TDATASEG_DATAKEY_S.NEXTVAL
42. Mapping scripts
New API (replacing old varValues)
Update multiple TDATASEG_T columns at
once
Multi-dimension better than script
#SQL preferred 1 update in one shot
43. Writing in the FDMEE process log
Add debugging code to your scripts
● Disable in Production (log level < 5)
● Use the FDMEE process log to learn
Use API functions to log messages
API function Use Log Level
logFatal(msg) Fatal error occurs All
logError(msg) Error occurs >=2
logWarn(msg) Warning condition occurs >=3
logInfo(msg) Informational message >=4
logDebug(msg) Debug message 5
44. Error handling in Import Scripts
Scripts evaluated before being executed
Lines skipped if there are evaluation errors
Hard to find the error
Why?
Better capture
the exception
45. Error handling in Event scripts
Errors shown in aif-WebApp.log
Use try-except to control errors
● Log the error in the FDMEE process log
46. Working the workflow status - Set
No published API available to set status
Update table AIF_PROCESS_DETAILS if needed
● Undocumented API fdmAPI.updateProcessDetails
Raise exception or sys.exit(“errmsg”)
Can use a dictionary for error messages
47. Highlights
Keep your scripts simple
Make it working before being Jythonic
Configure your IDE/Editor for PEP8
Don’t forget adding comments
Don’t reinvent the wheel… Google is your BF
Use the Java API
Understand the product inside out (log level 5)
Focus on Jython 2.5.1 (for now)
48. Call for papers is now open. Registration
opens May 2015.
Announcing
Infratects Top Gun US 2015
A technical conference with a focus on
Oracle Hyperion EPM
www.infratects.com/topgun
Friday, September 18, 2015
Hilton Granite Park Hotel
Dallas, Texas
49. You can always contact me
Email: francisco.amores@infratects.com
Mobile: +34674209000
LinkedIn: http://lnkd.in/dgpfvMW
Twitter: @akafdmee
Blog: http://akafdmee.blogspot.com
Join LinkedIn Group Oracle|Hyperion FDMEE
Q&A