ossiejhmoore

kstateexample_run.e

Feb 1st, 2017
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  
  3.     #Save this script to your [OTHOME]\scripts directory, then...
  4.    
  5.     #update your opentext.ini file as follows.....
  6.  
  7.     #update loader section's "load=" statement, add the ";kstateexample" expression to the end, like this...
  8.    
  9.     [loader]
  10.     load=sockserv;javaserver;notify;wfagent;agents;kstateexample
  11.  
  12.     #add this new section
  13.    
  14.     [kstateexample]
  15.     lib=.\bin\lljob.dll
  16.     name=kiniexample
  17.     prio=critical
  18.     timeout=5000
  19.     info=.\config\opentext.ini;kstateexample
  20.     StartScript=.\scripts\llfull.lxe
  21.     JobScript=.\scripts\kstateexample_run.e
  22.     CRON=* * * * *
  23.     SleepIntervalSec=10
  24.  
  25. */
  26. function Dynamic JobScript( \
  27.     Assoc       params, \
  28.     Dynamic     notCtxOut )
  29.    
  30.     Dynamic     retval
  31.     Record      r
  32.     Dynamic     ctxin
  33.     Dynamic     err
  34.     Dynamic     debugLevel
  35.     FilePrefs   prefs
  36.     String      filePrefsName
  37.     String      activityIDsStr
  38.     String      excludeActivityIDsStr
  39.     File        ctxout
  40.     Object      agent
  41.     Frame       f
  42.  
  43.     List        agentList = {}
  44.     List        excludeAgentList = {}
  45.     String      logPath = './logs/'
  46.     String      section = 'notify_run'
  47.    
  48.  
  49.     // get preference section
  50.     if ( IsFeature( params, '_LLJOB_SECTION_NAME_' ) )
  51.         section = params.( '_LLJOB_SECTION_NAME_' )
  52.     end
  53.     String      runLog = Str.Format( "%1_run%2.html", section, System.ThreadIndex() )
  54.  
  55.     // get preference file path
  56.     if ( IsFeature( params, '_LLJOB_CONFIG_FILE_' ) )
  57.         filePrefsName = params.( '_LLJOB_CONFIG_FILE_' )
  58.     else
  59.         filePrefsName = System.FilePrefsPath()
  60.     end
  61.    
  62.     if !File.Exists( filePrefsName )
  63.         echo( Str.Format( "Can not find configuration file: '%1'.", filePrefsName ) )
  64.     else
  65.         prefs = FilePrefs.Open( filePrefsName )
  66.    
  67.         if ( IsUndefined( prefs ) || IsError( prefs ) )    
  68.             echo( Str.Format( "Could not open prefs '%1'.", filePrefsName ) )
  69.         end
  70.     end
  71.    
  72.     logPath = GetMyPrefPath( prefs, section, 'Logpath', logPath ) + runLog
  73.     activityIDsStr = GetMyPref( prefs, section, 'ActivityIDs', '' )
  74.     debugLevel = Str.StringToValue( GetMyPref( prefs, section, 'Debug', '0' ) )
  75.  
  76.     FilePrefs.Close( prefs )
  77.  
  78.     // open per request run log based on preferences
  79.     ctxout = File.Open( logPath, File.WriteMode )
  80.  
  81.    
  82.    
  83.    
  84.     echo("[KSTATEEXAMPLE] start")
  85.     echo("[KSTATEEXAMPLE] Call to GetKiniParam('RecMan','holdsFolderID'): ", GetKiniParam('RecMan','holdsFolderID'))
  86.     echo("[KSTATEEXAMPLE] stop")
  87.  
  88.  
  89.  
  90.     //  close log file
  91.     File.Close( ctxout )
  92.  
  93.     if ( IsDefined( err ) )
  94.         echo( "Job error: ", err )
  95.         retval = err
  96.     else
  97.         echo( Date.Now(), " completed SUCCESS" )
  98.     end
  99.    
  100.     return 0
  101. end
  102.  
  103.  
  104. // check both section passed and the [general] sections
  105. function String GetMyPrefPath( FilePrefs prefs, String section, String prefName, String defReturn )
  106.     String      retVal = defReturn
  107.    
  108.     if ( IsDefined( prefs ) || !IsError( prefs ) )     
  109.         retVal = FilePrefs.GetPath( prefs, section, prefName )
  110.  
  111.         if ( IsError( retVal ) || IsUndefined( retVal ) )
  112.             retVal = FilePrefs.GetPath( prefs, 'general', prefName )
  113.  
  114.             if ( IsError( retVal ) || IsUndefined( retVal ) )
  115.                 //echo( "Could not find preference :" , prefName )
  116.                 retVal = defReturn
  117.             end
  118.         end
  119.     end
  120.    
  121.     return retVal
  122. end
  123.  
  124.  
  125. // check both section passed and the [general] sections
  126. function String GetMyPref( FilePrefs prefs, String section, String prefName, String defReturn )
  127.     String      retVal = defReturn
  128.    
  129.     if ( IsDefined( prefs ) || !IsError( prefs ) )     
  130.         retVal = FilePrefs.GetPref( prefs, section, prefName )
  131.  
  132.         if ( IsError( retVal ) || IsUndefined( retVal ) )
  133.             retVal = FilePrefs.GetPref( prefs, 'general', prefName )
  134.  
  135.             if ( IsError( retVal ) || IsUndefined( retVal ) )
  136.                 //echo( "Could not find preference :" , prefName )
  137.                 retVal = defReturn
  138.             end
  139.         end
  140.     end
  141.    
  142.     return retVal
  143. end
  144.  
  145.  
  146. function Object GetPrgCtx(String username)
  147.  
  148.     Assoc   dbCredentials
  149.     Assoc   tmpVal
  150.     Object  prgCtx
  151.     Dynamic dftConnection
  152.     String  msg
  153.    
  154.     prgCtx = Undefined
  155.     dftConnection = $Kernel.SystemPreferences.GetPrefGeneral( 'DftConnection' )
  156.    
  157.     dbCredentials.Ok           = true
  158.     dbCredentials.User         = Username
  159.     dbCredentials.Password     = Undefined
  160.     dbCredentials.DBConnection = dftConnection
  161.    
  162.     tmpVal = $LLIApi.PrgSession.CreateNewNamed(        \
  163.         dbCredentials.DBConnection,                    \
  164.         { dbCredentials.User, dbCredentials.Password } )
  165.    
  166.     if ( tmpVal.ok )
  167.         prgCtx = tmpVal.pSession
  168.     else
  169.         prgCtx = Undefined
  170.         msg = Str.Format(                           \
  171.             "Failed to create a prgCtx. Reason: %1" \
  172.             ,tmpVal.ErrMsg                          )
  173.         echo( msg )
  174.     end
  175.  
  176.     return prgCtx
  177.  
  178. end
  179.  
  180. function Assoc GetKiniParam(String section, String key, Object prgCtx = Undefined)
  181.  
  182.     Assoc retVal
  183.     retVal.ok     = false
  184.     retVal.ErrMsg = Undefined
  185.     retVal.Value  = Undefined
  186.  
  187.     Dynamic value
  188.    
  189.     if (IsUndefined(prgCtx))
  190.         prgCtx = GetPrgCtx("Admin")
  191.     end
  192.    
  193.     value = capi.IniGet(prgCtx.fDBConnect.fLogin, section, key)
  194.     if (IsError(value))
  195.         retVal.ErrMsg = Error.ErrorToString(value)
  196.     else
  197.         retVal.Value = value
  198.         retVal.ok = true
  199.     end
  200.    
  201.     if (!retVal.ok)
  202.         if (IsUndefined(retVal.ErrMsg))
  203.             retVal.ErrMsg = Str.Format("Failed call to get Kini Parameter for unknown reason.")
  204.         end
  205.     end
  206.     return retVal
  207. end
Advertisement
Add Comment
Please, Sign In to add comment