libis-services 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +36 -0
  6. data/Rakefile +6 -0
  7. data/lib/libis-services.rb +1 -0
  8. data/lib/libis/services.rb +21 -0
  9. data/lib/libis/services/aleph/search.rb +157 -0
  10. data/lib/libis/services/collective_access.rb +1 -0
  11. data/lib/libis/services/collective_access/cataloguing.rb +48 -0
  12. data/lib/libis/services/collective_access/connector.rb +151 -0
  13. data/lib/libis/services/collective_access/item_info.rb +36 -0
  14. data/lib/libis/services/collective_access/search.rb +26 -0
  15. data/lib/libis/services/collective_access/service.rb +80 -0
  16. data/lib/libis/services/digitool/digital_entity_manager.rb +223 -0
  17. data/lib/libis/services/digitool/digitool_connector.rb +46 -0
  18. data/lib/libis/services/digitool/meta_data_manager.rb +193 -0
  19. data/lib/libis/services/extend/http_fetch.rb +63 -0
  20. data/lib/libis/services/generic_search.rb +38 -0
  21. data/lib/libis/services/http_error.rb +21 -0
  22. data/lib/libis/services/oracle_client.rb +47 -0
  23. data/lib/libis/services/primo.rb +2 -0
  24. data/lib/libis/services/primo/limo.rb +33 -0
  25. data/lib/libis/services/primo/search.rb +46 -0
  26. data/lib/libis/services/rest_client.rb +66 -0
  27. data/lib/libis/services/rosetta.rb +1 -0
  28. data/lib/libis/services/rosetta/client.rb +107 -0
  29. data/lib/libis/services/rosetta/collection_handler.rb +45 -0
  30. data/lib/libis/services/rosetta/collection_info.rb +35 -0
  31. data/lib/libis/services/rosetta/deposit_activity.rb +48 -0
  32. data/lib/libis/services/rosetta/deposit_handler.rb +187 -0
  33. data/lib/libis/services/rosetta/ie.rb +19 -0
  34. data/lib/libis/services/rosetta/ie_handler.rb +29 -0
  35. data/lib/libis/services/rosetta/pds_handler.rb +60 -0
  36. data/lib/libis/services/rosetta/producer.rb +71 -0
  37. data/lib/libis/services/rosetta/producer_handler.rb +125 -0
  38. data/lib/libis/services/rosetta/service.rb +399 -0
  39. data/lib/libis/services/rosetta/sip.rb +26 -0
  40. data/lib/libis/services/rosetta/sip_handler.rb +30 -0
  41. data/lib/libis/services/rosetta/user.rb +70 -0
  42. data/lib/libis/services/rosetta/user_manager.rb +28 -0
  43. data/lib/libis/services/scope/search.rb +46 -0
  44. data/lib/libis/services/search_factory.rb +40 -0
  45. data/lib/libis/services/sharepoint/connector.rb +236 -0
  46. data/lib/libis/services/sharepoint/search.rb +19 -0
  47. data/lib/libis/services/soap_client.rb +57 -0
  48. data/lib/libis/services/soap_error.rb +22 -0
  49. data/lib/libis/services/version.rb +5 -0
  50. data/libis-services.gemspec +38 -0
  51. data/spec/primo_limo_spec.rb +394 -0
  52. data/spec/primo_search_spec.rb +39 -0
  53. data/spec/rosetta_collection_spec.rb +206 -0
  54. data/spec/rosetta_deposit_spec.rb +82 -0
  55. data/spec/rosetta_ie_spec.rb +345 -0
  56. data/spec/rosetta_pds_spec.rb +79 -0
  57. data/spec/rosetta_producer_spec.rb +270 -0
  58. data/spec/rosetta_sip_spec.rb +39 -0
  59. data/spec/spec_helper.rb +12 -0
  60. metadata +307 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3579b3767e5c7b66ebbc0c98c01f0c4164aafa89
