Class: MobyUtil::UserData
- Defined in:
- lib/tdriver/util/user_data/user_data.rb
Class Method Summary collapse
-
.retrieve(user_data_lname, language, table_name = nil) ⇒ Object
description Function for fetching user data from the user data DB.
Class Method Details
.retrieve(user_data_lname, language, table_name = nil) ⇒ Object
description
Function for fetching user data from the user data DB
arguments
user_data_lname
String
description: String containing user_data_lname to be used in fetching the translation
example: "uif_first_name"
language
String
description: Scring containing language to be used in fetching user information
example: "en"
table_name
String
description: Optional string containing the name of table to be used when user information, if empty the parameter user_data_server_database_tablename will be used
example: "user_data_week201042"
returns
String
description: User data string
Array
description: Array of values when multiple user data strings found
throws
UserDataNotFoundError
description: If the desired user data is not found
UserDataColumnNotFoundError
description: If the desired data column name to be used for the output is not found
SqlError
description: If there is and sql error while executing the query
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/tdriver/util/user_data/user_data.rb', line 62 def self.retrieve( user_data_lname, language, table_name = nil ) raise UserDataNotFoundError.new( "User data logical name can't be empty" ) if user_data_lname == nil # Get Localization parameters for DB Connection db_type = $parameters[ :user_data_db_type, nil ].to_s.downcase host = $parameters[ :user_data_server_ip ] username = $parameters[ :user_data_server_username ] password = $parameters[ :user_data_server_password ] database_name = $parameters[ :user_data_server_database_name ] table_name = $parameters[:user_data_server_database_tablename] if table_name.nil? or table_name.empty? db_connection = DBConnection.new( db_type, host, database_name, username, password ) query_string = "select `#{ language }` from #{ table_name } where lname = \'#{ user_data_lname }' and `#{ language }` <>\'#MISSING\'" begin result = MobyUtil::DBAccess.query( db_connection, query_string ) rescue # if column referring to language is not found then raise error for language not found raise UserDataColumnNotFoundError.new( "User data language column '#{ language }' was not found" ) unless $!..index( "Unknown column" ) == nil raise SqlError.new( $!. ) end # Return only the first column of the row or and array of the values of the first column if multiple rows have been found raise UserDataNotFoundError.new( "No user data for '#{ user_data_lname }' found for language '#{ language }'" ) if ( result.empty?) if result.length > 1 result_array = Array.new # array of rows! We want the first column of the first row result.each do |row| result_array << row[0] end return result_array else # Result is an Array of rows (Array<String>)! We want the first column of the first row. return result[0][0] end end |