<commit_before>require_relative "../../../../lib/search_abstractor"

class Soap::V1::EmployersController < ApplicationController

  before_filter  lambda { |controller| authenticate_soap_request!(controller.action_name)} , :only=>[:index, :show]
  before_filter  lambda { |controller| valid_params?(controller.action_name)}, :only=>[:index, :show]
  skip_before_filter :authenticate_user_from_token!
  skip_before_filter :authenticate_me!
  protect_from_forgery :except => [:get_by_hbx_id]
  before_filter :prepend_view_paths, :only=>[:index, :show]

  soap_service namespace: 'http://www.w3.org/2001/12/soap-envelope'

  @@logger = Logger.new("#{Rails.root}/log/soap.log")

  soap_action "index",
              :args => { :page => :integer, :hbx_id=> :integer, :fein=> :integer, :user_token=> :string },
              :return => :strings
  def index
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} params:#{params}"

    @employers = SearchAbstractor::EmployersSearch.search(params)

    Caches::MongoidCache.with_cache_for(Carrier) do
      @employers_xml = render_to_string "index"
    end

    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} @employers_xml:#{@employers_xml.inspect}"


    render :soap => @employers_xml
  end

  soap_action "show",
              :args => { :id => :string, :user_token=> :string },
              :return => :string
  def show
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} params:#{params}"

    @employer = Employer.find(params[:id])
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} @employer:#{@employer.inspect}"

    @employer_xml = render_to_string "show"

    render :soap => @employer_xml
  end

  private

  def valid_params?(action)
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} action_name#{action}: params:#{params}"

    case action_name.to_s
      when "show"
        unless  params["Envelope"]["Body"][action]["id"].present?
          render :status => :unprocessable_entity, :nothing => true
          return false
        end
      when "index"
        unless  params["Envelope"]["Body"][action]["hbx_id"].present? || params["Envelope"]["Body"][action]["fein"].present?
          render :status => :unprocessable_entity, :nothing => true
          return false
        end
    end

    return true

  end

  def prepend_view_paths
    prepend_view_path "#{Rails.root}/app/views/api/v1/"
  end

end<commit_msg>adding full path to view (api/v1/employers/index)<commit_after>require_relative "../../../../lib/search_abstractor"

class Soap::V1::EmployersController < ApplicationController

  before_filter  lambda { |controller| authenticate_soap_request!(controller.action_name)} , :only=>[:index, :show]
  before_filter  lambda { |controller| valid_params?(controller.action_name)}, :only=>[:index, :show]
  skip_before_filter :authenticate_user_from_token!
  skip_before_filter :authenticate_me!
  protect_from_forgery :except => [:get_by_hbx_id]
  before_filter :prepend_view_paths, :only=>[:index, :show]

  soap_service namespace: 'http://www.w3.org/2001/12/soap-envelope'

  @@logger = Logger.new("#{Rails.root}/log/soap.log")

  soap_action "index",
              :args => { :page => :integer, :hbx_id=> :integer, :fein=> :integer, :user_token=> :string },
              :return => :strings
  def index
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} params:#{params}"

    @employers = SearchAbstractor::EmployersSearch.search(params)

    Caches::MongoidCache.with_cache_for(Carrier) do
      @employers_xml = render_to_string "api/v1/employers/index"
    end

    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} @employers_xml:#{@employers_xml.inspect}"


    render :soap => @employers_xml
  end

  soap_action "show",
              :args => { :id => :string, :user_token=> :string },
              :return => :string
  def show
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} params:#{params}"

    @employer = Employer.find(params[:id])
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} @employer:#{@employer.inspect}"

    @employer_xml = render_to_string "api/v1/employers/show"

    render :soap => @employer_xml
  end

  private

  def valid_params?(action)
    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} action_name#{action}: params:#{params}"

    case action_name.to_s
      when "show"
        unless  params["Envelope"]["Body"][action]["id"].present?
          render :status => :unprocessable_entity, :nothing => true
          return false
        end
      when "index"
        unless  params["Envelope"]["Body"][action]["hbx_id"].present? || params["Envelope"]["Body"][action]["fein"].present?
          render :status => :unprocessable_entity, :nothing => true
          return false
        end
    end

    return true

  end

  def prepend_view_paths
    prepend_view_path "#{Rails.root}/app/views/api/v1/employers"

    @@logger.info "#{DateTime.now.to_s} class:#{self.class.name} method:#{__method__.to_s} view_paths:#{view_paths.inspect}"


  end

end
{'fraction_non_alphanumeric': 0.1614107109535361, 'fraction_numerical': 0.003918641537600299, 'mean_word_length': 4.009345794392523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6807732', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1786, 'n_words': 301}