Rubrique précédente: Examples

Rubrique suivante: CMDB Example

Translation Scripts - User Function Scripts; Examples

Example 1

Sub CheckIsUserExists

  If (Tools.IsUserExists("acme@Insight")) Then
    Tools.Log "'acme@Insight' User exist.", "I"
  Else
    Tools.Log "'acme@Insight' User does not exist.", "I"
  End If

  If (Tools.IsUserExists("acme")) Then
    Tools.Log "'acme' User exist.", "I"
  Else
    Tools.Log "'acme' User does not exist.", "I"
  End If

  If (Not Tools.IsUserExists("databaseMtn@INTERNAL")) Then
    Tools.Log "'DataBaseMtn@INTERNAL' User does not exist.", "I"
  Else
    Tools.Log "'DataBaseMtn@INTERNAL' User exist.", "I"
  End If

End Sub

Sub CheckGetUserFullName
  Tools.Log "GetUserFullName", "I"
  Tools.Log Tools.GetUserFullName("aaaa","bbbb"),"I"
  Tools.Log Tools.GetUserFullName("aaaa",""),"I"
  Tools.Log Tools.GetUserFullName("","bbbb"),"I"
  Tools.Log Tools.GetUserFullName("aa@aa","bb@bb"),"I"
End Sub


Sub CheckGetUserName
  Tools.Log "GetUserName", "I"
  Tools.Log Tools.GetUserName("aaaa@bbbb"),"I"
  Tools.Log Tools.GetUserName("aaaa@bb@bb"),"I"
  Tools.Log Tools.GetUserName("@bbbb"),"I"
  Tools.Log Tools.GetUserName("aa aa b@bbbb"),"I"
  Tools.Log Tools.GetUserName("aaaabbbb"),"I"
End Sub

Sub CheckGetOrganizationName
  Tools.Log "GetOrganizationName", "I"
  Tools.Log Tools.GetOrganizationName("aaaa@bbbb"),"I"
  Tools.Log Tools.GetOrganizationName("aaaa@bb@bb"),"I"
  Tools.Log Tools.GetOrganizationName("@bbbb"),"I"
  Tools.Log Tools.GetOrganizationName("aa aa b@bbbb"),"I"
  Tools.Log Tools.GetOrganizationName("aaaabbbb"),"I"
End Sub

Sub CheckSearchUsers
  SearchUsers "","","",""
  SearchUsers "INACTIVE","","",""
  SearchUsers "ACTIVE","","",""
  SearchUsers "","*i*","",""
  SearchUsers "","*e*","",""
  SearchUsers "","","Test",""
  SearchUsers "","","Bla",""
  SearchUsers "","","","my"
  SearchUsers "","","","*my*"
  SearchUsers "","acm*","","*my*"
End Sub

Sub SearchUsers (status, name, organization,description)
  Dim map

  Set map = Tools.SearchUsers(status, name, organization,description)
  Tools.Log "Search Users:   Name        =" & name
  Tools.log "                Organization=" & organization
  Tools.Log "                status      =" & status
  Tools.Log "                Description =" & description
  Tools.Log map.dump, "I"
End Sub

Sub CheckGetUserDetails
  GetUserDetails "acme@Test"
  'GetUserDetails "XXX@YYY"  ' search for user that does not exist. It must fail.

End Sub

Sub GetUserDetails (name)
  Dim map
  Set map = Tools.GetUserDetails(name)
  Tools.Log map.dump
End Sub

Sub CheckAddUser
  Dim map
  Set map = Tools.GetUserDetails("acme@Test")

  'Check user already exists
  'Tools.AddUserByMap map

  'Check with duplicate
  map("UserName") = "acme2"
  map("UserPassword") = "acme2"
  map("UserPasswordExpirationInterval") = "50"
  map("UserDescription") = "New description"
  map("UserStatus") = "INACTIVE"

  Tools.AddUserByMap map
  Tools.Commit
 
End Sub

Sub CheckUpdateUser
  Dim map
  Set map = Tools.GetUserDetails("acme@Test")

  'Check user already exists
  'Tools.AddUserByMap map

  map("UserName") = "acmeKrakover"
  map("UserPassword") = "acme"
  map("UserPasswordExpirationInterval") = "55.5"
  map("UserDescription") = "New description"
  map("UserGroups") = "acme test group"
  map("Roles") = "Supervisors"
  map("ContractParties") = "acme CP Group 123"

  Tools.Log map.dump
  Tools.UpdateUserByMap "acmeKrakover@Test", map
  Tools.Commit

End Sub

Example 2 - Running LDAP queries from within a translation script

In order to run LDAP queries from within a translation script, each specific, individual translation script must be configured so that it does not run in safe mode. Go to t_translation_script using a database access tool and manually change the script.

This can be done using an update query such as the following (change the where clause as required):

update t_translation_scripts
set safe_mode = 'N'
where script_id = …

In order to return the script to run in safe mode as default, reset it by running the following (using the same where clause as previously):

update t_translation_scripts
set safe_mode = 'Y'
where script_id = …

Example 3 - Translation Script - AddException

Option Explicit

Sub OnLoad()
  'Tools.log "Translation Script : In OnLoad procedure", "I"
End Sub

Sub OnTranslationEvent(EntryDetails)
  'Tools.log "Translation Script : In OnTranslationEvent function", "I"
End Sub

Sub Main()
  'Tools.log "Translation Script : In Main procedure", "I"
  
  Dim map2
  Set map2=Tools.CreateMap
  
  map2("Exception1")="Exception2"    
  map2("ExceptionName")="Exception2"    
  map2("ExceptionJustification")="Exception2"
  map2("ExceptionDescription")=""
  map2("ExceptionEffectiveFrom")="01/12/2009"
  map2("ExceptionEffectiveTo")="05/12/2009"
  map2("ExceptionTimeSlot")="Always"
  map2("ContractParties") = Tools.CreateMap
  'Uncomment the following line to assign the exception to contract party: contractParty1
  'map2("ContractParties")("contractPartyName")="contractParty1"
   map2("Contracts")= Tools.CreateMap
  'Comment out the following line if only assigning the exception to a contract party, and not a contract. The following key is in the format: ContractPartyNameContractName
  map2("Contracts")("contractParty1contract1")= "contract1"
  map2("Services")=Empty  
  map2("DomainCategories")=Empty  
  
Tools.AddException(map2)

Tools.Commit
  
End Sub

Function Result
  'Tools.log "Translation Script : In Result function", "I"
  'Result =
End Function