libis-services 1.0.5 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2ce00b4bcc3a7510bba4c67012c0a1552952d952
4
- data.tar.gz: 96428f5da531d60378045967800aeeab05091a5d
2
+ SHA256:
3
+ metadata.gz: d769686dc6aacfd5c2284f26e692fe0bb9b2dddcaf7493d39363395b043846c6
4
+ data.tar.gz: 327783e9345a9f65aee921dda2f834c6610acc9df6658fa3586dc449b01781bc
5
5
  SHA512:
6
- metadata.gz: a2540a1835aace4888073336db20174a2a06e8073db83e7a6c58f623045d6b102f712f923416bc18e8b23c8e07a3a366322439d92dfd72c9ca720f6a9a441d5a
7
- data.tar.gz: 95eb2d53eca5febf20098eaf1f917ec1133f00f4a08589e40bd1052a545bfb7d765a2558fe99d8e93eb3144fb4e5f74b49b7c527d8944d51c8b4b7a8f9c5b515
6
+ metadata.gz: 84ec4e272d57865eeca0454d5f7348bc4065a6a34202e3e9982e63c761b4c408125595608429209f02a0788f7b51024da9318e095c1a99e30fb74eadcfbc2fc6
7
+ data.tar.gz: 9ecfd46c5bf0ee6f60c204d556ce4590023d1a76e074781ecb2cf055527ca8de7693c78f49d1254e4c750db891c01b521bea9cfda8f8c1cc3e4cbc62d557e1b5
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'backports/rails/hash'
3
+ require 'libis/tools/extend/hash'
4
4
  require 'libis/tools/xml_document'
5
5
 
6
6
  require 'libis/services/generic_search'
@@ -1,5 +1,6 @@
1
1
  require 'oai'
2
2
  require 'libis/tools/extend/hash'
3
+ require 'libis/tools/xml_document'
3
4
  require 'libis/services/service_error'
4
5
 
5
6
  module Libis
@@ -8,15 +9,24 @@ module Libis
8
9
  include OAI::XPath
9
10
 
10
11
  class Query
11
- attr_accessor :from, :until, :set, :metadata_prefix
12
12
 
13
- def intialize(metadata_prefix = 'oai_dc')
14
- @from = @until = @set = nil
15
- @metadata_prefix = metadata_prefix
13
+ def initialize(options = {})
14
+ @options = options
15
+ @options[:metadata_prefix] ||= 'oai_dc'
16
+ end
17
+
18
+ def [](key, value)
19
+ @options[key] = value
16
20
  end
17
21
 
18
22
  def to_hash
19
- { from: @from, until: @until, metadata_prefix: @metadata_prefix, set: @set }.cleanup
23
+ {
24
+ from: @options[:from],
25
+ until: @options[:until],
26
+ metadata_prefix: @options[:metadata_prefix],
27
+ set: @options[:set],
28
+ resumption_token: @options[:token] || @options[:resumption_token]
29
+ }.cleanup
20
30
  end
21
31
 
22
32
  end
@@ -35,28 +45,41 @@ module Libis
35
45
  do_oai_request(:list_sets, options)
36
46
  end
37
47
 
38
- def metdata_formats(identifier = nil)
48
+ def metadata_formats(identifier = nil)
39
49
  do_oai_request(:list_metadata_formats, {identifier: identifier})
40
50
  end
41
51
 
42
- def identifiers(token = nil, query = Query.new)
43
- options = token ? {resumption_token: token} : query.to_hash
44
- do_oai_request(:list_identifiers, options)
52
+ def identifiers(token_or_query = nil)
53
+ do_oai_request(:list_identifiers, token_or_query_to_hash(token_or_query))
45
54
  end
46
55
 
47
- def records(token = nil, query = Query.new)
48
- options = token ? {resumption_token: token} : query.to_hash
49
- do_oai_request(:list_records, options)
56
+ def records(token_or_query = nil)
57
+ do_oai_request(:list_records, token_or_query_to_hash(token_or_query))
50
58
  end
