Sha256: b8375026b2a9592533e2b3d2189a4bc708d2dd23ab9bfd04054d6f54cdab7239

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

require 'libis/services/generic_search'
require 'libis/services/oracle_client'
require 'libis/tools/xml_document'

module Libis
  module Services
    module Scope

      class Search
        include ::Libis::Services::GenericSearch

        attr_reader :oracle

        def initialize
          @doc = nil
        end

        def connect(name, password)
          @oracle = OracleClient.new(
              'libis-db-scope.cc.kuleuven.be:1556/SCOPEP.kuleuven.be',
              name, password
          )
        end

        def find(term, options = {})
          super
        end

        def query(term, options = {})

          case options[:type] || 'REPCODE'
            when 'REPCODE'
              @oracle.call('kul_packages.scope_xml_meta_file_ed', [term.upcase])
            when 'ID'
              @oracle.call('kul_packages.scope_xml_meta_file_by_id', [term.to_i])
            else
              raise RuntimeError, "Invalid Scope search type '#{options[:type]}'"
          end
          term = term.gsub(/[-\/]/, '_')
          err_file = "/nas/vol03/oracle/SCOPEP/#{term}_err.XML"
          md_file = "/nas/vol03/oracle/SCOPEP/#{term}_md.XML"
          if File.exist? err_file
            doc = Libis::Tools::XmlDocument.open(err_file)
            msg = doc['/error/error_msg']
            detail = doc['/error/error_']
            File.delete(err_file) rescue nil
            @doc = nil
            raise RuntimeError, "Scope search failed: '#{msg}'. Details: '#{detail}'"
          elsif File.exist? md_file
            @doc = Libis::Tools::XmlDocument.open(md_file)
            File.delete(md_file) rescue nil
            @doc
          else
            raise RuntimeError, 'Scope search did not generate expected result file.'
          end
        end

        def each(_ = {})
          yield @doc
        end

        def next_record(_ = {})
          yield @doc
        end

      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
libis-services-0.1.17 lib/libis/services/scope/search.rb
libis-services-0.1.16 lib/libis/services/scope/search.rb
libis-services-0.1.15 lib/libis/services/scope/search.rb
libis-services-0.1.14 lib/libis/services/scope/search.rb
libis-services-0.1.13 lib/libis/services/scope/search.rb