EPM 整合代理程式的指令碼範例

以下指令碼範例說明,如何呼叫會提供匯率的外部 API,然後準備上傳用的資料,且其採用的格式必須能讓該資料被當作在 Oracle Enterprise Performance Management Cloud 的「資料交換」區段中定義的整合作業來處理。EPM Cloud 中的設定步驟,把代理程式例項當作整合作業的資料來源,並把某個 EPM 應用程式當作目標。請注意,這個指令碼只是個範例,我們無法保證它毫無缺點,因此請勿向 Oracle 客戶服務部提出關於該指令碼之任何相關疑問或問題的服務要求。

''' This jython script calls an external API to get exchange rates, and then generates a file which is picked up by the EPM Integration Agent '''

import json
import urllib2

''' Turn off SQL processing by AGENT '''

agentAPI.skipAction('true')

''' Set Proxy for HTTP call. Needed when connected via VPN ''' 

proxy = urllib2.ProxyHandler({'http': 'www-proxy.example.com:80' 'https': 'www-proxy.example.com:80'})
opener = urllib2.build_opener(proxy) urllib2.install_opener(opener)

''' Set up URL for rates download.  Please see the URL for additional information in regards to options. ''' 

currency = 'USD'
ratesurl = 'https://api.exchangeratesapi.io/latest?base=' + currency
fxrates = urllib2.urlopen(ratesurl)
text = json.loads(fxrates.read())
allrates = text['rates']

agentAPI.logInfo("Jython Script - RateExtract: URL - " + str(ratesurl))

''' Generate file for loading into the EPM Cloud '''

outfilename = agentContext["DATAFILENAME"]
outfile = open(outfilename, "w")

''' Generate header row '''

outfile.write("Account,Currency,Entity,From Currency,Scenario,View,Rate" + chr(10))

''' Generate a row for each rate '''

for toCur,toRate in allrates.iteritems():
    mystr = "Ending Rate" + "," + str(toCur) + "," + "FCCS_Global Assumptions" + "," + "FROM_" + str(currency) + "," + "Actual" + "," + "FCCS_Periodic" + "," + str(toRate) + chr(10)
    outfile.write(mystr)

outfile.close() 

agentAPI.logInfo("Jython Script - RateExtract: Output File Name - " + str(outfilename))