51
59
 
52
- def record(identifier, metadata_prefix)
60
+ def record(identifier, metadata_prefix = 'oai_dc')
53
61
  do_oai_request(:get_record, identifier: identifier, metadata_prefix: metadata_prefix)
54
62
  end
55
63
 
56
- private
64
+ protected
65
+
66
+ def token_or_query_to_hash(token_or_query)
67
+ case token_or_query
68
+ when Hash
69
+ Query.new(token_or_query).to_hash
70
+ when Query
71
+ token_or_query.to_hash
72
+ when String
73
+ { resumption_token: token_or_query }
74
+ else
75
+ {}
76
+ end
77
+ end
57
78
 
79
+ private
80
+
58
81
  def do_oai_request(method, options = {})
59
- response = @oai_client.send(method, options.cleanup)
82
+ response = options.cleanup.empty? ? @oai_client.send(method): @oai_client.send(method, options.cleanup)
60
83
  object_to_hash(response)
61
84
  rescue OAI::Exception => e
62
85
  raise Libis::Services::ServiceError, "OAI Error: #{e.code} - #{e.message}"
@@ -71,7 +94,7 @@ module Libis
71
94
  h[k] = object_to_hash(v)
72
95
  end
73
96
  when REXML::Element
74
- obj.to_s
97
+ Libis::Tools::XmlDocument.parse(obj.to_s).to_hash
75
98
  when OAI::Response, OAI::Header, OAI::Record, OAI::MetadataFormat, OAI::Set
76
99
  result = obj.instance_variables.map do |x|
77
100
  x[1..-1].to_sym
@@ -1,4 +1,12 @@
1
- require 'oci8'
1
+ # frozen_string_literal: true
2
+ if RUBY_PLATFORM == 'java'
3
+ require 'java'
4
+ require 'ojdbc8.jar'
5
+ require 'orai18n.jar'
6
+ java_import 'oracle.jdbc.pool.OracleDataSource'
7
+ else
8
+ require 'oci8'
9
+ end
2
10
 
3
11
  module Libis
4
12
  module Services
@@ -9,12 +17,27 @@ module Libis
9
17
 
10
18
  def initialize(url)
11
19
  @url = url
12
- @oci = OCI8.new(url)
20
+ @oci = if RUBY_PLATFORM == 'java'
21
+ raise RuntimeError, 'Malformed database URL' unless url =~ /^(.*)\/(.*)@(.*)$/
22
+ user, pass, db = $1, $2, $3
23
+ uri = "jdbc:oracle:thin:@#{db}"
24
+ ods = OracleDataSource.new
25
+ ods.set_url(uri)
26
+ ods.set_user(user)
27
+ ods.set_password(pass)
28
+ ods.get_connection
29
+ else
30
+ OCI8.new(url)
31
+ end
13
32
  ObjectSpace.define_finalizer(self, self.class.finalize(@oci))
14
33
  end
15
34
 
16
35
  def self.finalize(oci)
17
- proc { oci.logoff }
36
+ if RUBY_PLATFORM == 'java'
37
+ proc { oci.close }
38
+ else
39
+ proc { oci.logoff }
40
+ end
18
41
  end
19
42
 
20
43
  # @param [Boolean] value
@@ -60,7 +83,7 @@ module Libis
60
83
 
61
84
  def run(script, parameters = [])
62
85
  params = ''
63
- params = "\"" + parameters.join("\" \"") + "\"" if parameters and parameters.size > 0
86
+ params = "\"" + parameters.join("\" \"") + "\"" if parameters&.size.to_i > 0
64
87
  process_result `sqlplus -S #{url} @#{script} #{params}`
65
88
  end
66
89
 
@@ -19,6 +19,7 @@ module Libis
19
19
  include ::Libis::Tools::Logger
20
20
 
21
21
  def initialize(section, service, options = {})
