Friday, August 30, 2013

Using PyDev for Jython Scripts

Hi again!

I introduced new FDMEE scripting capabilities in my last entry.
So what´s next?
If you had time to play with new Script Editor I´m sure you already noticed few things: not interpreter, no colors, no indentation,etc.

If you come from FDM World then you will have to change your mind if you want to use Jython Scripts (they are mandatory for Import Scripts so...) If you have Java knowledge then it will be easier. And if you are Jythoner/Pythoner then you are lucky!

Even if you develop Event Scripts using VB Script you will see important differences from FDM. You can take a look to HFM Action Scripts which are located in  %EPM_ORACLE_HOME%\products\FinancialDataQuality\bin\

VB Scripts are executed using cscript (command-line version of the Windows Script Host -WSH) Therefore you need to declare input parameters for cscript, use WScript object, etc. Take a look!


For example, when data is loaded into HFM, you can see in the FDMEE process log how the HFM Action Script HFM_LOAD.vbs (see above) is executed... good for debugging :-)


So back to developing scripts. As Oracle suggests, your best option is to use a JAVA IDE to develop scripts. The most popular is Eclipse (or at least the one I´m going to use)
Is it enough? Not.
You need to install a Jython/Python Interpreter. I would recommend PyDev. You can use PyDev console to test your code and why not to learn Jython. 

To summarize your first steps:

1Install Eclipse
2. Install PyDev (follow instructions from in PyDev Site)
There is no installer for PyDev. You just have to install new software in Eclipse:


You have to configure the Jython Interpreter by selecting the Jython.jar file you want to use. I have selected the one coming with FDMEE installation as it is the one FDMEE provides:


3. Create your first project 
Don´t forget to select the Jython Interpreter you configured:


Amendment: I got some comments from colleague regarding Grammar version (thanks Craig!). Although there are more versions of Jython we will have to select the one aligned with the Jar we selected in previous step. We can check version by running command Java -JAR Jython.jar:


You can also check Jython version in any FDMEE Process log:


Grammar version can be adjusted after project has been created using the wizard (right click on project > PyDev - Interpreter/Grammar). As version provided by FDMEE is 2.5.1 we can then setup Grammar Version to 2.5 in order to ensure our Jython code will be working in FDMEE:



After project is setup you will have to add two JAR files in order to use FDMEE API objects (aif-apis.jar and aif-custom.jar which are located at EPM_ORACLE_HOME/products/FinancialDataQuality/lib). Appropiate JDBC driver is also needed. The 3 JAR files will be added as External Libraries:


4. Test the initialize script
In the FDMEE Admin guide you will find a sample script to initialize the FDMEE API. You can crate an empy PyDev module to develop it. Take into account that the parameter passed to fdmAPI.initContext function represents a valid Load ID. For example, you can find a valid one in table AIF_APPL_LOAD_AUDIT:


You can execute the script and see result in the PyDev console:


I would recommend you take a look to the new FDMEE Object Model and enjoy with new Jython in FDMEE

I wish you all a nice weekend!

FYI. You can follow us in Twitter (@akafdmee)

7 comments:

  1. Have you tested with 11.1.2.3.5.10? When testing in Eclipse or Notepad++, the following error is returned:
    fdmContext = fdmAPI.initContext(BigDecimal(392))
    at com.hyperion.aif.util.RegistryUtilCore.(RegistryUtilCore.java:54)

    at com.hyperion.aif.scripting.API.initLogger(API.java:973)

    at com.hyperion.aif.scripting.API.initContext(API.java:684)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)


    java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: oracle/core/ojdl/logging/ODLLogger


    ReplyDelete
    Replies
    1. Hi,
      yes.
      In PSU510 you have to include 2 additional libraries:
      ojdl.jar
      loj4j-1.2.14.jar

      I will write a post for that.

      Delete
    2. Thank you adding the additional Jar files worked.

      Delete
  2. I have followed all of the steps, added all of the JAR files and now I get this:

    fdmContext = fdmAPI.initContext(BigDecimal(77))
    at com.hyperion.aif.util.RegistryUtilCore.closeStatement(RegistryUtilCore.java:100)

    at com.hyperion.aif.util.RegistryUtilCore.getProfileOptionValue(RegistryUtilCore.java:362)

    at com.hyperion.aif.scripting.API.initLogger(API.java:973)

    at com.hyperion.aif.scripting.API.initContext(API.java:684)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:606)


    java.lang.AbstractMethodError: java.lang.AbstractMethodError: oracle.jdbc.driver.OracleResultSetImpl.isClosed()Z


    Can this be run on a local desktop or does it actually need to be on the server in which FDMEE is installed on?

    ReplyDelete
  3. Hi sirs,
    I am trying to write a Jython script for FDMEE 11.1.2.3.510 using eclipse IDE, I imported the required libraries aif-apis.jar, aif-custom.jar, 1.7 JDBC driver library, log4j-1.2.14.jar, and ojdl.jar.
    The initialization script is described below:
    import java.math.BigDecimal as BigDecimal
    import java.sql as sql
    import com.hyperion.aif.scripting.API as API
    fdmAPI = API()
    conn = None
    conn = sql.DriverManager.getConnection("jdbc:oracle:thin:@thypi-scan.mof.local:1521:THYP1", "CRP2_FDME", "CRP2FDME");
    conn.setAutoCommit(False)
    fdmAPI.initializeDevMode(conn);
    print "SUCCESS CONNECTING TO DB"
    fdmContext = fdmAPI.initContext(BigDecimal(1720))
    # I inserted a record in the AIF_APPL_LOAD_AUDIT with a LOADID = 1720
    #End Initialize Code Required for Dev Mode. Not required in production script
    #Code to be added to production script
    print fdmContext["LOCNAME"]
    print fdmContext["LOCKEY"]
    print fdmContext["APPID"]



    I am getting the error:
    fdmContext = fdmAPI.initContext(BigDecimal(1720))
    at com.hyperion.aif.scripting.API.getProcessLogFile(API.java:990)

    at com.hyperion.aif.scripting.API.initContext(API.java:681)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)


    java.lang.NullPointerException: java.lang.NullPointerException

    Can you help with a hint at least, I’ll be very thankful.

    Regards,
    Moha.

    ReplyDelete
  4. Francisco,

    I just wanted to talk you for this post, it was very helpful!

    -Mike Lau

    ReplyDelete
  5. what is SQL Server url available to connect to database using jython?

    ReplyDelete

Thanks for feedback!