Parent

AppException

Model class for App Exceptions. This model helps to show the details of the exceptions tracked by the server.

Public Class Methods

add_exception_class(app_name,exception_class) click to toggle source

This method is used to check the existance of exception class and call save_exception_class_in_config_file method

# File app/models/app_exception.rb, line 58
def add_exception_class(app_name,exception_class)
  if exception_class != ""
    save_exception_class_in_config_file(app_name,exception_class)
  else
    "can't be blank."
  end
end
count_closed(app_id) click to toggle source

Take App.id as argument and returns count of distinct closed exceptions for an Application

# File app/models/app_exception.rb, line 42
def count_closed(app_id)
  where(:app_id => app_id, :exception_status => CLOSED_EXCEPTION).count
end
count_ignored(app_id) click to toggle source

Take App.id as argument and returns count of distinct ignored exceptions for an Application

# File app/models/app_exception.rb, line 47
def count_ignored(app_id)
  where(:app_id => app_id, :exception_status => IGNORED_EXCEPTION).count
end
count_open(app_id) click to toggle source

Take App.id as argument and returns count of distinct open exceptions for an Application

# File app/models/app_exception.rb, line 37
def count_open(app_id)
  where(:app_id => app_id, :exception_status => OPEN_EXCEPTION).count
end
delete_exception_class_from_config(app_name,exception_class) click to toggle source

This method is used to delete the exception classes from configuration file

# File app/models/app_exception.rb, line 81
def delete_exception_class_from_config(app_name,exception_class)
  app_id = ApplicationSpecification.get_application_id_from_name(app_name)
  info = YAML::load_file(CONFIG_FILE_PATH) rescue nil
  info['Application Specification'][app_id]['permanently_ignored_list'].delete(exception_class)
  YAMLWriter.write(info, CONFIG_FILE_PATH, YAMLConfig::CONFIG)
  update_all_status_by_exception_class(app_name,exception_class,OPEN_EXCEPTION)
  exception_classes = info['Application Specification'][app_id]['permanently_ignored_list']
end
get_all(exception_status, app_id, page = 1, per_page = 5) click to toggle source

Gives the array of the five (open|closed|ignored) exceptions starting from the value of varriable ‘start’ for an application.

# File app/models/app_exception.rb, line 29
def get_all(exception_status, app_id, page = 1, per_page = 5)
  where(:app_id => app_id, 
        :exception_status => exception_status
        ).paginate(:page => page, 
        :per_page => per_page)
end
get_exception_classes(app_name) click to toggle source

This method is used to get all the exception classes from configuration file for the given app_id

# File app/models/app_exception.rb, line 91
def get_exception_classes(app_name)
  info = YAML::load_file(CONFIG_FILE_PATH) rescue nil
  app_data = info['Application Specification'].detect{|app_item| app_item["name"].eql?(app_name)}
  if not app_data['permanently_ignored_list']
    exception_classes = Array.new
  else
    exception_classes = app_data['permanently_ignored_list']
  end
end
get_exception_for_analyzer(exception_hash, app_id) click to toggle source

This function is used to fetch the first exception record for the given exception_message pattern , exception_class, exception_details.controller , exception_details.method and app_id

# File app/models/app_exception.rb, line 116
def get_exception_for_analyzer(exception_hash, app_id)
  where("exception_message like ? and exception_class = ? and controller = ? and method = ? and app_id = ?",
                      exception_hash[:exception_message].split(EXCEPTION_MESSAGE_SPLITER)[0] + '%',
                      exception_hash[:exception_class],
                      exception_hash[:controller],
                      exception_hash[:method],
                      app_id).first
end
get_exceptions_by_class(app_id,exception_class) click to toggle source

TODO Change function to fetch all exception records if we require all exception fields instead of id only

# File app/models/app_exception.rb, line 102
def get_exceptions_by_class(app_id,exception_class)
  where(:app_id => app_id, :exception_class => exception_class).select(:id)
end
save_exception_class_in_config_file(app_name,exception_class) click to toggle source

This method is used to add the exception classes into configuration file

# File app/models/app_exception.rb, line 67
def save_exception_class_in_config_file(app_name,exception_class)
  app_id = ApplicationSpecification.get_application_id_from_name(app_name)
  info = YAML::load_file(CONFIG_FILE_PATH) rescue nil
  info['Application Specification'][app_id]['permanently_ignored_list'] = Array.new if not info['Application Specification'][app_id]['permanently_ignored_list']
  if not info['Application Specification'][app_id]['permanently_ignored_list'].include?(exception_class)
    info['Application Specification'][app_id]['permanently_ignored_list'].push(exception_class)
    YAMLWriter.write(info, CONFIG_FILE_PATH, YAMLConfig::CONFIG)
    update_all_status_by_exception_class(app_name,exception_class,PERMANENTLY_IGNORED_EXCEPTION)
    return
  end
  "Exception class already exist."
end
update_all_status_by_exception_class(app_name,exception_class,status) click to toggle source

This method is used to change status of exceptions by searching the exception with exception_class

# File app/models/app_exception.rb, line 107
def update_all_status_by_exception_class(app_name,exception_class,status)
  app_id = App.get_application_data(app_name).id
  app_id_array = get_exceptions_by_class(app_id,exception_class)
  app_ids = app_id_array.collect { |a| a['id']}
  update_all_status_to(status,app_ids)
end
update_all_status_to(status, exceptions_id_array) click to toggle source

Update all exceptions status for given exceptions id array

# File app/models/app_exception.rb, line 52
def update_all_status_to(status, exceptions_id_array)
  update_all(["exception_status = ?",status], ["id in (#{exceptions_id_array.join(',')})"])      
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.