22
+ @clear_soap_action = true
22
23
  basic_auth = options.delete(:basic_auth)
23
24
  if basic_auth
24
25
  options[:basic_auth] = [
@@ -27,7 +28,7 @@ module Libis
27
28
  ]
28
29
  end
29
30
  opts = {strip_namespaces: true, logger: ::Libis::Tools::Config.logger}.merge options
30
- base_url = opts.delete(:url) || 'http://depot.lias.be'
31
+ base_url = opts.delete(:url) || 'https://repository.teneo.libis.be'
31
32
  configure "#{base_url}/dpsws/#{section}/#{service}?wsdl", opts
32
33
  end
33
34
 
@@ -46,16 +47,18 @@ module Libis
46
47
 
47
48
  protected
48
49
 
50
+ attr_reader :clear_soap_action
51
+
49
52
  def call_raw(operation, args = {})
50
- data = if @auth
51
- request operation.to_s.to_sym, args, headers: {'Authorization' => @auth}
52
- else
53
- request operation.to_s.to_sym, args
54
- end
53
+ opts = {}
54
+ opts[:soap_action] = nil if clear_soap_action
55
+ opts[:headers] = {:Authorization => @auth} if @auth
56
+ data = request operation.to_s.to_sym, args, opts
55
57
 
56
58
  # remove wrapper
57
59
  data = data["#{operation}_response".to_sym]
58
- data.delete(:'@xmlns:ns1')
60
+ data.delete_if {|key, _value| key.to_s =~ /^@/}
61
+ # data.delete(:'@xmlns:ns1')
59
62
 
60
63
  # drill down the returned Hash
61
64
  data = data.first.last while data.is_a?(Hash) && 1 == data.size
@@ -12,7 +12,7 @@ module Libis
12
12
  class CollectionHandler < Libis::Services::Rosetta::Client
13
13
 
14
14
 
15
- def initialize(base_url = 'http://depot.lias.be', options = {})
15
+ def initialize(base_url = 'https://repository.teneo.libis.be', options = {})
16
16
  super 'repository', 'CollectionWebServices', {url: base_url}.merge(options)
17
17
  end
18
18
 
@@ -9,7 +9,7 @@ module Libis
9
9
 
10
10
  class DepositHandler < ::Libis::Services::Rosetta::Client
11
11
 
12
- def initialize(base_url = 'http://depot.lias.be', options = {})
12
+ def initialize(base_url = 'https://repository.teneo.libis.be', options = {})
13
13
  super 'deposit', 'DepositWebServices', {url: base_url}.merge(options)
14
14
  end
15
15
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'libis/tools/xml_document'
4
+ require 'libis/tools/mets_file'
4
5
  require_relative 'client'
5
6
 
6
7
  module Libis
@@ -9,7 +10,7 @@ module Libis
9
10
 
10
11
  class IeHandler < Libis::Services::Rosetta::Client
11
12
 
12
- def initialize(base_url = 'http://depot.lias.be', options = {})
13
+ def initialize(base_url = 'https://repository.teneo.libis.be', options = {})
13
14
  super 'repository', 'IEWebServices', {url: base_url}.merge(options)
14
15
  end
15
16
 
@@ -1,17 +1,17 @@
1
1
  require 'libis/services/oai'
2
+ require 'libis/tools/xml_document'
2
3
 
3
4
  module Libis
4
5
  module Services
5
6
  module Rosetta
6
7
  class OaiPmh < Libis::Services::Oai
7
8
 
8
- def initialize(base_url = 'http://depot.lias.be', options = {})
9
+ def initialize(base_url = 'https://repository.teneo.libis.be', options = {})
9
10
  super(base_url + '/oaiprovider/request')
10
11
  end
11
12
 
12
- def collections(institute, token = nil, query = Query.new)
13
- query.set = "#{institute}-collections"
14
- records(token, query)
13
+ def collections(institute, token_or_query = nil)
14
+ records(token_or_query_to_hash(token_or_query).merge(set: "#{institute}-collections"))
15
15
  end
