Sha256: d56630a646947d0a2a0a39436b0b135501a568e6f8f12f47051c390b246aac76

Contents?: true

Size: 1.69 KB

Versions: 32

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true
# This class loads an authority.
module QaServer
  class AuthorityLoaderService
    class << self
      # Load a QA authority
      # @param authority_name [String] name of the authority to load (e.g. "agrovoc_direct")
      # @param status_log [ScenarioLogger] logger to hold failure information if the authority cannot be loaded
      # @return [Qa::Authorities::LinkedData::GenericAuthority] the instance of the authority that can receive QA requests OR nil if fails to load
      def load(authority_name:, status_log: nil)
        begin
          authority = load_authority(authority_name, status_log)
          return nil if authority.blank?
        rescue Exception => e
          if status_log.present?
            status_log.add(authority_name: authority_name,
                           status: QaServer::ScenarioValidator::FAIL,
                           error_message: "Unable to load authority '#{authority_name}'; cause: #{e.message}")
          end
          return nil
        end
        authority
      end

      private

        def authority_key(authority_name)
          authority_name.upcase.to_sym
        end

        def load_authority(authority_name, status_log)
          authority = Qa::Authorities::LinkedData::GenericAuthority.new(authority_key(authority_name))
          if authority.blank?
            if status_log.present?
              status_log.add(authority_name: authority_name,
                             status: QaServer::ScenarioValidator::FAIL,
                             error_message: "Unable to load authority '#{authority_name}'; cause: UNKNOWN")
            end
            return nil
          end
          authority
        end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
qa_server-7.4.0 app/services/qa_server/authority_loader_service.rb
qa_server-7.3.0 app/services/qa_server/authority_loader_service.rb
qa_server-7.2.1 app/services/qa_server/authority_loader_service.rb
qa_server-7.2.0 app/services/qa_server/authority_loader_service.rb
qa_server-7.1.3 app/services/qa_server/authority_loader_service.rb
qa_server-7.1.2 app/services/qa_server/authority_loader_service.rb
qa_server-7.1.1 app/services/qa_server/authority_loader_service.rb
qa_server-7.1.0 app/services/qa_server/authority_loader_service.rb
qa_server-7.0.0 app/services/qa_server/authority_loader_service.rb
qa_server-6.2.0 app/services/qa_server/authority_loader_service.rb
qa_server-6.1.0 app/services/qa_server/authority_loader_service.rb
qa_server-6.0.0 app/services/qa_server/authority_loader_service.rb
qa_server-5.5.1 app/services/qa_server/authority_loader_service.rb
qa_server-5.5.0 app/services/qa_server/authority_loader_service.rb
qa_server-5.4.0 app/services/qa_server/authority_loader_service.rb
qa_server-5.3.0 app/services/qa_server/authority_loader_service.rb
qa_server-5.2.1 app/services/qa_server/authority_loader_service.rb
qa_server-5.2.0 app/services/qa_server/authority_loader_service.rb
qa_server-5.1.0 app/services/qa_server/authority_loader_service.rb
qa_server-5.0.3 app/services/qa_server/authority_loader_service.rb