Class: MobyUtil::OperatorData

Inherits:
Object
  • Object
show all
Defined in:
lib/tdriver/util/operator_data/operator_data.rb

Class Method Summary collapse

Class Method Details

.retrieve(operator_data_lname, operator, table_name) ⇒ Object

description

Function to fetch a translation for a given logical name from the localisation DB

arguments

operator_data_lname

String
 description: operator data identifier
 example: "op_welcome_message""

operator

String
 description: Operator column name to be used when fetching operator data

example: “Orange”

table_name

String
 description: Name of the operator data table to use from the operator table DB
 example: "operator_data_week201042"

returns

String

description: Operator data string

throws

OperatorDataColumnNotFoundError

description: If the desired operator data is not found

OperatorDataColumnNotFoundError

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


59
60
61
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
# File 'lib/tdriver/util/operator_data/operator_data.rb', line 59

def self.retrieve( operator_data_lname, operator, table_name )
	
    raise OperatorDataNotFoundError.new( "Search string parameter cannot be nil" ) if operator_data_lname == nil

	# Get Localization parameters for DB Connection
	db_type =  $parameters[ :operator_data_db_type, nil ].to_s.downcase
	host =  $parameters[ :operator_data_server_ip ]
	username = $parameters[ :operator_data_server_username ]
	password = $parameters[ :operator_data_server_password ]
	database_name = $parameters[ :operator_data_server_database_name ]
	
	db_connection = DBConnection.new(  db_type, host, database_name, username, password )
	
	search_string = "#{ operator_data_lname }' AND `Operator` = '#{ operator }"			
	query_string =  "select `Value` from `#{ table_name }` where `LogicalName` = '#{ search_string }' and `LogicalName` <> '#MISSING'"

	begin
		result = MobyUtil::DBAccess.query( db_connection, query_string )
	rescue
	    # if data column to be searched is not found then raise error for search column not found
	    raise OperatorDataColumnNotFoundError.new( "Search column 'Value' not found in database" ) unless $!.message.index( "Unknown column" ) == nil
	    raise SqlError.new( $!.message )
    end

	# Return always the first column of the row
	raise OperatorDataNotFoundError.new("No matches found for search string '#{ operator_data_lname }' in search column 'LogicalName' for opreator #{ operator }" ) if ( result.empty?)
	# Result is an Array of rows (Array<String>)! We want the first column of the first row.
	return result[0][0]
	
end