16
16
 
17
17
  end
@@ -61,8 +61,9 @@ module Libis
61
61
  strip_namespaces: true,
62
62
  delete_namespace_attributes: true,
63
63
  empty_tag_value: nil,
64
- convert_tags_to: lambda { |tag| tag.to_sym }
64
+ convert_tags_to: lambda(&:to_sym)
65
65
  )
66
+ # noinspection RubyArgCount
66
67
  self.new(hash[:producer_info])
67
68
  end
68
69
  end
@@ -0,0 +1,56 @@
1
+ require 'virtus'
2
+
3
+ module Libis
4
+ module Services
5
+ module Rosetta
6
+ class ProducerAgent
7
+ # noinspection RubyResolve
8
+ include Virtus.model(nullify_blank: true)
9
+
10
+ attribute :first_name, String
11
+ attribute :last_name, String
12
+ attribute :user_name, String
13
+ attribute :job_title, String
14
+ attribute :street, String
15
+ attribute :suburb, String
16
+ attribute :city, String
17
+ attribute :country, String
18
+ attribute :address_5, String
19
+ attribute :zip, String
20
+ attribute :email_address, String
21
+ attribute :web_site_url, String
22
+ attribute :telephone_1, String
23
+ attribute :telephone_2, String
24
+ attribute :user_group, String
25
+
26
+ def to_hash
27
+ attributes.cleanup
28
+ end
29
+
30
+ def to_xml
31
+ Libis::Tools::XmlDocument.build do |xml|
32
+ # noinspection RubyResolve
33
+ xml.user_info {
34
+ xml.parent.default_namespace = 'http://www.exlibrisgroup.com/xsd/dps/backoffice/service'
35
+ self.attributes.each do |name, value|
36
+ xml.send(name, xmlns: '').text(value) if value
37
+ end
38
+ }
39
+ end.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::DEFAULT_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
40
+ end
41
+
42
+ def self.from_xml(xml)
43
+ xml_doc = Libis::Tools::XmlDocument.parse(xml)
44
+ hash = xml_doc.to_hash(
45
+ strip_namespaces: true,
46
+ delete_namespace_attributes: true,
47
+ empty_tag_value: nil,
48
+ convert_tags_to: lambda(&:to_sym)
49
+ )
50
+ # noinspection RubyArgCount
51
+ self.new(hash[:producer_info])
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -2,6 +2,7 @@
2
2
  require 'libis/tools/extend/hash'
3
3
  require 'libis/tools/xml_document'
4
4
  require_relative 'producer'
5
+ require_relative 'producer_agent'
5
6
  require_relative 'user'
6
7
 
7
8
  require_relative 'client'
@@ -12,7 +13,7 @@ module Libis
12
13
  class ProducerHandler < Libis::Services::Rosetta::Client
13
14
 
14
15
 
15
- def initialize(base_url = 'http://depot.lias.be', options = {})
16
+ def initialize(base_url = 'https://repository.teneo.libis.be', options = {})
16
17
  super 'backoffice', 'ProducerWebServices', {url: base_url}.merge(options)
17
18
  end
18
19
 
@@ -39,6 +40,7 @@ module Libis
39
40
  end
40
41
 
41
42
  def new_producer(producer_info)
43
+ # noinspection RubyArgCount
42
44
  producer_info = Rosetta::Producer.new(producer_info) unless producer_info.is_a?(Rosetta::Producer)
43
45
  call :create_producer, arg0: @pds_handle, arg1: producer_info.to_xml
44
46
  end
@@ -51,17 +53,18 @@ module Libis
51
53
  if agent_info
52
54
  info = agent(agent_id)
53
55
  return nil if info.nil?