4
+ data.tar.gz: b8e1fe27dceb49ad0d3fa234adaf4aedc942b3b9
5
+ SHA512:
6
+ metadata.gz: c54622890dce4e6f3325e26d5aa33792d9a109252c91d4a6ebd76c4e8844fd62efa01cc15331ea9ac46d58f8825ff414ce9ec300bf3dc45aeb911f28919ec7b7
7
+ data.tar.gz: 5dd37c5e3740b0b55d12a0b9b01ff8690a33d83f2c1ad7818d7a8f56c41b223b7d14d98798a45c237973a61e880ccd51ac64dd79e40f33424c2b8fcd2484f88e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.idea/
16
+
17
+ spec/credentials*
18
+ lib/jar
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libis-services.gemspec
4
+ gemspec name: 'libis-services', development_group: :test
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kris Dekeyser
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ [![Gem Version](https://badge.fury.io/rb/libis-services.svg)](http://badge.fury.io/rb/libis-services)
2
+ [![Build Status](https://travis-ci.org/Kris-LIBIS/LIBIS_Services.svg?branch=master)](https://travis-ci.org/Kris-LIBIS/LIBIS_Services)
3
+ [![Coverage Status](https://img.shields.io/coveralls/Kris-LIBIS/LIBIS_Services.svg)](https://coveralls.io/r/Kris-LIBIS/LIBIS_Services)
4
+ [![Dependency Status](https://gemnasium.com/Kris-LIBIS/LIBIS_Services.svg)](https://gemnasium.com/Kris-LIBIS/LIBIS_Services)
5
+
6
+ # Services
7
+
8
+ TODO: Write a gem description
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'Services'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install Services
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/[my-github-username]/Services/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require 'libis/services'
@@ -0,0 +1,21 @@
1
+ module Libis
2
+ module Services
3
+
4
+ autoload :HttpError, 'libis/services/http_error'
5
+ autoload :SoapError, 'libis/services/soap_error'
6
+
7
+ autoload :SoapClient, 'libis/services/soap_client'
8
+ autoload :RestClient, 'libis/services/rest_client'
9
+
10
+ autoload :OracleClient, 'libis/services/oracle_client'
11
+ autoload :DigitoolConnector, 'libis/services/digitool_connector'
12
+ autoload :DigitalEntityManager, 'libis/services/digital_entity_manager'
13
+ autoload :MetaDataManager, 'libis/services/meta_data_manager'
14
+
15
+ autoload :SharepointConnector, 'libis/services/sharepoint_connector'
16
+
17
+ autoload :Rosetta, 'libis/services/rosetta'
18
+ autoload :Primo, 'libis/services/primo'
19
+
20
+ end
21
+ end
@@ -0,0 +1,157 @@
1
+ # coding: utf-8
2
+
3
+ require 'backports/rails/hash'
4
+ require 'libis/tools/xml_document'
5
+
6
+ require 'libis/services/generic_search'
7
+
8
+ module Libis
9
+ module Services
10
+ module Aleph
11
+
12
+ class Search
13
+ include ::Libis::Services::GenericSearch
14
+
15
+ attr_accessor :host
16
+
17
+ def find(term, options = {})
18
+ super
19
+
20
+ response = execute_http_query("op=find&code=#{options[:index]}&request=#{options[:term]}&base=#{options[:dbase]}")
21
+ if response
22
+ set_number = response['//find/set_number'].to_s
23
+ num_records = response['//find/no_records'].to_i
24
+ session_id = response['//find/session-id'].to_s
25
+ return options.merge id: set_number, num_records: num_records, session_id: session_id, record_pointer: 1
26
+ end
27
+ {}
28
+
29
+ end
30
+
31
+ def each(options)
32
+
33
+ return unless ([:record_pointer, :num_records] & options.keys).size == 2
34
+
35
+ while options[:record_pointer] <= options[:num_records]
36
+ next_record(options) { |r| yield r }
37
+ end
38
+
39
+ options
40
+ end
41
+
42
+ def next_record(options = {}, &block)
43
+
44
+ return nil unless ([:record_pointer, :num_records, :set_number, :dbase] & options.keys).size == 4
45
+
46
+ if options[:record_pointer] <= options[:num_records]
47
+ response = execute_http_query(
48
+ 'op=present' +
49
+ "&set_entry=#{options[:record_pointer]}" +
50
+ "&set_number=#{options[:set_number]}" +
51
+ "&base=#{options[:dbase]}"
52
+ )
53
+
54
+ if response
55
+ response.add_node 'search', type: 'opac', host: host, base: options[:dbase]
56
+ set_entry = response['//set_entry'].to_i
57
+ if set_entry == options[:record_pointer]
58
+ add_item_data(response, options[:dbase])
59
+ block_given? ? yield response : return response
60
+ end
61
+ end
62
+ else
63
+ puts 'no record found'
64
+ end
65
+
66
+ ensure
67
+ options[:record_pointer] += 1
68
+
69
+ end
70
+
71
+ private
72
+
73
+ def add_item_data(xml_document, options)
74
+
75
+ doc_number = xml_document['//doc_number']
76
+ response = execute_http_query("op=item-data&base=#{options[:dbase]}&doc-number=#{doc_number}")
77
+
78
+ if response
79
+
80
+ oai_marc = xml_document.get_node(:oai_marc)
81
+
82
+ #noinspection RubyResolve
83
+ response.get_nodes(:item).each do |r|
84
+ collection = response.value(:collection, r)
85
+ location = response.value(:sub-library, r)
86
+ classification = response.value('call-no-1', r)
87
+
88
+ varfield = xml_document.add_node 'varfield', nil, oai_marc, id: '852', i1: ' ', i2: ' '
89
+
90
+ xml_document.add_node 'subfield', collection, varfield, label: 'b'
91
+ xml_document.add_node 'subfield', location, varfield, label: 'c'
92
+ xml_document.add_node 'subfield', classification.gsub('$$h', ''), varfield, label: 'h'
93
+
94
+ end
95
+ end
96
+ end
97
+
98
+
99
+ def execute_http_query(data)
100
+ raise Exception, 'No host set' if host.nil? || host.size == 0
101
+
102
+ redo_count = 10
103
+ xml_document = nil
104
+
105
+ redo_search = false
106
+
107
+ begin
108
+ redo_search = false
109
+
110
+ begin
111
+ redo_count = redo_count - 1
112
+ sleep_time = 0.1 # in minutes
113
+
114
+ response = Net::HTTP.fetch(host, :data => data, :action => :post)
115
+
116
+ if response.is_a?(Net::HTTPOK)
117
+ xml_document = Libis::Tools::XmlDocument.parse(response.body)
118
+ error = xml_document['//error']
119
+
120
+ unless xml_document && error.nil?
121
+ unless error == 'empty set'
122
+ puts
123
+ puts "----------> Error searching for #{data} --> '#{error}'"
124
+ puts
125
+ end
126
+ if error =~ /license/
127
+ redo_search = true
128
+ end
129
+ end
130
+ else
131
+ puts response.error!
132
+ end
133
+ rescue Exception => ex
134
+ sleep_time = 0.5
135
+ if ex.message =~ /503 "Service Temporarily Unavailable"/
136
+ sleep_time = 30
137
+ Libis::Tools::Config.logger.warn "OPAC Service temporarily unavailable - retrying after #{sleep_time} minutes"
138
+ else
139
+ Libis::Tools::Config.logger.error "Problem with OPAC: '#{ex.message}' - retrying after #{sleep_time} minutes"
140
+ ex.backtrace.each { |x| Libis::Tools::Config.error "#{x}" }
141
+ end
142
+ redo_search = true
143
+ end
144
+
145
+ sleep sleep_time * 60 if redo_search
146
+
147
+ end until redo_search == false or redo_count < 0
148
+
149
+ xml_document
150
+
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+ end
157
+ end
@@ -0,0 +1 @@
1
+ require 'libis/services/collective_access/service'
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ require_relative 'connector'
4
+
5
+ module Libis
6
+ module Services
7
+ module CollectiveAccess
8
+
9
+ class Cataloguing < Connector
10
+
11
+ def initialize(host = nil)
12
+ super 'Cataloguing', host
13
+ end
14
+
15
+ def add_item(fields, type = nil)
16
+ type ||= 'ca_objects'
17
+ r, a = soap_encode fields
18
+ request :add, type: type, fieldInfo: r, :attributes! => {fieldInfo: a}
19
+ end
20
+
21
+ def add_attributes(item, data, type = nil)
22
+ type ||= 'ca_objects'
23
+ r, a = soap_encode data
24
+ request :getAttributesByElement, type: type, item_id: item, attribute_code_or_id: attribute.to_s, attribute_list_array: r, :attributes! => {attribute_list_array: a}
25
+
26
+ end
27
+
28
+ def add_attribute(item, attribute, data, type = nil)
29
+ type ||= 'ca_objects'
30
+ r, a = soap_encode data
31
+ request :addAttribute, type: type, item_id: item, attribute_code_or_id: attribute.to_s, attribute_data_array: r, :attributes! => {attribute_data_array: a}
32
+ end
33
+
34
+ def remove(item, type = nil)
35
+ type ||= 'ca_objects'
36
+ request :remove, type: type, item_id: item
37
+ end
38
+
39
+ def remove_attributes(item, type = nil)
40
+ type ||= 'ca_objects'
41
+ request :removeAllAttributes, type: type, item_id: item
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,151 @@
1
+ # coding: utf-8
2
+
3
+ require 'libis/services/soap_client'
4
+
5
+ module Libis
6
+ module Services
7
+ module CollectiveAccess
8
+
9
+ #noinspection RubyStringKeysInHashInspection
10
+ class Connector
11
+ include Libis::Services::SoapClient
12
+
13
+ attr_accessor :type_cast
14
+
15
+ def initialize(service, host = nil)
16
+ @type_cast = true
17
+ @host = host || 'http://crkc.be.halotest.cc.kuleuven.be/ca_crkc'
18
+ @service = service
19
+ configure "#{@host}/service.php/#{@service.downcase}/#{@service}/soapWSDL?wsdl",
20
+ convert_request_keys_to: :none,
21
+ # convert_response_tags_to: lambda {
22
+ # |tag| %w(Envelope Body).include?(tag) ? tag.snakecase.to_sym : tag.to_sym
23
+ # },
24
+ strip_namespaces: true
25
+ end
26
+
27
+ def authenticate(name = nil, password = nil)
28
+ name ||= 'administrator'
29
+ password ||= 'administrator'
30
+ result = request :auth, username: name, password: password
31
+ result.to_i == 1
32
+ end
33
+
34
+ def deauthenticate
35
+ request :deauthenticate
36
+ end
37
+
38
+ protected
39
+
40
+ def result_parser(response)
41
+ result = response.hash
42
+ type_caster(result.first[1][result.first[1][:result].snakecase.to_sym])
43
+ end
44
+
45
+ def type_caster(result)
46
+ return result unless @type_cast
47
+ return result unless result.is_a? Hash
48
+
49
+ r = result
50
+
51
+ case r[:'@xsi:type']
52
+ when 'enc:Array'
53
+ elements = result[:item]
54
+ if elements.is_a? Array
55
+ r = Array.new
56
+ elements.each { |i| r << type_caster(i) }
57
+ else
58
+ r = type_caster(result[:item])
59
+ end
60
+
61
+ when 'ns2:Map'
62
+ r = {}
63
+ elements = result[:item]
64
+ unless elements.is_a? Array
65
+ elements = Array.new
66
+ elements << result[:item]
67
+ end
68
+
69
+ elements.each { |i|
70
+ key = i[:key]
71
+ value = i[:value]
72
+ value = type_caster(value)
73
+ r[key] = value
74
+ }
75
+ else
76
+ #do nothing
77
+ end
78
+ r
79
+ end
80
+
81
+ NS_ATTR_ENC = {'xmlns:enc' => 'http://schemas.xmlsoap.org/soap/encoding/'}
82
+ NS_ATTR_NS2 = {'xmlns:ns2' => 'http://xml.apache.org/xml-soap'}
83
+
84
+ def soap_encode(data)
85
+ result = data
86
+ attributes = nil
87
+ case data
88
+ when Array
89
+ i = data.size
90
+ t = type_string data[0]
91
+ attributes = {'xsi:type' => 'enc:Array'}
92
+ if t
93
+ attributes['enc:arrayType'] = "#{t}[#{i}]"
94
+ else
95
+ attributes['enc:arraySize'] = i
96
+ end
97
+ attributes.merge! NS_ATTR_ENC
98
+ if t =~ /^ns2:/
99
+ attributes.merge! NS_ATTR_NS2
100
+ end
101
+ result = Array.new
102
+ data.each { |x|
103
+ r, a = soap_encode x
104
+ i = {item: r}
105
+ i[:attributes!] = {item: a} if a
106
+ result << i
107
+ }
108
+ when Hash
109
+ attributes = {'xsi:type' => 'ns2:Map'}.merge NS_ATTR_NS2
110
+ result = {item: Array.new}
111
+ data.each { |k, v|
112
+ rk, ak = soap_encode k.to_s
113
+ rv, av = soap_encode v
114
+ i = {key: rk, value: rv}
115
+ i[:attributes!] = {}
116
+ i[:attributes!][:key] = ak if ak
117
+ i[:attributes!][:value] = av if av
118
+ result[:item] << i
119
+ }
120
+ else
121
+ t = type_string data
122
+ if t
123
+ attributes = {'xsi:type' => t}
124
+ attributes.merge! NS_ATTR_ENC if t =~ /^enc:/
125
+ attributes.merge! NS_ATTR_NS2 if t =~ /^ns2:/
126
+ end
127
+ end
128
+ return result, attributes
129
+ end
130
+
131
+ def type_string(data)
132
+ return nil if data.nil?
133
+ case data
134
+ when Array
135
+ 'enc:Array'
136
+ when Hash
137
+ 'ns2:Map'
138
+ when String
139
+ 'xsd:string'
140
+ when Integer
141
+ 'xsd:int'
142
+ else
143
+ 'xsd:string'
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ end
150
+ end
151
+ end