54
- (agent_info.is_a?(Rosetta::User) ? agent_info.attributes : agent_info).each do |name, value|
56
+ (agent_info.is_a?(Rosetta::ProducerAgent) ? agent_info.attributes : agent_info).each do |name, value|
55
57
  info[name] = value
56
58
  end
57
59
  call :update_producer_agent, arg0: @pds_handle, arg1: agent_id, arg2: info.to_xml
58
60
  else
59
- request_object :get_producer_agent, Rosetta::User, arg0: @pds_handle, arg1: agent_id
61
+ request_object :get_producer_agent, Rosetta::ProducerAgent, arg0: @pds_handle, arg1: agent_id
60
62
  end
61
63
  end
62
64
 
63
65
  def new_agent(agent_info)
64
- agent_info = Rosetta::User.new(agent_info) unless agent_info.is_a?(Rosetta::User)
66
+ # noinspection RubyArgCount
67
+ agent_info = Rosetta::ProducerAgent.new(agent_info) unless agent_info.is_a?(Rosetta::ProducerAgent)
65
68
  call :create_producer_agent, arg0: @pds_handle, arg1: agent_info.to_xml
66
69
  end
67
70
 
@@ -99,6 +102,7 @@ module Libis
99
102
  end
100
103
 
101
104
  def new_contact(contact_info)
105
+ # noinspection RubyArgCount
102
106
  contact_info = Rosetta::User.new(contact_info) unless contact_info.is_a?(Rosetta::User)
103
107
  call :create_contact, arg0: @pds_handle, arg1: contact_info.to_xml
104
108
  end
@@ -108,6 +112,7 @@ module Libis
108
112
  end
109
113
 
110
114
  def link_contact(contact_id, producer_id, primary = true)
115
+ # noinspection RubySimplifyBooleanInspection
111
116
  call :link_contact_to_producer, arg0: @pds_handle, arg1: producer_id, arg2: contact_id, arg3: (!!primary).to_s.upcase
112
117
  end
113
118
 
@@ -10,7 +10,8 @@ require 'libis/tools/mets_file'
10
10
 
11
11
  require 'csv'
12
12
  require 'write_xlsx'
13
- require 'backports'
13
+ require 'libis/tools/extend/hash'
14
+ require 'libis/tools/extend/string'
14
15
  require 'awesome_print'
15
16
 
16
17
  require_relative '../service_error'
@@ -25,7 +26,7 @@ module Libis
25
26
  attr_reader :pds_service, :producer_service, :deposit_service, :sip_service, :ie_service, :collection_service
26
27
 
27
28
  # @param [String] base_url
28
- def initialize(base_url = 'http://depot.lias.be', pds_url = 'https://pds.libis.be', opts = {})
29
+ def initialize(base_url = 'https://repository.teneo.libis.be', pds_url = 'https://pds.libis.be', opts = {})
29
30
  @pds_service = Libis::Services::Rosetta::PdsHandler.new pds_url
30
31
  @producer_service = Libis::Services::Rosetta::ProducerHandler.new base_url, opts
31
32
  @deposit_service = Libis::Services::Rosetta::DepositHandler.new base_url, opts
@@ -11,7 +11,7 @@ module Libis
11
11
 
12
12
  class SipHandler < Libis::Services::Rosetta::Client
13
13
 
14
- def initialize(base_url = 'http://depot.lias.be', options = {})
14
+ def initialize(base_url = 'https://repository.teneo.libis.be', options = {})
15
15
  super 'repository', 'SipWebServices', {url: base_url}.merge(options)
16
16
  end
17
17
 
@@ -60,8 +60,9 @@ module Libis
60
60
  strip_namespaces: true,
61
61
  delete_namespace_attributes: true,
62
62
  empty_tag_value: nil,
63
- convert_tags_to: lambda { |tag| tag.to_sym }
63
+ convert_tags_to: lambda(&:to_sym)
64
64
  )
65
+ # noinspection RubyArgCount
65
66
  self.new(hash[:producer_info])
66
67
  end
67
68
  end